-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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: VReplication parallel copy #8934
Conversation
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
…t startTransactionWithConsistentSnapshot Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Updates:
|
Whoa. All pre-existing tests are passing with the new logic. I'll start crafting specialized tests. |
Of course all tests passed. They weren't running the new flow after all. |
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Most test failures right now seems to originate again by the type of testing we do: our endtoend tests look for a specific sequence of queries, and now parallelism ruined it all... |
Thoughts on the design are welcome |
Signed-off-by: Shlomi Noach <[email protected]>
Any guesses / predictions as to how this might affect the memory usage on the vttablets? Both source and target. |
Great question, it will add |
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
Signed-off-by: Shlomi Noach <[email protected]>
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
This PR was closed because it has been stale for 7 days with no activity. |
Followup to #8056
This is an initial attempt at paralellizing VReplication copy; the main applicability is for MoveTables or Migrate, with multiple tables involved.
Recap
As quick recap from "The general VReplication flow" in #8056:
VReplication currently only ever copies one table at a time
Rows are read by
rowstreamer
using aLOCK TABLES READ
+ get GTID +START TRANSACTION WITH CONSISTENT SNAPSHOT
+UNLOCK TABLES
vcopier
invokes the above via gRPC, receives the rows and writes them down to target table + updatescopy_state
catchup and fast forward steps follow, applying events from the binary log
Why parallelize and what's the premise
Trivially we want to parallelize the copy to save time; we've seen as high as weeks-long mass imports of data.
Parallelization can occur in two places:
rowstreamer
vcopier
AUTO_INCREMENT
column. IfAUTO_INCREMENT
exists, basic tests show almost no gain with 2+ concurrent writes. We wish to focus on multi-table concurrency.We know gRPC is a major source of overhead, and so we want to avoid multiple gRPC calls; we also assume that parallel data transfer across the network is not faster than serial data transfer across the network, assuming we're able to keep the network busy/utilized.
How not to parallelize VReplication copy
We don't take current behavior and multiply
n
times in parallel. If we did that:n
gRPCsn
LOCK TABLE
statementsn
times the same binary log eventsn
VPlayers processing those duplicate eventsProposed solution
We want a single gRPC call that parallelizes into
n
workers in both ends: onrowstreamer
and onvcopier
; we want a singlevplayer
to process all binlog events.gRPC
We add a
VStreamRowsParallel()
function, withVStreamRowsParallelRequest
message. In essence, it's similar toVStreamRows
, but:lastPk
valuesObviously queries and the
lastPK
values correspond to each other.VStreamRowsResponse
is extended to includeTableName
.vcopier
will need this to differentiate between responses of different queries/tables.rowstreamer
VStreamRowsParallel
request with multiple queriessendQuery
for all queriesn
+1 DB connections. One for each table/plan, plus one global that creates a lock.LOCAL TABLES t1 READ, t2 READ, t3 READ, ...
querySTART TRANSACTION WITH CONSISTENT SNAPSHOT
UNLOCK TABLES
SELECT FROM t(i)
concurrently. Each maintains pktsizesend
rows. This is serialized.vreplication/vcopier
Much of the logic is already implictly supported, by virtue of
copy_state
backend table. VCopier supports multiple tables in a workflow (asMoveTables
supports-all
flag), and so catchup/fastforward know how to handle the existence of multiple plans and multiplelastPk
s.To simplify things, we will parallize by running batches of
n
tables at a time. This can, and will, have fragmentation. One or two of the tables will be larger than the others; some tables will complete first, but the batch will only complete when alln
tables are processed.We do it that way because this is what allows us to take a single table lock for all tables involved, and to keep our sanity while looking into GTID value.
Best approach would be to use a greedy alorithm: pick tables by size descending. this will parallaize more tables of same size at a time, which optimizes for less fragmentation (fragmentation == time wasted not parallelizing when we have an available slot).
VCopier needs to pick
n
tables at a time, compute plans for all these tables, and invokeStreamRowsParallel
. Possibly there will already belastPk
for some of those tables; this is trivially read fromcopy_state
with no significant changes other than reorganizing the data.We will create
n
workers. Ideally, each worker will write to a different table (we haven
tables), but it is possible thatrowstreamer
sends results from one table more frequelty. The logic to parallelize the writes onvcopier
is not trivial I think. We can allow for periodic parallelization of writes to same table if that simplifies the code.vcopier
needs to both parallelize (via goroutine) the writes, but at the same time be able to respond to thesend
function witherror
result. As I'm writing this the problem goes more complex in my mind... :(Then, calls to catchup/fastforward converge again; there's only one thread to run those.
Initial PR status:
parallel_rowstreamer.go
andsingle_rowstreamer.go
parallel_vcopier.go
; there is an initial refactor to support multiple concurrnet plans;; there is no parallelization yet, and vplayer needs to be extracted/encapsulated.Checklist
cc @rohit-nayak-ps @sougou @deepthi ; no need for code review right now, though you're welcome to, of course.