klsince commented on a change in pull request #7301: URL: https://github.com/apache/pinot/pull/7301#discussion_r690827715
########## File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/SingleFileIndexDirectory.java ########## @@ -387,4 +401,53 @@ public boolean isIndexRemovalSupported() { public String toString() { return _segmentDirectory.toString() + "/" + _indexFile.toString(); } + + @VisibleForTesting + static List<IndexEntry> copyIndicesTo(File indexFile, Map<IndexKey, IndexEntry> toBeRetained, File tmpIdxFile) + throws IOException { + // Copy index from original index file and append to temp file. + // Keep track of the index entry pointing to the temp index file. + List<IndexEntry> retained = new ArrayList<>(); + long nextOffset = 0; + // With FileChannel, we can seek to the data flexibly. + try (FileChannel srcCh = new RandomAccessFile(indexFile, "r").getChannel(); + FileChannel dstCh = new RandomAccessFile(tmpIdxFile, "rw").getChannel()) { + for (Map.Entry<IndexKey, IndexEntry> next : toBeRetained.entrySet()) { + IndexKey key = next.getKey(); + IndexEntry idxPos = next.getValue(); + copyIndexTo(srcCh, idxPos.startOffset, idxPos.size, dstCh); Review comment: inlined next.getKey(), but will keep idxPos as it's referred 4 times here. idxPos as short for `index position`. lemme know how you'd like name it :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org