Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaqizho committed Jun 14, 2022
2 parents d9f9d02 + 478fee0 commit fcdfb46
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/Page/V3/BlobStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ std::vector<BlobFileId> 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);

Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Storages/Page/V3/spacemap/SpaceMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class SpaceMap
virtual std::tuple<UInt64, UInt64, bool> 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;

Expand Down
14 changes: 6 additions & 8 deletions dbms/src/Storages/Page/V3/spacemap/SpaceMapRBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions dbms/src/Storages/Page/V3/spacemap/SpaceMapSTDMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fcdfb46

Please sign in to comment.