github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/fs/persistent_md_test.go (about)

     1  // Package fs provides mountpath and FQN abstractions and methods to resolve/map stored content
     2  /*
     3   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package fs_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/NVIDIA/aistore/cmn/fname"
    11  	"github.com/NVIDIA/aistore/fs"
    12  	"github.com/NVIDIA/aistore/tools"
    13  	"github.com/NVIDIA/aistore/tools/tassert"
    14  )
    15  
    16  type markerEntry struct {
    17  	marker string
    18  	exists bool
    19  }
    20  
    21  func checkMarkersExist(t *testing.T, xs ...markerEntry) {
    22  	for _, xctn := range xs {
    23  		exists := fs.MarkerExists(xctn.marker)
    24  		tassert.Fatalf(t, exists == xctn.exists, "%q marker (%t vs %t)", xctn.marker, exists, xctn.exists)
    25  	}
    26  }
    27  
    28  func TestMarkers(t *testing.T) {
    29  	const mpathsCnt = 5
    30  	mpaths := tools.PrepareMountPaths(t, mpathsCnt)
    31  	defer tools.RemoveMpaths(t, mpaths)
    32  
    33  	checkMarkersExist(t,
    34  		markerEntry{marker: fname.RebalanceMarker, exists: false},
    35  		markerEntry{marker: fname.ResilverMarker, exists: false},
    36  	)
    37  
    38  	fatalErr, writeErr := fs.PersistMarker(fname.RebalanceMarker)
    39  	tassert.CheckFatal(t, fatalErr)
    40  	tassert.CheckFatal(t, writeErr)
    41  
    42  	checkMarkersExist(t,
    43  		markerEntry{marker: fname.RebalanceMarker, exists: true},
    44  		markerEntry{marker: fname.ResilverMarker, exists: false},
    45  	)
    46  
    47  	fatalErr, writeErr = fs.PersistMarker(fname.ResilverMarker)
    48  	tassert.CheckFatal(t, fatalErr)
    49  	tassert.CheckFatal(t, writeErr)
    50  
    51  	checkMarkersExist(t,
    52  		markerEntry{marker: fname.RebalanceMarker, exists: true},
    53  		markerEntry{marker: fname.ResilverMarker, exists: true},
    54  	)
    55  
    56  	fs.RemoveMarker(fname.RebalanceMarker)
    57  
    58  	checkMarkersExist(t,
    59  		markerEntry{marker: fname.RebalanceMarker, exists: false},
    60  		markerEntry{marker: fname.ResilverMarker, exists: true},
    61  	)
    62  
    63  	fs.RemoveMarker(fname.ResilverMarker)
    64  
    65  	checkMarkersExist(t,
    66  		markerEntry{marker: fname.RebalanceMarker, exists: false},
    67  		markerEntry{marker: fname.ResilverMarker, exists: false},
    68  	)
    69  }
    70  
    71  func TestMarkersClear(t *testing.T) {
    72  	const mpathsCnt = 5
    73  	mpaths := tools.PrepareMountPaths(t, mpathsCnt)
    74  	defer tools.RemoveMpaths(t, mpaths)
    75  
    76  	checkMarkersExist(t,
    77  		markerEntry{marker: fname.RebalanceMarker, exists: false},
    78  		markerEntry{marker: fname.ResilverMarker, exists: false},
    79  	)
    80  
    81  	fatalErr, writeErr := fs.PersistMarker(fname.RebalanceMarker)
    82  	tassert.CheckFatal(t, fatalErr)
    83  	tassert.CheckFatal(t, writeErr)
    84  
    85  	fatalErr, writeErr = fs.PersistMarker(fname.ResilverMarker)
    86  	tassert.CheckFatal(t, fatalErr)
    87  	tassert.CheckFatal(t, writeErr)
    88  
    89  	checkMarkersExist(t,
    90  		markerEntry{marker: fname.RebalanceMarker, exists: true},
    91  		markerEntry{marker: fname.ResilverMarker, exists: true},
    92  	)
    93  
    94  	for _, mpath := range mpaths {
    95  		mpath.ClearMDs(true)
    96  	}
    97  
    98  	checkMarkersExist(t,
    99  		markerEntry{marker: fname.RebalanceMarker, exists: false},
   100  		markerEntry{marker: fname.ResilverMarker, exists: false},
   101  	)
   102  }