Skip to content

Commit

Permalink
feat: makesanpshot after truncate disk table
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 committed Oct 18, 2023
1 parent d33d416 commit 2476084
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/tablet/tablet_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,7 @@ void TabletImpl::SetExpire(RpcController* controller, const ::openmldb::api::Set
}

void TabletImpl::MakeSnapshotInternal(uint32_t tid, uint32_t pid, uint64_t end_offset,
std::shared_ptr<::openmldb::api::TaskInfo> task) {
std::shared_ptr<::openmldb::api::TaskInfo> task, bool is_force) {
PDLOG(INFO, "MakeSnapshotInternal begin, tid[%u] pid[%u]", tid, pid);
std::shared_ptr<Table> table;
std::shared_ptr<Snapshot> snapshot;
Expand Down Expand Up @@ -2524,7 +2524,7 @@ void TabletImpl::MakeSnapshotInternal(uint32_t tid, uint32_t pid, uint64_t end_o
uint64_t cur_offset = replicator->GetOffset();
uint64_t snapshot_offset = snapshot->GetOffset();
int ret = 0;
if (cur_offset < snapshot_offset + FLAGS_make_snapshot_threshold_offset && end_offset == 0) {
if (!is_force && cur_offset < snapshot_offset + FLAGS_make_snapshot_threshold_offset && end_offset == 0) {
PDLOG(INFO,
"offset can't reach the threshold. tid[%u] pid[%u] "
"cur_offset[%lu], snapshot_offset[%lu] end_offset[%lu]",
Expand Down Expand Up @@ -2597,7 +2597,7 @@ void TabletImpl::MakeSnapshot(RpcController* controller, const ::openmldb::api::
break;
}
}
snapshot_pool_.AddTask(boost::bind(&TabletImpl::MakeSnapshotInternal, this, tid, pid, offset, task_ptr));
snapshot_pool_.AddTask(boost::bind(&TabletImpl::MakeSnapshotInternal, this, tid, pid, offset, task_ptr, false));
response->set_code(::openmldb::base::ReturnCode::kOk);
response->set_msg("ok");
return;
Expand Down Expand Up @@ -2631,7 +2631,7 @@ void TabletImpl::SchedMakeSnapshot() {
}
for (auto iter = table_set.begin(); iter != table_set.end(); ++iter) {
PDLOG(INFO, "start make snapshot tid[%u] pid[%u]", iter->first, iter->second);
MakeSnapshotInternal(iter->first, iter->second, 0, std::shared_ptr<::openmldb::api::TaskInfo>());
MakeSnapshotInternal(iter->first, iter->second, 0, std::shared_ptr<::openmldb::api::TaskInfo>(), false);

Check warning on line 2634 in src/tablet/tablet_impl.cc

View check run for this annotation

Codecov / codecov/patch

src/tablet/tablet_impl.cc#L2634

Added line #L2634 was not covered by tests
}
// delay task one hour later avoid execute more than one time
snapshot_pool_.DelayTask(FLAGS_make_snapshot_check_interval + 60 * 60 * 1000,
Expand Down Expand Up @@ -3532,7 +3532,7 @@ base::Status TabletImpl::TruncateTableInternal(uint32_t tid, uint32_t pid) {
std::shared_ptr<Table> new_table;

Check warning on line 3532 in src/tablet/tablet_impl.cc

View check run for this annotation

Codecov / codecov/patch

src/tablet/tablet_impl.cc#L3532

Added line #L3532 was not covered by tests
new_table = std::make_shared<MemTable>(*table_meta);
if (!new_table->Init()) {
PDLOG(WARNING, "fail to init table. tid %u, pid %u", table_meta->tid(), table_meta->pid());
PDLOG(WARNING, "fail to init table. tid %u, pid %u", tid, pid);
return {::openmldb::base::ReturnCode::kTableMetaIsIllegal, "fail to init table"};

Check warning on line 3536 in src/tablet/tablet_impl.cc

View check run for this annotation

Codecov / codecov/patch

src/tablet/tablet_impl.cc#L3535-L3536

Added lines #L3535 - L3536 were not covered by tests
}
new_table->SetTableStat(::openmldb::storage::kNormal);
Expand All @@ -3556,6 +3556,7 @@ base::Status TabletImpl::TruncateTableInternal(uint32_t tid, uint32_t pid) {
if (auto status = disk_table->Truncate(); !status.OK()) {
return {::openmldb::base::ReturnCode::kTruncateTableFailed, status.GetMsg()};

Check warning on line 3557 in src/tablet/tablet_impl.cc

View check run for this annotation

Codecov / codecov/patch

src/tablet/tablet_impl.cc#L3557

Added line #L3557 was not covered by tests
}
snapshot_pool_.AddTask(boost::bind(&TabletImpl::MakeSnapshotInternal, this, tid, pid, 0, nullptr, true));
}
PDLOG(INFO, "truncate table success. tid[%u] pid[%u]", tid, pid);
return {};
Expand Down
2 changes: 1 addition & 1 deletion src/tablet/tablet_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class TabletImpl : public ::openmldb::api::TabletServer {
int CreateTableInternal(const ::openmldb::api::TableMeta* table_meta, std::string& msg); // NOLINT

void MakeSnapshotInternal(uint32_t tid, uint32_t pid, uint64_t end_offset,
std::shared_ptr<::openmldb::api::TaskInfo> task);
std::shared_ptr<::openmldb::api::TaskInfo> task, bool is_force);

void SendSnapshotInternal(const std::string& endpoint, uint32_t tid, uint32_t pid, uint32_t remote_tid,
std::shared_ptr<::openmldb::api::TaskInfo> task);
Expand Down

0 comments on commit 2476084

Please sign in to comment.