17
17
package com .netflix .hollow .api .producer ;
18
18
19
19
import static com .netflix .hollow .api .producer .ProducerListenerSupport .ProducerListeners ;
20
+ import static com .netflix .hollow .core .HollowStateEngine .HEADER_TAG_TYPE_RESHARDING_INVOKED ;
20
21
import static java .lang .System .currentTimeMillis ;
21
22
import static java .util .stream .Collectors .toList ;
22
23
@@ -92,14 +93,19 @@ abstract class AbstractHollowProducer {
92
93
93
94
boolean isInitialized ;
94
95
96
+ private final long targetMaxTypeShardSize ;
97
+ private final boolean allowTypeResharding ;
98
+ private final boolean focusHoleFillInFewestShards ;
99
+
100
+
95
101
@ Deprecated
96
102
public AbstractHollowProducer (
97
103
HollowProducer .Publisher publisher ,
98
104
HollowProducer .Announcer announcer ) {
99
105
this (new HollowFilesystemBlobStager (), publisher , announcer ,
100
106
Collections .emptyList (),
101
107
new VersionMinterWithCounter (), null , 0 ,
102
- DEFAULT_TARGET_MAX_TYPE_SHARD_SIZE , false , null ,
108
+ DEFAULT_TARGET_MAX_TYPE_SHARD_SIZE , false , false , null ,
103
109
new DummyBlobStorageCleaner (), new BasicSingleProducerEnforcer (),
104
110
null , true );
105
111
}
@@ -111,7 +117,7 @@ public AbstractHollowProducer(
111
117
this (b .stager , b .publisher , b .announcer ,
112
118
b .eventListeners ,
113
119
b .versionMinter , b .snapshotPublishExecutor ,
114
- b .numStatesBetweenSnapshots , b .targetMaxTypeShardSize , b .focusHoleFillInFewestShards ,
120
+ b .numStatesBetweenSnapshots , b .targetMaxTypeShardSize , b .focusHoleFillInFewestShards , b . allowTypeResharding ,
115
121
b .metricsCollector , b .blobStorageCleaner , b .singleProducerEnforcer ,
116
122
b .hashCodeFinder , b .doIntegrityCheck );
117
123
}
@@ -126,6 +132,7 @@ private AbstractHollowProducer(
126
132
int numStatesBetweenSnapshots ,
127
133
long targetMaxTypeShardSize ,
128
134
boolean focusHoleFillInFewestShards ,
135
+ boolean allowTypeResharding ,
129
136
HollowMetricsCollector <HollowProducerMetrics > metricsCollector ,
130
137
HollowProducer .BlobStorageCleaner blobStorageCleaner ,
131
138
SingleProducerEnforcer singleProducerEnforcer ,
@@ -140,11 +147,15 @@ private AbstractHollowProducer(
140
147
this .numStatesBetweenSnapshots = numStatesBetweenSnapshots ;
141
148
this .hashCodeFinder = hashCodeFinder ;
142
149
this .doIntegrityCheck = doIntegrityCheck ;
150
+ this .targetMaxTypeShardSize = targetMaxTypeShardSize ;
151
+ this .allowTypeResharding = allowTypeResharding ;
152
+ this .focusHoleFillInFewestShards = focusHoleFillInFewestShards ;
143
153
144
154
HollowWriteStateEngine writeEngine = hashCodeFinder == null
145
155
? new HollowWriteStateEngine ()
146
156
: new HollowWriteStateEngine (hashCodeFinder );
147
157
writeEngine .setTargetMaxTypeShardSize (targetMaxTypeShardSize );
158
+ writeEngine .allowTypeResharding (allowTypeResharding );
148
159
writeEngine .setFocusHoleFillInFewestShards (focusHoleFillInFewestShards );
149
160
150
161
this .objectMapper = new HollowObjectMapper (writeEngine );
@@ -283,6 +294,9 @@ private HollowProducer.ReadState restore(
283
294
HollowWriteStateEngine writeEngine = hashCodeFinder == null
284
295
? new HollowWriteStateEngine ()
285
296
: new HollowWriteStateEngine (hashCodeFinder );
297
+ writeEngine .setTargetMaxTypeShardSize (targetMaxTypeShardSize );
298
+ writeEngine .allowTypeResharding (allowTypeResharding );
299
+ writeEngine .setFocusHoleFillInFewestShards (focusHoleFillInFewestShards );
286
300
HollowWriteStateCreator .populateStateEngineWithTypeWriteStates (writeEngine , schemas );
287
301
HollowObjectMapper newObjectMapper = new HollowObjectMapper (writeEngine );
288
302
if (hashCodeFinder != null ) {
@@ -380,15 +394,9 @@ long runCycle(
380
394
381
395
// 3. Produce a new state if there's work to do
382
396
if (writeEngine .hasChangedSinceLastCycle ()) {
383
- writeEngine .addHeaderTag (HollowStateEngine .HEADER_TAG_SCHEMA_HASH , new HollowSchemaHash (writeEngine .getSchemas ()).getHash ());
384
397
boolean schemaChangedFromPriorVersion = readStates .hasCurrent () &&
385
398
!writeEngine .hasIdenticalSchemas (readStates .current ().getStateEngine ());
386
- if (schemaChangedFromPriorVersion ) {
387
- writeEngine .addHeaderTag (HollowStateEngine .HEADER_TAG_SCHEMA_CHANGE , Boolean .TRUE .toString ());
388
- } else {
389
- writeEngine .getHeaderTags ().remove (HollowStateEngine .HEADER_TAG_SCHEMA_CHANGE );
390
- }
391
- writeEngine .addHeaderTag (HollowStateEngine .HEADER_TAG_PRODUCER_TO_VERSION , String .valueOf (toVersion ));
399
+ updateHeaderTags (writeEngine , toVersion , schemaChangedFromPriorVersion );
392
400
393
401
// 3a. Publish, run checks & validation, then announce new state consumers
394
402
publish (listeners , toVersion , artifacts );
@@ -507,6 +515,17 @@ public void removeListener(HollowProducerEventListener listener) {
507
515
listeners .removeListener (listener );
508
516
}
509
517
518
+ private void updateHeaderTags (HollowWriteStateEngine writeEngine , long toVersion , boolean schemaChangedFromPriorVersion ) {
519
+ writeEngine .addHeaderTag (HollowStateEngine .HEADER_TAG_SCHEMA_HASH , new HollowSchemaHash (writeEngine .getSchemas ()).getHash ());
520
+ if (schemaChangedFromPriorVersion ) {
521
+ writeEngine .addHeaderTag (HollowStateEngine .HEADER_TAG_SCHEMA_CHANGE , Boolean .TRUE .toString ());
522
+ } else {
523
+ writeEngine .getHeaderTags ().remove (HollowStateEngine .HEADER_TAG_SCHEMA_CHANGE );
524
+ }
525
+ writeEngine .addHeaderTag (HollowStateEngine .HEADER_TAG_PRODUCER_TO_VERSION , String .valueOf (toVersion ));
526
+ writeEngine .getHeaderTags ().remove (HEADER_TAG_TYPE_RESHARDING_INVOKED );
527
+ }
528
+
510
529
void populate (
511
530
ProducerListeners listeners ,
512
531
HollowProducer .Incremental .IncrementalPopulator incrementalPopulator , HollowProducer .Populator populator ,
0 commit comments