From 0acb3f6f3d342703f53a56a7e69d310390b9c9ac Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Mon, 20 Jan 2020 19:39:16 +0530 Subject: [PATCH] Fix L0/L1 stall test (#1201) The test `TestL0Stall` and `TestL1Stall` would never fail because of errors in the manifest file. This commit fixes it. --- levels.go | 9 +++------ levels_test.go | 20 ++++---------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/levels.go b/levels.go index 8d621f3e5..ece4a5900 100644 --- a/levels.go +++ b/levels.go @@ -44,12 +44,9 @@ type levelsController struct { kv *DB cstatus compactStatus -} - -var ( // This is for getting timings between stalls. lastUnstalled time.Time -) +} // revertToManifest checks that all necessary table files exist and removes all table files not // referenced by the manifest. idMap is a set of table file id's that were read from the directory @@ -929,7 +926,7 @@ func (s *levelsController) addLevel0Table(t *table.Table) error { // Stall. Make sure all levels are healthy before we unstall. var timeStart time.Time { - s.elog.Printf("STALLED STALLED STALLED: %v\n", time.Since(lastUnstalled)) + s.elog.Printf("STALLED STALLED STALLED: %v\n", time.Since(s.lastUnstalled)) s.cstatus.RLock() for i := 0; i < s.kv.opt.MaxLevels; i++ { s.elog.Printf("level=%d. Status=%s Size=%d\n", @@ -956,7 +953,7 @@ func (s *levelsController) addLevel0Table(t *table.Table) error { } { s.elog.Printf("UNSTALLED UNSTALLED UNSTALLED: %v\n", time.Since(timeStart)) - lastUnstalled = time.Now() + s.lastUnstalled = time.Now() } } diff --git a/levels_test.go b/levels_test.go index 66df2de01..b7554fbd0 100644 --- a/levels_test.go +++ b/levels_test.go @@ -468,7 +468,7 @@ func TestL1Stall(t *testing.T) { db.lc.levels[1].totalSize = 100 go func() { tab := createEmptyTable(db) - db.lc.addLevel0Table(tab) + require.NoError(t, db.lc.addLevel0Table(tab)) tab.DecrRef() done <- true }() @@ -499,24 +499,12 @@ func createEmptyTable(db *DB) *table.Table { b := table.NewTableBuilder(opts) // Add one key so that we can open this table. b.Add(y.KeyWithTs([]byte("foo"), 1), y.ValueStruct{}, 0) - fd, err := y.CreateSyncedFile(table.NewFilename(db.lc.reserveFileID(), db.opt.Dir), true) - if err != nil { - panic(err) - } - if _, err := fd.Write(b.Finish()); err != nil { - panic(err) - } - tab, err := table.OpenTable(fd, table.Options{}) + // Open table in memory to avoid adding changes to manifest file. + tab, err := table.OpenInMemoryTable(b.Finish(), db.lc.reserveFileID(), &opts) if err != nil { panic(err) } - // Add dummy entry to manifest file so that it doesn't complain during compaction. - if err := db.manifest.addChanges([]*pb.ManifestChange{ - newCreateChange(tab.ID(), 0, 0, tab.CompressionType()), - }); err != nil { - panic(err) - } return tab } @@ -537,7 +525,7 @@ func TestL0Stall(t *testing.T) { go func() { tab := createEmptyTable(db) - db.lc.addLevel0Table(tab) + require.NoError(t, db.lc.addLevel0Table(tab)) tab.DecrRef() done <- true }()