Fixes a problem where duplicate ids might have been created during the compaction process
@@ -51,12 +51,16 @@ func (s *segmentCursorReplace) seek(key []byte) ([]byte, []byte, error) {
err = s.segment.replaceStratParseDataWithKeyInto(
s.segment.contents[node.Start:node.End], s.reusableNode)
+
+ // make sure to set the next offset before checking the error. The error
+ // could be 'Deleted' which would require that the offset is still advanced
+ // for the next cycle
+ s.nextOffset = node.End
+
if err != nil {
return s.reusableNode.primaryKey, nil, err
}
- s.nextOffset = node.End
-
return s.reusableNode.primaryKey, s.reusableNode.value, nil
}
@@ -83,12 +87,15 @@ func (s *segmentCursorReplace) first() ([]byte, []byte, error) {
s.nextOffset = s.segment.dataStartPos
err := s.segment.replaceStratParseDataWithKeyInto(
s.segment.contents[s.nextOffset:], s.reusableNode)
+
+ // make sure to set the next offset before checking the error. The error
+ // could be 'Deleted' which would require that the offset is still advanced
+ // for the next cycle
+ s.nextOffset = s.nextOffset + uint64(s.reusableNode.offset)
if err != nil {
return s.reusableNode.primaryKey, nil, err
}
- s.nextOffset = s.nextOffset + uint64(s.reusableNode.offset)
-
return s.reusableNode.primaryKey, s.reusableNode.value, nil
}
@@ -116,10 +123,14 @@ func (s *segmentCursorReplace) firstWithAllKeys() (segmentReplaceNode, error) {
s.nextOffset = s.segment.dataStartPos
parsed, err := s.segment.replaceStratParseDataWithKey(
s.segment.contents[s.nextOffset:])
+
+ // make sure to set the next offset before checking the error. The error
+ // could be 'Deleted' which would require that the offset is still advanced
+ // for the next cycle
+ s.nextOffset = s.nextOffset + uint64(parsed.offset)
if err != nil {
return parsed, err
}
- s.nextOffset = s.nextOffset + uint64(parsed.offset)
return parsed, nil
}
