github.com/m3db/m3@v1.5.0/src/dbnode/integration/disk_cleanup_test.go (about) 1 // +build integration 2 3 // Copyright (c) 2018 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/integration/generate" 30 "github.com/m3db/m3/src/dbnode/namespace" 31 xtime "github.com/m3db/m3/src/x/time" 32 33 "github.com/stretchr/testify/require" 34 ) 35 36 func TestDiskCleanup(t *testing.T) { 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 defer testSetup.Close() 45 46 md := testSetup.NamespaceMetadataOrFail(testNamespaces[0]) 47 blockSize := md.Options().RetentionOptions().BlockSize() 48 retentionPeriod := md.Options().RetentionOptions().RetentionPeriod() 49 50 // Create some fileset files and commit logs 51 var ( 52 shard = uint32(0) 53 numTimes = 10 54 fileTimes = make([]xtime.UnixNano, numTimes) 55 now = testSetup.NowFn()() 56 commitLogOpts = testSetup.StorageOpts().CommitLogOptions(). 57 SetFlushInterval(defaultIntegrationTestFlushInterval) 58 ) 59 ns1, err := namespace.NewMetadata(testNamespaces[0], namespace.NewOptions()) 60 require.NoError(t, err) 61 for i := 0; i < numTimes; i++ { 62 fileTimes[i] = now.Add(time.Duration(i) * blockSize) 63 } 64 writeDataFileSetFiles(t, testSetup.StorageOpts(), md, shard, fileTimes) 65 for _, clTime := range fileTimes { 66 data := map[xtime.UnixNano]generate.SeriesBlock{clTime: nil} 67 writeCommitLogDataSpecifiedTS( 68 t, testSetup, commitLogOpts, 69 data, ns1, clTime, false) 70 } 71 72 // Now start the server 73 log := testSetup.StorageOpts().InstrumentOptions().Logger() 74 log.Debug("disk cleanup test") 75 require.NoError(t, testSetup.StartServer()) 76 log.Debug("server is now up") 77 78 defer func() { 79 require.NoError(t, testSetup.StopServer()) 80 log.Debug("server is now down") 81 }() 82 83 // Move now forward by retentionPeriod + 2 * blockSize so fileset files 84 // and commit logs at now will be deleted 85 newNow := testSetup.NowFn()().Add(retentionPeriod).Add(2 * blockSize) 86 testSetup.SetNowFn(newNow) 87 88 // Check if files have been deleted 89 waitTimeout := 30 * time.Second 90 require.NoError(t, waitUntilDataCleanedUp(commitLogOpts, testNamespaces[0], shard, now, waitTimeout)) 91 }