コード例 #1
0
FullContainerKey::FullContainerKey(const KeyConstraint &constraint,
								   const void *data) :
	constraint_(constraint), body_(NULL), size_(0) {
	try {
		if (data == NULL) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"container/table name is empty");
		}

		ContainerKeyInStream in(util::ArrayInStream(data, sizeof(uint32_t)));
		if (ValueProcessor::varSizeIs1Byte(static_cast<const uint8_t*>(data)[0])
			|| ValueProcessor::varSizeIs4Byte(static_cast<const uint8_t*>(data)[0])) {
			size_ = static_cast<size_t>(decodeVarInt(in));
		}
		else {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"failed to decode container/table name size");
		}

		body_ = static_cast<const uint8_t*>(data) + in.base().position();

	}
	catch (std::exception &e) {
		GS_RETHROW_USER_ERROR(e,
			GS_EXCEPTION_MERGE_MESSAGE(e, "failed to construct container/table name"));
	}
}
コード例 #2
0
/*!
	@brief Starts a checkpoint.
*/
void CheckpointService::requestNormalCheckpoint(
	const Event::Source &eventSource) {
	if (lastMode_ == CP_SHUTDOWN) {
		return;
	}
	try {
		if (requestedShutdownCheckpoint_) {
			GS_THROW_USER_ERROR(GS_ERROR_CP_CONTROLLER_ILLEAGAL_STATE,
				"Checkpoint cancelled: already requested shutdown ("
				"lastMode="
					<< checkpointModeToString(lastMode_) << ")");
		}
		GS_TRACE_INFO(
			CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS, "[NormalCP]requested.");

		Event requestEvent(
			eventSource, CP_REQUEST_CHECKPOINT, CP_HANDLER_PARTITION_ID);

		EventByteOutStream out = requestEvent.getOutStream();
		int32_t mode = CP_REQUESTED;
		uint32_t flag = 0;
		std::string backupPath;  
		out << mode;
		out << flag;
		out << backupPath;

		ee_.add(requestEvent);
	}
	catch (std::exception &e) {
		clusterService_->setError(eventSource, &e);
		GS_RETHROW_SYSTEM_ERROR(e, "Request normal checkpoint failed. (reason="
									   << GS_EXCEPTION_MESSAGE(e) << ")");
	}
}
コード例 #3
0
/*!
	@brief Starts an event.
*/
void CheckpointService::start(const Event::Source &eventSource) {
	try {
		if (!initailized_) {
			GS_THROW_USER_ERROR(GS_ERROR_CP_SERVICE_NOT_INITIALIZED, "");
		}
		ee_.start();

		Event requestEvent(
			eventSource, CP_REQUEST_CHECKPOINT, CP_HANDLER_PARTITION_ID);

		EventByteOutStream out = requestEvent.getOutStream();

		int32_t mode = CP_NORMAL;
		uint32_t flag = 0;
		std::string backupPath;  
		out << mode;
		out << flag;
		out << backupPath;

		ee_.addTimer(requestEvent, changeTimeSecondToMilliSecond(cpInterval_));

		if (logWriteMode_ > 0 && logWriteMode_ < INT32_MAX) {
			Event flushLogEvent(
				eventSource, CP_TIMER_LOG_FLUSH, CP_SERIALIZED_PARTITION_ID);
			ee_.addPeriodicTimer(
				flushLogEvent, changeTimeSecondToMilliSecond(logWriteMode_));
		}
	}
	catch (std::exception &e) {
		clusterService_->setError(eventSource, &e);
		GS_RETHROW_SYSTEM_ERROR(
			e, "Start failed. (reason=" << GS_EXCEPTION_MESSAGE(e) << ")");
	}
}
コード例 #4
0
void ZlibUtils::uncompressData(
		const uint8_t* src, uint32_t srcSize,
		uint8_t* dest, uint32_t &destSize)
{
	int32_t flush = Z_FINISH;

	inflateStream_.zalloc = Z_NULL;
	inflateStream_.zfree = Z_NULL;
	inflateStream_.opaque = Z_NULL;

	if (inflateInit(&inflateStream_) != Z_OK) {
		GS_THROW_USER_ERROR(GS_ERROR_CM_UNCOMPRESSION_FAILED,
							  "inflateInit failed.");
	}

	inflateStream_.avail_in = srcSize;
	inflateStream_.avail_out = destSize;
	inflateStream_.next_in = (Bytef*)src;
	inflateStream_.next_out = (Bytef*)dest;

	int ret = Z_OK;
	do {
		ret = inflate(&inflateStream_, flush);
	} while(ret == Z_OK);

	if (ret != Z_STREAM_END) {
		GS_THROW_USER_ERROR(GS_ERROR_CM_UNCOMPRESSION_FAILED,
							  " There was not enough memory "
							  << ", or there was not enough room in the output "
							  "buffer. "
							  << " srcSize = " << srcSize
							  << ", desSize = " << destSize << ", ret = " << ret);
	}

	destSize = static_cast<uint32_t>(inflateStream_.total_out);

	if (inflateEnd(&inflateStream_) != Z_OK) {
		GS_THROW_USER_ERROR(GS_ERROR_CM_UNCOMPRESSION_FAILED,
							  "inflateEnd failed.");
	}
}
コード例 #5
0
ZlibUtils::ZlibUtils() :
isFirstTime_(true), compressionErrorCount_(0) {
	deflateStream_.zalloc = Z_NULL;
	deflateStream_.zfree = Z_NULL;
	deflateStream_.opaque = Z_NULL;

	inflateStream_.zalloc = Z_NULL;
	inflateStream_.zfree = Z_NULL;

	static const char* currentVersion = ZLIB_VERSION;
	if (currentVersion[0] != zlibVersion()[0]) {
		GS_THROW_USER_ERROR(GS_ERROR_CM_INCOMPATIBLE_ZLIB_VERSION,
				"the zlib library version (zlib_version) is incompatible"
				<< " with the version assumed, " << currentVersion
				<< ", but the library version, " << zlibVersion());
	}
}
コード例 #6
0
ファイル: row.cpp プロジェクト: AnggaSuherman/griddb_nosql
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>();
}
コード例 #7
0
void CheckpointService::runGroupCheckpoint(
	PartitionGroupId pgId, EventContext &ec, int32_t mode, uint32_t flag) {
	struct GroupCheckpointDataCleaner {
		explicit GroupCheckpointDataCleaner(
			CheckpointService &service, PartitionGroupId pgId)
			: service_(service), pgId_(pgId) {}

		~GroupCheckpointDataCleaner() {
			service_.groupCheckpointStatus_[pgId_] = GROUP_CP_COMPLETED;
		}
		CheckpointService &service_;
		const PartitionGroupId pgId_;
	} groupCpDataCleaner(*this, pgId);

	util::StackAllocator &alloc = ec.getAllocator();

	GS_TRACE_INFO(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
		"[CP_GROUP_START_REQUEST] mode=" << checkpointModeToString(mode)
										 << ", pgId=" << pgId);
	if (clusterService_->getManager()->isSyncRunning(pgId)) {
		GS_TRACE_INFO(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
			"[NOTE] Checkpoint pending by longTerm sync running, pgId="
				<< pgId << ", currentCpId ="
				<< logManager_->getLastCheckpointId(pgId) << ", limitTime="
				<< clusterService_->getManager()->getPendingLimitTime(pgId));
		return;
	}

	PartitionGroupLock pgLock(*transactionManager_, pgId);

	util::StackAllocator::Scope scope(alloc);  

	const PartitionId startPId = pgConfig_.getGroupBeginPartitionId(pgId);
	const PartitionId endPId = pgConfig_.getGroupEndPartitionId(pgId);
	const CheckpointId cpId = logManager_->getLastCheckpointId(pgId) + 1;

	GS_TRACE_INFO(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
		"[CP_GROUP_START] mode=" << checkpointModeToString(mode)
								 << ", pgId=" << pgId << ", cpId=" << cpId);

	uint64_t beforeAllocatedCheckpointBufferCount =
		chunkManager_->getChunkManagerStats()
			.getAllocatedCheckpointBufferCount();

	logManager_->flushFile(pgId);
	executeOnTransactionService(
		ec, PARTITION_GROUP_START, mode, startPId, cpId, true);

	if (clusterService_->isError()) {
		GS_THROW_USER_ERROR(GS_ERROR_CP_CONTROLLER_ILLEAGAL_STATE,
			"Checkpoint cancelled ("
			"systemErrorOccurred="
				<< clusterService_->isError() << ")");
	}
	ClusterManager *clsMgr = clusterService_->getManager();
	int32_t delayLimitInterval =
		clsMgr->getConfig().getCheckpointDelayLimitInterval();

	int64_t totalWriteCount = 0;
	int32_t delayTotalSleepInterval = 0;

	for (PartitionId pId = startPId; pId < endPId; pId++) {
		GS_TRACE_DEBUG(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
			"[CP_PARTITION_START] mode=" << checkpointModeToString(mode)
										 << ", pgId=" << pgId << ", pId=" << pId
										 << ", cpId=" << cpId);

		PartitionLock pLock(*transactionManager_, pId);

		delayTotalSleepInterval = 0;
		PartitionId currentChunkSyncPId = UNDEF_PARTITIONID;
		CheckpointId currentChunkSyncCPId = UNDEF_CHECKPOINT_ID;
		clsMgr->getCurrentChunkSync(currentChunkSyncPId, currentChunkSyncCPId);

		while (clsMgr->isSyncRunning(pgId) &&
			   delayTotalSleepInterval < delayLimitInterval &&
			   pId == currentChunkSyncPId) {  
			util::Thread::sleep(delaySleepTime_);
			delayTotalSleepInterval += delaySleepTime_;
		}
		if (delayTotalSleepInterval > 0) {
			GS_TRACE_INFO(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
				"Checkpoint operation(pgId="
					<< pgId << ") is delayed by sync operation, delayed time: "
					<< delayTotalSleepInterval);
		}

		struct ChunkStatusCleaner {
			explicit ChunkStatusCleaner(
				ChunkManager &chunkManager, PartitionId targetPId)
				: chunkManager_(chunkManager), targetPId_(targetPId) {}
			~ChunkStatusCleaner() {
				try {
				}
				catch (...) {
				}
			}
			ChunkManager &chunkManager_;
			PartitionId targetPId_;
		} chunkStatusCleaner(*chunkManager_, pId);

		const bool checkpointReady =
			dataStore_->isRestored(pId) && chunkManager_->existPartition(pId);

		executeOnTransactionService(ec, PARTITION_START, mode, pId, cpId, true);

		if (clusterService_->isError()) {
			GS_THROW_USER_ERROR(GS_ERROR_CP_CONTROLLER_ILLEAGAL_STATE,
				"Checkpoint cancelled ("
				"systemErrorOccurred="
					<< clusterService_->isError() << ")");
		}

		if (checkpointReady) {
			while (chunkManager_->isCopyLeft(pId)) {
				executeOnTransactionService(
					ec, COPY_CHUNK, mode, pId, cpId, true);
				if (clusterService_->isError()) {
					GS_THROW_USER_ERROR(GS_ERROR_CP_CONTROLLER_ILLEAGAL_STATE,
						"Checkpoint cancelled ("
						"systemErrorOccurred="
							<< clusterService_->isError() << ")");
				}

				totalWriteCount += chunkManager_->writeChunk(pId);

				if (mode != CP_AFTER_RECOVERY && mode != CP_SHUTDOWN) {
					util::Thread::sleep(chunkCopyIntervalMillis_);
				}
			}

			executeOnTransactionService(
				ec, PARTITION_END, mode, pId, cpId, true);

			if (clusterService_->isError()) {
				GS_THROW_USER_ERROR(GS_ERROR_CP_CONTROLLER_ILLEAGAL_STATE,
					"Checkpoint cancelled ("
					"systemErrorOccurred="
						<< clusterService_->isError() << ")");
			}
		}

		GS_TRACE_DEBUG(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
			"[CP_PARTITION_END] mode="
				<< checkpointModeToString(mode) << ", pgId=" << pgId
				<< ", pId=" << pId << ", cpId=" << cpId
				<< ", writeCount=" << totalWriteCount
				<< ", isReady=" << (checkpointReady ? "true" : "false"));

		if (pId + 1 < endPId) {
			pendingPartitionCount_--;

		}
		chunkManager_->flush(pgId);
		if (!parallelCheckpoint_) {
			for (uint32_t flushPgId = 0;
				 flushPgId < pgConfig_.getPartitionGroupCount(); ++flushPgId) {
				GS_TRACE_INFO(CHECKPOINT_SERVICE_DETAIL, GS_TRACE_CP_STATUS,
					"Flush Log while CP: flushPgId = " << flushPgId);
				logManager_->flushFile(
					flushPgId);  
			}
		}
	}

	chunkManager_->flush(pgId);
	logManager_->flushFile(pgId);
	executeOnTransactionService(
		ec, PARTITION_GROUP_END, mode, startPId, cpId, true);

	uint64_t cpMallocCount = chunkManager_->getChunkManagerStats()
								 .getAllocatedCheckpointBufferCount() -
							 beforeAllocatedCheckpointBufferCount;

	GS_TRACE_INFO(CHECKPOINT_SERVICE, GS_TRACE_CP_STATUS,
		"[CP_GROUP_END] mode=" << checkpointModeToString(mode)
							   << ", pgId=" << pgId << ", cpId=" << cpId
							   << ", bufferAllocateCount=" << cpMallocCount
							   << ", writeCount=" << totalWriteCount);

	if (clusterService_->isError()) {
		GS_THROW_USER_ERROR(GS_ERROR_CP_CONTROLLER_ILLEAGAL_STATE,
			"Checkpoint cancelled ("
			"systemErrorOccurred="
				<< clusterService_->isError() << ")");
	}

	pendingPartitionCount_--;

	lsnInfo_.endCheckpoint();

}
コード例 #8
0
void FullContainerKey::deserialize(util::StackAllocator &alloc,
								   FullContainerKeyComponents &components,
								   BitArray &upperCaseBit,
								   bool unNormalized) const {
	try {
		if (isEmpty()) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"container/table name is empty");
		}

		components.clear();
		upperCaseBit.clear();

		ContainerKeyInStream in(util::ArrayInStream(body_, size_));

		const char8_t *normalizedStr[3] = { NULL, NULL, NULL };

		uint8_t flag;
		in >> flag;

		if (flag & DBID_EXISTS) {
			in >> components.dbId_;
		}
		else {
			components.dbId_ = GS_PUBLIC_DB_ID;
		}

		components.baseNameSize_ = decodeVarInt(in);
		normalizedStr[0] = reinterpret_cast<const char8_t*>(body_ + in.base().position());
		in.base().position(in.base().position() + components.baseNameSize_);

		if (flag & LARGE_CONTAINERID_EXISTS) {
			components.largeContainerId_ = decodeVarLong(in);
		}

		if (flag & NODE_AFFINITY_NUM) {
			components.affinityNumber_ = decodeVarLong(in);
		}
		else if (flag & NODE_AFFINITY_STR) {
			components.affinityStringSize_ = decodeVarInt(in);
			normalizedStr[1] = reinterpret_cast<const char8_t*>(body_ + in.base().position());
			in.base().position(in.base().position() + components.affinityStringSize_);
		}

		if (flag & SYSTEM_PART_ID_NUM) {
			components.systemPartId_ = decodeVarLong(in);
		}
		else if (flag & SYSTEM_PART_ID_STR) {
			components.systemPartSize_ = decodeVarInt(in);
			normalizedStr[2] = reinterpret_cast<const char8_t*>(body_ + in.base().position());
			in.base().position(in.base().position() + components.systemPartSize_);
		}

		const uint64_t strLength = components.baseNameSize_
			+ components.affinityStringSize_
			+ components.systemPartSize_;

		if (in.base().remaining() != strLengthToBitLength(strLength)) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"size of container/table name is invalid");
		}
		else {
			upperCaseBit.reserve(strLength);
			upperCaseBit.putAll(body_ + in.base().position(), strLength);
			in.base().position(in.base().position() + in.base().remaining());
		}

		if (in.base().position() != size_) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"size of container/table name is invalid");
		}


		if (unNormalized) {
			util::XArray<char8_t> buf(alloc);
			buf.resize(static_cast<size_t>(strLength), '\0');
			uint64_t startPos = 0;

			createOriginalString(normalizedStr[0], components.baseNameSize_,
				buf.data()+startPos, upperCaseBit, startPos);
			components.baseName_ = buf.data()+startPos;
			startPos += components.baseNameSize_;

			if (components.affinityStringSize_ > 0) {
				createOriginalString(normalizedStr[1], components.affinityStringSize_,
					buf.data()+startPos, upperCaseBit, startPos);
				components.affinityString_ = buf.data()+startPos;
				startPos += components.affinityStringSize_;
			}

			if (components.systemPartSize_ > 0) {
				createOriginalString(normalizedStr[2], components.systemPartSize_,
					buf.data()+startPos, upperCaseBit, startPos);
				components.systemPart_ = buf.data()+startPos;
				startPos += components.systemPartSize_;
			}
		}
		else {
			components.baseName_ = normalizedStr[0];
			if (components.affinityStringSize_ > 0) {
				components.affinityString_ = normalizedStr[1];
			}
			if (components.systemPartSize_ > 0) {
				components.systemPart_ = normalizedStr[2];
			}
		}

	}
コード例 #9
0
void FullContainerKey::serialize(util::StackAllocator &alloc,
								 const FullContainerKeyComponents &components,
								 const BitArray &upperCaseBit) {
	try {
		util::XArray<char8_t> buf(alloc);
		buf.resize(static_cast<size_t>(components.getStringSize()), '\0');

		util::XArray<uint8_t> binary(alloc);
		util::XArrayOutStream<> arrayOut(binary);
		ContainerKeyOutStream out(arrayOut);

		const size_t flagPos = out.base().position();

		uint8_t flag = 0;
		out << flag;

		if (components.dbId_ != GS_PUBLIC_DB_ID) {
			flag |= DBID_EXISTS;
			out << components.dbId_;
		}

		{
			ValueProcessor::convertLowerCase(
				components.baseName_, components.baseNameSize_, buf.data());
			encodeString(out, buf.data(), components.baseNameSize_);
		}

		if (components.largeContainerId_ != UNDEF_LARGE_CONTAINERID) {
			flag |= LARGE_CONTAINERID_EXISTS;
			encodeVarLong(out, components.largeContainerId_);
		}

		if (components.affinityNumber_ != UNDEF_NODE_AFFINITY_NUMBER) {
			flag |= NODE_AFFINITY_NUM;
			encodeVarLong(out, components.affinityNumber_);
		}
		else if (components.affinityStringSize_ > 0) {
			flag |= NODE_AFFINITY_STR;
			ValueProcessor::convertLowerCase(
				components.affinityString_, components.affinityStringSize_, buf.data());
			encodeString(out, buf.data(), components.affinityStringSize_);
		}

		if (components.systemPartId_ != UNDEF_SYSTEM_PART_ID) {
			flag |= SYSTEM_PART_ID_NUM;
			encodeVarLong(out, components.systemPartId_);
		}
		else if (components.systemPartSize_ > 0) {
			flag |= SYSTEM_PART_ID_STR;
			ValueProcessor::convertLowerCase(
				components.systemPart_, components.systemPartSize_, buf.data());
			encodeString(out, buf.data(), components.systemPartSize_);
		}

		out.writeAll(upperCaseBit.data(), upperCaseBit.byteLength());

		const size_t lastPos = out.base().position();
		out.base().position(flagPos);
		out << flag;
		out.base().position(lastPos);

		if (binary.size() >= static_cast<size_t>(UINT32_MAX)) {
			GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
				"size of serialized container/table name exceeds maximum size");
		}

		body_ = binary.data();
		size_ = binary.size();


	}
	catch (std::exception &e) {
		GS_RETHROW_USER_ERROR_CODED(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID, e,
			"failed to serialize container/table name");
	}
}
コード例 #10
0
void FullContainerKey::validate(const FullContainerKeyComponents &components) const {
	try {
		uint64_t totalLength = 0;

		validateDbId(components.dbId_);

		const bool hasSystemPart =
			(components.systemPartId_ != UNDEF_SYSTEM_PART_ID || components.systemPartSize_ > 0);
		const bool hasLargeContainerId = (components.largeContainerId_ != UNDEF_LARGE_CONTAINERID);

		if (!constraint_.systemPartAllowed_ && hasSystemPart) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"system part is not allowed");
		}
		if (!constraint_.largeContainerIdAllowed_ && hasLargeContainerId) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"largeId is not allowed");
		}

		validateBaseContainerName(
			components.baseName_, components.baseNameSize_, hasSystemPart);
		totalLength += components.baseNameSize_;

		if (components.largeContainerId_ != UNDEF_LARGE_CONTAINERID) {
			validateLargeContainerId(components.largeContainerId_);
			util::NormalOStringStream oss;
			oss << components.largeContainerId_;
			totalLength += oss.str().length();
			totalLength++;
		}
		if (components.affinityNumber_ != UNDEF_NODE_AFFINITY_NUMBER) {
			validateAffinityNumber(components.affinityNumber_);
			util::NormalOStringStream oss;
			oss << components.affinityNumber_;
			totalLength += oss.str().length();
			totalLength++;
		}
		else if (components.affinityStringSize_ > 0) {
			validateExtendedName(components.affinityString_, components.affinityStringSize_, "node affinity");
			totalLength += components.affinityStringSize_;
			totalLength++;
		}

		if (components.systemPartId_ != UNDEF_SYSTEM_PART_ID) {
			validateSystemPartId(components.systemPartId_);
			util::NormalOStringStream oss;
			oss << components.systemPartId_;
			totalLength += oss.str().length();
			totalLength++;
		}
		else if (components.systemPartSize_ > 0) {
			validateExtendedName(components.systemPart_, components.systemPartSize_, "system part");
			totalLength += components.systemPartSize_;
			totalLength++;
		}

		if (totalLength <= 0) {
			GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
				"size of container/table name is zero");
		}
		if (totalLength > constraint_.maxTotalLength_) {
			GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
				"size of container/table name exceeds maximum size");
		}

	}
	catch (std::exception &e) {
		GS_RETHROW_USER_ERROR_CODED(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID, e,
			"failed to validate container/table name");
	}
}
コード例 #11
0
void FullContainerKey::parseAndValidate(DatabaseId dbId, const char8_t *str, uint32_t length,
										FullContainerKeyComponents &components,
										BitArray &upperCaseBit) const {
	try {
		size_t len = length;
		if (len <= 0) {
			GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
				"size of container/table name is zero");
		}
		if (len > constraint_.maxTotalLength_) {
			GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
				"size of container/table name exceeds maximum size");
		}

		size_t partCounter = 0;
		size_t sharpCounter = 0;
		size_t atmarkCounter = 0;
		const char8_t *part[4] = { NULL, NULL, NULL, NULL };
		uint32_t partLen[4] = { 0, 0, 0, 0 };

		part[partCounter] = str;

		for (size_t i = 0; i < len; i++) {
			if (str[i] == '#') {
				sharpCounter++;
				if (sharpCounter > 1) {
					GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
						"system part must be exactly one");
				}
				else if (atmarkCounter > 0) {
					GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
						"system part can not be described after node affinity");
				}

				partCounter++;
				if (i + 1 <= len) {
					part[partCounter] = str + (i+1);
				}

			}
			else if (str[i] == '@') {
				atmarkCounter++;
				if (atmarkCounter > 2) {
					GS_THROW_USER_ERROR(GS_ERROR_CM_LIMITS_EXCEEDED,
						"node affinity or largeId can not be described twice or more");
				}

				partCounter++;
				if (i + 1 <= len) {
					part[partCounter] = str + (i+1);
				}

			}
			else {
				partLen[partCounter]++;
			}
		}

		assert(partCounter == sharpCounter + atmarkCounter);


		components.clear();

		components.dbId_ = dbId;
		validateDbId(components.dbId_);

		components.baseName_ = part[0];
		components.baseNameSize_ = partLen[0];
		const bool hasSystemPart = (sharpCounter == 1);
		const bool hasLargeContainerId = (atmarkCounter > 1);

		if (!constraint_.systemPartAllowed_ && hasSystemPart) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"system part is not allowed");
		}
		if (!constraint_.largeContainerIdAllowed_ && hasLargeContainerId) {
			GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID,
				"largeId is not allowed");
		}

		validateBaseContainerName(
			components.baseName_, components.baseNameSize_, hasSystemPart);

		if (sharpCounter == 0) {
			if (atmarkCounter == 1) {
				validateAndSetNodeAffinity(part[1], partLen[1], components);
			}
			else if (atmarkCounter == 2) {
				validateAndSetLargeContainerId(part[1], partLen[1], components);
				validateAndSetNodeAffinity(part[2], partLen[2], components);
			}
		}
		else {
			validateAndSetSystemPart(part[1], partLen[1], components);
			if (atmarkCounter == 1) {
				validateAndSetNodeAffinity(part[2], partLen[2], components);
			}
			else if (atmarkCounter == 2) {
				validateAndSetLargeContainerId(part[2], partLen[2], components);
				validateAndSetNodeAffinity(part[3], partLen[3], components);
			}
		}

		setUpperCaseBit(components, upperCaseBit);

	}
	catch (std::exception &e) {
		GS_RETHROW_USER_ERROR_CODED(GS_ERROR_DS_DS_CONTAINER_NAME_INVALID, e,
			"failed to parse and validate container/table name : " << str);
	}
}
コード例 #12
0
void ZlibUtils::compressData(
		const uint8_t* src, uint32_t srcSize,
		uint8_t* dest, uint32_t &destSize)
{
	int32_t flush = Z_FINISH;

	deflateStream_.zalloc = Z_NULL;
	deflateStream_.zfree = Z_NULL;
	deflateStream_.opaque = Z_NULL;

	int32_t ret = deflateInit(&deflateStream_, COMPRESS_LEVEL);
	if (ret != Z_OK) {
		if (ret == Z_MEM_ERROR) {
			if (isFirstTime_) {
				GS_TRACE_WARNING(ZLIB_UTILS, GS_TRACE_CM_COMPRESSION_FAILED,
						"error occured in deflateInit.");
				isFirstTime_ = false;
			}
			destSize = srcSize;
			compressionErrorCount_++;
			return;
		}
		GS_THROW_USER_ERROR(GS_ERROR_CM_COMPRESSION_FAILED,
							  "deflateInit failed.");
	}

	deflateStream_.avail_in = srcSize;
	deflateStream_.avail_out = destSize;
	deflateStream_.next_in = (Bytef*)src;
	deflateStream_.next_out = (Bytef*)dest;

	do {
		ret = deflate(&deflateStream_, flush);
	} while (ret == Z_OK);

	if (ret != Z_STREAM_END) {
		if (isFirstTime_) {
			GS_TRACE_ERROR(ZLIB_UTILS, GS_TRACE_CM_COMPRESSION_FAILED,
						   "error occured in deflate.");
			isFirstTime_ = false;
		}
		destSize = srcSize;
		compressionErrorCount_++;
		return;
	} else {
		destSize = static_cast<uint32_t>(deflateStream_.total_out);
		if (srcSize < destSize) {
			destSize = srcSize;
		}
	}

	ret = deflateEnd(&deflateStream_);
	if (ret != Z_OK) {
		if (isFirstTime_) {
			GS_TRACE_ERROR(ZLIB_UTILS, GS_TRACE_CM_COMPRESSION_FAILED,
						   "error occured in deflateEnd.");
		}
		destSize = srcSize;
		compressionErrorCount_++;
		return;
	}
}
コード例 #13
0
void InterruptionChecker::errorCanceled() {
	GS_THROW_USER_ERROR(GS_ERROR_CM_CANCELED, "");
}