MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / LoadTableInternal

Method LoadTableInternal

src/tablet/tablet_impl.cc:3049–3118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3047}
3048
3049int TabletImpl::LoadTableInternal(
3050 uint32_t tid, uint32_t pid,
3051 std::shared_ptr<::fedb::api::TaskInfo> task_ptr) {
3052 do {
3053 // load snapshot data
3054 std::shared_ptr<Table> table = GetTable(tid, pid);
3055 if (!table) {
3056 PDLOG(WARNING, "table with tid %u and pid %u does not exist", tid,
3057 pid);
3058 break;
3059 }
3060 std::shared_ptr<Snapshot> snapshot = GetSnapshot(tid, pid);
3061 if (!snapshot) {
3062 PDLOG(WARNING, "snapshot with tid %u and pid %u does not exist",
3063 tid, pid);
3064 break;
3065 }
3066 std::shared_ptr<LogReplicator> replicator = GetReplicator(tid, pid);
3067 if (!replicator) {
3068 PDLOG(WARNING, "replicator with tid %u and pid %u does not exist",
3069 tid, pid);
3070 break;
3071 }
3072 {
3073 std::lock_guard<SpinMutex> spin_lock(spin_mutex_);
3074 table->SetTableStat(::fedb::storage::kLoading);
3075 }
3076 uint64_t latest_offset = 0;
3077 uint64_t snapshot_offset = 0;
3078 std::string db_root_path;
3079 bool ok =
3080 ChooseDBRootPath(tid, pid, db_root_path);
3081 if (!ok) {
3082 PDLOG(WARNING, "fail to find db root path for table tid %u pid %u",
3083 tid, pid);
3084 break;
3085 }
3086 std::string binlog_path = db_root_path + "/" + std::to_string(tid) +
3087 "_" + std::to_string(pid) + "/binlog/";
3088 ::fedb::storage::Binlog binlog(replicator->GetLogPart(), binlog_path);
3089 if (snapshot->Recover(table, snapshot_offset) &&
3090 binlog.RecoverFromBinlog(table, snapshot_offset, latest_offset)) {
3091 table->SetTableStat(::fedb::storage::kNormal);
3092 replicator->SetOffset(latest_offset);
3093 replicator->SetSnapshotLogPartIndex(snapshot->GetOffset());
3094 replicator->StartSyncing();
3095 table->SchedGc();
3096 gc_pool_.DelayTask(
3097 FLAGS_gc_interval * 60 * 1000,
3098 boost::bind(&TabletImpl::GcTable, this, tid, pid, false));
3099 io_pool_.DelayTask(
3100 FLAGS_binlog_sync_to_disk_interval,
3101 boost::bind(&TabletImpl::SchedSyncDisk, this, tid, pid));
3102 task_pool_.DelayTask(
3103 FLAGS_binlog_delete_interval,
3104 boost::bind(&TabletImpl::SchedDelBinlog, this, tid, pid));
3105 PDLOG(INFO, "load table success. tid %u pid %u", tid, pid);
3106 if (task_ptr) {

Callers

nothing calls this directly

Calls 10

to_stringFunction · 0.85
SetTableStatMethod · 0.80
GetLogPartMethod · 0.80
RecoverFromBinlogMethod · 0.80
StartSyncingMethod · 0.80
SchedGcMethod · 0.80
RecoverMethod · 0.45
SetOffsetMethod · 0.45
GetOffsetMethod · 0.45

Tested by

no test coverage detected