Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/5836#discussion_r29559857
--- Diff:
unsafe/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java ---
@@ -173,18 +173,31 @@ public BytesToBytesMap(
public Iterator<Location> iterator() {
return new Iterator<Location>() {
- private int nextPos = bitset.nextSetBit(0);
+ private int cur = 0;
+
+ private int pageCur = 0;
+
+ private MemoryBlock currentPage = dataPages.get(0);
+
+ private long addr = currentPage.getBaseOffset();
@Override
public boolean hasNext() {
- return nextPos != -1;
+ return cur != size;
}
@Override
public Location next() {
- final int pos = nextPos;
- nextPos = bitset.nextSetBit(nextPos + 1);
- return loc.with(pos, 0, true);
+ long keySize =
PlatformDependent.UNSAFE.getLong(memoryManager.getPage(addr), addr);
+ if (keySize == 0) {
--- End diff --
In order for this to be safe, we should guarantee that an empty (0) length
field is written at the end of the data page. By zeroing out allocated memory,
it looks like your change will accomplish this for pages that have leftover
padding space at the end, but I don't think that works in every case since
we're not guaranteed to have padding at the end of the data page. Instead, I
think that we should reserve an 8-byte word at the end of the page (so we're
guaranteed to have enough space to write the empty length marker), then write
the length marker when rolling over to a new page (or at the end of the
`currentPage` right before we begin iterating).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]