Esempio n. 1
0
/*!
	@brief Insert Row Object
*/
int32_t HashMap::insert(
	TransactionContext& txn, const void* constKey, OId oId) {
	assert(oId != UNDEF_OID);
	setDirty();

	void* key = const_cast<void*>(constKey);
	switch (hashMapImage_->keyType_) {
	case COLUMN_TYPE_STRING: {
		StringCursor stringCusor(reinterpret_cast<uint8_t*>(key));
		return insertObject<uint8_t*>(
			txn, stringCusor.str(), stringCusor.stringLength(), oId);
	} break;
	case COLUMN_TYPE_BOOL:
		return insertObject<bool>(txn, *reinterpret_cast<bool*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_BYTE:
		return insertObject<int8_t>(txn, *reinterpret_cast<int8_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_SHORT:
		return insertObject<int16_t>(txn, *reinterpret_cast<int16_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_INT:
		return insertObject<int32_t>(txn, *reinterpret_cast<int32_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_LONG:
		return insertObject<int64_t>(txn, *reinterpret_cast<int64_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_OID:
		return insertObject<uint64_t>(txn, *reinterpret_cast<uint64_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_FLOAT:
		return insertObject<float32>(txn, *reinterpret_cast<float32*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_DOUBLE:
		return insertObject<float64>(txn, *reinterpret_cast<float64*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_TIMESTAMP:
		return insertObject<Timestamp>(txn, *reinterpret_cast<uint64_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	case COLUMN_TYPE_BLOB:
		return insertObject<uint8_t>(txn, *reinterpret_cast<uint8_t*>(key),
			FixedSizeOfColumnType[hashMapImage_->keyType_], oId);
		break;
	default:
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_HM_UNEXPECTED_ERROR, "");
		break;
	}

	return GS_FAIL;  
}
/*!
	@brief Set array length
*/
void VariableArrayCursor::setArrayLength(uint32_t length) {
	if (elemNum_ == 0) {
		elemNum_ = length;
	}
	else {
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_DS_PARAMETER_INVALID, "");  
	}
}
/*!
	@brief Compare message field value with object field value
*/
int32_t ValueProcessor::compare(TransactionContext &txn,
	ObjectManager &objectManager, ColumnId columnId,
	MessageRowStore *messageRowStore, uint8_t *objectRowField) {
	const uint8_t *inputField;
	uint32_t inputFieldSize;
	messageRowStore->getField(columnId, inputField, inputFieldSize);

	ColumnType type =
		messageRowStore->getColumnInfoList()[columnId].getColumnType();

	int32_t result;
	switch (type) {
	case COLUMN_TYPE_BOOL:
	case COLUMN_TYPE_BYTE:
	case COLUMN_TYPE_SHORT:
	case COLUMN_TYPE_INT:
	case COLUMN_TYPE_LONG:
	case COLUMN_TYPE_FLOAT:
	case COLUMN_TYPE_DOUBLE:
	case COLUMN_TYPE_TIMESTAMP: {
		uint32_t objectRowFieldSize = 0;
		result = ComparatorTable::comparatorTable_[type][type](txn, inputField, inputFieldSize,
			objectRowField, objectRowFieldSize);
	} break;
	case COLUMN_TYPE_STRING:
		result = StringProcessor::compare(
			txn, objectManager, columnId, messageRowStore, objectRowField);
		break;
	case COLUMN_TYPE_GEOMETRY:
		result = GeometryProcessor::compare(
			txn, objectManager, columnId, messageRowStore, objectRowField);
		break;
	case COLUMN_TYPE_BLOB:
		result = BlobProcessor::compare(
			txn, objectManager, columnId, messageRowStore, objectRowField);
		break;
	case COLUMN_TYPE_STRING_ARRAY:
		result = StringArrayProcessor::compare(
			txn, objectManager, columnId, messageRowStore, objectRowField);
		break;
	case COLUMN_TYPE_BOOL_ARRAY:
	case COLUMN_TYPE_BYTE_ARRAY:
	case COLUMN_TYPE_SHORT_ARRAY:
	case COLUMN_TYPE_INT_ARRAY:
	case COLUMN_TYPE_LONG_ARRAY:
	case COLUMN_TYPE_FLOAT_ARRAY:
	case COLUMN_TYPE_DOUBLE_ARRAY:
	case COLUMN_TYPE_TIMESTAMP_ARRAY:
		result = ArrayProcessor::compare(
			txn, objectManager, columnId, messageRowStore, objectRowField);
		break;
	default:
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_TYPE_INVALID, "");
	}
	return result;
}
/*!
	@brief Get current element
*/
uint8_t *VariableArrayCursor::getElement(
	uint32_t &elemSize, uint32_t &elemCount) {
	if (elemCursor_ >= elemNum_) {
		assert(false);
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_DS_PARAMETER_INVALID, "");  
	}
	elemCount = elemCursor_;
	elemSize = ValueProcessor::decodeVarSize(curObject_.getCursor<uint8_t>());
	return curObject_.getCursor<uint8_t>();  
}
Esempio n. 5
0
/*!
	@brief Search Row Object
*/
int32_t HashMap::search(
	TransactionContext& txn, const void* constKey, uint32_t size, OId& oId) {
	assert(constKey != NULL);

	void* key = const_cast<void*>(constKey);

	switch (hashMapImage_->keyType_) {
	case COLUMN_TYPE_STRING:
		oId =
			searchObject<uint8_t*>(txn, reinterpret_cast<uint8_t*>(key), size);
		break;
	case COLUMN_TYPE_BOOL:
		oId = searchObject<bool>(txn, *reinterpret_cast<bool*>(key), size);
		break;
	case COLUMN_TYPE_BYTE:
		oId = searchObject<int8_t>(txn, *reinterpret_cast<int8_t*>(key), size);
		break;
	case COLUMN_TYPE_SHORT:
		oId =
			searchObject<int16_t>(txn, *reinterpret_cast<int16_t*>(key), size);
		break;
	case COLUMN_TYPE_INT:
		oId =
			searchObject<int32_t>(txn, *reinterpret_cast<int32_t*>(key), size);
		break;
	case COLUMN_TYPE_LONG:
		oId =
			searchObject<int64_t>(txn, *reinterpret_cast<int64_t*>(key), size);
		break;
	case COLUMN_TYPE_OID:
		oId = searchObject<uint64_t>(
			txn, *reinterpret_cast<uint64_t*>(key), size);
		break;
	case COLUMN_TYPE_FLOAT:
		oId =
			searchObject<float32>(txn, *reinterpret_cast<float32*>(key), size);
		break;
	case COLUMN_TYPE_DOUBLE:
		oId =
			searchObject<float64>(txn, *reinterpret_cast<float64*>(key), size);
		break;
	case COLUMN_TYPE_TIMESTAMP:
		oId = searchObject<Timestamp>(
			txn, *reinterpret_cast<uint64_t*>(key), size);
		break;
	case COLUMN_TYPE_BLOB:
		oId =
			searchObject<uint8_t>(txn, *reinterpret_cast<uint8_t*>(key), size);
		break;
	default:
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_HM_UNEXPECTED_ERROR, "");
		break;
	}
	return GS_FAIL;  
}
/*!
	@brief Set field value to message
*/
void ValueProcessor::getField(TransactionContext &txn,
	ObjectManager &objectManager, ColumnId columnId, const Value *objectValue,
	MessageRowStore *messageRowStore) {

	if (objectValue->isNullValue()) {
		messageRowStore->setNull(columnId);
		return;
	}

	ColumnType type =
		messageRowStore->getColumnInfoList()[columnId].getColumnType();

	switch (type) {
	case COLUMN_TYPE_BOOL:
	case COLUMN_TYPE_BYTE:
	case COLUMN_TYPE_SHORT:
	case COLUMN_TYPE_INT:
	case COLUMN_TYPE_LONG:
	case COLUMN_TYPE_FLOAT:
	case COLUMN_TYPE_DOUBLE:
	case COLUMN_TYPE_TIMESTAMP:
		messageRowStore->setField(
			columnId, objectValue->data(), FixedSizeOfColumnType[type]);
		break;
	case COLUMN_TYPE_STRING:
		StringProcessor::getField(
			txn, objectManager, columnId, objectValue, messageRowStore);
		break;
	case COLUMN_TYPE_GEOMETRY:
		GeometryProcessor::getField(
			txn, objectManager, columnId, objectValue, messageRowStore);
		break;
	case COLUMN_TYPE_BLOB:
		BlobProcessor::getField(
			txn, objectManager, columnId, objectValue, messageRowStore);
		break;
	case COLUMN_TYPE_STRING_ARRAY:
		StringArrayProcessor::getField(
			txn, objectManager, columnId, objectValue, messageRowStore);
		break;
	case COLUMN_TYPE_BOOL_ARRAY:
	case COLUMN_TYPE_BYTE_ARRAY:
	case COLUMN_TYPE_SHORT_ARRAY:
	case COLUMN_TYPE_INT_ARRAY:
	case COLUMN_TYPE_LONG_ARRAY:
	case COLUMN_TYPE_FLOAT_ARRAY:
	case COLUMN_TYPE_DOUBLE_ARRAY:
	case COLUMN_TYPE_TIMESTAMP_ARRAY:
		ArrayProcessor::getField(
			txn, objectManager, columnId, objectValue, messageRowStore);
		break;
	default:
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_TYPE_INVALID, "");
	}
}
/*!
	@brief Compare object field values
*/
int32_t ValueProcessor::compare(TransactionContext &txn,
	ObjectManager &objectManager, ColumnType type, uint8_t *srcObjectRowField,
	uint8_t *targetObjectRowField) {
	int32_t result;
	switch (type) {
	case COLUMN_TYPE_BOOL:
	case COLUMN_TYPE_BYTE:
	case COLUMN_TYPE_SHORT:
	case COLUMN_TYPE_INT:
	case COLUMN_TYPE_LONG:
	case COLUMN_TYPE_FLOAT:
	case COLUMN_TYPE_DOUBLE:
	case COLUMN_TYPE_TIMESTAMP: {
		uint32_t srcObjectRowFieldSize = 0;
		uint32_t targetObjectRowFieldSize = 0;
		result = ComparatorTable::comparatorTable_[type][type](txn, srcObjectRowField,
			srcObjectRowFieldSize, targetObjectRowField,
			targetObjectRowFieldSize);
	} break;
	case COLUMN_TYPE_STRING:
		result = StringProcessor::compare(
			txn, objectManager, type, srcObjectRowField, targetObjectRowField);
		break;
	case COLUMN_TYPE_GEOMETRY:
		result = GeometryProcessor::compare(
			txn, objectManager, type, srcObjectRowField, targetObjectRowField);
		break;
	case COLUMN_TYPE_BLOB:
		result = BlobProcessor::compare(
			txn, objectManager, type, srcObjectRowField, targetObjectRowField);
		break;
	case COLUMN_TYPE_STRING_ARRAY:
		result = StringArrayProcessor::compare(
			txn, objectManager, type, srcObjectRowField, targetObjectRowField);
		break;
	case COLUMN_TYPE_BOOL_ARRAY:
	case COLUMN_TYPE_BYTE_ARRAY:
	case COLUMN_TYPE_SHORT_ARRAY:
	case COLUMN_TYPE_INT_ARRAY:
	case COLUMN_TYPE_LONG_ARRAY:
	case COLUMN_TYPE_FLOAT_ARRAY:
	case COLUMN_TYPE_DOUBLE_ARRAY:
	case COLUMN_TYPE_TIMESTAMP_ARRAY:
		result = ArrayProcessor::compare(
			txn, objectManager, type, srcObjectRowField, targetObjectRowField);
		break;
	default:
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_TYPE_INVALID, "");
	}
	return result;
}
Esempio n. 8
0
GSTraceFormatter::GSTraceFormatter(const char8_t *secretHexKey)
	: secret_(true), traceLocationVisible_(false) {
	util::NormalIStringStream iss(secretHexKey);
	util::NormalOStringStream oss;
	util::HexConverter::decode(oss, iss);

	std::string keyStr = oss.str();
	secretKey_.reserve(keyStr.size());

	for (std::string::iterator it = keyStr.begin(); it != keyStr.end(); ++it) {
		secretKey_.push_back(static_cast<uint8_t>(*it));
	}

	if (secretKey_.empty()) {
		GS_THROW_SYSTEM_ERROR(GS_ERROR_CM_INTERNAL_ERROR, "Empty secret key");
	}
}
/*!
	@brief Get field value Object
*/
void VariableArrayCursor::getField(
	const ColumnInfo &columnInfo, BaseObject &baseObject) {
	uint32_t variableColumnNum =
		columnInfo.getColumnOffset();  
	uint32_t varColumnNth = 0;
	while (nextElement()) {
		;  
		if (varColumnNth == variableColumnNum) {
			break;
		}
		++varColumnNth;
	}
	if (varColumnNth != variableColumnNum) {
		assert(false);
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_DS_PARAMETER_INVALID,
			"varColumnNth(" << varColumnNth << ") != variableColumnNum"
							<< variableColumnNum);
	}
	baseObject.copyReference(curObject_.getBaseOId(), curObject_.getBaseAddr());
	baseObject.moveCursor(
		curObject_.getCursor<uint8_t>() - curObject_.getBaseAddr());
}
Esempio n. 10
0
void HashMap::split(TransactionContext& txn) {
	if (hashMapImage_->split_ == hashMapImage_->front_) {
		hashMapImage_->split_ = 0;
		hashMapImage_->front_ = hashMapImage_->front_ << 1;
		hashMapImage_->toSplit_ = false;
	}

	uint64_t bucketAddr0 = hashMapImage_->split_;
	uint64_t bucketAddr1 = hashMapImage_->rear_;
	hashMapImage_->split_++;
	hashMapImage_->rear_++;

	if (hashMapImage_->rear_ > hashArray_.size()) {
		hashArray_.twiceHashArray(txn);

		if (hashMapImage_->rear_ > hashArray_.size()) {
			GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_HM_MAX_ARRY_SIZE_OVER, "");
		}
	}

	Bucket splitBucket(
		txn, *getObjectManager(), maxArraySize_, maxCollisionArraySize_);
	hashArray_.get(txn, bucketAddr0, splitBucket);
	Bucket::Cursor cursor(txn, *getObjectManager());
	splitBucket.set(txn, cursor);
	if (cursor.size_ == 0) {
		;  
	}
	else {
		util::XArray<OId> remainOIdList(txn.getDefaultAllocator());
		Bucket newBucket1(
			txn, *getObjectManager(), maxArraySize_, maxCollisionArraySize_);
		hashArray_.get(txn, bucketAddr1, newBucket1);
		size_t bucket0Size = 0;
		size_t bucket1Size = 0;

		bool isCurrent = splitBucket.next(txn, cursor);
		while (isCurrent) {
			OId oId = splitBucket.getCurrentOId(cursor);
			uint32_t addr = hashBucketAddrFromObject<T>(txn, oId);
			if (addr == bucketAddr0) {
				bucket0Size++;
				remainOIdList.push_back(oId);
			}
			else {
				bucket1Size++;
				newBucket1.append(txn, oId);
			}
			isCurrent = splitBucket.next(txn, cursor);
		}
		cursor.array_.reset();

		if (bucket1Size > 0) {
			splitBucket.clear(txn);
			for (size_t i = 0; i < remainOIdList.size(); i++) {
				splitBucket.append(txn, remainOIdList[i]);
			}
		}
		else if (bucket0Size > 1) {
			remainOIdList.clear();
		}
	}

	return;
}
Esempio n. 11
0
/*!
	@brief Search Row Objects
*/
int32_t HashMap::search(TransactionContext& txn, const void* constKey,
	uint32_t size, ResultSize limit, util::XArray<OId>& idList) {
	if (limit == 0) {
		return GS_SUCCESS;
	}
	if (constKey == NULL) {
		getAll(txn, limit, idList);
		return GS_SUCCESS;
	}

	void* key = const_cast<void*>(constKey);

	switch (hashMapImage_->keyType_) {
	case COLUMN_TYPE_STRING:
		return searchObject<uint8_t*>(
			txn, reinterpret_cast<uint8_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_BOOL:
		return searchObject<bool>(
			txn, *reinterpret_cast<bool*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_BYTE:
		return searchObject<int8_t>(
			txn, *reinterpret_cast<int8_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_SHORT:
		return searchObject<int16_t>(
			txn, *reinterpret_cast<int16_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_INT:
		return searchObject<int32_t>(
			txn, *reinterpret_cast<int32_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_LONG:
		return searchObject<int64_t>(
			txn, *reinterpret_cast<int64_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_OID:
		return searchObject<uint64_t>(
			txn, *reinterpret_cast<uint64_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_FLOAT:
		return searchObject<float32>(
			txn, *reinterpret_cast<float32*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_DOUBLE:
		return searchObject<float64>(
			txn, *reinterpret_cast<float64*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_TIMESTAMP:
		return searchObject<Timestamp>(
			txn, *reinterpret_cast<uint64_t*>(key), size, limit, idList);
		break;
	case COLUMN_TYPE_BLOB:
		return searchObject<uint8_t>(
			txn, *reinterpret_cast<uint8_t*>(key), size, limit, idList);
		break;
	default:
		GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_HM_UNEXPECTED_ERROR, "");
		break;
	}
	return GS_FAIL;  
}