Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new assertion #45

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions level_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,21 @@ func (s *levelHandler) deleteTables(toDel []*table.Table) error {
}
s.tables = newTables

assertTablesOrder(newTables)

s.Unlock() // Unlock s _before_ we DecrRef our tables, which can be slow.

return decrRefs(toDel)
}

func assertTablesOrder(tables []*table.Table) {
for i := 0; i < len(tables)-1; i++ {
y.AssertTrue(y.CompareKeys(tables[i].Smallest(), tables[i].Biggest()) <= 0)
y.AssertTrue(y.CompareKeys(tables[i].Smallest(), tables[i+1].Smallest()) < 0)
y.AssertTrue(y.CompareKeys(tables[i].Biggest(), tables[i+1].Biggest()) < 0)
}
}

// replaceTables will replace tables[left:right] with newTables. Note this EXCLUDES tables[right].
// You must call decr() to delete the old tables _after_ writing the update to the manifest.
func (s *levelHandler) replaceTables(newTables []*table.Table) error {
Expand All @@ -110,6 +120,9 @@ func (s *levelHandler) replaceTables(newTables []*table.Table) error {
return nil
}

assertTablesOrder(newTables)
assertTablesOrder(s.tables)

s.Lock() // We s.Unlock() below.

// Increase totalSize first.
Expand Down Expand Up @@ -142,6 +155,7 @@ func (s *levelHandler) replaceTables(newTables []*table.Table) error {
t = t[numAdded:]
y.AssertTrue(len(s.tables[right:]) == copy(t, s.tables[right:]))
s.tables = tables
assertTablesOrder(tables)
s.Unlock() // s.Unlock before we DecrRef tables -- that can be slow.
return decrRefs(toDecr)
}
Expand Down