w41ter commented on code in PR #36786:
URL: https://github.com/apache/doris/pull/36786#discussion_r1663385220


##########
cloud/src/meta-service/meta_service.h:
##########
@@ -280,6 +283,13 @@ class MetaServiceImpl : public cloud::MetaService {
             const AlterInstanceRequest* request,
             std::function<std::pair<MetaServiceCode, 
std::string>(InstanceInfoPB*)> action);
 
+    using check_create_table_type = std::function<const std::tuple<
+            const ::google::protobuf::RepeatedField<int64_t>, std::string,
+            std::function<std::string(std::string, int64_t)>>(const 
CheckKVRequest* request)>;
+    void check_create_table(std::string instance_id, const CheckKVRequest* 
request,

Review Comment:
   It is not a public API, hide it in .cpp file



##########
cloud/src/meta-service/meta_service_partition.cpp:
##########
@@ -614,4 +619,90 @@ void 
MetaServiceImpl::drop_partition(::google::protobuf::RpcController* controll
     }
 }
 
+void MetaServiceImpl::check_create_table(std::string instance_id, const 
CheckKVRequest* request,
+                                         CheckKVResponse* response, 
MetaServiceCode* code,
+                                         std::string* msg, 
check_create_table_type get_check_info) {
+    std::unique_ptr<Transaction> txn;
+    TxnErrorCode err = txn_kv_->create_txn(&txn);
+    if (err != TxnErrorCode::TXN_OK) {
+        *code = cast_as<ErrCategory::READ>(err);
+        *msg = "failed to create txn";
+        return;
+    }
+    auto& [keys, hint, key_func] = get_check_info(request);
+

Review Comment:
   ```suggestion
   ```



##########
cloud/src/meta-service/meta_service_partition.cpp:
##########
@@ -614,4 +619,90 @@ void 
MetaServiceImpl::drop_partition(::google::protobuf::RpcController* controll
     }
 }
 
+void MetaServiceImpl::check_create_table(std::string instance_id, const 
CheckKVRequest* request,
+                                         CheckKVResponse* response, 
MetaServiceCode* code,
+                                         std::string* msg, 
check_create_table_type get_check_info) {
+    std::unique_ptr<Transaction> txn;
+    TxnErrorCode err = txn_kv_->create_txn(&txn);
+    if (err != TxnErrorCode::TXN_OK) {
+        *code = cast_as<ErrCategory::READ>(err);
+        *msg = "failed to create txn";
+        return;
+    }
+    auto& [keys, hint, key_func] = get_check_info(request);
+
+    if (keys.empty()) {
+        *code = MetaServiceCode::INVALID_ARGUMENT;
+        *msg = "empty keys";
+        return;
+    }
+
+    for (auto id : keys) {
+        auto key = key_func(instance_id, id);
+        err = check_recycle_key_exist(txn.get(), key);
+        if (err == TxnErrorCode::TXN_KEY_NOT_FOUND) {
+            continue;
+        } else if (err == TxnErrorCode::TXN_OK) {
+            // find not match, prepare commit
+            *code = MetaServiceCode::ALREADY_EXISTED;
+            *msg = "prepare and commit rpc not match, recycle key remained";
+            return;
+        } else {
+            // err != TXN_OK, fdb read err
+            *code = cast_as<ErrCategory::READ>(err);
+            *msg = "ms read key error";
+            return;
+        }
+    }
+    LOG_INFO("check {} success request={}", hint, request->ShortDebugString());
+    return;
+}
+
+void MetaServiceImpl::check_kv(::google::protobuf::RpcController* controller,
+                               const CheckKVRequest* request, CheckKVResponse* 
response,
+                               ::google::protobuf::Closure* done) {
+    RPC_PREPROCESS(check_kv);
+    instance_id = get_instance_id(resource_mgr_, request->cloud_unique_id());
+    if (instance_id.empty()) {
+        code = MetaServiceCode::INVALID_ARGUMENT;
+        msg = "empty instance_id";
+        return;
+    }
+    if (!request->has_op()) {
+        code = MetaServiceCode::INVALID_ARGUMENT;
+        msg = "op not given";
+        return;
+    }
+    if (!request->has_check_keys()) {
+        code = MetaServiceCode::INVALID_ARGUMENT;
+        msg = "empty check keys";
+        return;
+    }
+    RPC_RATE_LIMIT(check_kv);
+    switch (request->op()) {
+    case CheckKVRequest::CREATE_INDEX_AFTER_FE_COMMIT: {
+        check_create_table(
+                instance_id, request, response, &code, &msg, [](const 
CheckKVRequest* request) {
+                    return std::make_tuple(request->check_keys().index_ids(), 
"index",
+                                           [](std::string instance_id, int64_t 
id) {
+                                               return 
recycle_index_key({instance_id, id});

Review Comment:
   ```suggestion
                                                  return 
recycle_index_key({std::move(instance_id), id});
   ```



-- 
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

Reply via email to