github.com/m3db/m3@v1.5.0/src/dbnode/integration/disk_cleanup_deletes_inactive_directories_test.go (about)

     1  // +build integration
     2  
     3  // Copyright (c) 2016 Uber Technologies, Inc.
     4  //
     5  // Permission is hereby granted, free of charge, to any person obtaining a copy
     6  // of this software and associated documentation files (the "Software"), to deal
     7  // in the Software without restriction, including without limitation the rights
     8  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     9  // copies of the Software, and to permit persons to whom the Software is
    10  // furnished to do so, subject to the following conditions:
    11  //
    12  // The above copyright notice and this permission notice shall be included in
    13  // all copies or substantial portions of the Software.
    14  //
    15  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    16  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    17  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    18  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    19  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    21  // THE SOFTWARE.
    22  
    23  package integration
    24  
    25  import (
    26  	"testing"
    27  	"time"
    28  
    29  	"github.com/m3db/m3/src/dbnode/namespace"
    30  	"github.com/m3db/m3/src/dbnode/sharding"
    31  
    32  	"github.com/stretchr/testify/require"
    33  )
    34  
    35  func TestDiskCleanupInactiveDirectories(t *testing.T) {
    36  	var resetSetup TestSetup
    37  	if testing.Short() {
    38  		t.SkipNow() // Just skip if we're doing a short run
    39  	}
    40  	// Test setup
    41  	testOpts := NewTestOptions(t)
    42  	testSetup, err := NewTestSetup(t, testOpts, nil)
    43  	require.NoError(t, err)
    44  
    45  	md := testSetup.NamespaceMetadataOrFail(testNamespaces[0])
    46  
    47  	// Start tte server
    48  	log := testSetup.StorageOpts().InstrumentOptions().Logger()
    49  	log.Info("disk cleanup directories test")
    50  	require.NoError(t, testSetup.StartServer())
    51  
    52  	// Stop the server at the end of the test
    53  
    54  	var (
    55  		fsCleanupErr = make(chan error)
    56  		nsResetErr   = make(chan error)
    57  		nsCleanupErr = make(chan error)
    58  
    59  		fsWaitTimeout = 30 * time.Second
    60  		nsWaitTimeout = 10 * time.Second
    61  
    62  		namespaces = []namespace.Metadata{md}
    63  		shardSet   = testSetup.DB().ShardSet()
    64  		shards     = shardSet.All()
    65  		extraShard = shards[0]
    66  	)
    67  
    68  	// Now create some fileset files and commit logs
    69  	shardSet, err = sharding.NewShardSet(shards[1:], shardSet.HashFn())
    70  	require.NoError(t, err)
    71  	testSetup.DB().AssignShardSet(shardSet)
    72  
    73  	clOpts := testSetup.StorageOpts().CommitLogOptions()
    74  	// Check filesets are good to go
    75  	go func() {
    76  		fsCleanupErr <- waitUntilDataFileSetsCleanedUp(clOpts,
    77  			testSetup.DB().Namespaces(), extraShard.ID(), fsWaitTimeout)
    78  	}()
    79  	log.Info("blocking until file cleanup is received")
    80  	require.NoError(t, <-fsCleanupErr)
    81  
    82  	// Server needs to restart for namespace changes to be absorbed
    83  	go func() {
    84  		var resetErr error
    85  		resetSetup, resetErr = waitUntilNamespacesHaveReset(testSetup, namespaces, shardSet)
    86  		nsResetErr <- resetErr
    87  	}()
    88  	defer func() {
    89  		require.NoError(t, resetSetup.StopServer())
    90  	}()
    91  	nsToDelete := testNamespaces[1]
    92  	log.Info("blocking until namespaces have reset and deleted")
    93  	go func() {
    94  		time.Sleep(10 * time.Second)
    95  	}()
    96  	require.NoError(t, <-nsResetErr)
    97  
    98  	filePathPrefix := testSetup.StorageOpts().CommitLogOptions().FilesystemOptions().FilePathPrefix()
    99  	go func() {
   100  		nsCleanupErr <- waitUntilNamespacesCleanedUp(filePathPrefix, nsToDelete, nsWaitTimeout)
   101  	}()
   102  	log.Info("blocking until the namespace cleanup is received")
   103  	require.NoError(t, <-nsCleanupErr)
   104  }