Skip to content

Commit

Permalink
Fix L0/L1 stall test (#1201)
Browse files Browse the repository at this point in the history
The test `TestL0Stall` and `TestL1Stall` would never fail
because of errors in the manifest file. This commit fixes it.
  • Loading branch information
Ibrahim Jarif authored Jan 20, 2020
1 parent 7e5a956 commit 0acb3f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
9 changes: 3 additions & 6 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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()
}
}

Expand Down
20 changes: 4 additions & 16 deletions levels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}()
Expand Down

0 comments on commit 0acb3f6

Please sign in to comment.