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: LargeTxn spill: Store kv pairs of large txns in dedicated CFs #8775

Open
wants to merge 86 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
9575a2b
make RegionDataReadInfo easy to add fields
CalvinNeo Feb 1, 2024
c2c4344
rename writeBlockByRegion to writeCommittedByRegion
CalvinNeo Feb 1, 2024
4503747
template ReadList
CalvinNeo Feb 2, 2024
815b236
some basic spill structure
CalvinNeo Feb 2, 2024
690cf94
try decode without version
CalvinNeo Feb 2, 2024
b67cd19
still need to fix DecodingStorageSchemaSnapshot
CalvinNeo Feb 4, 2024
f56a23d
make it work in a pathetic way
CalvinNeo Feb 5, 2024
0c9e50b
fmt
CalvinNeo Feb 5, 2024
be71bd5
make it kind of readable
CalvinNeo Feb 5, 2024
82d7fe1
remote spill
CalvinNeo Feb 5, 2024
d8da170
tidy
CalvinNeo Feb 5, 2024
f595338
tidy2
CalvinNeo Feb 5, 2024
b6d54c5
introduce AtomicReadWriteCtx to disable decoding uncommitted data
CalvinNeo Feb 5, 2024
b78482d
remove useless codes
CalvinNeo Feb 5, 2024
1c06f70
fix decode
CalvinNeo Feb 5, 2024
99feff8
fix fap test
CalvinNeo Feb 5, 2024
f87956a
log
CalvinNeo Feb 6, 2024
2b4116c
remove spill impl
CalvinNeo Feb 6, 2024
f733fc4
fmt
CalvinNeo Feb 6, 2024
78f14fb
Merge branch 'master' into big-txn-1
CalvinNeo Feb 6, 2024
dcee203
Merge branch 'master' into big-txn-1
CalvinNeo Feb 6, 2024
db58a19
address
CalvinNeo Feb 6, 2024
215aec1
Merge branch 'big-txn-1' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 6, 2024
5b5fc18
address
CalvinNeo Feb 6, 2024
ab48246
Update dbms/src/Storages/KVStore/Decode/RegionDataRead.h
CalvinNeo Feb 6, 2024
57a5b6f
Update dbms/src/Storages/KVStore/Decode/RegionDataRead.h
CalvinNeo Feb 6, 2024
24f1d4d
Update dbms/src/Storages/KVStore/Decode/PartitionStreams.cpp
CalvinNeo Feb 6, 2024
8c2625d
Update dbms/src/Storages/KVStore/MultiRaft/Spill/RegionUncommittedDat…
CalvinNeo Feb 6, 2024
b1a89f4
replace has_version_column with with_version_column
CalvinNeo Feb 6, 2024
2c781d1
Merge branch 'big-txn-1' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 6, 2024
8a01e3d
Update dbms/src/Storages/KVStore/MultiRaft/Spill/RegionUncommittedDat…
CalvinNeo Feb 6, 2024
ffeab59
fix
CalvinNeo Feb 6, 2024
b18c4f4
Merge branch 'big-txn-1' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 6, 2024
f9f04c4
Update dbms/src/Storages/KVStore/Decode/DecodingStorageSchemaSnapshot…
CalvinNeo Feb 6, 2024
902239a
address
CalvinNeo Feb 7, 2024
e520200
Merge branch 'big-txn-1' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 7, 2024
9467ea3
Merge branch 'master' into big-txn-1
CalvinNeo Feb 7, 2024
1d3a01b
Merge branch 'master' into big-txn-1
CalvinNeo Feb 7, 2024
0f2b954
f
CalvinNeo Feb 19, 2024
589593a
change back
CalvinNeo Feb 19, 2024
07e6705
add spill
CalvinNeo Feb 19, 2024
ba40684
add spill 2
CalvinNeo Feb 19, 2024
24be10c
resolve some todb
CalvinNeo Feb 19, 2024
c0aff91
fix
CalvinNeo Feb 19, 2024
125c98b
fix
CalvinNeo Feb 19, 2024
baada2f
intiial
CalvinNeo Feb 19, 2024
481592d
Merge branch 'master' into big-txn-3
CalvinNeo Feb 19, 2024
6916e34
initial
CalvinNeo Feb 20, 2024
ad99890
move
CalvinNeo Feb 20, 2024
428a8dd
Merge branch 'big-txn-3' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 20, 2024
c520009
fix
CalvinNeo Feb 20, 2024
3715290
fix tests
CalvinNeo Feb 20, 2024
22a58b5
move DebugRegion
CalvinNeo Feb 21, 2024
7d390f7
fix
CalvinNeo Feb 21, 2024
26d157a
fix
CalvinNeo Feb 21, 2024
f6ba84c
remove
CalvinNeo Feb 21, 2024
dad1e02
introduce insertWithTs
CalvinNeo Feb 21, 2024
432f5b1
reduce mutMeta
CalvinNeo Feb 21, 2024
fd43a42
mut meta
CalvinNeo Feb 21, 2024
02cfd53
f
CalvinNeo Feb 22, 2024
5048e64
address comment
CalvinNeo Feb 22, 2024
f959782
add debug kvstore and RegionSerdeOpts
CalvinNeo Feb 22, 2024
84b504b
remove some annoying friend
CalvinNeo Feb 22, 2024
065a0e2
address cmt
CalvinNeo Feb 22, 2024
ac9f08d
move DebugRegion to debug
CalvinNeo Feb 22, 2024
01a9ce2
fix fmt
CalvinNeo Feb 22, 2024
5b2f954
f
CalvinNeo Feb 22, 2024
41e2db7
Update dbms/src/Debug/MockKVStore/MockUtils.h
CalvinNeo Feb 22, 2024
c25a0a0
fix
CalvinNeo Feb 22, 2024
a76e686
Merge branch 'big-txn-3' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 22, 2024
b7c389d
f
CalvinNeo Feb 22, 2024
9a842ae
t
CalvinNeo Feb 22, 2024
66f53cb
Level2Key
CalvinNeo Feb 23, 2024
3ac4186
rwo level iter
CalvinNeo Feb 23, 2024
0b5bce3
remove
CalvinNeo Feb 23, 2024
4d57919
tidy
CalvinNeo Feb 23, 2024
ee5fe90
test
CalvinNeo Feb 23, 2024
221b199
fmt
CalvinNeo Feb 23, 2024
3400c34
Update dbms/src/Storages/KVStore/MultiRaft/RegionData.cpp
CalvinNeo Feb 23, 2024
3a4baf1
convert std exception to DB::exception
CalvinNeo Feb 23, 2024
5ac5f4b
Merge branch 'big-txn-3' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 23, 2024
efb00b7
Merge branch 'master' into big-txn-3
CalvinNeo Feb 23, 2024
34d4792
fix
CalvinNeo Feb 23, 2024
5524a87
Merge branch 'big-txn-3' of ssh://github.com/CalvinNeo/tics into big-…
CalvinNeo Feb 23, 2024
1e6be5d
Merge branch 'master' into big-txn-3
CalvinNeo Mar 5, 2024
841c613
Merge branch 'master' into big-txn-3
CalvinNeo Mar 6, 2024
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
1 change: 1 addition & 0 deletions dbms/src/Common/FailPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace DB
M(force_set_fap_candidate_store_id) \
M(force_not_clean_fap_on_destroy) \
M(delta_tree_create_node_fail) \
M(force_write_to_large_txn_default) \
M(disable_flush_cache)

#define APPLY_FOR_PAUSEABLE_FAILPOINTS_ONCE(M) \
Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Debug/MockKVStore/MockUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ inline metapb::Region createRegionInfo(
inline RegionMeta createRegionMeta(
UInt64 id,
DB::TableID table_id,
const HandleID from = 0,
const HandleID to = 300,
std::optional<raft_serverpb::RaftApplyState> apply_state = std::nullopt)
{
return RegionMeta(
/*peer=*/createPeer(31, true),
/*region=*/createRegionInfo(id, RecordKVFormat::genKey(table_id, 0), RecordKVFormat::genKey(table_id, 300)),
/*region=*/createRegionInfo(id, RecordKVFormat::genKey(table_id, from), RecordKVFormat::genKey(table_id, to)),
/*apply_state_=*/apply_state.value_or(initialApplyState()));
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgKVStore/dbgFuncMockRaftCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <Common/typeid_cast.h>
#include <Debug/DBGInvoker.h>
#include <Debug/MockTiDB.h>
#include <Debug/MockTiKV.h>
#include <Debug/dbgKVStore/MockTiKV.h>
#include <Debug/dbgKVStore/dbgFuncMockRaftCommand.h>
#include <Debug/dbgTools.h>
#include <Interpreters/Context.h>
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgKVStore/dbgFuncMockRaftSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <Common/typeid_cast.h>
#include <Debug/MockKVStore/MockSSTReader.h>
#include <Debug/MockTiDB.h>
#include <Debug/MockTiKV.h>
#include <Debug/dbgKVStore/MockTiKV.h>
#include <Debug/dbgKVStore/dbgFuncMockRaftCommand.h>
#include <Debug/dbgKVStore/dbgFuncRegion.h>
#include <Debug/dbgTools.h>
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgKVStore/dbgFuncRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <Common/FmtUtils.h>
#include <Common/typeid_cast.h>
#include <Debug/MockTiDB.h>
#include <Debug/MockTiKV.h>
#include <Debug/dbgKVStore/MockTiKV.h>
#include <Debug/dbgKVStore/dbgFuncRegion.h>
#include <Debug/dbgKVStore/dbgKVStore.h>
#include <Debug/dbgTools.h>
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Debug/dbgKVStore/dbgKVStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
namespace DB::RegionBench
{

RegionSerdeOpts & DebugKVStore::mutRegionSerdeOpts()
{
return kvstore.region_persister->region_serde_opts;
}

void DebugKVStore::mockRemoveRegion(DB::RegionID region_id, RegionTable & region_table)
{
auto task_lock = kvstore.genTaskLock();
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Debug/dbgKVStore/dbgKVStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct DebugKVStore
KVStore * operator->() { return &kvstore; }
KVStore * operator->() const { return &kvstore; }

RegionSerdeOpts & mutRegionSerdeOpts();
template <typename RegionPtrWrap>
void onSnapshot(const RegionPtrWrap & r, RegionPtr old_region, UInt64 old_region_index, TMTContext & tmt)
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgNaturalDag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.

#include <Debug/MockTiDB.h>
#include <Debug/MockTiKV.h>
#include <Debug/dbgFuncCoprocessor.h>
#include <Debug/dbgKVStore/MockTiKV.h>
#include <Debug/dbgNaturalDag.h>
#include <Debug/dbgTools.h>
#include <Flash/Coprocessor/DAGContext.h>
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Debug/dbgTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <Common/typeid_cast.h>
#include <Debug/MockTiDB.h>
#include <Debug/MockTiKV.h>
#include <Debug/dbgKVStore/MockTiKV.h>
#include <Debug/dbgKVStore/dbgKVStore.h>
#include <Debug/dbgTools.h>
#include <Interpreters/Context.h>
Expand Down Expand Up @@ -560,10 +560,12 @@ void concurrentBatchInsert(
Context & context)
{
TMTContext & tmt = context.getTMTContext();
auto & orig_kvs = tmt.getKVStore();
auto debug_kvs = DebugKVStore(*orig_kvs);

RegionID curr_max_region_id(InvalidRegionID);
HandleID curr_max_handle_id = 0;
tmt.getKVStore()->traverseRegions([&](const RegionID region_id, const RegionPtr & region) {
debug_kvs->traverseRegions([&](const RegionID region_id, const RegionPtr & region) {
curr_max_region_id
= (curr_max_region_id == InvalidRegionID) ? region_id : std::max<RegionID>(curr_max_region_id, region_id);
const auto range = region->getRange();
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Storages/KVStore/KVStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class KVStore final : private boost::noncopyable
FileUsageStatistics getFileUsageStatistics() const;
// Proxy will validate and refit the config items from the toml file.
const ProxyConfigSummary & getProxyConfigSummay() const { return proxy_config_summary; }
const RegionPersister & getRegionPersister() const { return *region_persister; }

public: // Region Management
void restore(PathPool & path_pool, const TiFlashRaftProxyHelper *);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ FastAddPeerProto::CheckpointIngestInfoPersisted CheckpointIngestInfo::serializeM
// Although the region is the first peer of this region in this store, we can't write it to formal KVStore for now.
// Otherwise it could be uploaded and then overwritten.
WriteBufferFromOwnString wb;
RegionPersister::computeRegionWriteBuffer(*region, wb);
RegionPersister::computeRegionWriteBuffer(
*region,
wb,
tmt.getKVStore()->getRegionPersister().getRegionSerdeOpts());
ingest_info_persisted.set_region_info(wb.releaseStr());
}
ingest_info_persisted.set_remote_store_id(remote_store_id);
Expand Down
24 changes: 19 additions & 5 deletions dbms/src/Storages/KVStore/MultiRaft/RegionCFDataBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Storages/KVStore/MultiRaft/RegionCFDataTrait.h>
#include <Storages/KVStore/MultiRaft/RegionData.h>
#include <Storages/KVStore/MultiRaft/RegionRangeKeys.h>
#include <Storages/KVStore/MultiRaft/Spill/LargeTxnDefaultCf.h>

namespace DB
{
Expand All @@ -39,6 +40,21 @@ const TiKVValue & RegionCFDataBase<Trait>::getTiKVValue(const Value & val)
return *getTiKVValuePtr<Value>(val);
}

RegionDataRes insertWithTs(
RegionCFDataBase<RegionDefaultCFDataTrait> & default_cf,
TiKVKey && key,
TiKVValue && value,
Timestamp ts,
DupCheck mode)
{
const auto & raw_key = RecordKVFormat::decodeTiKVKey(key);
auto kv_pair = RegionDefaultCFDataTrait::genKVPairWithTs(std::move(key), ts, raw_key, std::move(value));
if (!kv_pair)
return 0;

return default_cf.doInsert(std::move(*kv_pair), mode);
}

template <typename Trait>
RegionDataRes RegionCFDataBase<Trait>::insert(TiKVKey && key, TiKVValue && value, DupCheck mode)
{
Expand All @@ -47,7 +63,7 @@ RegionDataRes RegionCFDataBase<Trait>::insert(TiKVKey && key, TiKVValue && value
if (!kv_pair)
return 0;

return insert(std::move(*kv_pair), mode);
return doInsert(std::move(*kv_pair), mode);
}

template <>
Expand All @@ -70,7 +86,7 @@ RegionDataRes RegionCFDataBase<RegionLockCFDataTrait>::insert(TiKVKey && key, Ti
}

template <typename Trait>
RegionDataRes RegionCFDataBase<Trait>::insert(std::pair<Key, Value> && kv_pair, DupCheck mode)
RegionDataRes RegionCFDataBase<Trait>::doInsert(std::pair<Key, Value> && kv_pair, DupCheck mode)
{
auto & map = data;
TiKVValue prev_value;
Expand Down Expand Up @@ -265,15 +281,12 @@ size_t RegionCFDataBase<Trait>::splitInto(const RegionRange & range, RegionCFDat
{
const auto & [start_key, end_key] = range;
size_t size_changed = 0;

{
auto & ori_map = data;
auto & tar_map = new_region_data.data;

for (auto it = ori_map.begin(); it != ori_map.end();)
{
const auto & key = getTiKVKey(it->second);

if (start_key.compare(key) <= 0 && end_key.compare(key) > 0)
{
size_changed += calcTiKVKeyValueSize(it->second);
Expand Down Expand Up @@ -336,4 +349,5 @@ typename RegionCFDataBase<Trait>::Data & RegionCFDataBase<Trait>::getDataMut()
template struct RegionCFDataBase<RegionWriteCFDataTrait>;
template struct RegionCFDataBase<RegionDefaultCFDataTrait>;
template struct RegionCFDataBase<RegionLockCFDataTrait>;
template struct RegionCFDataBase<LargeDefaultCFDataTrait>;
} // namespace DB
17 changes: 12 additions & 5 deletions dbms/src/Storages/KVStore/MultiRaft/RegionCFDataBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

namespace DB
{

struct RegionDefaultCFDataTrait;
struct TiKVRangeKey;

using RegionRange = RegionRangeKeys::RegionRange;
using RegionDataRes = int64_t;

Expand All @@ -43,7 +44,6 @@ struct RegionCFDataBase
using Status = bool;

static const TiKVKey & getTiKVKey(const Value & val);

static const TiKVValue & getTiKVValue(const Value & val);

RegionDataRes insert(TiKVKey && key, TiKVValue && value, DupCheck mode = DupCheck::Deny);
Expand All @@ -52,7 +52,7 @@ struct RegionCFDataBase

static size_t calcTiKVKeyValueSize(const TiKVKey & key, const TiKVValue & value);

size_t remove(const Key & key, bool quiet = false);
size_t remove(const Key & key, bool quiet);

static bool cmp(const Map & a, const Map & b);

Expand All @@ -68,19 +68,26 @@ struct RegionCFDataBase
size_t mergeFrom(const RegionCFDataBase & ori_region_data);

size_t serialize(WriteBuffer & buf) const;

static size_t deserialize(ReadBuffer & buf, RegionCFDataBase & new_region_data);

const Data & getData() const;

Data & getDataMut();

RegionDataRes doInsert(std::pair<Key, Value> && kv_pair, DupCheck mode = DupCheck::Deny);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can be keep as "private"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, i found that i can't...


private:
static bool shouldIgnoreRemove(const Value & value);
RegionDataRes insert(std::pair<Key, Value> && kv_pair, DupCheck mode = DupCheck::Deny);

private:
Data data;
};

RegionDataRes insertWithTs(
RegionCFDataBase<RegionDefaultCFDataTrait> & default_cf,
TiKVKey && key,
TiKVValue && value,
Timestamp ts,
DupCheck mode);

} // namespace DB
15 changes: 14 additions & 1 deletion dbms/src/Storages/KVStore/MultiRaft/RegionCFDataTrait.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct RegionWriteCFDataTrait
static UInt8 getWriteType(const Value & value) { return std::get<2>(value).write_type; }
};


struct RegionDefaultCFDataTrait
{
using Key = std::pair<RawTiDBPK, Timestamp>;
Expand All @@ -80,6 +79,20 @@ struct RegionDefaultCFDataTrait
std::make_shared<const TiKVValue>(std::move(value))));
}

static std::optional<Map::value_type> genKVPairWithTs(
TiKVKey && key,
Timestamp ts,
const DecodedTiKVKey & raw_key,
TiKVValue && value)
{
RawTiDBPK tidb_pk = RecordKVFormat::getRawTiDBPK(raw_key);
return Map::value_type(
Key(std::move(tidb_pk), ts),
Value(
std::make_shared<const TiKVKey>(std::move(key)),
std::make_shared<const TiKVValue>(std::move(value))));
}

static std::shared_ptr<const TiKVValue> getTiKVValue(const Map::const_iterator & it)
{
return std::get<1>(it->second);
Expand Down
Loading