Fix: getting rid of EncOOOXOR from chunk encoding#12111
Fix: getting rid of EncOOOXOR from chunk encoding#12111codesome merged 5 commits intoprometheus:mainfrom
Conversation
jesusvazquez
left a comment
There was a problem hiding this comment.
So far the work looks good 💪
I left one nitpick about the naming of a couple of functions.
The most important comment is the one in the head where the head is still aware of ooo chunk encodings. I think we can fix this refactoring the function by adding a boolean saying if the chunk is ooo but lets wait for @codesome 's comments.
Great work!
tsdb/chunks/head_chunks.go
Outdated
| RestoreOutOfOrderMask = 0b01111111 | ||
| ) | ||
|
|
||
| func (cdm *ChunkDiskMapper) OutOfOrderEncoding(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { |
There was a problem hiding this comment.
I would rename this to ApplyOutOfOrderEncoding or something like that since its actually applying a mask over the giving encoding.
There was a problem hiding this comment.
Ok, will rename it as suggested.
There was a problem hiding this comment.
ApplyOutOfOrderMask is my suggestion. We are not changing encoding here. Reminder: we are not considering this bit as a part of encoding. For ChunkDiskMapper, only the last 7 bits are the encoding.
tsdb/chunks/head_chunks.go
Outdated
| return (e & OutOfOrderMask) != 0 | ||
| } | ||
|
|
||
| func (cdm *ChunkDiskMapper) OutOfOrderDecoding(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { |
There was a problem hiding this comment.
Same as above, we're applying a mask to decode
There was a problem hiding this comment.
Ok, will rename it as suggested.
There was a problem hiding this comment.
After getting rid of RestoreOutOfOrderMask as suggested, this can be renamed as UnapplyOutOfOrderMask.
tsdb/head.go
Outdated
| isOOO := h.chunkDiskMapper.IsOutOfOrderChunk(encoding) | ||
| // flip the first bit to restore the original encoding | ||
| if isOOO { | ||
| encoding = h.chunkDiskMapper.OutOfOrderDecoding(encoding) |
There was a problem hiding this comment.
Hm I wonder what could be done here, it seems here the head is aware of OOO chunk encodings and this is precisely what we wanted to hide in the chunk disk mapper.
Maybe we could change the function to return a boolean saying if its OOO instead of the encoding and then if its OOO we add it to oooMmappedChunks and if its not we add it to mmappedChunks
What do you think @codesome
There was a problem hiding this comment.
@jesusvazquez Can you point out as to which function you want to return bool.
The current function is part of the load chunks from initial read. I have tried to put all the logic in CDM. Do you want me to pass this bool as part of the callback function inside the IterateAllChunks ?
There was a problem hiding this comment.
Right! I believe I added the encoding to that function when we added the OOO chunks. If you notice the usages I think it should be fairly easy to change.
prometheus/tsdb/chunks/head_chunks.go
Line 765 in 3330d85
I would change that signature to something like
func (cdm *ChunkDiskMapper) IterateAllChunks(f func(seriesRef HeadSeriesRef, chunkRef ChunkDiskMapperRef, mint, maxt int64, numSamples uint16, isOOO bool) error) (err error) {
That will force you to refactor the call in
Line 737 in 1f0cc09
There was a problem hiding this comment.
+1 with what @jesusvazquez said. Let's change the function signature to return the isOOO boolean such that head doesn't need to infer it from the chunk encoding. The encoding coming out of ChunkDiskMapper here should have that ooo bit removed.
tsdb/chunks/head_chunks.go
Outdated
| OutOfOrderMask = 0b10000000 | ||
| RestoreOutOfOrderMask = 0b01111111 |
There was a problem hiding this comment.
We can use a single variable and get the RestoreOutOfOrderMask as ^OutOfOrderMask (note the uint8, else it can be buggy) https://goplay.tools/snippet/dCb5_qkFCbL
| OutOfOrderMask = 0b10000000 | |
| RestoreOutOfOrderMask = 0b01111111 | |
| OutOfOrderMask = uint8(0b10000000) |
tsdb/chunks/head_chunks.go
Outdated
| chkEnc := mmapFile.byteSlice.Range(chkStart, chkStart+ChunkEncodingSize)[0] | ||
|
|
||
| sourceChkEnc := chunkenc.Encoding(chkEnc) | ||
| if cdm.IsOutOfOrderChunk(sourceChkEnc) { |
There was a problem hiding this comment.
You don't need this if check. You can simply just apply the bit mask everytime.
tsdb/chunks/head_chunks.go
Outdated
| RestoreOutOfOrderMask = 0b01111111 | ||
| ) | ||
|
|
||
| func (cdm *ChunkDiskMapper) OutOfOrderEncoding(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { |
There was a problem hiding this comment.
ApplyOutOfOrderMask is my suggestion. We are not changing encoding here. Reminder: we are not considering this bit as a part of encoding. For ChunkDiskMapper, only the last 7 bits are the encoding.
tsdb/chunks/head_chunks.go
Outdated
| return (e & OutOfOrderMask) != 0 | ||
| } | ||
|
|
||
| func (cdm *ChunkDiskMapper) OutOfOrderDecoding(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { |
There was a problem hiding this comment.
After getting rid of RestoreOutOfOrderMask as suggested, this can be renamed as UnapplyOutOfOrderMask.
|
@codesome / @jesusvazquez any other changes need in this PR. Do let me know. |
tsdb/chunks/head_chunks.go
Outdated
| // Chunk encodings for out-of-order chunks. | ||
| // These encodings must be only used by the Head block for its internal bookkeeping. | ||
| const ( | ||
| OutOfOrderMask = 0b10000000 |
There was a problem hiding this comment.
This should be uint8 to begin with and don't need typecasting elsewhere, else it can lead buggy code if not used correctly.
| OutOfOrderMask = 0b10000000 | |
| OutOfOrderMask = uint8(0b10000000) |
tsdb/chunks/head_chunks.go
Outdated
| chkEnc := mmapFile.byteSlice.Range(chkStart, chkStart+ChunkEncodingSize)[0] | ||
|
|
||
| sourceChkEnc := chunkenc.Encoding(chkEnc) | ||
| // update the chunk encoding by restoring the original encoding, if needed |
There was a problem hiding this comment.
Other than the reword, in Prometheus we start comments with capital letters where applicable and end with a full stop.
| // update the chunk encoding by restoring the original encoding, if needed | |
| // Extract the encoding from the byte. ChunkDiskMapper uses only the last 7 bits for the encoding. |
tsdb/chunks/head_chunks.go
Outdated
| // flip the first bit to restore the original encoding | ||
| if isOOO { | ||
| chkEnc = cdm.UnapplyOutOfOrderMask(chkEnc) | ||
| } |
There was a problem hiding this comment.
Same reword as the other comment + don't need the if block.
| // flip the first bit to restore the original encoding | |
| if isOOO { | |
| chkEnc = cdm.UnapplyOutOfOrderMask(chkEnc) | |
| } | |
| // Extract the encoding from the byte. ChunkDiskMapper uses only the last 7 bits for the encoding. | |
| chkEnc = cdm.UnapplyOutOfOrderMask(chkEnc) |
tsdb/chunks/head_chunks.go
Outdated
| return (e & OutOfOrderMask) != 0 | ||
| } | ||
|
|
||
| func (cdm *ChunkDiskMapper) UnapplyOutOfOrderMask(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { |
There was a problem hiding this comment.
On another thought, I think this is better. Making it less specific to OOO such that it can be extended later if needed.
| func (cdm *ChunkDiskMapper) UnapplyOutOfOrderMask(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { | |
| func (cdm *ChunkDiskMapper) RemoveMasks(sourceEncoding chunkenc.Encoding) chunkenc.Encoding { |
Signed-off-by: mabhi <[email protected]>
…O encoding logic Signed-off-by: mabhi <[email protected]>
Signed-off-by: mabhi <[email protected]>
Signed-off-by: mabhi <[email protected]>
codesome
left a comment
There was a problem hiding this comment.
Last comment and we can merge. LGTM!
Signed-off-by: mabhi <[email protected]>
Explanation
Getting rid of EncOOOXOR from chunk encoding, as this is not an encoding but a flag to mark OOO encoded chunks
Related Issue:
Fixes #11835
Proposed Changes
OOOXORChunkstructChunkDiskMapperwith the responsibility to verify for OOOChunks, apply OOO header and restore original encodingisOOOflag to persist the extra 1st bit and that would be used during reads to check for OOO chunks and restore the original encoding for further processing.Proof Manifests