-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ccl/backupccl,ccl/importccl: disable merges during IMPORT and RESTORE
Add a facility for periodically gossiping keys which disable range merges for a set of tables. This is used by IMPORT and RESTORE to disable range merges on tables being imported / restored. This is done to prevent the merge queue from fighting against the splitting performed by IMPORT and RESTORE. Fixes #29268 Release note (enterprise change): Disable range merges on tables that are being restored or imported into.
- Loading branch information
1 parent
cfd53f6
commit 80eba6d
Showing
9 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2018 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package gossipccl | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/gossip" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
) | ||
|
||
const ( | ||
disableMergesInterval = 10 * time.Second | ||
) | ||
|
||
// DisableMerges starts a goroutine which periodically gossips keys that | ||
// disable merging for the specified table IDs. The goroutine until the | ||
// associated context is done (usually via cancellation). | ||
func DisableMerges(ctx context.Context, g *gossip.Gossip, tableIDs []uint32) { | ||
if len(tableIDs) == 0 { | ||
// Nothing to do. | ||
return | ||
} | ||
|
||
disable := func() { | ||
for _, id := range tableIDs { | ||
key := gossip.MakeTableDisableMergesKey(id) | ||
err := g.AddInfo(key, nil /* value */, disableMergesInterval*2 /* ttl */) | ||
if err != nil { | ||
log.Infof(ctx, "failed to gossip: %s: %v", key, err) | ||
} | ||
} | ||
} | ||
|
||
// Disable merging synchronously before we start the periodic loop below. | ||
disable() | ||
|
||
s := g.Stopper() | ||
// We don't care if this task can't be started as that only occurs if the | ||
// stopper is stopping. | ||
_ = s.RunAsyncTask(ctx, "disable-merges", func(ctx context.Context) { | ||
ticker := time.NewTicker(disableMergesInterval) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ticker.C: | ||
disable() | ||
case <-ctx.Done(): | ||
return | ||
case <-s.ShouldQuiesce(): | ||
return | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2018 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package gossipccl | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/gossip" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/metric" | ||
"github.com/cockroachdb/cockroach/pkg/util/stop" | ||
) | ||
|
||
func TestDisableMerges(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
stopper := stop.NewStopper() | ||
defer stopper.Stop(context.Background()) | ||
|
||
testCases := []struct { | ||
tableIDs []uint32 | ||
}{ | ||
{tableIDs: nil}, | ||
{tableIDs: []uint32{0}}, | ||
{tableIDs: []uint32{1, 2, 9, 10}}, | ||
} | ||
for _, c := range testCases { | ||
t.Run("", func(t *testing.T) { | ||
g := gossip.NewTest(1, nil /* rpcContext */, nil, /* grpcServer */ | ||
stopper, metric.NewRegistry()) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
DisableMerges(ctx, g, c.tableIDs) | ||
for _, id := range c.tableIDs { | ||
key := gossip.MakeTableDisableMergesKey(id) | ||
if _, err := g.GetInfo(key); err != nil { | ||
t.Fatalf("expected to find %s, but got %v", key, err) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters