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

storage: avoid stopping twice in merge test #28902

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions pkg/storage/client_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
)

func adminMergeArgs(key roachpb.Key) *roachpb.AdminMergeRequest {
Expand Down Expand Up @@ -1752,20 +1753,28 @@ func TestStoreRangeMergeDuringShutdown(t *testing.T) {
// Install a filter that triggers a shutdown when stop is non-zero and the
// rhsDesc requests a new lease.
var mtc *multiTestContext
var rhsDesc *roachpb.RangeDescriptor
var stop int32
var state struct {
syncutil.Mutex
rhsDesc *roachpb.RangeDescriptor
stop, stopping bool
}
storeCfg.TestingKnobs.TestingPostApplyFilter = func(args storagebase.ApplyFilterArgs) *roachpb.Error {
if atomic.LoadInt32(&stop) != 0 && args.RangeID == rhsDesc.RangeID && args.IsLeaseRequest {
state.Lock()
if state.stop && !state.stopping && args.RangeID == state.rhsDesc.RangeID && args.IsLeaseRequest {
// Shut down the store. The lease acquisition will notice that a merge is
// in progress and attempt to run a task to watch for its completion.
// Shutting down the store before running leasePostApply will prevent that
// task from launching. This error path would previously fatal a node
// incorrectly (#27552).
state.stopping = true
state.Unlock()
go mtc.Stop()
// Sleep to give the shutdown time to propagate. The test appeared to work
// without this sleep, but best to be somewhat robust to different
// goroutine schedules.
time.Sleep(10 * time.Millisecond)
} else {
state.Unlock()
}
return nil
}
Expand All @@ -1775,11 +1784,13 @@ func TestStoreRangeMergeDuringShutdown(t *testing.T) {
store := mtc.Store(0)
stopper := mtc.engineStoppers[0]

var err error
_, rhsDesc, err = createSplitRanges(ctx, store)
_, rhsDesc, err := createSplitRanges(ctx, store)
if err != nil {
t.Fatal(err)
}
state.Lock()
state.rhsDesc = rhsDesc
state.Unlock()

// Simulate a merge transaction by launching a transaction that lays down
// intents on the two copies of the RHS range descriptor.
Expand All @@ -1793,7 +1804,9 @@ func TestStoreRangeMergeDuringShutdown(t *testing.T) {

// Indicate to the store filter installed above that the next lease
// acquisition for the RHS should trigger a shutdown.
atomic.StoreInt32(&stop, 1)
state.Lock()
state.stop = true
state.Unlock()

// Expire all leases.
mtc.advanceClock(ctx)
Expand Down