Skip to content

Commit 3b06bb3

Browse files
committed
kvserver: dump memFS on test failure
Informs #150660.
1 parent 54a8470 commit 3b06bb3

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

pkg/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ ALL_TESTS = [
819819
"//pkg/util/unique:unique_test",
820820
"//pkg/util/uuid:uuid_test",
821821
"//pkg/util/vector:vector_test",
822+
"//pkg/util/vfsutil:vfsutil_test",
822823
"//pkg/util:util_test",
823824
"//pkg/workload/bank:bank_test",
824825
"//pkg/workload/cli:cli_test",
@@ -2791,6 +2792,8 @@ GO_TARGETS = [
27912792
"//pkg/util/uuid:uuid_test",
27922793
"//pkg/util/vector:vector",
27932794
"//pkg/util/vector:vector_test",
2795+
"//pkg/util/vfsutil:vfsutil",
2796+
"//pkg/util/vfsutil:vfsutil_test",
27942797
"//pkg/util:util",
27952798
"//pkg/util:util_test",
27962799
"//pkg/workload/bank:bank",

pkg/kv/kvserver/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ go_test(
558558
"//pkg/util/tracing/tracingpb",
559559
"//pkg/util/uint128",
560560
"//pkg/util/uuid",
561+
"//pkg/util/vfsutil",
561562
"@com_github_cockroachdb_cockroach_go_v2//crdb",
562563
"@com_github_cockroachdb_crlib//crtime",
563564
"@com_github_cockroachdb_datadriven//:datadriven",

pkg/kv/kvserver/consistency_queue_test.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kvserver_test
88
import (
99
"context"
1010
"fmt"
11-
io "io"
11+
"io"
1212
"math/rand"
1313
"path/filepath"
1414
"strconv"
@@ -40,7 +40,9 @@ import (
4040
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
4141
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
4242
"github.com/cockroachdb/cockroach/pkg/util/uuid"
43+
"github.com/cockroachdb/cockroach/pkg/util/vfsutil"
4344
"github.com/cockroachdb/errors"
45+
"github.com/cockroachdb/pebble/vfs"
4446
"github.com/stretchr/testify/assert"
4547
"github.com/stretchr/testify/require"
4648
)
@@ -236,7 +238,8 @@ func TestCheckConsistencyReplay(t *testing.T) {
236238

237239
func TestCheckConsistencyInconsistent(t *testing.T) {
238240
defer leaktest.AfterTest(t)()
239-
defer log.Scope(t).Close(t)
241+
scope := log.Scope(t)
242+
defer scope.Close(t)
240243

241244
// Test expects simple MVCC value encoding.
242245
storage.DisableMetamorphicSimpleValueEncoding(t)
@@ -261,19 +264,38 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
261264
}
262265

263266
serverArgsPerNode := make(map[int]base.TestServerArgs, numStores)
267+
var vfsIDs []string
264268
for i := 0; i < numStores; i++ {
269+
id := strconv.FormatInt(int64(i), 10)
270+
vfsIDs = append(vfsIDs, id)
265271
serverArgsPerNode[i] = base.TestServerArgs{
266272
Knobs: base.TestingKnobs{
267273
Store: &testKnobs,
268274
Server: &server.TestingKnobs{StickyVFSRegistry: stickyVFSRegistry},
269275
},
270276
StoreSpecs: []base.StoreSpec{{
271277
InMemory: true,
272-
StickyVFSID: strconv.FormatInt(int64(i), 10),
278+
StickyVFSID: id,
273279
}},
274280
}
275281
}
276282

283+
// If the test fails, preserve the in-memory VFSes so that we can poke at them.
284+
defer func() {
285+
if !t.Failed() {
286+
return
287+
}
288+
289+
// NB: scope has a directory even under -show-logs.
290+
outDir := filepath.Join(scope.GetDirectory(), "stores")
291+
t.Logf("dumping sticky VFS to %s", outDir)
292+
for i := 0; i < numStores; i++ {
293+
fs := stickyVFSRegistry.Get(vfsIDs[i])
294+
dest := filepath.Join(outDir, fmt.Sprintf("s%d", i+1))
295+
assert.NoError(t, vfsutil.CopyRecursive(fs, vfs.Default, "/", dest))
296+
}
297+
}()
298+
277299
tc = testcluster.StartTestCluster(t, numStores, base.TestClusterArgs{
278300
ReplicationMode: base.ReplicationAuto,
279301
ServerArgsPerNode: serverArgsPerNode,
@@ -302,7 +324,7 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
302324
}
303325

304326
onDiskCheckpointPaths := func(nodeIdx int) []string {
305-
fs := stickyVFSRegistry.Get(strconv.FormatInt(int64(nodeIdx), 10))
327+
fs := stickyVFSRegistry.Get(vfsIDs[nodeIdx])
306328
store := tc.GetFirstStoreFromServer(t, nodeIdx)
307329
checkpointPath := filepath.Join(store.TODOEngine().GetAuxiliaryDir(), "checkpoints")
308330
checkpoints, _ := fs.List(checkpointPath)
@@ -384,7 +406,7 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
384406
// Create a new store on top of checkpoint location inside existing in-mem
385407
// VFS to verify its contents.
386408
ctx := context.Background()
387-
memFS := stickyVFSRegistry.Get(strconv.FormatInt(int64(i), 10))
409+
memFS := stickyVFSRegistry.Get(vfsIDs[i])
388410
env, err := fs.InitEnv(ctx, memFS, cps[0], fs.EnvConfig{RW: fs.ReadOnly}, nil /* statsCollector */)
389411
require.NoError(t, err)
390412
cpEng, err := storage.Open(ctx, env, cluster.MakeClusterSettings(),
@@ -417,8 +439,7 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
417439

418440
// A death rattle should have been written on s2. Note that the VFSes are
419441
// zero-indexed whereas store IDs are one-indexed.
420-
fs := stickyVFSRegistry.Get("1")
421-
f, err := fs.Open(base.PreventedStartupFile(s2AuxDir))
442+
f, err := stickyVFSRegistry.Get(vfsIDs[1]).Open(base.PreventedStartupFile(s2AuxDir))
422443
require.NoError(t, err)
423444
b, err := io.ReadAll(f)
424445
require.NoError(t, err)

0 commit comments

Comments
 (0)