Exemplo n.º 1
0
BaseContainer::RowArray::RowArray(TransactionContext &txn, BaseContainer *container) 
	: rowArrayImplList_(txn.getDefaultAllocator()),
	rowArrayStorage_(txn.getPartitionId(), *container->getObjectManager()),
	rowCache_(txn, container), defaultImpl_(NULL) {

	if (container->getContainerType() == COLLECTION_CONTAINER) {
		latestParam_.rowDataOffset_ = getColFixedOffset();
		latestParam_.rowIdOffset_ = getColRowIdOffset();
		latestParam_.rowHeaderOffset_ = COL_ROW_HEADER_OFFSET;
	} else if (container->getContainerType() == TIME_SERIES_CONTAINER) {
		latestParam_.rowDataOffset_ = sizeof(RowHeader);
		latestParam_.rowIdOffset_ = latestParam_.rowDataOffset_ +
		   container->getColumnInfo(ColumnInfo::ROW_KEY_COLUMN_ID)
		   .getColumnOffset();
		latestParam_.rowHeaderOffset_ = TIM_ROW_HEADER_OFFSET;
	} else {
		assert(false);
		GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_TYPE_INVALID, "");
	}

	latestParam_.varColumnNum_ = container->getVariableColumnNum();
	latestParam_.varHeaderSize_ = ValueProcessor::getEncodedVarSize(latestParam_.varColumnNum_);
	latestParam_.columnNum_ = container->getColumnNum();
	latestParam_.nullOffsetDiff_ = 0;
	latestParam_.columnOffsetDiff_ = 0;

	latestParam_.rowSize_ = container->getRowSize();
	latestParam_.rowFixedColumnSize_ = container->getRowFixedColumnSize();
	latestParam_.nullbitsSize_ = container->getNullbitsSize();
	latestParam_.nullsOffset_ = latestParam_.rowSize_ - (latestParam_.nullbitsSize_ + latestParam_.rowFixedColumnSize_);

	typedef BaseContainer::RowArrayImpl<BaseContainer, BaseContainer::ROW_ARRAY_GENERAL> GeneralRowArrayImpl;
	typedef BaseContainer::RowArrayImpl<BaseContainer, BaseContainer::ROW_ARRAY_PLAIN> PlainRowArrayImpl;

	util::StackAllocator &alloc = txn.getDefaultAllocator();
	GeneralRowArrayImpl *generalImpl = ALLOC_NEW(alloc) GeneralRowArrayImpl(
		txn, container, rowArrayStorage_, rowCache_, latestParam_);
	PlainRowArrayImpl *plainImpl = reinterpret_cast<PlainRowArrayImpl *>(generalImpl);
	rowArrayImplList_.push_back(generalImpl);
	rowArrayImplList_.push_back(plainImpl);
	defaultImpl_ = getImpl<BaseContainer, BaseContainer::ROW_ARRAY_GENERAL>();
}
StringCursor::StringCursor(TransactionContext &txn, const char *str)
	: BaseObject(NULL), zeroLengthStr_(ZERO_LENGTH_STR_BINARY_) {
	setBaseOId(UNDEF_OID);
	if (str == NULL) {
		setBaseAddr(&zeroLengthStr_);
		length_ = 0;
	}
	else {
		length_ = static_cast<uint32_t>(strlen(str));
		size_t offset = ValueProcessor::getEncodedVarSize(length_);  
		setBaseAddr(
			ALLOC_NEW(txn.getDefaultAllocator()) uint8_t[offset + length_]);

		uint64_t encodedLength = ValueProcessor::encodeVarSize(length_);
		memcpy(getBaseAddr(), &encodedLength, offset);
		memcpy(getBaseAddr() + offset, str, length_);
		moveCursor(offset);
	}
}
Exemplo n.º 3
0
BaseContainer::RowCache::RowCache(TransactionContext &txn, BaseContainer *container)
	: fieldCacheList_(txn.getDefaultAllocator()) {
	ObjectManager &objectManager = *(container->getObjectManager());
	new (frontFieldCache_.addr())
			FieldCache(txn.getPartitionId(), objectManager);

	const uint32_t varCount = container->getVariableColumnNum();

	lastCachedField_ = 0;

	if (varCount > 0) {
		assert(fieldCacheList_.empty());
		fieldCacheList_.resize(varCount);
		for (uint32_t i = varCount; i > 0; i--) {
			void *addr = &fieldCacheList_[i - 1];
			new (addr) FieldCache(txn.getPartitionId(), objectManager);
		}
	}
}
Exemplo n.º 4
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;
}