-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 8byte offsets in chunk based raw index creator #5285
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.pinot.core.io.writer.impl.v1; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
@@ -37,6 +38,8 @@ | |
*/ | ||
public abstract class BaseChunkSingleValueWriter implements SingleColumnSingleValueWriter { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(BaseChunkSingleValueWriter.class); | ||
private static final int FILE_HEADER_ENTRY_CHUNK_OFFSET_SIZE_V1V2 = Integer.BYTES; | ||
private static final int FILE_HEADER_ENTRY_CHUNK_OFFSET_SIZE_V3 = Long.BYTES; | ||
|
||
protected final FileChannel _dataFile; | ||
protected ByteBuffer _header; | ||
|
@@ -45,7 +48,9 @@ public abstract class BaseChunkSingleValueWriter implements SingleColumnSingleVa | |
protected final ChunkCompressor _chunkCompressor; | ||
|
||
protected int _chunkSize; | ||
protected int _dataOffset; | ||
protected long _dataOffset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
private final int _headerEntryChunkOffsetSize; | ||
|
||
/** | ||
* Constructor for the class. | ||
|
@@ -64,13 +69,25 @@ protected BaseChunkSingleValueWriter(File file, ChunkCompressorFactory.Compressi | |
throws FileNotFoundException { | ||
_chunkSize = chunkSize; | ||
_chunkCompressor = ChunkCompressorFactory.getCompressor(compressionType); | ||
|
||
_headerEntryChunkOffsetSize = getHeaderEntryChunkOffsetSize(version); | ||
_dataOffset = writeHeader(compressionType, totalDocs, numDocsPerChunk, sizeOfEntry, version); | ||
_chunkBuffer = ByteBuffer.allocateDirect(chunkSize); | ||
_compressedBuffer = ByteBuffer.allocateDirect(chunkSize * 2); | ||
_dataFile = new RandomAccessFile(file, "rw").getChannel(); | ||
} | ||
|
||
public static int getHeaderEntryChunkOffsetSize(int version) { | ||
switch (version) { | ||
case 1: | ||
case 2: | ||
return FILE_HEADER_ENTRY_CHUNK_OFFSET_SIZE_V1V2; | ||
case 3: | ||
return FILE_HEADER_ENTRY_CHUNK_OFFSET_SIZE_V3; | ||
default: | ||
throw new IllegalStateException("Invalid version: " + version); | ||
} | ||
} | ||
|
||
@Override | ||
public void setChar(int row, char ch) { | ||
throw new UnsupportedOperationException(); | ||
|
@@ -139,7 +156,7 @@ public void close() | |
private int writeHeader(ChunkCompressorFactory.CompressionType compressionType, int totalDocs, int numDocsPerChunk, | ||
int sizeOfEntry, int version) { | ||
int numChunks = (totalDocs + numDocsPerChunk - 1) / numDocsPerChunk; | ||
int headerSize = (numChunks + 7) * Integer.BYTES; // 7 items written before chunk indexing. | ||
int headerSize = (7 * Integer.BYTES) + (numChunks * _headerEntryChunkOffsetSize); | ||
|
||
_header = ByteBuffer.allocateDirect(headerSize); | ||
|
||
|
@@ -196,7 +213,12 @@ protected void writeChunk() { | |
throw new RuntimeException(e); | ||
} | ||
|
||
_header.putInt(_dataOffset); | ||
if (_headerEntryChunkOffsetSize == Integer.BYTES) { | ||
_header.putInt((int)_dataOffset); | ||
} else if (_headerEntryChunkOffsetSize == Long.BYTES) { | ||
_header.putLong(_dataOffset); | ||
} | ||
|
||
_dataOffset += sizeToWrite; | ||
|
||
_chunkBuffer.clear(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.
I would also introduce a
private final _headerEntryChunkOffsetSize
here, and initialize it by calling a methodgetHeaderEntryChunkOffssetSize(version)
in the writer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@mcvsubbu , this actually comes handy now itself since I haven't bumped the version of fixed byte chunk writer. It is still on version 2 and using 4-byte chunk offset entries in file header. So the current changes protect compatibility of v1/v2 for var-byte, read/write new var byte in v3 and still continue to read/write fixed byte indexes in v1/v2.
I am having mixed opinions on bumping up the version of fixed byte chunk writer to use 8byte offsets as well. The thing is that if we don't bump it up and tomorrow file format for fixed byte changes (for some reason), then we will bump it up to 3. At that time it will automatically get 8-byte offsets by virtue of being at version >=3. So may be do it now and keep the versions same.
The flip side is that you would ideally want to evolve fixed-byte and var-byte formats independently (which is what is done in this PR by keeping the fixed byte writer still at version 2). Obviously if we separate out base class and duplicate code, then things will be simplified but that's not the best option. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and var byte formats cannot evolve independently unless we split the base class like you said. Some duplication can be avoided, but in the end, the version number at the top should decide what the format is, underneath.
I guess the con side of moving this for fixed byte will be that storage will (almost) double for the fixed byte no-dictionary columns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No my bad. It will be double offset per chunk, so it should be ok. Let us just make it 8 bytes for all like we discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. It is better to keep the version/format same so we will use 8-byte chunk offsets for fixed-byte indexes as well.
Storage overhead - Consider a segment with 10million rows. Since we currently pack 1000 rows in a fixed byte chunk, there will be 10k chunks. If the file header has 8-byte chunk offsets instead of 4, the storage overhead for the raw forward index of the particular column goes up by 40KB (10000 chunks * 4). Extrapolating this to 1000 segments on the server with roughly 5 fixed width no dictionary columns per segment, we are looking at 40KB * 1000 * 5 = 200MB
Will make the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes as discussed