Skip to content

Commit

Permalink
Rename kv to db, and move Infof to db.opt
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain committed Jan 14, 2019
1 parent 56a2843 commit fd5f30a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,41 +75,41 @@ func revertToManifest(kv *DB, mf *Manifest, idMap map[uint64]struct{}) error {
return nil
}

func newLevelsController(kv *DB, mf *Manifest) (*levelsController, error) {
y.AssertTrue(kv.opt.NumLevelZeroTablesStall > kv.opt.NumLevelZeroTables)
func newLevelsController(db *DB, mf *Manifest) (*levelsController, error) {
y.AssertTrue(db.opt.NumLevelZeroTablesStall > db.opt.NumLevelZeroTables)
s := &levelsController{
kv: kv,
elog: kv.elog,
levels: make([]*levelHandler, kv.opt.MaxLevels),
kv: db,
elog: db.elog,
levels: make([]*levelHandler, db.opt.MaxLevels),
}
s.cstatus.levels = make([]*levelCompactStatus, kv.opt.MaxLevels)
s.cstatus.levels = make([]*levelCompactStatus, db.opt.MaxLevels)

for i := 0; i < kv.opt.MaxLevels; i++ {
s.levels[i] = newLevelHandler(kv, i)
for i := 0; i < db.opt.MaxLevels; i++ {
s.levels[i] = newLevelHandler(db, i)
if i == 0 {
// Do nothing.
} else if i == 1 {
// Level 1 probably shouldn't be too much bigger than level 0.
s.levels[i].maxTotalSize = kv.opt.LevelOneSize
s.levels[i].maxTotalSize = db.opt.LevelOneSize
} else {
s.levels[i].maxTotalSize = s.levels[i-1].maxTotalSize * int64(kv.opt.LevelSizeMultiplier)
s.levels[i].maxTotalSize = s.levels[i-1].maxTotalSize * int64(db.opt.LevelSizeMultiplier)
}
s.cstatus.levels[i] = new(levelCompactStatus)
}

// Compare manifest against directory, check for existent/non-existent files, and remove.
if err := revertToManifest(kv, mf, getIDMap(kv.opt.Dir)); err != nil {
if err := revertToManifest(db, mf, getIDMap(db.opt.Dir)); err != nil {
return nil, err
}

// Some files may be deleted. Let's reload.
var flags uint32 = y.Sync
if kv.opt.ReadOnly {
if db.opt.ReadOnly {
flags |= y.ReadOnly
}

var mu sync.Mutex
tables := make([][]*table.Table, kv.opt.MaxLevels)
tables := make([][]*table.Table, db.opt.MaxLevels)
var maxFileID uint64

// We found that using 3 goroutines allows disk throughput to be utilized to its max.
Expand All @@ -123,10 +123,10 @@ func newLevelsController(kv *DB, mf *Manifest) (*levelsController, error) {
defer tick.Stop()

for fileID, tableManifest := range mf.Tables {
fname := table.NewFilename(fileID, kv.opt.Dir)
fname := table.NewFilename(fileID, db.opt.Dir)
select {
case <-tick.C:
Infof("%d tables out of %d opened in %s\n", atomic.LoadInt32(&numOpened),
db.opt.Infof("%d tables out of %d opened in %s\n", atomic.LoadInt32(&numOpened),
len(mf.Tables), time.Since(start).Round(time.Millisecond))
default:
}
Expand All @@ -149,7 +149,7 @@ func newLevelsController(kv *DB, mf *Manifest) (*levelsController, error) {
return
}

t, err := table.OpenTable(fd, kv.opt.TableLoadingMode)
t, err := table.OpenTable(fd, db.opt.TableLoadingMode)
if err != nil {
rerr = errors.Wrapf(err, "Opening table: %q", fname)
return
Expand All @@ -164,7 +164,7 @@ func newLevelsController(kv *DB, mf *Manifest) (*levelsController, error) {
closeAllTables(tables)
return nil, err
}
Infof("All %d tables opened in %s\n", atomic.LoadInt32(&numOpened),
db.opt.Infof("All %d tables opened in %s\n", atomic.LoadInt32(&numOpened),
time.Since(start).Round(time.Millisecond))
s.nextFileID = maxFileID + 1
for i, tbls := range tables {
Expand All @@ -179,7 +179,7 @@ func newLevelsController(kv *DB, mf *Manifest) (*levelsController, error) {

// Sync directory (because we have at least removed some files, or previously created the
// manifest file).
if err := syncDir(kv.opt.Dir); err != nil {
if err := syncDir(db.opt.Dir); err != nil {
_ = s.close()
return nil, err
}
Expand Down

0 comments on commit fd5f30a

Please sign in to comment.