SWJTU-ZhangLei commented on code in PR #38243: URL: https://github.com/apache/doris/pull/38243#discussion_r1708566789
########## cloud/src/meta-service/meta_service.cpp: ########## @@ -237,46 +238,63 @@ void MetaServiceImpl::get_version(::google::protobuf::RpcController* controller, partition_version_key({instance_id, db_id, table_id, partition_id}, &ver_key); } - std::unique_ptr<Transaction> txn; - TxnErrorCode err = txn_kv_->create_txn(&txn); - if (err != TxnErrorCode::TXN_OK) { - msg = "failed to create txn"; - code = cast_as<ErrCategory::CREATE>(err); - return; - } + do { + code = MetaServiceCode::OK; + std::unique_ptr<Transaction> txn; + TxnErrorCode err = txn_kv_->create_txn(&txn); + if (err != TxnErrorCode::TXN_OK) { + msg = "failed to create txn"; + code = cast_as<ErrCategory::CREATE>(err); + return; + } - std::string ver_val; - // 0 for success get a key, 1 for key not found, negative for error - err = txn->get(ver_key, &ver_val); - VLOG_DEBUG << "xxx get version_key=" << hex(ver_key); - if (err == TxnErrorCode::TXN_OK) { - if (is_table_version) { - int64_t version = 0; - if (!txn->decode_atomic_int(ver_val, &version)) { - code = MetaServiceCode::PROTOBUF_PARSE_ERR; - msg = "malformed table version value"; - return; - } - response->set_version(version); - } else { - VersionPB version_pb; - if (!version_pb.ParseFromString(ver_val)) { - code = MetaServiceCode::PROTOBUF_PARSE_ERR; - msg = "malformed version value"; - return; + std::string ver_val; + // 0 for success get a key, 1 for key not found, negative for error + err = txn->get(ver_key, &ver_val); + VLOG_DEBUG << "xxx get version_key=" << hex(ver_key); + if (err == TxnErrorCode::TXN_OK) { + if (is_table_version) { + int64_t version = 0; + if (!txn->decode_atomic_int(ver_val, &version)) { + code = MetaServiceCode::PROTOBUF_PARSE_ERR; + msg = "malformed table version value"; + return; + } + response->set_version(version); + } else { + VersionPB version_pb; + if (!version_pb.ParseFromString(ver_val)) { + code = MetaServiceCode::PROTOBUF_PARSE_ERR; + msg = "malformed version value"; + return; + } + + if (version_pb.has_txn_id()) { + txn.reset(); + std::shared_ptr<TxnLazyCommitTask> task = + txn_lazy_committer_->submit(instance_id, version_pb.txn_id()); + + std::tie(code, msg) = task->wait(); + if (code != MetaServiceCode::OK) { + LOG(WARNING) + << "wait txn lazy commit failed, txn_id=" << version_pb.txn_id(); + return; + } + } + + response->set_version(version_pb.version()); + response->add_version_update_time_ms(version_pb.update_time_ms()); } - response->set_version(version_pb.version()); - response->add_version_update_time_ms(version_pb.update_time_ms()); + { TEST_SYNC_POINT_CALLBACK("get_version_code", &code); } + return; + } else if (err == TxnErrorCode::TXN_KEY_NOT_FOUND) { + msg = "not found"; + code = MetaServiceCode::VERSION_NOT_FOUND; + return; } - { TEST_SYNC_POINT_CALLBACK("get_version_code", &code); } - return; - } else if (err == TxnErrorCode::TXN_KEY_NOT_FOUND) { - msg = "not found"; - code = MetaServiceCode::VERSION_NOT_FOUND; - return; - } - msg = fmt::format("failed to get txn, err={}", err); - code = cast_as<ErrCategory::READ>(err); + msg = fmt::format("failed to get txn, err={}", err); + code = cast_as<ErrCategory::READ>(err); + } while (false); Review Comment: > remove the `while`, since the `continue` are removed. done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org