TuningConfig   A
last analyzed

Complexity

Total Complexity 27

Size/Duplication

Total Lines 421
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 27
eloc 56
c 1
b 0
f 0
dl 0
loc 421
ccs 79
cts 79
cp 1
rs 10

25 Methods

Rating   Name   Duplication   Size   Complexity  
A setMaxRowsInMemory() 0 5 1
A __construct() 0 13 3
A toArray() 0 3 1
A setPartitionsSpec() 0 5 1
A setSegmentWriteOutMediumFactory() 0 5 1
A setChatHandlerNumRetries() 0 5 1
A setIndexSpec() 0 5 1
A setSplitHintSpec() 0 5 1
A setReportParseExceptions() 0 5 1
A setMaxBytesInMemory() 0 5 1
A setPushTimeout() 0 5 1
A setMaxRetry() 0 5 1
A setMaxRowsPerSegment() 0 5 1
A setChatHandlerTimeout() 0 5 1
A setType() 0 5 1
A setMaxNumConcurrentSubTasks() 0 5 1
A setTaskStatusCheckPeriodMs() 0 5 1
A setMaxTotalRows() 0 5 1
A setMaxPendingPersists() 0 5 1
A setMaxNumSegmentsToMerge() 0 5 1
A setMaxNumSubTasks() 0 5 1
A setTotalNumMergeTasks() 0 5 1
A setForceGuaranteedRollup() 0 5 1
A setNumShards() 0 5 1
A setIndexSpecForIntermediatePersists() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\TuningConfig;
5
6
class TuningConfig implements TuningConfigInterface
7
{
8
    /**
9
     * @var array<string,string|int|bool|array<string,string|int>>
10
     */
11
    protected array $properties = [];
12
13
    /**
14
     * TuningConfig constructor.
15
     *
16
     * @param array<string,string|int|bool|array<string,string|int>> $properties
17
     */
18 11
    public function __construct(array $properties = [])
19
    {
20 11
        foreach ($properties as $key => $value) {
21
22 9
            $method = 'set' . $key;
23
24 9
            $callable = [$this, $method];
25 9
            if (!is_callable($callable)) {
26 2
                $this->properties[$key] = $value;
27 2
                continue;
28
            }
29
30 7
            call_user_func($callable, $value);
31
        }
32
    }
33
34
    /**
35
     * Return the context as it can be used in the druid query.
36
     *
37
     * @return array<string,string|int|bool|array<string,string|int>>
38
     */
39 9
    public function toArray(): array
40
    {
41 9
        return $this->properties;
42
    }
43
44
    /**
45
     * The task type
46
     *
47
     * @param string $type
48
     *
49
     * @return $this
50
     * @required
51
     */
52 7
    public function setType(string $type): self
53
    {
54 7
        $this->properties['type'] = $type;
55
56 7
        return $this;
57
    }
58
59
    /**
60
     * Used in sharding. Determines how many rows are in each segment.
61
     * Default: 5000000
62
     *
63
     * @param int $maxRowsPerSegment
64
     *
65
     * @return $this
66
     */
67 3
    public function setMaxRowsPerSegment(int $maxRowsPerSegment): self
68
    {
69 3
        $this->properties['maxRowsPerSegment'] = $maxRowsPerSegment;
70
71 3
        return $this;
72
    }
73
74
    /**
75
     * Used in determining when intermediate persists to disk should occur. Normally user does not need to set this,
76
     * but depending on the nature of data, if rows are short in terms of bytes, user may not want to store a million
77
     * rows in memory and this value should be set.
78
     *
79
     * Default: 1000000
80
     *
81
     * @param int $maxRowsInMemory
82
     *
83
     * @return $this
84
     */
85 2
    public function setMaxRowsInMemory(int $maxRowsInMemory): self
86
    {
87 2
        $this->properties['maxRowsInMemory'] = $maxRowsInMemory;
88
89 2
        return $this;
90
    }
91
92
    /**
93
     * Used in determining when intermediate persists to disk should occur. Normally this is computed internally and
94
     * user does not need to set it. This value represents number of bytes to aggregate in heap memory before
95
     * persisting. This is based on a rough estimate of memory usage and not actual usage. The maximum heap memory
96
     * usage for indexing is maxBytesInMemory * (2 + maxPendingPersists)
97
     *
98
     * Default: 1/6 of max JVM memory
99
     *
100
     * @param int $maxBytesInMemory
101
     *
102
     * @return $this
103
     */
104 1
    public function setMaxBytesInMemory(int $maxBytesInMemory): self
105
    {
106 1
        $this->properties['maxBytesInMemory'] = $maxBytesInMemory;
107
108 1
        return $this;
109
    }
110
111
    /**
112
     * Total number of rows in segments waiting for being pushed. Used in determining when intermediate pushing should
113
     * occur.
114
     *
115
     * Default: 20000000
116
     *
117
     * @param int $maxTotalRows
118
     *
119
     * @return $this
120
     */
121 1
    public function setMaxTotalRows(int $maxTotalRows): self
122
    {
123 1
        $this->properties['maxTotalRows'] = $maxTotalRows;
124
125 1
        return $this;
126
    }
127
128
    /**
129
     * Directly specify the number of shards to create. If this is specified and 'intervals' is specified in the
130
     * granularitySpec, the index task can skip to determine intervals/partitions pass through the data. numShards
131
     * cannot be specified if maxRowsPerSegment is set.
132
     *
133
     * Default: null
134
     *
135
     * @param int $numShards
136
     *
137
     * @return $this
138
     */
139 1
    public function setNumShards(int $numShards): self
140
    {
141 1
        $this->properties['numShards'] = $numShards;
142
143 1
        return $this;
144
    }
145
146
    /**
147
     * Used to give a hint to control the amount of data that each first phase task reads.
148
     * This hint could be ignored depending on the implementation of the input source. See Split hint spec for more
149
     * details.
150
     *
151
     * @see https://druid.apache.org/docs/0.20.2/ingestion/native-batch.html#split-hint-spec
152
     *
153
     * @param array<string,string|int> $splitHintSpec
154
     *
155
     * @return \Level23\Druid\TuningConfig\TuningConfig
156
     */
157 1
    public function setSplitHintSpec(array $splitHintSpec): self
158
    {
159 1
        $this->properties['splitHintSpec'] = $splitHintSpec;
160
161 1
        return $this;
162
    }
163
164
    /**
165
     * Defines how to partition data in each timeChunk, see PartitionsSpec
166
     *
167
     * @see https://druid.apache.org/docs/0.20.2/ingestion/native-batch.html#partitionsspec
168
     *
169
     * @param array<string,string|int> $partitionsSpec
170
     *
171
     * @return $this
172
     */
173 1
    public function setPartitionsSpec(array $partitionsSpec): self
174
    {
175 1
        $this->properties['partitionsSpec'] = $partitionsSpec;
176
177 1
        return $this;
178
    }
179
180
    /**
181
     * Defines segment storage format options to be used at indexing time
182
     *
183
     * @see https://druid.apache.org/docs/latest/ingestion/native_tasks.html#indexspec
184
     *
185
     * @param array<string,string|int> $indexSpec
186
     *
187
     * @return $this
188
     */
189 1
    public function setIndexSpec(array $indexSpec): self
190
    {
191 1
        $this->properties['indexSpec'] = $indexSpec;
192
193 1
        return $this;
194
    }
195
196
    /**
197
     * Defines segment storage format options to be used at indexing time for intermediate persisted temporary segments.
198
     * This can be used to disable dimension/metric compression on intermediate segments to reduce memory required for
199
     * final merging. however, disabling compression on intermediate segments might increase page cache use while they
200
     * are used before getting merged into final segment published, see IndexSpec for possible values.
201
     *
202
     * @see https://druid.apache.org/docs/0.20.2/ingestion/index.html#indexspec
203
     *
204
     * @param array<string,string|int> $indexSpecForIntermediatePersists
205
     *
206
     * @return $this
207
     */
208 1
    public function setIndexSpecForIntermediatePersists(array $indexSpecForIntermediatePersists): self
209
    {
210 1
        $this->properties['indexSpecForIntermediatePersists'] = $indexSpecForIntermediatePersists;
211
212 1
        return $this;
213
    }
214
215
    /**
216
     * Maximum number of persists that can be pending but not started. If this limit would be exceeded by a new
217
     * intermediate persist, ingestion will block until the currently-running persist finishes. Maximum heap memory
218
     * usage for indexing scales with maxRowsInMemory * (2 + maxPendingPersists).
219
     *
220
     * Default: 0 (meaning one persist can be running concurrently with ingestion, and none can be queued up)
221
     *
222
     * @param int $maxPendingPersists
223
     *
224
     * @return $this
225
     */
226 1
    public function setMaxPendingPersists(int $maxPendingPersists): self
227
    {
228 1
        $this->properties['maxPendingPersists'] = $maxPendingPersists;
229
230 1
        return $this;
231
    }
232
233
    /**
234
     * If true, exceptions encountered during parsing will be thrown and will halt ingestion; if false, unparseable
235
     * rows and fields will be skipped.
236
     *
237
     * Default: false
238
     *
239
     * @param bool $reportParseExceptions
240
     *
241
     * @return $this
242
     */
243 1
    public function setReportParseExceptions(bool $reportParseExceptions): self
244
    {
245 1
        $this->properties['reportParseExceptions'] = $reportParseExceptions;
246
247 1
        return $this;
248
    }
249
250
    /**
251
     * Forces guaranteeing the perfect rollup. The perfect rollup optimizes the total size of generated segments and
252
     * querying time while indexing time will be increased. If this is set to true, intervals in granularitySpec must
253
     * be set and hashed or single_dim must be used for partitionsSpec. This flag cannot be used with appendToExisting
254
     * of IOConfig.
255
     *
256
     * @param bool $forceGuaranteedRollup
257
     *
258
     * @return $this
259
     */
260 1
    public function setForceGuaranteedRollup(bool $forceGuaranteedRollup): self
261
    {
262 1
        $this->properties['forceGuaranteedRollup'] = $forceGuaranteedRollup;
263
264 1
        return $this;
265
    }
266
267
    /**
268
     * Milliseconds to wait for pushing segments. It must be >= 0, where 0 means to wait forever.
269
     *
270
     * Default: 0
271
     *
272
     * @param int $pushTimeout
273
     *
274
     * @return $this
275
     */
276 1
    public function setPushTimeout(int $pushTimeout): self
277
    {
278 1
        $this->properties['pushTimeout'] = $pushTimeout;
279
280 1
        return $this;
281
    }
282
283
    /**
284
     * Segment write-out medium to use when creating segments. See SegmentWriteOutMediumFactory.
285
     *
286
     * Default: Not specified, the value from druid.peon.defaultSegmentWriteOutMediumFactory.type is used
287
     *
288
     * @param string $segmentWriteOutMediumFactory
289
     *
290
     * @return $this
291
     */
292 1
    public function setSegmentWriteOutMediumFactory(string $segmentWriteOutMediumFactory): self
293
    {
294 1
        $this->properties['segmentWriteOutMediumFactory'] = $segmentWriteOutMediumFactory;
295
296 1
        return $this;
297
    }
298
299
    /**
300
     * Maximum number of worker tasks which can be run in parallel at the same time. The supervisor task would spawn
301
     * worker tasks up to maxNumConcurrentSubTasks regardless of the current available task slots.
302
     * If this value is set to 1, the supervisor task processes data ingestion on its own instead of
303
     * spawning worker tasks. If this value is set to too large, too many worker tasks can be created which might
304
     * block other ingestion. Check Capacity Planning for more details.
305
     *
306
     * @param int $maxNumConcurrentSubTasks
307
     *
308
     * @return $this
309
     */
310 1
    public function setMaxNumConcurrentSubTasks(int $maxNumConcurrentSubTasks): self
311
    {
312 1
        $this->properties['maxNumConcurrentSubTasks'] = $maxNumConcurrentSubTasks;
313
314 1
        return $this;
315
    }
316
317
    /**
318
     * Maximum number of tasks which can be run at the same time. The supervisor task would spawn worker tasks up to
319
     * maxNumSubTasks regardless of the available task slots. If this value is set to 1, the supervisor task processes
320
     * data ingestion on its own instead of spawning worker tasks. If this value is set to too large, too many worker
321
     * tasks can be created which might block other ingestion. Check Capacity Planning for more details.
322
     *
323
     * Default: 1
324
     *
325
     * @param int $maxNumSubTasks
326
     *
327
     * @return $this
328
     */
329 3
    public function setMaxNumSubTasks(int $maxNumSubTasks): self
330
    {
331 3
        $this->properties['maxNumSubTasks'] = $maxNumSubTasks;
332
333 3
        return $this;
334
    }
335
336
    /**
337
     * Maximum number of retries on task failures.
338
     *
339
     * Default: 3
340
     *
341
     * @param int $maxRetry
342
     *
343
     * @return $this
344
     */
345 1
    public function setMaxRetry(int $maxRetry): self
346
    {
347 1
        $this->properties['maxRetry'] = $maxRetry;
348
349 1
        return $this;
350
    }
351
352
    /**
353
     * Maximum limit for the number of segments that a single task can merge at the same time in the second phase.
354
     * Used only forceGuaranteedRollup is set.
355
     *
356
     * @param int $maxNumSegmentsToMerge
357
     *
358
     * @return $this
359
     */
360 1
    public function setMaxNumSegmentsToMerge(int $maxNumSegmentsToMerge): self
361
    {
362 1
        $this->properties['maxNumSegmentsToMerge'] = $maxNumSegmentsToMerge;
363
364 1
        return $this;
365
    }
366
367
    /**
368
     * Total number of tasks to merge segments in the merge phase when partitionsSpec is set to hashed or single_dim.
369
     *
370
     * @param int $totalNumMergeTasks
371
     *
372
     * @return $this
373
     */
374 1
    public function setTotalNumMergeTasks(int $totalNumMergeTasks): self
375
    {
376 1
        $this->properties['totalNumMergeTasks'] = $totalNumMergeTasks;
377
378 1
        return $this;
379
    }
380
381
    /**
382
     * Polling period in milliseconds to check running task statuses.
383
     *
384
     * Default: 1000
385
     *
386
     * @param int $taskStatusCheckPeriodMs
387
     *
388
     * @return $this
389
     */
390 1
    public function setTaskStatusCheckPeriodMs(int $taskStatusCheckPeriodMs): self
391
    {
392 1
        $this->properties['taskStatusCheckPeriodMs'] = $taskStatusCheckPeriodMs;
393
394 1
        return $this;
395
    }
396
397
    /**
398
     * Timeout for reporting the pushed segments in worker tasks.
399
     *
400
     * Default: PT10S
401
     *
402
     * @param string $chatHandlerTimeout
403
     *
404
     * @return $this
405
     */
406 1
    public function setChatHandlerTimeout(string $chatHandlerTimeout): self
407
    {
408 1
        $this->properties['chatHandlerTimeout'] = $chatHandlerTimeout;
409
410 1
        return $this;
411
    }
412
413
    /**
414
     * Retries for reporting the pushed segments in worker tasks.
415
     *
416
     * Default: 5
417
     *
418
     * @param int $chatHandlerNumRetries
419
     *
420
     * @return $this
421
     */
422 1
    public function setChatHandlerNumRetries(int $chatHandlerNumRetries): self
423
    {
424 1
        $this->properties['chatHandlerNumRetries'] = $chatHandlerNumRetries;
425
426 1
        return $this;
427
    }
428
}