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

[WIP] Proactive flush of delta merge layer phase 1 #7558

Closed
wants to merge 22 commits into from

Conversation

CalvinNeo
Copy link
Member

@CalvinNeo CalvinNeo commented May 29, 2023

What problem does this PR solve?

Issue Number: close #7564

Problem Summary:

Take over #7088

On KVStore's side:

  1. Filter all passive persistence request from proxy by sending fn_try_flush_data.
  2. Call compactLogByRowKeyRange when there is a need for flush.
  3. Call notifyCompactLog to inform proxy.

On Proxy's side:

  1. Receive notifyCompactLog
  2. Call schedule_compact_log_task, send a CheckCompact request to ApplyRouter.
  3. Call check_pending_compact_log which will persist the ideal truncated_state from TiFlash.

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Signed-off-by: hehechen <awd123456sss@gmail.com>
Signed-off-by: hehechen <awd123456sss@gmail.com>
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 29, 2023

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2023
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2023
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
f
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@CalvinNeo
Copy link
Member Author

/run-all-tests

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

1 similar comment
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

@CalvinNeo
Copy link
Member Author

/run-integration-test

@purelind
Copy link
Collaborator

/run-build-release

@sre-bot
Copy link
Collaborator

sre-bot commented May 30, 2023

@CalvinNeo
Copy link
Member Author

/run-build-release

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

@sre-bot
Copy link
Collaborator

sre-bot commented May 31, 2023

@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

@sre-bot
Copy link
Collaborator

sre-bot commented Jun 19, 2023

@CalvinNeo
Copy link
Member Author

image

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

@sre-bot
Copy link
Collaborator

sre-bot commented Jun 19, 2023

@CalvinNeo
Copy link
Member Author

When foreground flusing region 8880, we need also flush reigon 554

#0  __lll_lock_wait (futex=futex@entry=0x7f4e948c6618, private=0) at lowlevellock.c:52
#1  0x00007f517ec8e131 in __GI___pthread_mutex_lock (mutex=0x7f4e948c6618) at ../nptl/pthread_mutex_lock.c:115
#2  0x00007f5183174026 in std::__1::recursive_mutex::lock() () from /tidb-deploy/tiflash-9000/bin/tiflash/libc++.so.1
#3  0x0000000007fa97cd in std::__1::lock_guard<std::__1::recursive_mutex>::lock_guard (__m=..., this=<optimized out>) at /usr/local/bin/../include/c++/v1/__mutex_base:90
#4  DB::RegionTaskLock::RegionTaskLock (mutex_=..., this=<optimized out>) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/RegionManager.h:89
#5  DB::RegionTaskCtrl::genRegionTaskLock (this=0x7f517deffb80, region_id=554) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:123
#6  DB::RegionManager::genRegionTaskLock (this=0x7f517deffac0, region_id=554) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:128
#7  DB::KVStore::notifyCompactLog (this=0x7f517deffac0, region_id=554, compact_index=<optimized out>, compact_term=10, is_background=false, lock_held=false)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:1010
#8  DB::KVStore::compactLogByRowKeyRange (this=0x7f517deffac0, tmt=..., rowkey_range=..., keyspace_id=<optimized out>, table_id=<optimized out>, is_background=false)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:969
#9  0x0000000007379222 in DB::DM::DeltaMergeStore::triggerCompactLog (this=0x7f514ae5b020, dm_context=..., segment=..., is_background=false)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp:950
#10 0x000000000735a6b0 in DB::DM::DeltaMergeStore::checkSegmentUpdate (this=0x7f514ae5b020, dm_context=..., segment=..., thread_type=<optimized out>)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp:1447
#11 0x0000000007356ba4 in DB::DM::DeltaMergeStore::write (this=0x7f514ae5b020, db_context=..., db_settings=..., block=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp:678
#12 0x0000000007fbe87c in DB::StorageDeltaMerge::write (this=0x7f517385d618, block=..., settings=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/StorageDeltaMerge.cpp:536
#13 DB::writeRegionDataToStorage(DB::Context&, DB::RegionPtrWithBlock const&, std::__1::vector<std::__1::tuple<DB::RawTiDBPK, unsigned char, unsigned long, std::__1::shared_ptr<DB::StringObject<false> const> >, std::__1::allocator<std::__1::tuple<DB::RawTiDBPK, unsigned char, unsigned long, std::__1::shared_ptr<DB::StringObject<false> const> > > >&, std::__1::shared_ptr<DB::Logger> const&)::$_2::operator()(bool) const (this=0x7f4e00862d80, force_decode=<optimized out>) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/PartitionStreams.cpp:148
#14 0x0000000007fbacfa in DB::writeRegionDataToStorage (context=..., region=..., data_list_read=..., log=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/PartitionStreams.cpp:181
#15 0x0000000007fba9bc in DB::RegionTable::writeBlockByRegion (context=..., region=..., data_list_to_remove=..., log=..., lock_region=<optimized out>)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/PartitionStreams.cpp:359
#16 0x0000000007fe4fe2 in DB::Region::handleWriteRaftCmd (this=<optimized out>, cmds=..., index=<optimized out>, term=<optimized out>, tmt=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/Region.cpp:737
#17 0x0000000007f9f27d in DB::KVStore::handleWriteRaftCmd (this=0x7f517deffac0, cmds=..., region_id=8880, index=154510, term=8, tmt=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:301
#18 0x0000000007fc2d05 in HandleWriteRaftCmd (server=<optimized out>, cmds=..., header=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/ProxyFFI.cpp:97
#19 0x00007f51804f0bd8 in <engine_store_ffi::observer::TiFlashObserver<T,ER> as raftstore::coprocessor::QueryObserver>::post_exec_query () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#20 0x00007f51814085fd in raftstore::store::fsm::apply::ApplyDelegate<EK>::apply_raft_cmd () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#21 0x00007f51814222a8 in raftstore::store::fsm::apply::ApplyDelegate<EK>::process_raft_cmd () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#22 0x00007f5181427c04 in raftstore::store::fsm::apply::ApplyDelegate<EK>::handle_raft_committed_entries () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#23 0x00007f51813f840c in raftstore::store::fsm::apply::ApplyFsm<EK>::handle_apply () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#24 0x00007f51813fcf6b in raftstore::store::fsm::apply::ApplyFsm<EK>::handle_tasks () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#25 0x00007f51805d4bee in <raftstore::store::fsm::apply::ApplyPoller<EK> as batch_system::batch::PollHandler<raftstore::store::fsm::apply::ApplyFsm<EK>,raftstore::store::fsm::apply::ControlFsm>>::handle_normal () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#26 0x00007f5180541463 in batch_system::batch::Poller<N,C,Handler>::poll () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#27 0x00007f5180638e78 in std::sys_common::backtrace::__rust_begin_short_backtrace () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#28 0x00007f518068294e in core::ops::function::FnOnce::call_once{{vtable-shim}} () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so

When forground flushing 554, we need also flushing 8880

#0  __lll_lock_wait (futex=futex@entry=0x7f515dfbf4d8, private=0) at lowlevellock.c:52
#1  0x00007f517ec8e131 in __GI___pthread_mutex_lock (mutex=0x7f515dfbf4d8) at ../nptl/pthread_mutex_lock.c:115
#2  0x00007f5183174026 in std::__1::recursive_mutex::lock() () from /tidb-deploy/tiflash-9000/bin/tiflash/libc++.so.1
#3  0x0000000007fa97cd in std::__1::lock_guard<std::__1::recursive_mutex>::lock_guard (__m=..., this=<optimized out>) at /usr/local/bin/../include/c++/v1/__mutex_base:90
#4  DB::RegionTaskLock::RegionTaskLock (mutex_=..., this=<optimized out>) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/RegionManager.h:89
#5  DB::RegionTaskCtrl::genRegionTaskLock (this=0x7f517deffb80, region_id=8880) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:123
#6  DB::RegionManager::genRegionTaskLock (this=0x7f517deffac0, region_id=8880) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:128
#7  DB::KVStore::notifyCompactLog (this=0x7f517deffac0, region_id=8880, compact_index=<optimized out>, compact_term=8, is_background=false, lock_held=false)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:1010
#8  DB::KVStore::compactLogByRowKeyRange (this=0x7f517deffac0, tmt=..., rowkey_range=..., keyspace_id=<optimized out>, table_id=<optimized out>, is_background=false)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:969
#9  0x0000000007379222 in DB::DM::DeltaMergeStore::triggerCompactLog (this=0x7f514ae5b020, dm_context=..., segment=..., is_background=false)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp:950
#10 0x000000000735a6b0 in DB::DM::DeltaMergeStore::checkSegmentUpdate (this=0x7f514ae5b020, dm_context=..., segment=..., thread_type=<optimized out>)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp:1447
#11 0x0000000007356ba4 in DB::DM::DeltaMergeStore::write (this=0x7f514ae5b020, db_context=..., db_settings=..., block=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp:678
#12 0x0000000007fbe87c in DB::StorageDeltaMerge::write (this=0x7f517385d618, block=..., settings=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/StorageDeltaMerge.cpp:536
#13 DB::writeRegionDataToStorage(DB::Context&, DB::RegionPtrWithBlock const&, std::__1::vector<std::__1::tuple<DB::RawTiDBPK, unsigned char, unsigned long, std::__1::shared_ptr<DB::StringObject<false> const> >, std::__1::allocator<std::__1::tuple<DB::RawTiDBPK, unsigned char, unsigned long, std::__1::shared_ptr<DB::StringObject<false> const> > > >&, std::__1::shared_ptr<DB::Logger> const&)::$_2::operator()(bool) const (this=0x7f4e00a63d80, force_decode=<optimized out>) at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/PartitionStreams.cpp:148
#14 0x0000000007fbacfa in DB::writeRegionDataToStorage (context=..., region=..., data_list_read=..., log=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/PartitionStreams.cpp:181
#15 0x0000000007fba9bc in DB::RegionTable::writeBlockByRegion (context=..., region=..., data_list_to_remove=..., log=..., lock_region=<optimized out>)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/PartitionStreams.cpp:359
#16 0x0000000007fe4fe2 in DB::Region::handleWriteRaftCmd (this=<optimized out>, cmds=..., index=<optimized out>, term=<optimized out>, tmt=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/Region.cpp:737
#17 0x0000000007f9f27d in DB::KVStore::handleWriteRaftCmd (this=0x7f517deffac0, cmds=..., region_id=554, index=125161, term=10, tmt=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/KVStore.cpp:301
#18 0x0000000007fc2d05 in HandleWriteRaftCmd (server=<optimized out>, cmds=..., header=...)
    at /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tics/dbms/src/Storages/Transaction/ProxyFFI.cpp:97
#19 0x00007f51804f0bd8 in <engine_store_ffi::observer::TiFlashObserver<T,ER> as raftstore::coprocessor::QueryObserver>::post_exec_query () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#20 0x00007f51814085fd in raftstore::store::fsm::apply::ApplyDelegate<EK>::apply_raft_cmd () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#21 0x00007f51814222a8 in raftstore::store::fsm::apply::ApplyDelegate<EK>::process_raft_cmd () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#22 0x00007f5181427c04 in raftstore::store::fsm::apply::ApplyDelegate<EK>::handle_raft_committed_entries () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#23 0x00007f51813f840c in raftstore::store::fsm::apply::ApplyFsm<EK>::handle_apply () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#24 0x00007f51813fcf6b in raftstore::store::fsm::apply::ApplyFsm<EK>::handle_tasks () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#25 0x00007f51805d4bee in <raftstore::store::fsm::apply::ApplyPoller<EK> as batch_system::batch::PollHandler<raftstore::store::fsm::apply::ApplyFsm<EK>,raftstore::store::fsm::apply::ControlFsm>>::handle_normal () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so
#26 0x00007f5180541463 in batch_system::batch::Poller<N,C,Handler>::poll () from /tidb-deploy/tiflash-9000/bin/tiflash/libtiflash_proxy.so

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 20, 2023
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

@sre-bot
Copy link
Collaborator

sre-bot commented Jun 20, 2023

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jun 30, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from calvinneo. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

1 similar comment
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@CalvinNeo
Copy link
Member Author

/run-build-release comment=true

@sre-bot
Copy link
Collaborator

sre-bot commented Jul 3, 2023

a
Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
@CalvinNeo CalvinNeo changed the title Proactive flush of delta merge layer [WIP] Proactive flush of delta merge layer phase 1 Jul 6, 2023
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 6, 2023
@CalvinNeo CalvinNeo closed this Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve passive flush of TiFlash
4 participants