Skip to content

Commit

Permalink
avoid init useless DeltaMergeStore (#5705)
Browse files Browse the repository at this point in the history
ref #5665
  • Loading branch information
lidezhu authored Aug 26, 2022
1 parent 61e436b commit b109a12
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
13 changes: 8 additions & 5 deletions dbms/src/Interpreters/AsynchronousMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ void AsynchronousMetrics::update()

if (auto dt_storage = std::dynamic_pointer_cast<StorageDeltaMerge>(table); dt_storage)
{
auto stat = dt_storage->getStore()->getStat();
calculateMax(max_dt_stable_oldest_snapshot_lifetime, stat.storage_stable_oldest_snapshot_lifetime);
calculateMax(max_dt_delta_oldest_snapshot_lifetime, stat.storage_delta_oldest_snapshot_lifetime);
calculateMax(max_dt_meta_oldest_snapshot_lifetime, stat.storage_meta_oldest_snapshot_lifetime);
calculateMax(max_dt_background_tasks_length, stat.background_tasks_length);
if (auto store = dt_storage->getStoreIfInited(); store)
{
auto stat = store->getStat();
calculateMax(max_dt_stable_oldest_snapshot_lifetime, stat.storage_stable_oldest_snapshot_lifetime);
calculateMax(max_dt_delta_oldest_snapshot_lifetime, stat.storage_delta_oldest_snapshot_lifetime);
calculateMax(max_dt_meta_oldest_snapshot_lifetime, stat.storage_meta_oldest_snapshot_lifetime);
calculateMax(max_dt_background_tasks_length, stat.background_tasks_length);
}
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions dbms/src/Storages/Page/V3/BlobStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,13 +982,10 @@ std::vector<BlobFileId> BlobStore::getGCStats()
// Avoid divide by zero
if (right_margin == 0)
{
if (unlikely(stat->sm_valid_rate != 0))
{
throw Exception(fmt::format("Current blob is empty, but valid rate is not 0. [blob_id={}][valid_size={}][valid_rate={}]",
stat->id,
stat->sm_valid_size,
stat->sm_valid_rate));
}
// Note `stat->sm_total_size` isn't strictly the same as the actual size of underlying BlobFile after restart tiflash,
// because some entry may be deleted but the actual disk space is not reclaimed in previous run.
// TODO: avoid always truncate on empty BlobFile
RUNTIME_CHECK_MSG(stat->sm_valid_size == 0, "Current blob is empty, but valid size is not 0. [blob_id={}] [valid_size={}] [valid_rate={}]", stat->id, stat->sm_valid_size, stat->sm_valid_rate);

// If current blob empty, the size of in disk blob may not empty
// So we need truncate current blob, and let it be reused.
Expand Down
9 changes: 9 additions & 0 deletions dbms/src/Storages/StorageDeltaMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,15 @@ void StorageDeltaMerge::deleteRows(const Context & context, size_t delete_rows)
LOG_FMT_ERROR(log, "Rows after delete range not match, expected: {}, got: {}", (total_rows - delete_rows), after_delete_rows);
}

DM::DeltaMergeStorePtr StorageDeltaMerge::getStoreIfInited()
{
if (storeInited())
{
return _store;
}
return nullptr;
}

std::pair<DB::DecodingStorageSchemaSnapshotConstPtr, BlockUPtr> StorageDeltaMerge::getSchemaSnapshotAndBlockForDecoding(const TableStructureLockHolder & table_structure_lock, bool need_block)
{
(void)table_structure_lock;
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Storages/StorageDeltaMerge.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class StorageDeltaMerge
return getAndMaybeInitStore();
}

DM::DeltaMergeStorePtr getStoreIfInited();

bool isCommonHandle() const override { return is_common_handle; }

size_t getRowKeyColumnSize() const override { return rowkey_column_size; }
Expand Down

0 comments on commit b109a12

Please sign in to comment.