Skip to content

Commit f4477a0

Browse files
committed
resharding- support force feature coverage for testing
1 parent b664623 commit f4477a0

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

hollow/src/main/java/com/netflix/hollow/api/producer/AbstractHollowProducer.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ abstract class AbstractHollowProducer {
9595
boolean isInitialized;
9696

9797
private final long targetMaxTypeShardSize;
98-
private final boolean allowTypeResharding;
9998
private final boolean focusHoleFillInFewestShards;
100-
99+
private final boolean allowTypeResharding;
100+
private final boolean forceCoverageOfTypeResharding; // exercise re-sharding often (for testing)
101101

102102
@Deprecated
103103
public AbstractHollowProducer(
@@ -106,7 +106,7 @@ public AbstractHollowProducer(
106106
this(new HollowFilesystemBlobStager(), publisher, announcer,
107107
Collections.emptyList(),
108108
new VersionMinterWithCounter(), null, 0,
109-
DEFAULT_TARGET_MAX_TYPE_SHARD_SIZE, false, false, null,
109+
DEFAULT_TARGET_MAX_TYPE_SHARD_SIZE, false, false, false, null,
110110
new DummyBlobStorageCleaner(), new BasicSingleProducerEnforcer(),
111111
null, true);
112112
}
@@ -118,7 +118,8 @@ public AbstractHollowProducer(
118118
this(b.stager, b.publisher, b.announcer,
119119
b.eventListeners,
120120
b.versionMinter, b.snapshotPublishExecutor,
121-
b.numStatesBetweenSnapshots, b.targetMaxTypeShardSize, b.focusHoleFillInFewestShards, b.allowTypeResharding,
121+
b.numStatesBetweenSnapshots, b.targetMaxTypeShardSize, b.focusHoleFillInFewestShards,
122+
b.allowTypeResharding, b.forceCoverageOfTypeResharding,
122123
b.metricsCollector, b.blobStorageCleaner, b.singleProducerEnforcer,
123124
b.hashCodeFinder, b.doIntegrityCheck);
124125
}
@@ -134,6 +135,7 @@ private AbstractHollowProducer(
134135
long targetMaxTypeShardSize,
135136
boolean focusHoleFillInFewestShards,
136137
boolean allowTypeResharding,
138+
boolean forceCoverageOfTypeResharding,
137139
HollowMetricsCollector<HollowProducerMetrics> metricsCollector,
138140
HollowProducer.BlobStorageCleaner blobStorageCleaner,
139141
SingleProducerEnforcer singleProducerEnforcer,
@@ -150,6 +152,7 @@ private AbstractHollowProducer(
150152
this.doIntegrityCheck = doIntegrityCheck;
151153
this.targetMaxTypeShardSize = targetMaxTypeShardSize;
152154
this.allowTypeResharding = allowTypeResharding;
155+
this.forceCoverageOfTypeResharding = forceCoverageOfTypeResharding;
153156
this.focusHoleFillInFewestShards = focusHoleFillInFewestShards;
154157

155158
HollowWriteStateEngine writeEngine = hashCodeFinder == null
@@ -399,6 +402,12 @@ long runCycle(
399402
!writeEngine.hasIdenticalSchemas(readStates.current().getStateEngine());
400403
updateHeaderTags(writeEngine, toVersion, schemaChangedFromPriorVersion);
401404

405+
if (allowTypeResharding && forceCoverageOfTypeResharding) {
406+
int randomFactor = (int) Math.pow(2, (int) (Math.random() * 9) - 4); // random power of 2 in the range [-4, 4]
407+
long adjustedShardSize = targetMaxTypeShardSize * randomFactor;
408+
writeEngine.setTargetMaxTypeShardSize(adjustedShardSize);
409+
}
410+
402411
// 3a. Publish, run checks & validation, then announce new state consumers
403412
publish(listeners, toVersion, artifacts);
404413

hollow/src/main/java/com/netflix/hollow/api/producer/HollowProducer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.ArrayList;
4444
import java.util.List;
4545
import java.util.Map;
46-
import java.util.Vector;
4746
import java.util.concurrent.Executor;
4847

4948
/**
@@ -732,6 +731,7 @@ public static class Builder<B extends HollowProducer.Builder<B>> {
732731
int numStatesBetweenSnapshots = 0;
733732
boolean focusHoleFillInFewestShards = false;
734733
boolean allowTypeResharding = false;
734+
boolean forceCoverageOfTypeResharding = false;
735735
long targetMaxTypeShardSize = DEFAULT_TARGET_MAX_TYPE_SHARD_SIZE;
736736
HollowMetricsCollector<HollowProducerMetrics> metricsCollector;
737737
BlobStorageCleaner blobStorageCleaner = new DummyBlobStorageCleaner();
@@ -883,7 +883,20 @@ public B withFocusHoleFillInFewestShards(boolean focusHoleFillInFewestShards) {
883883
* Also requires consumers of the delta chain to be on a recent Hollow library version that supports re-sharding at the time of delta application.
884884
*/
885885
public B withTypeResharding(boolean allowTypeResharding) {
886+
return (B) withTypeResharding(allowTypeResharding, false);
887+
}
888+
889+
/**
890+
* Experimental: Setting this will allow producer to adjust number of shards per type in the course of a delta chain.
891+
*
892+
* @param allowTypeResharding enable type resharding feature, see {@link #withTypeResharding(boolean)} for more details.
893+
* @param forceCoverage a boolean indicating whether to attempt to induce resharding on every cycle. This a feature
894+
* for exercising resharding coverage frequently in test environments, and is not expected
895+
* to be set for production environments.
896+
*/
897+
public B withTypeResharding(boolean allowTypeResharding, boolean forceCoverage) {
886898
this.allowTypeResharding = allowTypeResharding;
899+
this.forceCoverageOfTypeResharding = forceCoverage;
887900
return (B) this;
888901
}
889902

0 commit comments

Comments
 (0)