Skip to content

Commit

Permalink
fixup! feat: concat indexes in the same object
Browse files Browse the repository at this point in the history
Apply latest suggestions
  • Loading branch information
jeqo committed Oct 10, 2023
1 parent 867d8b0 commit fb3bc34
Showing 1 changed file with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,15 @@
import static org.apache.kafka.server.log.remote.storage.RemoteStorageManager.IndexType;

public class SegmentIndexesV1Builder {
final Map<IndexType, SegmentIndexV1> indexes = new HashMap<>(IndexType.values().length);
int currentPosition = 0;
private final Map<IndexType, SegmentIndexV1> indexes = new HashMap<>(IndexType.values().length);
private int currentPosition = 0;

public SegmentIndexesV1Builder add(final IndexType indexType, final int size) {
if (indexes.containsKey(indexType)) {
throw new IllegalStateException("Index " + indexType + " is already added");
}
switch (indexType) {
case OFFSET:
indexes.put(IndexType.OFFSET, new SegmentIndexV1(0, size));
currentPosition += size;
break;
case TIMESTAMP:
indexes.put(IndexType.TIMESTAMP, new SegmentIndexV1(currentPosition, size));
currentPosition += size;
break;
case PRODUCER_SNAPSHOT:
indexes.put(IndexType.PRODUCER_SNAPSHOT, new SegmentIndexV1(currentPosition, size));
currentPosition += size;
break;
case LEADER_EPOCH:
indexes.put(IndexType.LEADER_EPOCH, new SegmentIndexV1(currentPosition, size));
currentPosition += size;
break;
case TRANSACTION:
indexes.put(IndexType.TRANSACTION, new SegmentIndexV1(currentPosition, size));
currentPosition += size;
break;
default:
throw new IllegalStateException("Unknown index type");
}
indexes.put(indexType, new SegmentIndexV1(currentPosition, size));
currentPosition += size;
return this;
}

Expand Down

0 comments on commit fb3bc34

Please sign in to comment.