Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Dec 7, 2022
1 parent 4eb1ce2 commit f2b7ede
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
10 changes: 3 additions & 7 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,9 @@ func diffNodes(nodes1 []*Node, nodes2 []*Node) ([]*Node, []*Node) {
node2 := nodes2[i2]
switch bytes.Compare(node1.key, node2.key) {
case 0:
if node1.version == node2.version {
// we assume they are the same nodes without comparing hashes,
// since they have the same (height, key, version).
if bytes.Compare(nodes1[i1].hash, nodes2[i2].hash) != 0 {
panic("invariant")
}
} else {
// we assume they are the same nodes without comparing hashes
// if they have the same (height, key, version).
if node1.version != node2.version {
// overridden by same key
orphaned = append(orphaned, node1)
new = append(new, node2)
Expand Down
32 changes: 11 additions & 21 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ func (ndb *nodeDB) resetBatch() error {
return nil
}

// Contract: successor must exists, predecessor can be 0 if don't exists.
// calls deleteOrphans, deleteRoot
// Contract:
// - successor must exists, predecessor can be 0 if don't exists.
// - predecessor < version < successor
// - no other versions between predecessor, version, successor
func (ndb *nodeDB) deleteVersion(version, predecessor, successor int64) error {
if err := ndb.deleteOrphans(version, predecessor, successor); err != nil {
return err
Expand Down Expand Up @@ -471,7 +473,9 @@ func (ndb *nodeDB) rollbackVersion(version, predecessor int64) error {
stack = append(stack, node.rightHash, node.leftHash)
}
}
ndb.batch.Delete(ndb.rootKey(version))
if err := ndb.batch.Delete(ndb.rootKey(version)); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -605,8 +609,10 @@ func (ndb *nodeDB) DeleteFastNode(key []byte) error {
}

// deleteOrphans deletes orphaned nodes from disk by comparing the related versions.
// Contract: predecessor < version < successor, and there's no other version in between.
// predecessor could be 0 if don't exists, successor must exist.
// Contract:
// - predecessor < version < successor
// - there's no other version in between
// - predecessor could be 0 if don't exists, successor must exist.
func (ndb *nodeDB) deleteOrphans(version, predecessor, successor int64) error {
var (
root1, root2 *Node
Expand Down Expand Up @@ -730,22 +736,6 @@ func (ndb *nodeDB) getNextVersion(version int64) (int64, error) {
return 0, nil
}

// deleteRoot deletes the root entry from disk, but not the node it points to.
func (ndb *nodeDB) deleteRoot(version int64, checkLatestVersion bool) error {
latestVersion, err := ndb.getLatestVersion()
if err != nil {
return err
}

if checkLatestVersion && version == latestVersion {
return errors.New("tried to delete latest version")
}
if err := ndb.batch.Delete(ndb.rootKey(version)); err != nil {
return err
}
return nil
}

// Traverse fast nodes and return error if any, nil otherwise
func (ndb *nodeDB) traverseFastNodes(fn func(k, v []byte) error) error {
return ndb.traversePrefix(fastKeyFormat.Key(), fn)
Expand Down

0 comments on commit f2b7ede

Please sign in to comment.