@@ -167,62 +167,68 @@ public String toString() {
167
167
justification = "Field is written by Gson" )
168
168
@ Override
169
169
public void init (InitParameters params ) {
170
- ExecutorConfig [] execConfigs =
171
- new Gson ().fromJson (params .getOptions ().get ("executors" ), ExecutorConfig [].class );
172
170
173
- List <Executor > tmpExec = new ArrayList <>();
171
+ if (params .getOptions ().containsKey ("executors" )
172
+ && !params .getOptions ().get ("executors" ).isBlank ()) {
174
173
175
- for (ExecutorConfig executorConfig : execConfigs ) {
176
- Long maxSize = executorConfig .maxSize == null ? null
177
- : ConfigurationTypeHelper .getFixedMemoryAsBytes (executorConfig .maxSize );
174
+ ExecutorConfig [] execConfigs =
175
+ new Gson ().fromJson (params .getOptions ().get ("executors" ), ExecutorConfig [].class );
178
176
179
- CompactionExecutorId ceid ;
177
+ List < Executor > tmpExec = new ArrayList <>() ;
180
178
181
- // If not supplied, GSON will leave type null. Default to internal
182
- if (executorConfig .type == null ) {
183
- executorConfig .type = "internal" ;
184
- }
179
+ for (ExecutorConfig executorConfig : execConfigs ) {
180
+ Long maxSize = executorConfig .maxSize == null ? null
181
+ : ConfigurationTypeHelper .getFixedMemoryAsBytes (executorConfig .maxSize );
185
182
186
- switch (executorConfig .type ) {
187
- case "internal" :
188
- Preconditions .checkArgument (null == executorConfig .queue ,
189
- "'queue' should not be specified for internal compactions" );
190
- int numThreads = Objects .requireNonNull (executorConfig .numThreads ,
191
- "'numThreads' must be specified for internal type" );
192
- ceid = params .getExecutorManager ().createExecutor (executorConfig .name , numThreads );
193
- break ;
194
- case "external" :
195
- Preconditions .checkArgument (null == executorConfig .numThreads ,
196
- "'numThreads' should not be specified for external compactions" );
197
- String queue = Objects .requireNonNull (executorConfig .queue ,
198
- "'queue' must be specified for external type" );
199
- ceid = params .getExecutorManager ().getExternalExecutor (queue );
200
- break ;
201
- default :
202
- throw new IllegalArgumentException ("type must be 'internal' or 'external'" );
203
- }
204
- tmpExec .add (new Executor (ceid , maxSize ));
205
- }
183
+ CompactionExecutorId ceid ;
206
184
207
- Collections .sort (tmpExec , Comparator .comparing (Executor ::getMaxSize ,
208
- Comparator .nullsLast (Comparator .naturalOrder ())));
185
+ // If not supplied, GSON will leave type null. Default to internal
186
+ if (executorConfig .type == null ) {
187
+ executorConfig .type = "internal" ;
188
+ }
209
189
210
- executors = List .copyOf (tmpExec );
190
+ switch (executorConfig .type ) {
191
+ case "internal" :
192
+ Preconditions .checkArgument (null == executorConfig .queue ,
193
+ "'queue' should not be specified for internal compactions" );
194
+ int numThreads = Objects .requireNonNull (executorConfig .numThreads ,
195
+ "'numThreads' must be specified for internal type" );
196
+ ceid = params .getExecutorManager ().createExecutor (executorConfig .name , numThreads );
197
+ break ;
198
+ case "external" :
199
+ Preconditions .checkArgument (null == executorConfig .numThreads ,
200
+ "'numThreads' should not be specified for external compactions" );
201
+ String queue = Objects .requireNonNull (executorConfig .queue ,
202
+ "'queue' must be specified for external type" );
203
+ ceid = params .getExecutorManager ().getExternalExecutor (queue );
204
+ break ;
205
+ default :
206
+ throw new IllegalArgumentException ("type must be 'internal' or 'external'" );
207
+ }
208
+ tmpExec .add (new Executor (ceid , maxSize ));
209
+ }
211
210
212
- if ( executors . stream (). filter ( e -> e . getMaxSize () == null ). count () > 1 ) {
213
- throw new IllegalArgumentException (
214
- "Can only have one executor w/o a maxSize. " + params . getOptions (). get ( "executors" ));
215
- }
211
+ Collections . sort ( tmpExec , Comparator . comparing ( Executor :: getMaxSize ,
212
+ Comparator . nullsLast ( Comparator . naturalOrder ())));
213
+
214
+ executors = List . copyOf ( tmpExec );
216
215
217
- // use the add method on the Set interface to check for duplicate maxSizes
218
- Set <Long > maxSizes = new HashSet <>();
219
- executors .forEach (e -> {
220
- if (!maxSizes .add (e .getMaxSize ())) {
216
+ if (executors .stream ().filter (e -> e .getMaxSize () == null ).count () > 1 ) {
221
217
throw new IllegalArgumentException (
222
- "Duplicate maxSize set in executors . " + params .getOptions ().get ("executors" ));
218
+ "Can only have one executor w/o a maxSize . " + params .getOptions ().get ("executors" ));
223
219
}
224
- });
225
220
221
+ // use the add method on the Set interface to check for duplicate maxSizes
222
+ Set <Long > maxSizes = new HashSet <>();
223
+ executors .forEach (e -> {
224
+ if (!maxSizes .add (e .getMaxSize ())) {
225
+ throw new IllegalArgumentException (
226
+ "Duplicate maxSize set in executors. " + params .getOptions ().get ("executors" ));
227
+ }
228
+ });
229
+ } else {
230
+ throw new IllegalStateException ("No defined executors for this planner" );
231
+ }
226
232
determineMaxFilesToCompact (params );
227
233
}
228
234
0 commit comments