Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KVStore: Record decoded memory of each Region #9780

Merged
merged 38 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d0e7fac
initial
CalvinNeo Jan 10, 2025
41c12d8
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 10, 2025
29fc1cb
update in a class
CalvinNeo Jan 13, 2025
088a290
add snapshot
CalvinNeo Jan 13, 2025
2fdec72
full lock
CalvinNeo Jan 14, 2025
edba8cf
fix tests
CalvinNeo Jan 14, 2025
9bbdb95
fmt
CalvinNeo Jan 14, 2025
eb9c790
simple
CalvinNeo Jan 14, 2025
92abc36
rename
CalvinNeo Jan 14, 2025
490db1b
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 17, 2025
cec9f51
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 20, 2025
e9d2db9
fix test
CalvinNeo Jan 20, 2025
3e61ebe
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 20, 2025
4b7241a
mode
CalvinNeo Jan 20, 2025
b001db5
Merge branch 'record-table-memory-usage' of github.com:CalvinNeo/tics…
CalvinNeo Jan 20, 2025
e5a31ad
remove last_flush_time
CalvinNeo Jan 21, 2025
ce6b53f
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 21, 2025
65f00cf
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 22, 2025
655f026
Update dbms/src/Storages/KVStore/MultiRaft/RegionData.cpp
CalvinNeo Jan 22, 2025
a7cb61f
Update dbms/src/Storages/KVStore/MultiRaft/RegionCFDataBase.cpp
CalvinNeo Jan 23, 2025
c1ffbc6
Update dbms/src/Storages/KVStore/MultiRaft/RegionData.h
CalvinNeo Jan 23, 2025
582d1e4
address comments
CalvinNeo Jan 23, 2025
8d30697
Merge branch 'record-table-memory-usage' of github.com:CalvinNeo/tics…
CalvinNeo Jan 23, 2025
be7aba6
format
CalvinNeo Jan 23, 2025
fe573b3
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 23, 2025
1127547
fix test
CalvinNeo Jan 24, 2025
8c56f06
Merge branch 'record-table-memory-usage' of github.com:CalvinNeo/tics…
CalvinNeo Jan 24, 2025
7ebfefc
fix
CalvinNeo Jan 24, 2025
e7251d7
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 24, 2025
6dae288
Merge branch 'master' into record-table-memory-usage
CalvinNeo Jan 24, 2025
d08d2c2
Remove unnecessary functions in `RegionCFDataBase` (#13)
JaySon-Huang Jan 24, 2025
fb5c158
some fmt
CalvinNeo Jan 24, 2025
942619b
Remove reportXXX
CalvinNeo Jan 24, 2025
1580de6
remove some codes
CalvinNeo Jan 24, 2025
cf90899
fix memory
CalvinNeo Jan 25, 2025
37f3084
fix
CalvinNeo Jan 25, 2025
00ea7c6
format
CalvinNeo Jan 25, 2025
4118c98
fix lint
JaySon-Huang Jan 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions dbms/src/Debug/MockKVStore/MockUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,70 @@ inline RegionPtr makeRegion(RegionMeta && meta)
return std::make_shared<Region>(std::move(meta), nullptr);
}

// Generates a lock value which fills all fields, only for test use.
inline TiKVValue encodeFullLockCfValue(
UInt8 lock_type,
const String & primary,
Timestamp ts,
UInt64 ttl,
const String * short_value,
Timestamp min_commit_ts,
Timestamp for_update_ts,
uint64_t txn_size,
const std::vector<std::string> & async_commit,
const std::vector<uint64_t> & rollback,
UInt64 generation = 0)
{
auto lock_value = RecordKVFormat::encodeLockCfValue(lock_type, primary, ts, ttl, short_value, min_commit_ts);
WriteBufferFromOwnString res;
res.write(lock_value.getStr().data(), lock_value.getStr().size());
{
res.write(RecordKVFormat::MIN_COMMIT_TS_PREFIX);
RecordKVFormat::encodeUInt64(min_commit_ts, res);
}
{
res.write(RecordKVFormat::FOR_UPDATE_TS_PREFIX);
RecordKVFormat::encodeUInt64(for_update_ts, res);
}
{
res.write(RecordKVFormat::TXN_SIZE_PREFIX);
RecordKVFormat::encodeUInt64(txn_size, res);
}
{
res.write(RecordKVFormat::ROLLBACK_TS_PREFIX);
TiKV::writeVarUInt(rollback.size(), res);
for (auto ts : rollback)
{
RecordKVFormat::encodeUInt64(ts, res);
}
}
{
res.write(RecordKVFormat::ASYNC_COMMIT_PREFIX);
TiKV::writeVarUInt(async_commit.size(), res);
for (const auto & s : async_commit)
{
writeVarInt(s.size(), res);
res.write(s.data(), s.size());
}
}
{
res.write(RecordKVFormat::LAST_CHANGE_PREFIX);
RecordKVFormat::encodeUInt64(12345678, res);
TiKV::writeVarUInt(87654321, res);
}
{
res.write(RecordKVFormat::TXN_SOURCE_PREFIX_FOR_LOCK);
TiKV::writeVarUInt(876543, res);
}
{
res.write(RecordKVFormat::PESSIMISTIC_LOCK_WITH_CONFLICT_PREFIX);
}
if (generation > 0)
{
res.write(RecordKVFormat::GENERATION_PREFIX);
RecordKVFormat::encodeUInt64(generation, res);
}
return TiKVValue(res.releaseStr());
}

} // namespace DB::RegionBench
13 changes: 8 additions & 5 deletions dbms/src/Storages/KVStore/Decode/RegionTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ namespace FailPoints
extern const char force_set_num_regions_for_table[];
} // namespace FailPoints

void RegionTable::InternalRegion::updateRegionCacheBytes(size_t cache_bytes_)
{
cache_bytes = cache_bytes_;
}

RegionTable::Table & RegionTable::getOrCreateTable(const KeyspaceID keyspace_id, const TableID table_id)
{
auto ks_table_id = KeyspaceTableID{keyspace_id, table_id};
Expand Down Expand Up @@ -156,7 +161,7 @@ void RegionTable::updateRegion(const Region & region)
{
std::lock_guard lock(mutex);
auto & internal_region = getOrInsertRegion(region);
internal_region.cache_bytes = region.dataSize();
internal_region.updateRegionCacheBytes(region.dataSize());
}

namespace
Expand Down Expand Up @@ -308,9 +313,7 @@ RegionDataReadInfoList RegionTable::tryWriteBlockByRegion(const RegionPtr & regi

func_update_region([&](InternalRegion & internal_region) -> bool {
internal_region.pause_flush = false;
internal_region.cache_bytes = region->dataSize();

internal_region.last_flush_time = Clock::now();
internal_region.updateRegionCacheBytes(region->dataSize());
return true;
});

Expand Down Expand Up @@ -380,7 +383,7 @@ void RegionTable::shrinkRegionRange(const Region & region)
std::lock_guard lock(mutex);
auto & internal_region = getOrInsertRegion(region);
internal_region.range_in_table = region.getRange()->rawKeys();
internal_region.cache_bytes = region.dataSize();
internal_region.updateRegionCacheBytes(region.dataSize());
}

void RegionTable::extendRegionRange(const RegionID region_id, const RegionRangeKeys & region_range_keys)
Expand Down
5 changes: 4 additions & 1 deletion dbms/src/Storages/KVStore/Decode/RegionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ class RegionTable : private boost::noncopyable
, range_in_table(range_in_table_)
{}

void updateRegionCacheBytes(size_t);

RegionID region_id;
std::pair<DecodedTiKVKeyPtr, DecodedTiKVKeyPtr> range_in_table;
bool pause_flush = false;
JaySon-Huang marked this conversation as resolved.
Show resolved Hide resolved

private:
Int64 cache_bytes = 0;
Timepoint last_flush_time = Clock::now();
};

using InternalRegions = std::unordered_map<RegionID, InternalRegion>;
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/KVStore/MultiRaft/RaftCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ std::pair<EngineStoreApplyRes, DM::WriteResult> Region::handleWriteRaftCmd(
if unlikely (is_v2)
{
// There may be orphan default key in a snapshot.
write_size += doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::AllowSame);
write_size += doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::AllowSame).payload;
}
else
{
write_size += doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::Deny);
write_size += doInsert(cf, std::move(tikv_key), std::move(tikv_value), DupCheck::Deny).payload;
}
}
catch (Exception & e)
Expand Down
Loading