platoneko commented on code in PR #34269:
URL: https://github.com/apache/doris/pull/34269#discussion_r1584066103


##########
cloud/src/meta-service/meta_service.cpp:
##########
@@ -326,48 +331,59 @@ void 
MetaServiceImpl::batch_get_version(::google::protobuf::RpcController* contr
             code = cast_as<ErrCategory::CREATE>(err);
             break;
         }
-        for (size_t i = response->versions_size(); i < num_acquired; ++i) {
-            int64_t db_id = request->db_ids(i);
-            int64_t table_id = request->table_ids(i);
-            int64_t partition_id = request->partition_ids(i);
-            std::string ver_key;
-            if (is_table_version) {
-                table_version_key({instance_id, db_id, table_id}, &ver_key);
-            } else {
-                partition_version_key({instance_id, db_id, table_id, 
partition_id}, &ver_key);
+
+        for (size_t i = response->versions_size(); i < num_acquired; i += 
BATCH_SIZE) {
+            size_t limit = (i + BATCH_SIZE < num_acquired) ? i + BATCH_SIZE : 
num_acquired;
+            version_keys.clear();
+            version_values.clear();
+            for (size_t j = i; j < limit; j++) {
+                int64_t db_id = request->db_ids(j);
+                int64_t table_id = request->table_ids(j);
+                int64_t partition_id = request->partition_ids(j);
+                std::string ver_key;
+                if (is_table_version) {
+                    table_version_key({instance_id, db_id, table_id}, 
&ver_key);
+                } else {
+                    partition_version_key({instance_id, db_id, table_id, 
partition_id}, &ver_key);
+                }
+                version_keys.push_back(std::move(ver_key));
             }
 
-            // TODO(walter) support batch get.
-            std::string ver_val;
-            err = txn->get(ver_key, &ver_val, true);
+            err = txn->batch_get(&version_values, version_keys);
             TEST_SYNC_POINT_CALLBACK("batch_get_version_err", &err);
-            VLOG_DEBUG << "xxx get version_key=" << hex(ver_key);
-            if (err == TxnErrorCode::TXN_OK) {
-                if (is_table_version) {
-                    int64_t version = *reinterpret_cast<const 
int64_t*>(ver_val.data());
+            if (err == TxnErrorCode::TXN_TOO_OLD) {
+                // txn too old, fallback to non-snapshot versions.
+                LOG(WARNING) << "batch_get_version execution time exceeds the 
txn mvcc window, "
+                                "fallback to acquire non-snapshot versions, 
partition_ids_size="
+                             << request->partition_ids_size() << ", index=" << 
i;
+                break;
+            } else if (err != TxnErrorCode::TXN_OK) {
+                msg = fmt::format("failed to batch get versions, index={}, 
err={}", i, err);
+                code = cast_as<ErrCategory::READ>(err);
+                break;
+            }
+
+            for (auto&& value : version_values) {
+                if (!value.has_value()) {
+                    // return -1 if the target version is not exists.
+                    response->add_versions(-1);
+                } else if (is_table_version) {
+                    if (value->size() != sizeof(int64_t)) {
+                        code = MetaServiceCode::PROTOBUF_PARSE_ERR;
+                        msg = "malformed table version value";
+                        break;
+                    }
+                    int64_t version = *reinterpret_cast<const 
int64_t*>(value->data());

Review Comment:
   
https://apple.github.io/foundationdb/api-c.html?highlight=fdb_mutation_type_add



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