From 882de97b5c7ffd2dc3bae51214e26b692f439e3f Mon Sep 17 00:00:00 2001 From: Sunjeet Singh Date: Tue, 3 Sep 2024 19:10:09 -0700 Subject: [PATCH] shard holders for other types --- .../core/read/engine/HollowTypeReadState.java | 6 --- .../HollowListTypeReshardingStrategy.java | 1 - .../list/HollowListTypeShardsHolder.java | 53 +++++++++++++++++++ .../map/HollowMapTypeReshardingStrategy.java | 1 - .../engine/map/HollowMapTypeShardsHolder.java | 53 +++++++++++++++++++ ...llowObjectDeltaHistoricalStateCreator.java | 2 +- .../object/HollowObjectTypeReadState.java | 42 +++++++-------- .../HollowObjectTypeReshardingStrategy.java | 1 - ...java => HollowObjectTypeShardsHolder.java} | 18 +++++-- .../set/HollowSetTypeReshardingStrategy.java | 1 - .../engine/set/HollowSetTypeShardsHolder.java | 53 +++++++++++++++++++ .../object/HollowObjectTypeReadStateTest.java | 6 +-- 12 files changed, 198 insertions(+), 39 deletions(-) create mode 100644 hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeShardsHolder.java create mode 100644 hollow/src/main/java/com/netflix/hollow/core/read/engine/map/HollowMapTypeShardsHolder.java rename hollow/src/main/java/com/netflix/hollow/core/read/engine/object/{ObjectTypeShardsHolder.java => HollowObjectTypeShardsHolder.java} (59%) create mode 100644 hollow/src/main/java/com/netflix/hollow/core/read/engine/set/HollowSetTypeShardsHolder.java diff --git a/hollow/src/main/java/com/netflix/hollow/core/read/engine/HollowTypeReadState.java b/hollow/src/main/java/com/netflix/hollow/core/read/engine/HollowTypeReadState.java index c1924fc88..bb5e3bed7 100644 --- a/hollow/src/main/java/com/netflix/hollow/core/read/engine/HollowTypeReadState.java +++ b/hollow/src/main/java/com/netflix/hollow/core/read/engine/HollowTypeReadState.java @@ -280,12 +280,6 @@ public void reshard(int newNumShards) { HollowTypeReadStateShard[] newShards = Arrays.copyOfRange(getShardsVolatile().getShards(), 0, newNumShards); updateShardsVolatile(newShards); - // setShardsVolatile( // SNAP: TODO: constructor has HollowObjectTypeReadStateShard[] parameter - // getShardsVolatile().getClass().getConstructor(HollowTypeReadStateShard[].class).newInstance( - // newShards - // ) - //); // SNAP: TODO: is this better addressed with a factory method in the interface, or by switching over to an abstract class? - // SNAP: TODO: can do generics with reflective constructor invocation here, or create an abstract method reassignShardsHolder(), or check instanceOf or assignableFrom // Re-sharding done. // shardsVolatile now contains newNumShards shards where each shard contains diff --git a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeReshardingStrategy.java b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeReshardingStrategy.java index dd68baacf..ac8035e8b 100644 --- a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeReshardingStrategy.java +++ b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeReshardingStrategy.java @@ -13,7 +13,6 @@ public HollowTypeDataElementsSplitter createDataElementsSplitter(HollowTypeDataE @Override public HollowTypeDataElementsJoiner createDataElementsJoiner(HollowTypeDataElements[] from) { - // SNAP: TODO: array casting? return new HollowListTypeDataElementsJoiner((HollowListTypeDataElements[]) from); } } diff --git a/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeShardsHolder.java b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeShardsHolder.java new file mode 100644 index 000000000..e81108e5f --- /dev/null +++ b/hollow/src/main/java/com/netflix/hollow/core/read/engine/list/HollowListTypeShardsHolder.java @@ -0,0 +1,53 @@ +package com.netflix.hollow.core.read.engine.list; + +import com.netflix.hollow.core.read.engine.HollowTypeReadStateShard; +import com.netflix.hollow.core.read.engine.ShardsHolder; + +public class HollowListTypeShardsHolder extends ShardsHolder { + final HollowListTypeReadStateShard shards[]; + final int shardNumberMask; + + /** + * Thread safe construction of ShardHolder with given shards + * @param fromShards shards to be used + */ + public HollowListTypeShardsHolder(HollowTypeReadStateShard[] fromShards) { + this.shards = new HollowListTypeReadStateShard[fromShards.length]; + for (int i=0; i