@@ -8,7 +8,7 @@ package kvserver_test
8
8
import (
9
9
"context"
10
10
"fmt"
11
- io "io"
11
+ "io"
12
12
"math/rand"
13
13
"path/filepath"
14
14
"strconv"
@@ -40,7 +40,9 @@ import (
40
40
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
41
41
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
42
42
"github.com/cockroachdb/cockroach/pkg/util/uuid"
43
+ "github.com/cockroachdb/cockroach/pkg/util/vfsutil"
43
44
"github.com/cockroachdb/errors"
45
+ "github.com/cockroachdb/pebble/vfs"
44
46
"github.com/stretchr/testify/assert"
45
47
"github.com/stretchr/testify/require"
46
48
)
@@ -236,7 +238,8 @@ func TestCheckConsistencyReplay(t *testing.T) {
236
238
237
239
func TestCheckConsistencyInconsistent (t * testing.T ) {
238
240
defer leaktest .AfterTest (t )()
239
- defer log .Scope (t ).Close (t )
241
+ scope := log .Scope (t )
242
+ defer scope .Close (t )
240
243
241
244
// Test expects simple MVCC value encoding.
242
245
storage .DisableMetamorphicSimpleValueEncoding (t )
@@ -261,19 +264,38 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
261
264
}
262
265
263
266
serverArgsPerNode := make (map [int ]base.TestServerArgs , numStores )
267
+ var vfsIDs []string
264
268
for i := 0 ; i < numStores ; i ++ {
269
+ id := strconv .FormatInt (int64 (i ), 10 )
270
+ vfsIDs = append (vfsIDs , id )
265
271
serverArgsPerNode [i ] = base.TestServerArgs {
266
272
Knobs : base.TestingKnobs {
267
273
Store : & testKnobs ,
268
274
Server : & server.TestingKnobs {StickyVFSRegistry : stickyVFSRegistry },
269
275
},
270
276
StoreSpecs : []base.StoreSpec {{
271
277
InMemory : true ,
272
- StickyVFSID : strconv . FormatInt ( int64 ( i ), 10 ) ,
278
+ StickyVFSID : id ,
273
279
}},
274
280
}
275
281
}
276
282
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
+
277
299
tc = testcluster .StartTestCluster (t , numStores , base.TestClusterArgs {
278
300
ReplicationMode : base .ReplicationAuto ,
279
301
ServerArgsPerNode : serverArgsPerNode ,
@@ -302,7 +324,7 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
302
324
}
303
325
304
326
onDiskCheckpointPaths := func (nodeIdx int ) []string {
305
- fs := stickyVFSRegistry .Get (strconv . FormatInt ( int64 ( nodeIdx ), 10 ) )
327
+ fs := stickyVFSRegistry .Get (vfsIDs [ nodeIdx ] )
306
328
store := tc .GetFirstStoreFromServer (t , nodeIdx )
307
329
checkpointPath := filepath .Join (store .TODOEngine ().GetAuxiliaryDir (), "checkpoints" )
308
330
checkpoints , _ := fs .List (checkpointPath )
@@ -384,7 +406,7 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
384
406
// Create a new store on top of checkpoint location inside existing in-mem
385
407
// VFS to verify its contents.
386
408
ctx := context .Background ()
387
- memFS := stickyVFSRegistry .Get (strconv . FormatInt ( int64 ( i ), 10 ) )
409
+ memFS := stickyVFSRegistry .Get (vfsIDs [ i ] )
388
410
env , err := fs .InitEnv (ctx , memFS , cps [0 ], fs.EnvConfig {RW : fs .ReadOnly }, nil /* statsCollector */ )
389
411
require .NoError (t , err )
390
412
cpEng , err := storage .Open (ctx , env , cluster .MakeClusterSettings (),
@@ -417,8 +439,7 @@ func TestCheckConsistencyInconsistent(t *testing.T) {
417
439
418
440
// A death rattle should have been written on s2. Note that the VFSes are
419
441
// 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 ))
422
443
require .NoError (t , err )
423
444
b , err := io .ReadAll (f )
424
445
require .NoError (t , err )
0 commit comments