This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new a15fffd3798 branch-3.1: [opt](meta-service) Add changed value hex for
set_value API #52050 (#52594)
a15fffd3798 is described below
commit a15fffd37984d511481d1c13959a43d4ded8ae22
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jul 2 10:57:34 2025 +0800
branch-3.1: [opt](meta-service) Add changed value hex for set_value API
#52050 (#52594)
Cherry-picked from #52050
Co-authored-by: deardeng <[email protected]>
---
cloud/src/meta-service/http_encode_key.cpp | 38 ++++++++++++++++++++++++++----
cloud/test/meta_service_http_test.cpp | 3 ++-
2 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/cloud/src/meta-service/http_encode_key.cpp
b/cloud/src/meta-service/http_encode_key.cpp
index b851d0956f6..fcb2b81a6a8 100644
--- a/cloud/src/meta-service/http_encode_key.cpp
+++ b/cloud/src/meta-service/http_encode_key.cpp
@@ -23,6 +23,7 @@
#include <google/protobuf/util/json_util.h>
#include <bit>
+#include <fstream>
#include <iomanip>
#include <sstream>
#include <string>
@@ -32,6 +33,7 @@
#include <utility>
#include <vector>
+#include "common/config.h"
#include "common/logging.h"
#include "common/util.h"
#include "cpp/sync_point.h"
@@ -326,6 +328,34 @@ HttpResponse process_http_get_value(TxnKv* txn_kv, const
brpc::URI& uri) {
return http_text_reply(MetaServiceCode::OK, "", readable_value);
}
+std::string handle_kv_output(std::string_view key, std::string_view value,
+ std::string_view original_value_json,
+ std::string_view serialized_value_to_save) {
+ std::stringstream final_output;
+ final_output << "original_value_hex=" << hex(value) << "\n"
+ << "key_hex=" << hex(key) << "\n"
+ << "original_value_json=" << original_value_json << "\n"
+ << "changed_value_hex=" << hex(serialized_value_to_save) <<
"\n";
+ std::string final_json_str = final_output.str();
+ LOG(INFO) << final_json_str;
+ if (final_json_str.size() > 25000) {
+ std::string file_path = fmt::format("/tmp/{}.txt", hex(key));
+ LOG(INFO) << "write to file=" << file_path << ", key=" << hex(key)
+ << " size=" << final_json_str.size();
+ try {
+ std::ofstream kv_file(file_path);
+ if (kv_file.is_open()) {
+ kv_file << final_json_str;
+ kv_file.close();
+ }
+ } catch (...) {
+ LOG(INFO) << "write tmp file failed.";
+ }
+ }
+
+ return final_json_str;
+}
+
HttpResponse process_http_set_value(TxnKv* txn_kv, brpc::Controller* cntl) {
const brpc::URI& uri = cntl->http_request().uri();
std::string body = cntl->request_attachment().to_string();
@@ -426,12 +456,10 @@ HttpResponse process_http_set_value(TxnKv* txn_kv,
brpc::Controller* cntl) {
}
LOG(WARNING) << "set_value saved, key=" << hex(key);
- std::stringstream final_json;
- final_json << "original_value_hex=" << hex(value.value()) << "\n"
- << "key_hex=" << hex(key) << "\n"
- << "original_value_json=" << original_value_json << "\n";
+ std::string final_json_str =
+ handle_kv_output(key, value.value(), original_value_json,
serialized_value_to_save);
- return http_text_reply(MetaServiceCode::OK, "", final_json.str());
+ return http_text_reply(MetaServiceCode::OK, "", final_json_str);
}
HttpResponse process_http_encode_key(const brpc::URI& uri) {
diff --git a/cloud/test/meta_service_http_test.cpp
b/cloud/test/meta_service_http_test.cpp
index b3f68b36a7f..ba20931985f 100644
--- a/cloud/test/meta_service_http_test.cpp
+++ b/cloud/test/meta_service_http_test.cpp
@@ -1979,7 +1979,8 @@ TEST(HttpEncodeKeyTest, ProcessHttpSetValue) {
std::stringstream final_json;
final_json << "original_value_hex=" <<
hex(initial_rowset_meta.SerializeAsString()) << "\n"
<< "key_hex=" << hex(initial_key) << "\n"
- << "original_value_json=" << proto_to_json(initial_rowset_meta)
<< "\n";
+ << "original_value_json=" << proto_to_json(initial_rowset_meta)
<< "\n"
+ << "changed_value_hex=" <<
hex(new_rowset_meta.SerializeAsString()) << "\n";
// std::cout << "xxx " << final_json.str() << std::endl;
EXPECT_EQ(response.body, final_json.str());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]