diff --git a/dbms/src/Storages/Page/V3/BlobStore.cpp b/dbms/src/Storages/Page/V3/BlobStore.cpp index 30a03599b0b..3bd0bd9c4fa 100644 --- a/dbms/src/Storages/Page/V3/BlobStore.cpp +++ b/dbms/src/Storages/Page/V3/BlobStore.cpp @@ -1038,7 +1038,7 @@ std::vector BlobStore::getGCStats() if (right_margin != stat->sm_total_size) { auto blobfile = getBlobFile(stat->id); - LOG_FMT_INFO(log, "Truncate blob file [blob_id={}] [origin size={}] [truncated size={}]", stat->id, stat->sm_total_size, right_margin); + LOG_FMT_TRACE(log, "Truncate blob file [blob_id={}] [origin size={}] [truncated size={}]", stat->id, stat->sm_total_size, right_margin); blobfile->truncate(right_margin); blobstore_gc_info.appendToTruncatedBlob(stat->id, stat->sm_total_size, right_margin, stat->sm_valid_rate); diff --git a/dbms/src/Storages/Page/V3/spacemap/SpaceMap.h b/dbms/src/Storages/Page/V3/spacemap/SpaceMap.h index 7528d0cf31b..d230b2f3e35 100644 --- a/dbms/src/Storages/Page/V3/spacemap/SpaceMap.h +++ b/dbms/src/Storages/Page/V3/spacemap/SpaceMap.h @@ -95,9 +95,9 @@ class SpaceMap virtual std::tuple searchInsertOffset(size_t size) = 0; /** - * Get the used boundary of current SpaceMap. - * If last node is [xxx, end]. Then `[margin_offset, +∞)` is not used at all. Return the `start` of last node. - * If last node is not [xxx, end]. Then right margin must be `end`. + * Get the used boundary of this SpaceMap. + * The return value (`used_boundary`) means that `[used_bounary + 1, +∞)` is safe to be truncated. + * If the `used_boundary` is equal to the `end` of this SpaceMap, it means that there is no space to be truncated. */ virtual UInt64 getUsedBoundary() = 0; diff --git a/dbms/src/Storages/Page/V3/spacemap/SpaceMapRBTree.cpp b/dbms/src/Storages/Page/V3/spacemap/SpaceMapRBTree.cpp index b17a73b85fa..4bd53b93e07 100644 --- a/dbms/src/Storages/Page/V3/spacemap/SpaceMapRBTree.cpp +++ b/dbms/src/Storages/Page/V3/spacemap/SpaceMapRBTree.cpp @@ -744,15 +744,13 @@ UInt64 RBTreeSpaceMap::getUsedBoundary() auto * entry = node_to_entry(node); - // If last node is not [xxx, end] - // Then we should return `end` rather than last node start + // If the `offset+size` of the last free node is not equal to `end`, it means the range `[last_node.offset, end)` is marked as used, + // then we should return `end` as the used boundary. // - // When there is a space with a span of [xxx, end], - // Then `getUsedBoundary` will return an incorrect right margin. - // ex. - // 1. Space limit is 100. So current space is [0, 100] - // 2. Mark a span {offset=90, size=10} as used, then the free range in SpaceMap is [0, 90). - // 3. without this check, `getUsedBoundary` will return 0. This is incorrect. + // eg. + // 1. The spacemap manage a space of `[0, 100]` + // 2. A span {offset=90, size=10} is marked as used, then the free range in SpaceMap is `[0, 90)` + // 3. The return value should be 100 if (entry->start + entry->count != end) { return end; diff --git a/dbms/src/Storages/Page/V3/spacemap/SpaceMapSTDMap.h b/dbms/src/Storages/Page/V3/spacemap/SpaceMapSTDMap.h index 0af6838c1e8..41ddd77d03a 100644 --- a/dbms/src/Storages/Page/V3/spacemap/SpaceMapSTDMap.h +++ b/dbms/src/Storages/Page/V3/spacemap/SpaceMapSTDMap.h @@ -120,15 +120,13 @@ class STDMapSpaceMap const auto & last_node_it = free_map.rbegin(); - // If last node is not [xxx, end] - // Then we should return `end` rather than last node start + // If the `offset+size` of the last free node is not equal to `end`, it means the range `[last_node.offset, end)` is marked as used, + // then we should return `end` as the used boundary. // - // When there is a space with a span of [xxx, end], - // Then `getUsedBoundary` will return an incorrect right margin. - // ex. - // 1. Space limit is 100. So current space is [0, 100] - // 2. Mark a span {offset=90, size=10} as used, then the free range in SpaceMap is [0, 90). - // 3. without this check, `getUsedBoundary` will return 0. This is incorrect. + // eg. + // 1. The spacemap manage a space of `[0, 100]` + // 2. A span {offset=90, size=10} is marked as used, then the free range in SpaceMap is `[0, 90)` + // 3. The return value should be 100 if (last_node_it->first + last_node_it->second != end) { return end;