This is an automated email from the ASF dual-hosted git repository.
w41ter pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new dc3bb256021 [fix](cloud) Recycle operation logs if multi version
status is WRITE_ONLY (#57552)
dc3bb256021 is described below
commit dc3bb25602121f9787a63930218d41eba82cb7c2
Author: walter <[email protected]>
AuthorDate: Mon Nov 3 14:47:40 2025 +0800
[fix](cloud) Recycle operation logs if multi version status is WRITE_ONLY
(#57552)
and require mv status is READ_WRITE to turn on snapshot (so the
min_versionstamp of the operation log will be set).
---
cloud/src/meta-service/meta_service_resource.cpp | 17 +++++++++--
cloud/src/recycler/recycler_operation_log.cpp | 4 ++-
cloud/test/meta_service_test.cpp | 36 +++++++++++++++++++++++-
3 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/cloud/src/meta-service/meta_service_resource.cpp
b/cloud/src/meta-service/meta_service_resource.cpp
index 7dec92eb8f5..d91f36cca75 100644
--- a/cloud/src/meta-service/meta_service_resource.cpp
+++ b/cloud/src/meta-service/meta_service_resource.cpp
@@ -2044,13 +2044,26 @@ std::pair<MetaServiceCode, std::string>
handle_snapshot_switch(const std::string
}
// Check if snapshot is not ready (UNSUPPORTED state)
- if (instance->snapshot_switch_status() == SNAPSHOT_SWITCH_DISABLED) {
+ if (!instance->has_snapshot_switch_status() ||
+ instance->snapshot_switch_status() == SNAPSHOT_SWITCH_DISABLED) {
return std::make_pair(MetaServiceCode::INVALID_ARGUMENT,
- "Snapshot not ready, instance_id: " +
instance_id);
+ "Snapshot is not ready, instance_id: " +
instance_id);
} else if (value == "false" && instance->snapshot_switch_status() ==
SNAPSHOT_SWITCH_OFF) {
return std::make_pair(
MetaServiceCode::INVALID_ARGUMENT,
"Snapshot is already set to SNAPSHOT_SWITCH_OFF, instance_id:
" + instance_id);
+ } else if (value == "true" && instance->multi_version_status() !=
MULTI_VERSION_READ_WRITE) {
+ // If the multi_version_status is not READ_WRITE, cannot enable
snapshot because the
+ // operation logs will be recycled directly since min_versionstamp is
not set when multi
+ // version status is WRITE_ONLY
+ std::string url =
+ "${MS_ENDPOINT}/MetaService/http/"
+
"set_multi_version_status?multi_version_status=MULTI_VERSION_READ_WRITE";
+ return std::make_pair(MetaServiceCode::INVALID_ARGUMENT,
+ fmt::format("Cannot enable snapshot when
multi_version_status is not "
+ "MULTI_VERSION_READ_WRITE. Consider
enabling "
+ "MULTI_VERSION_READ_WRITE status by
curl {}",
+ instance_id));
} else if (value == "true") {
instance->set_snapshot_switch_status(SNAPSHOT_SWITCH_ON);
diff --git a/cloud/src/recycler/recycler_operation_log.cpp
b/cloud/src/recycler/recycler_operation_log.cpp
index 05142497548..be081ef9cf8 100644
--- a/cloud/src/recycler/recycler_operation_log.cpp
+++ b/cloud/src/recycler/recycler_operation_log.cpp
@@ -633,7 +633,9 @@ int InstanceRecycler::recycle_operation_logs() {
return -1;
}
- if (!operation_log.has_min_timestamp()) {
+ // Recycle operation log directly if multi_version_status is
WRITE_ONLY.
+ if (!operation_log.has_min_timestamp() &&
+ instance_info_.multi_version_status() !=
MultiVersionStatus::MULTI_VERSION_WRITE_ONLY) {
LOG_WARNING("operation log has not set the min_timestamp")
.tag("key", hex(key))
.tag("version", log_versionstamp.version())
diff --git a/cloud/test/meta_service_test.cpp b/cloud/test/meta_service_test.cpp
index 6e2a42a6749..7594aeca6f2 100644
--- a/cloud/test/meta_service_test.cpp
+++ b/cloud/test/meta_service_test.cpp
@@ -11569,7 +11569,7 @@ TEST(MetaServiceTest, SetSnapshotPropertyTest) {
meta_service->alter_instance(reinterpret_cast<::google::protobuf::RpcController*>(&cntl),
&req, &res, nullptr);
ASSERT_EQ(res.status().code(), MetaServiceCode::INVALID_ARGUMENT);
- ASSERT_TRUE(res.status().msg().find("Snapshot not ready") !=
std::string::npos);
+ ASSERT_TRUE(res.status().msg().find("Snapshot is not ready") !=
std::string::npos);
}
// Initialize snapshot switch status to OFF so we can test snapshot
functionality
@@ -11584,6 +11584,7 @@ TEST(MetaServiceTest, SetSnapshotPropertyTest) {
InstanceInfoPB instance;
instance.ParseFromString(val);
instance.set_snapshot_switch_status(SNAPSHOT_SWITCH_OFF);
+ instance.set_multi_version_status(MULTI_VERSION_READ_WRITE);
val = instance.SerializeAsString();
txn->put(key, val);
ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
@@ -11923,6 +11924,38 @@ TEST(MetaServiceTest, SnapshotConfigLimitsTest) {
ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
}
+ {
+ brpc::Controller cntl;
+ AlterInstanceRequest alter_req;
+ AlterInstanceResponse alter_res;
+ alter_req.set_op(AlterInstanceRequest::SET_SNAPSHOT_PROPERTY);
+ alter_req.set_instance_id("test_snapshot_config_instance");
+
(*alter_req.mutable_properties())[AlterInstanceRequest_SnapshotProperty_Name(
+ AlterInstanceRequest::ENABLE_SNAPSHOT)] = "true";
+
+
meta_service->alter_instance(reinterpret_cast<::google::protobuf::RpcController*>(&cntl),
+ &alter_req, &alter_res, nullptr);
+ ASSERT_EQ(alter_res.status().code(),
MetaServiceCode::INVALID_ARGUMENT);
+ ASSERT_TRUE(alter_res.status().msg().find("MULTI_VERSION_READ_WRITE")
!= std::string::npos);
+ }
+
+ // Set multi-version status to READ_WRITE
+ {
+ InstanceKeyInfo key_info {"test_snapshot_config_instance"};
+ std::string key;
+ std::string val;
+ instance_key(key_info, &key);
+ std::unique_ptr<Transaction> txn;
+ ASSERT_EQ(meta_service->txn_kv()->create_txn(&txn),
TxnErrorCode::TXN_OK);
+ ASSERT_EQ(txn->get(key, &val), TxnErrorCode::TXN_OK);
+ InstanceInfoPB instance;
+ instance.ParseFromString(val);
+ instance.set_multi_version_status(MULTI_VERSION_READ_WRITE);
+ val = instance.SerializeAsString();
+ txn->put(key, val);
+ ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
+ }
+
// Enable snapshot for this instance
{
brpc::Controller cntl;
@@ -12076,6 +12109,7 @@ TEST(MetaServiceTest, SnapshotDefaultValuesTest) {
InstanceInfoPB instance;
instance.ParseFromString(val);
instance.set_snapshot_switch_status(SNAPSHOT_SWITCH_OFF);
+ instance.set_multi_version_status(MULTI_VERSION_READ_WRITE);
val = instance.SerializeAsString();
txn->put(key, val);
ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]