From 3933c5648c016c752c11ab90d7ea3cbfab06d5b6 Mon Sep 17 00:00:00 2001 From: Eduardo Ramirez Date: Fri, 30 Aug 2024 08:39:06 -0700 Subject: [PATCH] Refactor set and map for copyBucketsFrom --- .../list/HollowListTypeDataElements.java | 14 +++++++++++ .../HollowListTypeDataElementsJoiner.java | 22 ++++-------------- .../HollowListTypeDataElementsSplitter.java | 18 +++------------ .../engine/map/HollowMapTypeDataElements.java | 18 +++++++++++++++ .../map/HollowMapTypeDataElementsJoiner.java | 22 +++--------------- .../HollowMapTypeDataElementsSplitter.java | 23 +++---------------- .../engine/set/HollowSetTypeDataElements.java | 2 -- ...ollowSetTypeDataElementsSplitJoinTest.java | 4 +++- 8 files changed, 49 insertions(+), 74 deletions(-) diff --git a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElements.java b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElements.java index bba58719a..006dc888d 100644 --- a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElements.java +++ b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElements.java @@ -113,4 +113,18 @@ public long getStartElement(int ordinal) { public long getEndElement(int ordinal) { return listPointerData.getElementValue((long)ordinal * bitsPerListPointer, bitsPerListPointer); } + + public void copyElementsFrom(long startElement, HollowListTypeDataElements src, long srcStartElement, long srcEndElement) { + if (bitsPerElement == src.bitsPerElement) { + // fast path can bulk copy elements + long numElements = srcEndElement - srcStartElement; + elementData.copyBits(src.elementData, srcStartElement * bitsPerElement, startElement * bitsPerElement, numElements * bitsPerElement); + } else { + for (long element=srcStartElement;element> fromOrdinalShift; - if (fromOrdinal <= from[fromIndex].maxOrdinal) { + if (fromOrdinal <= from[fromIndex].maxOrdinal) { // else lopsided shard for e.g. when consumers skip type shards with no additions HollowListTypeDataElements source = from[fromIndex]; long startElement = source.getStartElement(fromOrdinal); long endElement = source.getEndElement(fromOrdinal); - if (source.bitsPerElement == to.bitsPerElement) { - // fastpath can bulk copy elements. emptyBucketValue is same since bitsPerElement is same - long numElements = endElement - startElement; - int bitsPerElement = source.bitsPerElement; - to.elementData.copyBits(source.elementData, startElement * bitsPerElement, elementCounter * bitsPerElement, numElements * bitsPerElement); - elementCounter += numElements; - } else { - for (long element = startElement; element < endElement; element++) { - int elementOrdinal = (int) source.elementData.getElementValue(element * source.bitsPerElement, source.bitsPerElement); - to.elementData.setElementValue(elementCounter * to.bitsPerElement, to.bitsPerElement, elementOrdinal); - elementCounter++; - } - } - } // else: lopsided shard for e.g. when consumers skip type shards with no additions. - // nothing is written to elementData and the cached value of elementCounter is written to listPointerData. - + long numElements = endElement - startElement; + to.copyElementsFrom(elementCounter, source, startElement, endElement); + elementCounter += numElements; + } to.listPointerData.setElementValue((long) to.bitsPerListPointer * ordinal, to.bitsPerListPointer, elementCounter); } } diff --git a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElementsSplitter.java b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElementsSplitter.java index b26aec70c..6562ac574 100644 --- a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElementsSplitter.java +++ b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeDataElementsSplitter.java @@ -71,21 +71,9 @@ public void copyRecords() { long endElement = from.getEndElement(ordinal); HollowListTypeDataElements target = to[toIndex]; - if (from.bitsPerElement == target.bitsPerElement) { - // fast path can bulk copy elements. emptyBucketValue is same since bitsPerElement is same - long numElements = endElement - startElement; - int bitsPerElement = from.bitsPerElement; - target.elementData.copyBits(from.elementData, startElement * bitsPerElement, elementCounter[toIndex] * bitsPerElement, numElements * bitsPerElement); - elementCounter[toIndex] += numElements; - } else { - // slow path(but more compact) not exercised until populateSats above supports split shard specific bitsPerElement - // (which would make sense to add once HollowListTypeWriteState's gatherStatistics supports assigning bitsPerElement at a shard level) - for (long element=startElement;element