Skip to content

Commit 7d581a4

Browse files
authored
fix(backup): limit the backup interval to be larger than 86400 seconds (apache#1883)
1 parent febb958 commit 7d581a4

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

src/meta/meta_backup_service.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ metric_entity_ptr instantiate_backup_policy_metric_entity(const std::string &pol
7575
return METRIC_ENTITY_backup_policy.instantiate(entity_id, {{"policy_name", policy_name}});
7676
}
7777

78+
bool validate_backup_interval(int64_t backup_interval_seconds, std::string &hint_message)
79+
{
80+
// The backup interval must be larger than checkpoint reserve time.
81+
// Or the next cold backup checkpoint may be cleared by the clear operation.
82+
if (backup_interval_seconds <= FLAGS_cold_backup_checkpoint_reserve_minutes * 60) {
83+
hint_message = fmt::format(
84+
"backup interval must be larger than cold_backup_checkpoint_reserve_minutes={}",
85+
FLAGS_cold_backup_checkpoint_reserve_minutes);
86+
return false;
87+
}
88+
89+
// There is a bug occurred in backup if the backup interval is less than 1 day, this is a
90+
// temporary resolution, the long term plan is to remove periodic backup.
91+
// See details https://github.com/apache/incubator-pegasus/issues/1081.
92+
if (backup_interval_seconds < 86400) {
93+
hint_message = fmt::format("backup interval must be >= 86400 (1 day)");
94+
return false;
95+
}
96+
97+
return true;
98+
}
99+
78100
} // anonymous namespace
79101

80102
backup_policy_metrics::backup_policy_metrics(const std::string &policy_name)
@@ -1281,13 +1303,10 @@ void backup_service::add_backup_policy(dsn::message_ex *msg)
12811303
std::set<int32_t> app_ids;
12821304
std::map<int32_t, std::string> app_names;
12831305

1284-
// The backup interval must be greater than checkpoint reserve time.
1285-
// Or the next cold backup checkpoint may be cleared by the clear operation.
1286-
if (request.backup_interval_seconds <= FLAGS_cold_backup_checkpoint_reserve_minutes * 60) {
1306+
std::string hint_message;
1307+
if (!validate_backup_interval(request.backup_interval_seconds, hint_message)) {
12871308
response.err = ERR_INVALID_PARAMETERS;
1288-
response.hint_message = fmt::format(
1289-
"backup interval must be greater than FLAGS_cold_backup_checkpoint_reserve_minutes={}",
1290-
FLAGS_cold_backup_checkpoint_reserve_minutes);
1309+
response.hint_message = hint_message;
12911310
_meta_svc->reply_data(msg, response);
12921311
msg->release_ref();
12931312
return;
@@ -1628,17 +1647,19 @@ void backup_service::modify_backup_policy(configuration_modify_backup_policy_rpc
16281647
}
16291648

16301649
if (request.__isset.new_backup_interval_sec) {
1631-
if (request.new_backup_interval_sec > 0) {
1650+
std::string hint_message;
1651+
if (validate_backup_interval(request.new_backup_interval_sec, hint_message)) {
16321652
LOG_INFO("{}: policy will change backup interval from {}s to {}s",
16331653
cur_policy.policy_name,
16341654
cur_policy.backup_interval_seconds,
16351655
request.new_backup_interval_sec);
16361656
cur_policy.backup_interval_seconds = request.new_backup_interval_sec;
16371657
have_modify_policy = true;
16381658
} else {
1639-
LOG_WARNING("{}: invalid backup_interval_sec({})",
1659+
LOG_WARNING("{}: invalid backup_interval_sec({}), {}",
16401660
cur_policy.policy_name,
1641-
request.new_backup_interval_sec);
1661+
request.new_backup_interval_sec,
1662+
hint_message);
16421663
}
16431664
}
16441665

src/meta/test/backup_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ TEST_F(meta_backup_service_test, test_add_backup_policy)
821821
fake_wait_rpc(r, resp);
822822

823823
std::string hint_message = fmt::format(
824-
"backup interval must be greater than FLAGS_cold_backup_checkpoint_reserve_minutes={}",
824+
"backup interval must be larger than cold_backup_checkpoint_reserve_minutes={}",
825825
FLAGS_cold_backup_checkpoint_reserve_minutes);
826826
ASSERT_EQ(ERR_INVALID_PARAMETERS, resp.err);
827827
ASSERT_EQ(hint_message, resp.hint_message);

src/test/function_test/restore/test_restore.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,9 @@ class restore_test : public test_util
6161
NO_FATALS(write_data(kTestCount));
6262

6363
std::vector<int32_t> app_ids({table_id_});
64-
// NOTICE: we enqueue a time task to check whether policy should start backup periodically,
65-
// the period is 5min, so the time between two backup is at least 5min, but if we set the
66-
// 'backup_interval_seconds' smaller enough such as smaller than the time of finishing once
67-
// backup, we can start next backup immediately when current backup is finished.
68-
// The backup interval must be greater than checkpoint reserve time, see
69-
// backup_service::add_backup_policy() for details.
7064
ASSERT_EQ(
7165
ERR_OK,
72-
ddl_client_->add_backup_policy("policy_1", "local_service", app_ids, 700, 6, "24:0"));
66+
ddl_client_->add_backup_policy("policy_1", "local_service", app_ids, 86400, 6, "24:0"));
7367
}
7468

7569
void TearDown() override { ASSERT_EQ(ERR_OK, ddl_client_->drop_app(table_name_, 0)); }

0 commit comments

Comments
 (0)