diff --git a/key_format.go b/key_format.go index 597c0efbf..fb71e0212 100644 --- a/key_format.go +++ b/key_format.go @@ -38,6 +38,7 @@ func (kf *KeyFormat) KeyBytes(segments ...[]byte) []byte { panic(fmt.Errorf("length of segment %X provided to KeyFormat.Key() is longer than the %d bytes "+ "required by layout for segment %d", s, l, i)) } + // Big endian so pad on left if not given the full width for this segment copy(key[n+(l-len(s)):n+l], s) n += l } @@ -101,7 +102,7 @@ func scan(a interface{}, value []byte) { case *[]byte: *v = value default: - panic(fmt.Errorf("KeyFormat.scan() does not support scanning value of type %T: %v", a, a)) + panic(fmt.Errorf("KeyFormat scan() does not support scanning value of type %T: %v", a, a)) } } @@ -122,6 +123,6 @@ func format(a interface{}) []byte { case []byte: return v default: - panic(fmt.Errorf("KeyFormat.format() does not support formatting value of type %T: %v", a, a)) + panic(fmt.Errorf("KeyFormat format() does not support formatting value of type %T: %v", a, a)) } } diff --git a/nodedb.go b/nodedb.go index a589a5fc2..1844ded05 100644 --- a/nodedb.go +++ b/nodedb.go @@ -17,19 +17,19 @@ const ( ) var ( - // All node keys are prefixed with this. This ensures no collision is - // possible with the other keys, and makes them easier to traverse. - nodeKeyFormat = NewKeyFormat('n', hashSize) + // All node keys are prefixed with the byte 'n'. This ensures no collision is + // possible with the other keys, and makes them easier to traverse. They are indexed by the node hash. + nodeKeyFormat = NewKeyFormat('n', hashSize) // n // Orphans are keyed in the database by their expected lifetime. // The first number represents the *last* version at which the orphan needs // to exist, while the second number represents the *earliest* version at // which it is expected to exist - which starts out by being the version // of the node being orphaned. - orphanKeyFormat = NewKeyFormat('o', int64Size, int64Size, hashSize) + orphanKeyFormat = NewKeyFormat('o', int64Size, int64Size, hashSize) // o - // r/ - rootKeyFormat = NewKeyFormat('r', int64Size) + // Root nodes are indexed separately by their version + rootKeyFormat = NewKeyFormat('r', int64Size) // r ) type nodeDB struct {