-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add builder for EngineConfig #5618
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,114 +154,6 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() { | |
|
||
private final TranslogFactory translogFactory; | ||
|
||
public EngineConfig( | ||
ShardId shardId, | ||
ThreadPool threadPool, | ||
IndexSettings indexSettings, | ||
Engine.Warmer warmer, | ||
Store store, | ||
MergePolicy mergePolicy, | ||
Analyzer analyzer, | ||
Similarity similarity, | ||
CodecService codecService, | ||
Engine.EventListener eventListener, | ||
QueryCache queryCache, | ||
QueryCachingPolicy queryCachingPolicy, | ||
TranslogConfig translogConfig, | ||
TimeValue flushMergesAfter, | ||
List<ReferenceManager.RefreshListener> externalRefreshListener, | ||
List<ReferenceManager.RefreshListener> internalRefreshListener, | ||
Sort indexSort, | ||
CircuitBreakerService circuitBreakerService, | ||
LongSupplier globalCheckpointSupplier, | ||
Supplier<RetentionLeases> retentionLeasesSupplier, | ||
LongSupplier primaryTermSupplier, | ||
TombstoneDocSupplier tombstoneDocSupplier | ||
) { | ||
this( | ||
shardId, | ||
threadPool, | ||
indexSettings, | ||
warmer, | ||
store, | ||
mergePolicy, | ||
analyzer, | ||
similarity, | ||
codecService, | ||
eventListener, | ||
queryCache, | ||
queryCachingPolicy, | ||
translogConfig, | ||
null, | ||
flushMergesAfter, | ||
externalRefreshListener, | ||
internalRefreshListener, | ||
indexSort, | ||
circuitBreakerService, | ||
globalCheckpointSupplier, | ||
retentionLeasesSupplier, | ||
primaryTermSupplier, | ||
tombstoneDocSupplier | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new {@link org.opensearch.index.engine.EngineConfig} | ||
*/ | ||
EngineConfig( | ||
ShardId shardId, | ||
ThreadPool threadPool, | ||
IndexSettings indexSettings, | ||
Engine.Warmer warmer, | ||
Store store, | ||
MergePolicy mergePolicy, | ||
Analyzer analyzer, | ||
Similarity similarity, | ||
CodecService codecService, | ||
Engine.EventListener eventListener, | ||
QueryCache queryCache, | ||
QueryCachingPolicy queryCachingPolicy, | ||
TranslogConfig translogConfig, | ||
TranslogDeletionPolicyFactory translogDeletionPolicyFactory, | ||
TimeValue flushMergesAfter, | ||
List<ReferenceManager.RefreshListener> externalRefreshListener, | ||
List<ReferenceManager.RefreshListener> internalRefreshListener, | ||
Sort indexSort, | ||
CircuitBreakerService circuitBreakerService, | ||
LongSupplier globalCheckpointSupplier, | ||
Supplier<RetentionLeases> retentionLeasesSupplier, | ||
LongSupplier primaryTermSupplier, | ||
TombstoneDocSupplier tombstoneDocSupplier | ||
) { | ||
this( | ||
shardId, | ||
threadPool, | ||
indexSettings, | ||
warmer, | ||
store, | ||
mergePolicy, | ||
analyzer, | ||
similarity, | ||
codecService, | ||
eventListener, | ||
queryCache, | ||
queryCachingPolicy, | ||
translogConfig, | ||
translogDeletionPolicyFactory, | ||
flushMergesAfter, | ||
externalRefreshListener, | ||
internalRefreshListener, | ||
indexSort, | ||
circuitBreakerService, | ||
globalCheckpointSupplier, | ||
retentionLeasesSupplier, | ||
primaryTermSupplier, | ||
tombstoneDocSupplier, | ||
false, | ||
new InternalTranslogFactory() | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new {@link org.opensearch.index.engine.EngineConfig} | ||
*/ | ||
|
@@ -573,4 +465,192 @@ public TombstoneDocSupplier getTombstoneDocSupplier() { | |
public TranslogDeletionPolicyFactory getCustomTranslogDeletionPolicyFactory() { | ||
return translogDeletionPolicyFactory; | ||
} | ||
|
||
/** | ||
* Builder for EngineConfig class | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public static class Builder { | ||
private ShardId shardId; | ||
private ThreadPool threadPool; | ||
private IndexSettings indexSettings; | ||
private Engine.Warmer warmer; | ||
private Store store; | ||
private MergePolicy mergePolicy; | ||
private Analyzer analyzer; | ||
private Similarity similarity; | ||
private CodecService codecService; | ||
private Engine.EventListener eventListener; | ||
private QueryCache queryCache; | ||
private QueryCachingPolicy queryCachingPolicy; | ||
private TranslogConfig translogConfig; | ||
private TimeValue flushMergesAfter; | ||
private List<ReferenceManager.RefreshListener> externalRefreshListener; | ||
private List<ReferenceManager.RefreshListener> internalRefreshListener; | ||
private Sort indexSort; | ||
private CircuitBreakerService circuitBreakerService; | ||
private LongSupplier globalCheckpointSupplier; | ||
private Supplier<RetentionLeases> retentionLeasesSupplier; | ||
private LongSupplier primaryTermSupplier; | ||
private TombstoneDocSupplier tombstoneDocSupplier; | ||
private TranslogDeletionPolicyFactory translogDeletionPolicyFactory = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the others fields are implicitly assigned to null. Can probably remove this for consistency. |
||
private boolean isReadOnlyReplica = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
private TranslogFactory translogFactory = new InternalTranslogFactory(); | ||
|
||
public Builder setShardId(ShardId shardId) { | ||
this.shardId = shardId; | ||
return this; | ||
} | ||
|
||
public Builder setThreadPool(ThreadPool threadPool) { | ||
this.threadPool = threadPool; | ||
return this; | ||
} | ||
|
||
public Builder setIndexSettings(IndexSettings indexSettings) { | ||
this.indexSettings = indexSettings; | ||
return this; | ||
} | ||
|
||
public Builder setWarmer(Engine.Warmer warmer) { | ||
this.warmer = warmer; | ||
return this; | ||
} | ||
|
||
public Builder setStore(Store store) { | ||
this.store = store; | ||
return this; | ||
} | ||
|
||
public Builder setMergePolicy(MergePolicy mergePolicy) { | ||
this.mergePolicy = mergePolicy; | ||
return this; | ||
} | ||
|
||
public Builder setAnalyzer(Analyzer analyzer) { | ||
this.analyzer = analyzer; | ||
return this; | ||
} | ||
|
||
public Builder setSimilarity(Similarity similarity) { | ||
this.similarity = similarity; | ||
return this; | ||
} | ||
|
||
public Builder setCodecService(CodecService codecService) { | ||
this.codecService = codecService; | ||
return this; | ||
} | ||
|
||
public Builder setEventListener(Engine.EventListener eventListener) { | ||
this.eventListener = eventListener; | ||
return this; | ||
} | ||
|
||
public Builder setQueryCache(QueryCache queryCache) { | ||
this.queryCache = queryCache; | ||
return this; | ||
} | ||
|
||
public Builder setQueryCachingPolicy(QueryCachingPolicy queryCachingPolicy) { | ||
this.queryCachingPolicy = queryCachingPolicy; | ||
return this; | ||
} | ||
|
||
public Builder setTranslogConfig(TranslogConfig translogConfig) { | ||
this.translogConfig = translogConfig; | ||
return this; | ||
} | ||
|
||
public Builder setFlushMergesAfter(TimeValue flushMergesAfter) { | ||
this.flushMergesAfter = flushMergesAfter; | ||
return this; | ||
} | ||
|
||
public Builder setExternalRefreshListener(List<ReferenceManager.RefreshListener> externalRefreshListener) { | ||
this.externalRefreshListener = externalRefreshListener; | ||
return this; | ||
} | ||
|
||
public Builder setInternalRefreshListener(List<ReferenceManager.RefreshListener> internalRefreshListener) { | ||
this.internalRefreshListener = internalRefreshListener; | ||
return this; | ||
} | ||
|
||
public Builder setIndexSort(Sort indexSort) { | ||
this.indexSort = indexSort; | ||
return this; | ||
} | ||
|
||
public Builder setCircuitBreakerService(CircuitBreakerService circuitBreakerService) { | ||
this.circuitBreakerService = circuitBreakerService; | ||
return this; | ||
} | ||
|
||
public Builder setGlobalCheckpointSupplier(LongSupplier globalCheckpointSupplier) { | ||
this.globalCheckpointSupplier = globalCheckpointSupplier; | ||
return this; | ||
} | ||
|
||
public Builder setRetentionLeasesSupplier(Supplier<RetentionLeases> retentionLeasesSupplier) { | ||
this.retentionLeasesSupplier = retentionLeasesSupplier; | ||
return this; | ||
} | ||
|
||
public Builder setPrimaryTermSupplier(LongSupplier primaryTermSupplier) { | ||
this.primaryTermSupplier = primaryTermSupplier; | ||
return this; | ||
} | ||
|
||
public Builder setTombstoneDocSupplier(TombstoneDocSupplier tombstoneDocSupplier) { | ||
this.tombstoneDocSupplier = tombstoneDocSupplier; | ||
return this; | ||
} | ||
|
||
public Builder setTranslogDeletionPolicyFactory(TranslogDeletionPolicyFactory translogDeletionPolicyFactory) { | ||
this.translogDeletionPolicyFactory = translogDeletionPolicyFactory; | ||
return this; | ||
} | ||
|
||
public Builder setIsReadOnlyReplica(boolean isReadOnlyReplica) { | ||
this.isReadOnlyReplica = isReadOnlyReplica; | ||
return this; | ||
} | ||
|
||
public Builder setTranslogFactory(TranslogFactory translogFactory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: For the setters in a builder we usually drop the i.e. |
||
this.translogFactory = translogFactory; | ||
return this; | ||
} | ||
|
||
public EngineConfig createEngineConfig() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, but |
||
return new EngineConfig( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another nitpick...assuming this constructor can be made private, then you can pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this. Will change in next commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for the review comment from @andrross. Without a private constructor here, the builder for |
||
shardId, | ||
threadPool, | ||
indexSettings, | ||
warmer, | ||
store, | ||
mergePolicy, | ||
analyzer, | ||
similarity, | ||
codecService, | ||
eventListener, | ||
queryCache, | ||
queryCachingPolicy, | ||
translogConfig, | ||
translogDeletionPolicyFactory, | ||
flushMergesAfter, | ||
externalRefreshListener, | ||
internalRefreshListener, | ||
indexSort, | ||
circuitBreakerService, | ||
globalCheckpointSupplier, | ||
retentionLeasesSupplier, | ||
primaryTermSupplier, | ||
tombstoneDocSupplier, | ||
isReadOnlyReplica, | ||
translogFactory | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this Builder make certain ctor parameters optional? How do we know we don't miss out on all mandatory ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
build
method still calls the constructor (which is private now) so all the validations on parameters remain same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree on the validation but the notion of what are mandatory parameters and what are optional is diluted. Previously everything was mandatory, but is there something we could do to ease that and make this of the type EngineConfig#builder(mandatory_params).optionalParam(param).build(this)