MCPcopy Create free account
hub / github.com/ByConity/ByConity / commitTransaction

Method commitTransaction

src/CloudServices/CnchServerServiceImpl.cpp:314–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312
313
314void CnchServerServiceImpl::commitTransaction(
315 google::protobuf::RpcController * /*cntl*/,
316 const Protos::CommitTransactionReq * request,
317 Protos::CommitTransactionResp * response,
318 google::protobuf::Closure * done)
319{
320 ContextPtr context_ptr = getContext();
321
322 RPCHelpers::serviceHandler(
323 done, response, [request = request, response = response, done = done, &global_context = *context_ptr, log = log] {
324 brpc::ClosureGuard done_guard(done);
325 response->set_commit_ts(0);
326
327 try
328 {
329 /// Check validity of consumer before committing parts & offsets in case a new consumer has been scheduled
330 if (request->has_kafka_storage_id())
331 {
332 auto storage_id = RPCHelpers::createStorageID(request->kafka_storage_id());
333 auto bgthread = global_context.getCnchBGThread(CnchBGThreadType::Consumer, storage_id);
334 auto *manager = dynamic_cast<CnchKafkaConsumeManager *>(bgthread.get());
335
336 if (!manager->checkWorkerClient(storage_id.getTableName(), request->kafka_consumer_index()))
337 throw Exception(
338 "check validity of worker client for " + storage_id.getFullTableName() + " failed",
339 ErrorCodes::CNCH_KAFKA_TASK_NEED_STOP);
340 LOG_TRACE(
341 log,
342 "Check consumer {} OK. Now commit parts and offsets for Kafka transaction\n",storage_id.getFullTableName());
343 }
344
345 auto & txn_coordinator = global_context.getCnchTransactionCoordinator();
346 auto txn_id = request->txn_id();
347 auto txn = txn_coordinator.getTransaction(txn_id);
348
349 // if (request->has_insertion_label())
350 // {
351 // if (UUIDHelpers::Nil == txn->getMainTableUUID())
352 // throw Exception("Main table is not set when using insertion label", ErrorCodes::LOGICAL_ERROR);
353
354 // txn->setInsertionLabel(std::make_shared<InsertionLabel>(
355 // txn->getMainTableUUID(), request->insertion_label(), txn->getTransactionID().toUInt64()));
356 // }
357
358 auto commit_ts = txn->commit();
359 response->set_commit_ts(commit_ts.toUInt64());
360
361 LOG_TRACE(log, "Committed transaction from worker side: {}\n", request->txn_id());
362 }
363 catch (...)
364 {
365 tryLogCurrentException(log, __PRETTY_FUNCTION__);
366 RPCHelpers::handleException(response->mutable_exception());
367 }
368 });
369}
370
371void CnchServerServiceImpl::precommitTransaction(

Callers

nothing calls this directly

Calls 14

serviceHandlerFunction · 0.85
createStorageIDFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
handleExceptionFunction · 0.85
getCnchBGThreadMethod · 0.80
checkWorkerClientMethod · 0.80
getFullTableNameMethod · 0.80
txn_idMethod · 0.80
getTransactionMethod · 0.80
toUInt64Method · 0.80
ExceptionClass · 0.50
getMethod · 0.45

Tested by

no test coverage detected