Skip to content

Commit 0acb3f6

Browse files
author
Ibrahim Jarif
authored
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.
1 parent 7e5a956 commit 0acb3f6

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

levels.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ type levelsController struct {
4444
kv *DB
4545

4646
cstatus compactStatus
47-
}
48-
49-
var (
5047
// This is for getting timings between stalls.
5148
lastUnstalled time.Time
52-
)
49+
}
5350

5451
// revertToManifest checks that all necessary table files exist and removes all table files not
5552
// 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 {
929926
// Stall. Make sure all levels are healthy before we unstall.
930927
var timeStart time.Time
931928
{
932-
s.elog.Printf("STALLED STALLED STALLED: %v\n", time.Since(lastUnstalled))
929+
s.elog.Printf("STALLED STALLED STALLED: %v\n", time.Since(s.lastUnstalled))
933930
s.cstatus.RLock()
934931
for i := 0; i < s.kv.opt.MaxLevels; i++ {
935932
s.elog.Printf("level=%d. Status=%s Size=%d\n",
@@ -956,7 +953,7 @@ func (s *levelsController) addLevel0Table(t *table.Table) error {
956953
}
957954
{
958955
s.elog.Printf("UNSTALLED UNSTALLED UNSTALLED: %v\n", time.Since(timeStart))
959-
lastUnstalled = time.Now()
956+
s.lastUnstalled = time.Now()
960957
}
961958
}
962959

levels_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func TestL1Stall(t *testing.T) {
468468
db.lc.levels[1].totalSize = 100
469469
go func() {
470470
tab := createEmptyTable(db)
471-
db.lc.addLevel0Table(tab)
471+
require.NoError(t, db.lc.addLevel0Table(tab))
472472
tab.DecrRef()
473473
done <- true
474474
}()
@@ -499,24 +499,12 @@ func createEmptyTable(db *DB) *table.Table {
499499
b := table.NewTableBuilder(opts)
500500
// Add one key so that we can open this table.
501501
b.Add(y.KeyWithTs([]byte("foo"), 1), y.ValueStruct{}, 0)
502-
fd, err := y.CreateSyncedFile(table.NewFilename(db.lc.reserveFileID(), db.opt.Dir), true)
503-
if err != nil {
504-
panic(err)
505-
}
506502

507-
if _, err := fd.Write(b.Finish()); err != nil {
508-
panic(err)
509-
}
510-
tab, err := table.OpenTable(fd, table.Options{})
503+
// Open table in memory to avoid adding changes to manifest file.
504+
tab, err := table.OpenInMemoryTable(b.Finish(), db.lc.reserveFileID(), &opts)
511505
if err != nil {
512506
panic(err)
513507
}
514-
// Add dummy entry to manifest file so that it doesn't complain during compaction.
515-
if err := db.manifest.addChanges([]*pb.ManifestChange{
516-
newCreateChange(tab.ID(), 0, 0, tab.CompressionType()),
517-
}); err != nil {
518-
panic(err)
519-
}
520508

521509
return tab
522510
}
@@ -537,7 +525,7 @@ func TestL0Stall(t *testing.T) {
537525

538526
go func() {
539527
tab := createEmptyTable(db)
540-
db.lc.addLevel0Table(tab)
528+
require.NoError(t, db.lc.addLevel0Table(tab))
541529
tab.DecrRef()
542530
done <- true
543531
}()

0 commit comments

Comments
 (0)