diff --git a/dbms/src/Interpreters/AsynchronousMetrics.cpp b/dbms/src/Interpreters/AsynchronousMetrics.cpp index 3f6ac940ab4..dfaf5b24943 100644 --- a/dbms/src/Interpreters/AsynchronousMetrics.cpp +++ b/dbms/src/Interpreters/AsynchronousMetrics.cpp @@ -177,11 +177,14 @@ void AsynchronousMetrics::update() if (auto dt_storage = std::dynamic_pointer_cast(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); + } } } } diff --git a/dbms/src/Storages/Page/V3/BlobStore.cpp b/dbms/src/Storages/Page/V3/BlobStore.cpp index 75fb5f2e332..493a61a22a4 100644 --- a/dbms/src/Storages/Page/V3/BlobStore.cpp +++ b/dbms/src/Storages/Page/V3/BlobStore.cpp @@ -982,13 +982,10 @@ std::vector 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. diff --git a/dbms/src/Storages/StorageDeltaMerge.cpp b/dbms/src/Storages/StorageDeltaMerge.cpp index 54aad8c8a1b..d908c9a46ed 100644 --- a/dbms/src/Storages/StorageDeltaMerge.cpp +++ b/dbms/src/Storages/StorageDeltaMerge.cpp @@ -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 StorageDeltaMerge::getSchemaSnapshotAndBlockForDecoding(const TableStructureLockHolder & table_structure_lock, bool need_block) { (void)table_structure_lock; diff --git a/dbms/src/Storages/StorageDeltaMerge.h b/dbms/src/Storages/StorageDeltaMerge.h index 9e4ab12ad4f..4fb1f3032da 100644 --- a/dbms/src/Storages/StorageDeltaMerge.h +++ b/dbms/src/Storages/StorageDeltaMerge.h @@ -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; }