[SPARK-31425][SQL][CORE] UnsafeKVExternalSorter/VariableLengthRowBasedKeyValueBatch should also respect UnsafeAlignedOffset#28195
[SPARK-31425][SQL][CORE] UnsafeKVExternalSorter/VariableLengthRowBasedKeyValueBatch should also respect UnsafeAlignedOffset#28195Ngone51 wants to merge 13 commits intoapache:masterfrom
Conversation
|
Test build #121147 has finished for PR 28195 at commit
|
|
ping @cloud-fan @jiangxb1987 @kiszk Please take a look thanks! |
| // the key address instead of storing the absolute address of the value, the key and value | ||
| // must be stored in the same memory page. | ||
| // (8 byte key length) (key) (value) (8 byte pointer to next value) | ||
| // (uao: klen + vlen + uaolen) (uao: klen) (key) (value) (8 byte pointer to next value) |
There was a problem hiding this comment.
what does (uao: klen + vlen + uaolen) (uao: klen) mean?
There was a problem hiding this comment.
it's (total length) (key length) ...?
There was a problem hiding this comment.
yes, if total length here doesn't include the first uaoSize.
There was a problem hiding this comment.
How about using the similar description at lines 56-61?
There was a problem hiding this comment.
It will be a little bit redundant? Maybe just, (total length) (key length) (key) (value) (8 byte pointer to next value) ?
|
can we have a test? |
|
@Ngone51 Did you run other tests in the environment at uao=8. Then, did they pass? I am curious that the following files also depends on |
|
No, I'll check them later and fix together if needed. |
yet, I updated Seems better if we could update all those related tests to test both as well. |
| |once it has processed $fallbackStartsAt input rows). | ||
| |The query is ${actual.queryExecution} | ||
| |$errorMessage | ||
| """.stripMargin |
|
Test build #121195 has finished for PR 28195 at commit
|
|
I fixed BTW, I believe we don't need to fix |
| * probably be using sorting instead of hashing for better cache locality. | ||
| * | ||
| * The key and values under the hood are stored together, in the following format: | ||
| * The key and values under the hood are stored together, in the following format(uaoSize = 4): |
| long offset = keyRow.getBaseOffset(); | ||
| int klen = keyRow.getSizeInBytes(); | ||
| int vlen = Platform.getInt(base, offset - 8) - klen - 4; | ||
| int vlen = UnsafeAlignedOffset.getSize(base, offset - uaoSize - uaoSize) - klen - uaoSize; |
| totalLength = Platform.getInt(base, offsetInPage) - 4; | ||
| currentklen = Platform.getInt(base, offsetInPage + 4); | ||
| int uaoSize = UnsafeAlignedOffset.getUaoSize(); | ||
| int doubleUaoSize = uaoSize + uaoSize; |
There was a problem hiding this comment.
|
Test build #121262 has finished for PR 28195 at commit
|
|
Test build #121276 has finished for PR 28195 at commit
|
|
retest this please. |
|
Thank you for updating |
|
|
||
| fail(newErrorMessage) | ||
| case None => // Success | ||
| } |
There was a problem hiding this comment.
I am not confident, but do we need to call setUaoSize(0) at the end of this test? This is because TEST_UAO_SIZE is static.
There was a problem hiding this comment.
Oh, yeah. I think we have to reset it.
|
Test build #121284 has finished for PR 28195 at commit
|
|
Test build #121297 has finished for PR 28195 at commit
|
|
|
||
| public static int getUaoSize() { | ||
| return UAO_SIZE; | ||
| return TEST_UAO_SIZE == 0 ? UAO_SIZE : TEST_UAO_SIZE; |
There was a problem hiding this comment.
nit: you can use Utils.isTesting instead
There was a problem hiding this comment.
Other tests might not set UAO size manually, then we'll get 0 in this case.
There was a problem hiding this comment.
We should handle the logic of setting/reverting the size in the test code.
There was a problem hiding this comment.
then, we need to figure out all the test cases where used UnsafeAlignedOffset, right?
There was a problem hiding this comment.
Why do we need to do that? The default value of TEST_UAO_SIZE should be the same as UAO_SIZE, only if you want to test other values then you need to change it.
There was a problem hiding this comment.
Ok, I get your point. Let me update it later.
There was a problem hiding this comment.
hmm...unfortunately, unsafe project doesn't depend on core. So we can not access the Utils.
| * | ||
| * The key and values under the hood are stored together, in the following format: | ||
| * The key and values under the hood are stored together, in the following format(in case of | ||
| * uaoSize = 4): |
There was a problem hiding this comment.
why not replace the number below with uaoSize?
There was a problem hiding this comment.
I was supposed to do so but it requires more changes in the original content and it is not so clean compares to a concrete number. So I am not sure if we should do. Do you have strong prefer to change in uaoSize way?
There was a problem hiding this comment.
The current way doesn't make it clear whether each number 4 represents the uaoSize.
| Object vbase, long voff, int vlen) { | ||
| final long recordLength = 8L + klen + vlen + 8; | ||
| int uaoSize = UnsafeAlignedOffset.getUaoSize(); | ||
| int doubleUaoSize = 2 * uaoSize; |
There was a problem hiding this comment.
doubleUaoSize sounds strange, I'd keep the 2 * uaoSize in the computation...
| // Get encoded memory address | ||
| // baseObject + baseOffset point to the beginning of the key data in the map, but that | ||
| // the KV-pair's length data is stored in the word immediately before that address | ||
| // the KV-pair's length data is stored at 2 * uaoSize bytes immediately before that address |
There was a problem hiding this comment.
sorry I don't get it here why the address is related to uaoSize?
There was a problem hiding this comment.
The record format is:
(total length) (key length) (key) (value) (8 byte pointer to next value)
| |
uaoSize uaoSize
And we now get keyOffset, so we need back walk for 2 usao sizes to get the address of the record.
There was a problem hiding this comment.
so you mean we need to add back 2 * uaoSize to cover the space of storing total length and key length? If that's the case then it makes sense.
|
Test build #121324 has finished for PR 28195 at commit
|
|
Test build #121368 has finished for PR 28195 at commit
|
|
thanks, merging to master/3.0! |
…dKeyValueBatch should also respect UnsafeAlignedOffset ### What changes were proposed in this pull request? Make `UnsafeKVExternalSorter` / `VariableLengthRowBasedKeyValueBatch ` also respect `UnsafeAlignedOffset` when reading the record and update some out of date comemnts. ### Why are the changes needed? Since `BytesToBytesMap` respects `UnsafeAlignedOffset` when writing the record, `UnsafeKVExternalSorter` should also respect `UnsafeAlignedOffset` when reading the record from `BytesToBytesMap` otherwise it will causes data correctness issue. Unlike `UnsafeKVExternalSorter` may reading records from `BytesToBytesMap`, `VariableLengthRowBasedKeyValueBatch` writes and reads records by itself. Thus, similar to #22053 and [comment](#22053 (comment)) there, fix for `VariableLengthRowBasedKeyValueBatch` more likely an improvement for the support of SPARC platform. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? Manually tested `HashAggregationQueryWithControlledFallbackSuite` with `UAO_SIZE=8` to simulate SPARC platform. And tests only pass with this fix. Closes #28195 from Ngone51/fix_uao. Authored-by: yi.wu <yi.wu@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com> (cherry picked from commit 40f9dbb) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
|
thanks all! |
What changes were proposed in this pull request?
Make
UnsafeKVExternalSorter/VariableLengthRowBasedKeyValueBatchalso respectUnsafeAlignedOffsetwhen reading the record and update some out of date comemnts.Why are the changes needed?
Since
BytesToBytesMaprespectsUnsafeAlignedOffsetwhen writing the record,UnsafeKVExternalSortershould also respectUnsafeAlignedOffsetwhen reading the record fromBytesToBytesMapotherwise it will causes data correctness issue.Unlike
UnsafeKVExternalSortermay reading records fromBytesToBytesMap,VariableLengthRowBasedKeyValueBatchwrites and reads records by itself. Thus, similar to #22053 and comment there, fix forVariableLengthRowBasedKeyValueBatchmore likely an improvement for the support of SPARC platform.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Manually tested
HashAggregationQueryWithControlledFallbackSuitewithUAO_SIZE=8to simulate SPARC platform. And tests only pass with this fix.