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

Support pre_exec in Proxy #5386

Merged
merged 13 commits into from
Jul 19, 2022
14 changes: 1 addition & 13 deletions dbms/src/Storages/Transaction/KVStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,7 @@ EngineStoreApplyRes KVStore::handleUselessAdminRaftCmd(

curr_region.handleWriteRaftCmd({}, index, term, tmt);

const auto check_sync_log = [&]() {
if (cmd_type != raft_cmdpb::AdminCmdType::CompactLog)
{
// ignore ComputeHash, VerifyHash or other useless cmd.
return false;
}
else
{
return canFlushRegionDataImpl(curr_region_ptr, true, /* try_until_succeed */ false, tmt, region_task_lock);
}
};

if (check_sync_log())
if (cmd_type == raft_cmdpb::AdminCmdType::CompactLog)
CalvinNeo marked this conversation as resolved.
Show resolved Hide resolved
{
return EngineStoreApplyRes::Persist;
}
Expand Down
62 changes: 62 additions & 0 deletions dbms/src/Storages/Transaction/tests/gtest_kvstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RegionKVStoreTest : public ::testing::Test
static void testKVStore();
static void testRegion();
static void testReadIndex();
static void testNewProxy();

private:
static void testRaftSplit(KVStore & kvs, TMTContext & tmt);
Expand All @@ -54,6 +55,66 @@ class RegionKVStoreTest : public ::testing::Test
static void testRaftMergeRollback(KVStore & kvs, TMTContext & tmt);
};

void RegionKVStoreTest::testNewProxy()
{
CalvinNeo marked this conversation as resolved.
Show resolved Hide resolved
std::string path = TiFlashTestEnv::getTemporaryPath("/region_kvs_tmp") + "/basic";

Poco::File file(path);
if (file.exists())
file.remove(true);
file.createDirectories();

auto ctx = TiFlashTestEnv::getContext(
DB::Settings(),
Strings{
path,
});
KVStore & kvs = *ctx.getTMTContext().getKVStore();
MockRaftStoreProxy proxy_instance;
TiFlashRaftProxyHelper proxy_helper;
{
proxy_helper = MockRaftStoreProxy::SetRaftStoreProxyFFIHelper(RaftStoreProxyPtr{&proxy_instance});
proxy_instance.init(100);
}
kvs.restore(&proxy_helper);
{
auto store = metapb::Store{};
store.set_id(1234);
kvs.setStore(store);
ASSERT_EQ(kvs.getStoreID(), store.id());
}
{
ASSERT_EQ(kvs.getRegion(0), nullptr);
auto task_lock = kvs.genTaskLock();
auto lock = kvs.genRegionWriteLock(task_lock);
{
auto region = makeRegion(1, RecordKVFormat::genKey(1, 0), RecordKVFormat::genKey(1, 10));
lock.regions.emplace(1, region);
lock.index.add(region);
}
}
{
kvs.tryPersist(1);
kvs.gcRegionPersistedCache(Seconds{0});
}
{
// test CompactLog
raft_cmdpb::AdminRequest request;
raft_cmdpb::AdminResponse response;
auto region = kvs.getRegion(1);
region->markCompactLog();
kvs.setRegionCompactLogConfig(100000, 1000, 1000);
request.mutable_compact_log();
request.set_cmd_type(::raft_cmdpb::AdminCmdType::CompactLog);
// CompactLog always returns true now, even if we can't do a flush.
// We use a tryFlushData to pre-filter.
ASSERT_EQ(kvs.handleAdminRaftCmd(std::move(request), std::move(response), 1, 5, 1, ctx.getTMTContext()), EngineStoreApplyRes::Persist);

// Filter
ASSERT_EQ(kvs.tryFlushRegionData(1, false, ctx.getTMTContext()), false);
}
}
CalvinNeo marked this conversation as resolved.
Show resolved Hide resolved

void RegionKVStoreTest::testReadIndex()
{
std::string path = TiFlashTestEnv::getTemporaryPath("/region_kvs_tmp") + "/basic";
Expand Down Expand Up @@ -1405,6 +1466,7 @@ TEST_F(RegionKVStoreTest, KVStore)
try
{
testKVStore();
testNewProxy();
}
CATCH

Expand Down