gavinchou commented on code in PR #54084:
URL: https://github.com/apache/doris/pull/54084#discussion_r2242408985
##########
cloud/src/meta-store/txn_kv.cpp:
##########
@@ -731,6 +731,107 @@ TxnErrorCode
Transaction::batch_get(std::vector<std::optional<std::string>>* res
return TxnErrorCode::TXN_OK;
}
+TxnErrorCode Transaction::batch_scan(
+ std::vector<std::optional<std::pair<std::string, std::string>>>* res,
+ const std::vector<std::string>& keys, const BatchGetOptions& opts) {
+ struct FDBFutureDelete {
+ void operator()(FDBFuture* future) { fdb_future_destroy(future); }
+ };
+
+ res->clear();
+ if (keys.empty()) {
+ return TxnErrorCode::TXN_OK;
+ }
+
+ StopWatch sw;
+ auto stop_watcher = [&sw](int*) { g_bvar_txn_kv_range_get <<
sw.elapsed_us(); };
+ std::unique_ptr<int, decltype(stop_watcher)> defer((int*)0x01,
std::move(stop_watcher));
+
+ size_t num_keys = keys.size();
+ res->reserve(keys.size());
+ g_bvar_txn_kv_get_count_normalized << keys.size();
+ std::vector<std::unique_ptr<FDBFuture, FDBFutureDelete>> futures;
+ futures.reserve(opts.concurrency);
+
+ fdb_bool_t snapshot = opts.snapshot ? 1 : 0;
+ fdb_bool_t reverse = opts.reverse ? 1 : 0;
+ for (size_t i = 0; i < num_keys; i += opts.concurrency) {
+ size_t batch_size = std::min(i + opts.concurrency, num_keys);
+ for (size_t j = i; j < batch_size; j++) {
+ const auto& key = keys[j];
+ FDBFuture* fut;
+ if (reverse) {
+ fut = fdb_transaction_get_range(
+ txn_, FDB_KEYSEL_FIRST_GREATER_THAN((uint8_t*)"", 0),
+ FDB_KEYSEL_FIRST_GREATER_THAN((uint8_t*)key.data(),
key.size()),
+ 1, // limit: take the first one
+ 0, // target_bytes, unlimited
+ FDBStreamingMode::FDB_STREAMING_MODE_WANT_ALL,
+ 0, // iteration
+ snapshot, // snapshot
+ reverse // reverse
+ );
+ } else {
+ fut = fdb_transaction_get_range(
+ txn_,
FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)key.data(), key.size()),
+ FDB_KEYSEL_FIRST_GREATER_THAN((uint8_t*)"\xFF", 1),
+ 1, // limit: take the first one
+ 0, // target_bytes, unlimited
+ FDBStreamingMode::FDB_STREAMING_MODE_WANT_ALL,
+ 0, // iteration
+ snapshot, // snapshot
+ reverse // reverse
+ );
+ }
+
+ futures.emplace_back(fut);
+ approximate_bytes_ += key.size() * 2;
Review Comment:
why not increase `approximate_bytes_` when process the output param, that is
more accurate
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]