• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9960

30 Aug 2023 04:02AM CUT coverage: 47.758% (+0.001%) from 47.757%
#9960

push

travis_ci

web-flow
[IOTDB-6119] Add ConfigNode leader service check (#10985)

43 of 43 new or added lines in 7 files covered. (100.0%)

80379 of 168305 relevant lines covered (47.76%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.68
/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/config/RatisConfig.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.consensus.config;
21

22
import org.apache.iotdb.commons.client.property.ClientPoolProperty.DefaultProperty;
23

24
import org.apache.ratis.grpc.GrpcConfigKeys.Server;
25
import org.apache.ratis.server.RaftServerConfigKeys;
26
import org.apache.ratis.util.SizeInBytes;
27
import org.apache.ratis.util.TimeDuration;
28

29
import java.util.Optional;
30
import java.util.concurrent.TimeUnit;
31

32
public class RatisConfig {
33

34
  private final Rpc rpc;
35
  private final LeaderElection leaderElection;
36
  private final Snapshot snapshot;
37
  private final ThreadPool threadPool;
38
  private final Log log;
39
  private final Grpc grpc;
40
  private final Client client;
41
  private final Impl impl;
42
  private final LeaderLogAppender leaderLogAppender;
43
  private final Read read;
44
  private final Utils utils;
45

46
  private RatisConfig(
47
      Rpc rpc,
48
      LeaderElection leaderElection,
49
      Snapshot snapshot,
50
      ThreadPool threadPool,
51
      Log log,
52
      Grpc grpc,
53
      Client client,
54
      Impl impl,
55
      LeaderLogAppender leaderLogAppender,
56
      Read read,
57
      Utils utils) {
1✔
58
    this.rpc = rpc;
1✔
59
    this.leaderElection = leaderElection;
1✔
60
    this.snapshot = snapshot;
1✔
61
    this.threadPool = threadPool;
1✔
62
    this.log = log;
1✔
63
    this.grpc = grpc;
1✔
64
    this.client = client;
1✔
65
    this.impl = impl;
1✔
66
    this.leaderLogAppender = leaderLogAppender;
1✔
67
    this.read = read;
1✔
68
    this.utils = utils;
1✔
69
  }
1✔
70

71
  public Rpc getRpc() {
72
    return rpc;
1✔
73
  }
74

75
  public LeaderElection getLeaderElection() {
76
    return leaderElection;
1✔
77
  }
78

79
  public Snapshot getSnapshot() {
80
    return snapshot;
1✔
81
  }
82

83
  public ThreadPool getThreadPool() {
84
    return threadPool;
1✔
85
  }
86

87
  public Log getLog() {
88
    return log;
1✔
89
  }
90

91
  public Grpc getGrpc() {
92
    return grpc;
1✔
93
  }
94

95
  public Client getClient() {
96
    return client;
1✔
97
  }
98

99
  public Impl getImpl() {
100
    return impl;
1✔
101
  }
102

103
  public LeaderLogAppender getLeaderLogAppender() {
104
    return leaderLogAppender;
1✔
105
  }
106

107
  public Read getRead() {
108
    return read;
1✔
109
  }
110

111
  public Utils getUtils() {
112
    return utils;
1✔
113
  }
114

115
  public static Builder newBuilder() {
116
    return new Builder();
1✔
117
  }
118

119
  public static class Builder {
1✔
120

121
    private Rpc rpc;
122
    private LeaderElection leaderElection;
123
    private Snapshot snapshot;
124
    private ThreadPool threadPool;
125
    private Log log;
126
    private Grpc grpc;
127
    private Client client;
128
    private Impl impl;
129
    private LeaderLogAppender leaderLogAppender;
130
    private Read read;
131
    private Utils utils;
132

133
    public RatisConfig build() {
134
      return new RatisConfig(
1✔
135
          Optional.ofNullable(rpc).orElseGet(() -> Rpc.newBuilder().build()),
1✔
136
          Optional.ofNullable(leaderElection).orElseGet(() -> LeaderElection.newBuilder().build()),
1✔
137
          Optional.ofNullable(snapshot).orElseGet(() -> Snapshot.newBuilder().build()),
1✔
138
          Optional.ofNullable(threadPool).orElseGet(() -> ThreadPool.newBuilder().build()),
1✔
139
          Optional.ofNullable(log).orElseGet(() -> Log.newBuilder().build()),
1✔
140
          Optional.ofNullable(grpc).orElseGet(() -> Grpc.newBuilder().build()),
1✔
141
          Optional.ofNullable(client).orElseGet(() -> Client.newBuilder().build()),
1✔
142
          Optional.ofNullable(impl).orElseGet(() -> Impl.newBuilder().build()),
1✔
143
          Optional.ofNullable(leaderLogAppender)
1✔
144
              .orElseGet(() -> LeaderLogAppender.newBuilder().build()),
1✔
145
          Optional.ofNullable(read).orElseGet(() -> Read.newBuilder().build()),
1✔
146
          Optional.ofNullable(utils).orElseGet(() -> Utils.newBuilder().build()));
1✔
147
    }
148

149
    public Builder setRpc(Rpc rpc) {
150
      this.rpc = rpc;
1✔
151
      return this;
1✔
152
    }
153

154
    public Builder setLeaderElection(LeaderElection leaderElection) {
155
      this.leaderElection = leaderElection;
×
156
      return this;
×
157
    }
158

159
    public Builder setSnapshot(Snapshot snapshot) {
160
      this.snapshot = snapshot;
1✔
161
      return this;
1✔
162
    }
163

164
    public Builder setThreadPool(ThreadPool threadPool) {
165
      this.threadPool = threadPool;
×
166
      return this;
×
167
    }
168

169
    public Builder setLog(Log log) {
170
      this.log = log;
1✔
171
      return this;
1✔
172
    }
173

174
    public Builder setGrpc(Grpc grpc) {
175
      this.grpc = grpc;
1✔
176
      return this;
1✔
177
    }
178

179
    public Builder setClient(Client client) {
180
      this.client = client;
1✔
181
      return this;
1✔
182
    }
183

184
    public Builder setImpl(Impl impl) {
185
      this.impl = impl;
1✔
186
      return this;
1✔
187
    }
188

189
    public Builder setLeaderLogAppender(LeaderLogAppender leaderLogAppender) {
190
      this.leaderLogAppender = leaderLogAppender;
1✔
191
      return this;
1✔
192
    }
193

194
    public Builder setRead(Read read) {
195
      this.read = read;
1✔
196
      return this;
1✔
197
    }
198

199
    public void setUtils(Utils utils) {
200
      this.utils = utils;
×
201
    }
×
202
  }
203

204
  /** server rpc timeout related. */
205
  public static class Rpc {
206

207
    private final TimeDuration timeoutMin;
208
    private final TimeDuration timeoutMax;
209
    private final TimeDuration requestTimeout;
210
    private final TimeDuration sleepTime;
211
    private final TimeDuration slownessTimeout;
212
    private final TimeDuration firstElectionTimeoutMin;
213
    private final TimeDuration firstElectionTimeoutMax;
214

215
    private Rpc(
216
        TimeDuration timeoutMin,
217
        TimeDuration timeoutMax,
218
        TimeDuration requestTimeout,
219
        TimeDuration sleepTime,
220
        TimeDuration slownessTimeout,
221
        TimeDuration firstElectionTimeoutMin,
222
        TimeDuration firstElectionTimeoutMax) {
1✔
223
      this.timeoutMin = timeoutMin;
1✔
224
      this.timeoutMax = timeoutMax;
1✔
225
      this.requestTimeout = requestTimeout;
1✔
226
      this.sleepTime = sleepTime;
1✔
227
      this.slownessTimeout = slownessTimeout;
1✔
228
      this.firstElectionTimeoutMin = firstElectionTimeoutMin;
1✔
229
      this.firstElectionTimeoutMax = firstElectionTimeoutMax;
1✔
230
    }
1✔
231

232
    public TimeDuration getTimeoutMin() {
233
      return timeoutMin;
1✔
234
    }
235

236
    public TimeDuration getTimeoutMax() {
237
      return timeoutMax;
1✔
238
    }
239

240
    public TimeDuration getRequestTimeout() {
241
      return requestTimeout;
1✔
242
    }
243

244
    public TimeDuration getSleepTime() {
245
      return sleepTime;
1✔
246
    }
247

248
    public TimeDuration getSlownessTimeout() {
249
      return slownessTimeout;
1✔
250
    }
251

252
    public TimeDuration getFirstElectionTimeoutMin() {
253
      return firstElectionTimeoutMin;
1✔
254
    }
255

256
    public TimeDuration getFirstElectionTimeoutMax() {
257
      return firstElectionTimeoutMax;
1✔
258
    }
259

260
    public static Rpc.Builder newBuilder() {
261
      return new Rpc.Builder();
1✔
262
    }
263

264
    public static class Builder {
1✔
265

266
      private TimeDuration timeoutMin = TimeDuration.valueOf(2, TimeUnit.SECONDS);
1✔
267
      private TimeDuration timeoutMax = TimeDuration.valueOf(4, TimeUnit.SECONDS);
1✔
268
      private TimeDuration requestTimeout = TimeDuration.valueOf(20, TimeUnit.SECONDS);
1✔
269
      private TimeDuration sleepTime = TimeDuration.valueOf(1, TimeUnit.SECONDS);
1✔
270
      private TimeDuration slownessTimeout = TimeDuration.valueOf(10, TimeUnit.MINUTES);
1✔
271

272
      private TimeDuration firstElectionTimeoutMin =
1✔
273
          TimeDuration.valueOf(50, TimeUnit.MILLISECONDS);
1✔
274

275
      private TimeDuration firstElectionTimeoutMax =
1✔
276
          TimeDuration.valueOf(150, TimeUnit.MILLISECONDS);
1✔
277

278
      public Rpc build() {
279
        return new Rpc(
1✔
280
            timeoutMin,
281
            timeoutMax,
282
            requestTimeout,
283
            sleepTime,
284
            slownessTimeout,
285
            firstElectionTimeoutMin,
286
            firstElectionTimeoutMax);
287
      }
288

289
      public Rpc.Builder setTimeoutMin(TimeDuration timeoutMin) {
290
        this.timeoutMin = timeoutMin;
1✔
291
        return this;
1✔
292
      }
293

294
      public Rpc.Builder setTimeoutMax(TimeDuration timeoutMax) {
295
        this.timeoutMax = timeoutMax;
1✔
296
        return this;
1✔
297
      }
298

299
      public Rpc.Builder setRequestTimeout(TimeDuration requestTimeout) {
300
        this.requestTimeout = requestTimeout;
1✔
301
        return this;
1✔
302
      }
303

304
      public Rpc.Builder setSleepTime(TimeDuration sleepTime) {
305
        this.sleepTime = sleepTime;
×
306
        return this;
×
307
      }
308

309
      public Rpc.Builder setSlownessTimeout(TimeDuration slownessTimeout) {
310
        this.slownessTimeout = slownessTimeout;
×
311
        return this;
×
312
      }
313

314
      public Rpc.Builder setFirstElectionTimeoutMax(TimeDuration firstElectionTimeoutMax) {
315
        this.firstElectionTimeoutMax = firstElectionTimeoutMax;
1✔
316
        return this;
1✔
317
      }
318

319
      public Rpc.Builder setFirstElectionTimeoutMin(TimeDuration firstElectionTimeoutMin) {
320
        this.firstElectionTimeoutMin = firstElectionTimeoutMin;
1✔
321
        return this;
1✔
322
      }
323
    }
324
  }
325

326
  public static class LeaderElection {
327

328
    private final TimeDuration leaderStepDownWaitTimeKey;
329
    private final boolean preVote;
330

331
    private LeaderElection(TimeDuration leaderStepDownWaitTimeKey, boolean preVote) {
1✔
332
      this.leaderStepDownWaitTimeKey = leaderStepDownWaitTimeKey;
1✔
333
      this.preVote = preVote;
1✔
334
    }
1✔
335

336
    public TimeDuration getLeaderStepDownWaitTimeKey() {
337
      return leaderStepDownWaitTimeKey;
1✔
338
    }
339

340
    public boolean isPreVote() {
341
      return preVote;
1✔
342
    }
343

344
    public static LeaderElection.Builder newBuilder() {
345
      return new LeaderElection.Builder();
1✔
346
    }
347

348
    public static class Builder {
1✔
349

350
      private TimeDuration leaderStepDownWaitTimeKey = TimeDuration.valueOf(30, TimeUnit.SECONDS);
1✔
351
      private boolean preVote = RaftServerConfigKeys.LeaderElection.PRE_VOTE_DEFAULT;
1✔
352

353
      public LeaderElection build() {
354
        return new LeaderElection(leaderStepDownWaitTimeKey, preVote);
1✔
355
      }
356

357
      public LeaderElection.Builder setLeaderStepDownWaitTimeKey(
358
          TimeDuration leaderStepDownWaitTimeKey) {
359
        this.leaderStepDownWaitTimeKey = leaderStepDownWaitTimeKey;
×
360
        return this;
×
361
      }
362

363
      public LeaderElection.Builder setPreVote(boolean preVote) {
364
        this.preVote = preVote;
×
365
        return this;
×
366
      }
367
    }
368
  }
369

370
  public static class Snapshot {
371

372
    private final boolean autoTriggerEnabled;
373
    private final long creationGap;
374
    private final long autoTriggerThreshold;
375
    private final int retentionFileNum;
376

377
    private Snapshot(
378
        boolean autoTriggerEnabled,
379
        long creationGap,
380
        long autoTriggerThreshold,
381
        int retentionFileNum) {
1✔
382
      this.autoTriggerEnabled = autoTriggerEnabled;
1✔
383
      this.creationGap = creationGap;
1✔
384
      this.autoTriggerThreshold = autoTriggerThreshold;
1✔
385
      this.retentionFileNum = retentionFileNum;
1✔
386
    }
1✔
387

388
    public boolean isAutoTriggerEnabled() {
389
      return autoTriggerEnabled;
1✔
390
    }
391

392
    public long getCreationGap() {
393
      return creationGap;
1✔
394
    }
395

396
    public long getAutoTriggerThreshold() {
397
      return autoTriggerThreshold;
1✔
398
    }
399

400
    public int getRetentionFileNum() {
401
      return retentionFileNum;
1✔
402
    }
403

404
    public static Snapshot.Builder newBuilder() {
405
      return new Snapshot.Builder();
1✔
406
    }
407

408
    public static class Builder {
1✔
409

410
      private boolean autoTriggerEnabled = true;
1✔
411
      private long creationGap = RaftServerConfigKeys.Snapshot.CREATION_GAP_DEFAULT;
1✔
412
      private long autoTriggerThreshold =
1✔
413
          RaftServerConfigKeys.Snapshot.AUTO_TRIGGER_THRESHOLD_DEFAULT;
414
      private int retentionFileNum = RaftServerConfigKeys.Snapshot.RETENTION_FILE_NUM_DEFAULT;
1✔
415

416
      public Snapshot build() {
417
        return new Snapshot(
1✔
418
            autoTriggerEnabled, creationGap, autoTriggerThreshold, retentionFileNum);
419
      }
420

421
      public Snapshot.Builder setAutoTriggerEnabled(boolean autoTriggerEnabled) {
422
        this.autoTriggerEnabled = autoTriggerEnabled;
×
423
        return this;
×
424
      }
425

426
      public Snapshot.Builder setCreationGap(long creationGap) {
427
        this.creationGap = creationGap;
1✔
428
        return this;
1✔
429
      }
430

431
      public Snapshot.Builder setAutoTriggerThreshold(long autoTriggerThreshold) {
432
        this.autoTriggerThreshold = autoTriggerThreshold;
1✔
433
        return this;
1✔
434
      }
435

436
      public Snapshot.Builder setRetentionFileNum(int retentionFileNum) {
437
        this.retentionFileNum = retentionFileNum;
×
438
        return this;
×
439
      }
440
    }
441
  }
442

443
  public static class ThreadPool {
444

445
    private final boolean proxyCached;
446
    private final int proxySize;
447
    private final boolean serverCached;
448
    private final int serverSize;
449
    private final boolean clientCached;
450
    private final int clientSize;
451

452
    private ThreadPool(
453
        boolean proxyCached,
454
        int proxySize,
455
        boolean serverCached,
456
        int serverSize,
457
        boolean clientCached,
458
        int clientSize) {
1✔
459
      this.proxyCached = proxyCached;
1✔
460
      this.proxySize = proxySize;
1✔
461
      this.serverCached = serverCached;
1✔
462
      this.serverSize = serverSize;
1✔
463
      this.clientCached = clientCached;
1✔
464
      this.clientSize = clientSize;
1✔
465
    }
1✔
466

467
    public boolean isProxyCached() {
468
      return proxyCached;
1✔
469
    }
470

471
    public int getProxySize() {
472
      return proxySize;
1✔
473
    }
474

475
    public boolean isServerCached() {
476
      return serverCached;
1✔
477
    }
478

479
    public int getServerSize() {
480
      return serverSize;
1✔
481
    }
482

483
    public boolean isClientCached() {
484
      return clientCached;
1✔
485
    }
486

487
    public int getClientSize() {
488
      return clientSize;
1✔
489
    }
490

491
    public static ThreadPool.Builder newBuilder() {
492
      return new ThreadPool.Builder();
1✔
493
    }
494

495
    public static class Builder {
1✔
496

497
      private boolean proxyCached = RaftServerConfigKeys.ThreadPool.PROXY_CACHED_DEFAULT;
1✔
498
      private int proxySize = RaftServerConfigKeys.ThreadPool.PROXY_SIZE_DEFAULT;
1✔
499
      private boolean serverCached = RaftServerConfigKeys.ThreadPool.SERVER_CACHED_DEFAULT;
1✔
500
      private int serverSize = RaftServerConfigKeys.ThreadPool.SERVER_SIZE_DEFAULT;
1✔
501
      private boolean clientCached = RaftServerConfigKeys.ThreadPool.CLIENT_CACHED_DEFAULT;
1✔
502
      private int clientSize = RaftServerConfigKeys.ThreadPool.CLIENT_SIZE_DEFAULT;
1✔
503

504
      public ThreadPool build() {
505
        return new ThreadPool(
1✔
506
            proxyCached, proxySize, serverCached, serverSize, clientCached, clientSize);
507
      }
508

509
      public ThreadPool.Builder setProxyCached(boolean proxyCached) {
510
        this.proxyCached = proxyCached;
×
511
        return this;
×
512
      }
513

514
      public ThreadPool.Builder setProxySize(int proxySize) {
515
        this.proxySize = proxySize;
×
516
        return this;
×
517
      }
518

519
      public ThreadPool.Builder setServerCached(boolean serverCached) {
520
        this.serverCached = serverCached;
×
521
        return this;
×
522
      }
523

524
      public ThreadPool.Builder setServerSize(int serverSize) {
525
        this.serverSize = serverSize;
×
526
        return this;
×
527
      }
528

529
      public ThreadPool.Builder setClientCached(boolean clientCached) {
530
        this.clientCached = clientCached;
×
531
        return this;
×
532
      }
533

534
      public ThreadPool.Builder setClientSize(int clientSize) {
535
        this.clientSize = clientSize;
×
536
        return this;
×
537
      }
538
    }
539
  }
540

541
  public static class Log {
542

543
    private final boolean useMemory;
544
    private final int queueElementLimit;
545
    private final SizeInBytes queueByteLimit;
546
    private final int purgeGap;
547
    private final boolean purgeUptoSnapshotIndex;
548
    private final long preserveNumsWhenPurge;
549
    private final SizeInBytes segmentSizeMax;
550
    private final int segmentCacheNumMax;
551
    private final SizeInBytes segmentCacheSizeMax;
552
    private final SizeInBytes preallocatedSize;
553
    private final SizeInBytes writeBufferSize;
554
    private final int forceSyncNum;
555
    private final boolean unsafeFlushEnabled;
556

557
    private Log(
558
        boolean useMemory,
559
        int queueElementLimit,
560
        SizeInBytes queueByteLimit,
561
        int purgeGap,
562
        boolean purgeUptoSnapshotIndex,
563
        long preserveNumsWhenPurge,
564
        SizeInBytes segmentSizeMax,
565
        int segmentCacheNumMax,
566
        SizeInBytes segmentCacheSizeMax,
567
        SizeInBytes preallocatedSize,
568
        SizeInBytes writeBufferSize,
569
        int forceSyncNum,
570
        boolean unsafeFlushEnabled) {
1✔
571
      this.useMemory = useMemory;
1✔
572
      this.queueElementLimit = queueElementLimit;
1✔
573
      this.queueByteLimit = queueByteLimit;
1✔
574
      this.purgeGap = purgeGap;
1✔
575
      this.purgeUptoSnapshotIndex = purgeUptoSnapshotIndex;
1✔
576
      this.preserveNumsWhenPurge = preserveNumsWhenPurge;
1✔
577
      this.segmentSizeMax = segmentSizeMax;
1✔
578
      this.segmentCacheNumMax = segmentCacheNumMax;
1✔
579
      this.segmentCacheSizeMax = segmentCacheSizeMax;
1✔
580
      this.preallocatedSize = preallocatedSize;
1✔
581
      this.writeBufferSize = writeBufferSize;
1✔
582
      this.forceSyncNum = forceSyncNum;
1✔
583
      this.unsafeFlushEnabled = unsafeFlushEnabled;
1✔
584
    }
1✔
585

586
    public boolean isUseMemory() {
587
      return useMemory;
1✔
588
    }
589

590
    public int getQueueElementLimit() {
591
      return queueElementLimit;
1✔
592
    }
593

594
    public SizeInBytes getQueueByteLimit() {
595
      return queueByteLimit;
1✔
596
    }
597

598
    public int getPurgeGap() {
599
      return purgeGap;
1✔
600
    }
601

602
    public boolean isPurgeUptoSnapshotIndex() {
603
      return purgeUptoSnapshotIndex;
1✔
604
    }
605

606
    public SizeInBytes getSegmentSizeMax() {
607
      return segmentSizeMax;
1✔
608
    }
609

610
    public int getSegmentCacheNumMax() {
611
      return segmentCacheNumMax;
1✔
612
    }
613

614
    public SizeInBytes getSegmentCacheSizeMax() {
615
      return segmentCacheSizeMax;
1✔
616
    }
617

618
    public SizeInBytes getPreallocatedSize() {
619
      return preallocatedSize;
1✔
620
    }
621

622
    public SizeInBytes getWriteBufferSize() {
623
      return writeBufferSize;
1✔
624
    }
625

626
    public int getForceSyncNum() {
627
      return forceSyncNum;
1✔
628
    }
629

630
    public boolean isUnsafeFlushEnabled() {
631
      return unsafeFlushEnabled;
1✔
632
    }
633

634
    public long getPreserveNumsWhenPurge() {
635
      return preserveNumsWhenPurge;
1✔
636
    }
637

638
    public static Log.Builder newBuilder() {
639
      return new Log.Builder();
1✔
640
    }
641

642
    public static class Builder {
1✔
643

644
      private boolean useMemory = false;
1✔
645
      private int queueElementLimit = 4096;
1✔
646
      private SizeInBytes queueByteLimit = SizeInBytes.valueOf("64MB");
1✔
647
      private int purgeGap = 1024;
1✔
648
      private boolean purgeUptoSnapshotIndex = true;
1✔
649
      private long preserveNumsWhenPurge = 1000;
1✔
650
      private SizeInBytes segmentSizeMax = SizeInBytes.valueOf("24MB");
1✔
651
      private int segmentCacheNumMax = 2;
1✔
652
      private SizeInBytes segmentCacheSizeMax = SizeInBytes.valueOf("200MB");
1✔
653
      private SizeInBytes preallocatedSize = SizeInBytes.valueOf("4MB");
1✔
654
      private SizeInBytes writeBufferSize = SizeInBytes.valueOf("64KB");
1✔
655
      private int forceSyncNum = 128;
1✔
656
      private boolean unsafeFlushEnabled = true;
1✔
657

658
      public Log build() {
659
        return new Log(
1✔
660
            useMemory,
661
            queueElementLimit,
662
            queueByteLimit,
663
            purgeGap,
664
            purgeUptoSnapshotIndex,
665
            preserveNumsWhenPurge,
666
            segmentSizeMax,
667
            segmentCacheNumMax,
668
            segmentCacheSizeMax,
669
            preallocatedSize,
670
            writeBufferSize,
671
            forceSyncNum,
672
            unsafeFlushEnabled);
673
      }
674

675
      public Log.Builder setUseMemory(boolean useMemory) {
676
        this.useMemory = useMemory;
×
677
        return this;
×
678
      }
679

680
      public Log.Builder setQueueElementLimit(int queueElementLimit) {
681
        this.queueElementLimit = queueElementLimit;
×
682
        return this;
×
683
      }
684

685
      public Log.Builder setQueueByteLimit(SizeInBytes queueByteLimit) {
686
        this.queueByteLimit = queueByteLimit;
×
687
        return this;
×
688
      }
689

690
      public Log.Builder setPurgeGap(int purgeGap) {
691
        this.purgeGap = purgeGap;
1✔
692
        return this;
1✔
693
      }
694

695
      public Log.Builder setPurgeUptoSnapshotIndex(boolean purgeUptoSnapshotIndex) {
696
        this.purgeUptoSnapshotIndex = purgeUptoSnapshotIndex;
1✔
697
        return this;
1✔
698
      }
699

700
      public Log.Builder setPreserveNumsWhenPurge(long preserveNumsWhenPurge) {
701
        this.preserveNumsWhenPurge = preserveNumsWhenPurge;
1✔
702
        return this;
1✔
703
      }
704

705
      public Log.Builder setSegmentSizeMax(SizeInBytes segmentSizeMax) {
706
        this.segmentSizeMax = segmentSizeMax;
1✔
707
        return this;
1✔
708
      }
709

710
      public Log.Builder setSegmentCacheNumMax(int segmentCacheNumMax) {
711
        this.segmentCacheNumMax = segmentCacheNumMax;
×
712
        return this;
×
713
      }
714

715
      public Log.Builder setSegmentCacheSizeMax(SizeInBytes segmentCacheSizeMax) {
716
        this.segmentCacheSizeMax = segmentCacheSizeMax;
×
717
        return this;
×
718
      }
719

720
      public Log.Builder setPreallocatedSize(SizeInBytes preallocatedSize) {
721
        this.preallocatedSize = preallocatedSize;
×
722
        return this;
×
723
      }
724

725
      public Log.Builder setWriteBufferSize(SizeInBytes writeBufferSize) {
726
        this.writeBufferSize = writeBufferSize;
×
727
        return this;
×
728
      }
729

730
      public Log.Builder setForceSyncNum(int forceSyncNum) {
731
        this.forceSyncNum = forceSyncNum;
1✔
732
        return this;
1✔
733
      }
734

735
      public Log.Builder setUnsafeFlushEnabled(boolean unsafeFlushEnabled) {
736
        this.unsafeFlushEnabled = unsafeFlushEnabled;
1✔
737
        return this;
1✔
738
      }
739
    }
740
  }
741

742
  public static class Grpc {
743

744
    private final SizeInBytes messageSizeMax;
745
    private final SizeInBytes flowControlWindow;
746
    private final boolean asyncRequestThreadPoolCached;
747
    private final int asyncRequestThreadPoolSize;
748
    private final int leaderOutstandingAppendsMax;
749

750
    private Grpc(
751
        SizeInBytes messageSizeMax,
752
        SizeInBytes flowControlWindow,
753
        boolean asyncRequestThreadPoolCached,
754
        int asyncRequestThreadPoolSize,
755
        int leaderOutstandingAppendsMax) {
1✔
756
      this.messageSizeMax = messageSizeMax;
1✔
757
      this.flowControlWindow = flowControlWindow;
1✔
758
      this.asyncRequestThreadPoolCached = asyncRequestThreadPoolCached;
1✔
759
      this.asyncRequestThreadPoolSize = asyncRequestThreadPoolSize;
1✔
760
      this.leaderOutstandingAppendsMax = leaderOutstandingAppendsMax;
1✔
761
    }
1✔
762

763
    public SizeInBytes getMessageSizeMax() {
764
      return messageSizeMax;
1✔
765
    }
766

767
    public SizeInBytes getFlowControlWindow() {
768
      return flowControlWindow;
1✔
769
    }
770

771
    public boolean isAsyncRequestThreadPoolCached() {
772
      return asyncRequestThreadPoolCached;
1✔
773
    }
774

775
    public int getAsyncRequestThreadPoolSize() {
776
      return asyncRequestThreadPoolSize;
1✔
777
    }
778

779
    public int getLeaderOutstandingAppendsMax() {
780
      return leaderOutstandingAppendsMax;
1✔
781
    }
782

783
    public static Grpc.Builder newBuilder() {
784
      return new Grpc.Builder();
1✔
785
    }
786

787
    public static class Builder {
1✔
788

789
      private SizeInBytes messageSizeMax = SizeInBytes.valueOf("512MB");
1✔
790
      private SizeInBytes flowControlWindow = SizeInBytes.valueOf("4MB");
1✔
791
      private boolean asyncRequestThreadPoolCached =
1✔
792
          Server.ASYNC_REQUEST_THREAD_POOL_CACHED_DEFAULT;
793
      private int asyncRequestThreadPoolSize = Server.ASYNC_REQUEST_THREAD_POOL_SIZE_DEFAULT;
1✔
794
      private int leaderOutstandingAppendsMax = Server.LEADER_OUTSTANDING_APPENDS_MAX_DEFAULT;
1✔
795

796
      public Grpc build() {
797
        return new Grpc(
1✔
798
            messageSizeMax,
799
            flowControlWindow,
800
            asyncRequestThreadPoolCached,
801
            asyncRequestThreadPoolSize,
802
            leaderOutstandingAppendsMax);
803
      }
804

805
      public Grpc.Builder setMessageSizeMax(SizeInBytes messageSizeMax) {
806
        this.messageSizeMax = messageSizeMax;
×
807
        return this;
×
808
      }
809

810
      public Grpc.Builder setFlowControlWindow(SizeInBytes flowControlWindow) {
811
        this.flowControlWindow = flowControlWindow;
1✔
812
        return this;
1✔
813
      }
814

815
      public Grpc.Builder setAsyncRequestThreadPoolCached(boolean asyncRequestThreadPoolCached) {
816
        this.asyncRequestThreadPoolCached = asyncRequestThreadPoolCached;
×
817
        return this;
×
818
      }
819

820
      public Grpc.Builder setAsyncRequestThreadPoolSize(int asyncRequestThreadPoolSize) {
821
        this.asyncRequestThreadPoolSize = asyncRequestThreadPoolSize;
×
822
        return this;
×
823
      }
824

825
      public Grpc.Builder setLeaderOutstandingAppendsMax(int leaderOutstandingAppendsMax) {
826
        this.leaderOutstandingAppendsMax = leaderOutstandingAppendsMax;
1✔
827
        return this;
1✔
828
      }
829
    }
830
  }
831

832
  public static class Client {
833

834
    private final long clientRequestTimeoutMillis;
835
    private final int clientMaxRetryAttempt;
836
    private final long clientRetryInitialSleepTimeMs;
837
    private final long clientRetryMaxSleepTimeMs;
838
    private final int coreClientNumForEachNode;
839
    private final int maxClientNumForEachNode;
840

841
    public Client(
842
        long clientRequestTimeoutMillis,
843
        int clientMaxRetryAttempt,
844
        long clientRetryInitialSleepTimeMs,
845
        long clientRetryMaxSleepTimeMs,
846
        int coreClientNumForEachNode,
847
        int maxClientNumForEachNode) {
1✔
848
      this.clientRequestTimeoutMillis = clientRequestTimeoutMillis;
1✔
849
      this.clientMaxRetryAttempt = clientMaxRetryAttempt;
1✔
850
      this.clientRetryInitialSleepTimeMs = clientRetryInitialSleepTimeMs;
1✔
851
      this.clientRetryMaxSleepTimeMs = clientRetryMaxSleepTimeMs;
1✔
852
      this.coreClientNumForEachNode = coreClientNumForEachNode;
1✔
853
      this.maxClientNumForEachNode = maxClientNumForEachNode;
1✔
854
    }
1✔
855

856
    public long getClientRequestTimeoutMillis() {
857
      return clientRequestTimeoutMillis;
×
858
    }
859

860
    public int getClientMaxRetryAttempt() {
861
      return clientMaxRetryAttempt;
1✔
862
    }
863

864
    public long getClientRetryInitialSleepTimeMs() {
865
      return clientRetryInitialSleepTimeMs;
1✔
866
    }
867

868
    public long getClientRetryMaxSleepTimeMs() {
869
      return clientRetryMaxSleepTimeMs;
1✔
870
    }
871

872
    public int getCoreClientNumForEachNode() {
873
      return coreClientNumForEachNode;
1✔
874
    }
875

876
    public int getMaxClientNumForEachNode() {
877
      return maxClientNumForEachNode;
1✔
878
    }
879

880
    public static Client.Builder newBuilder() {
881
      return new Builder();
1✔
882
    }
883

884
    public static class Builder {
1✔
885

886
      private long clientRequestTimeoutMillis = 10000;
1✔
887
      private int clientMaxRetryAttempt = 10;
1✔
888
      private long clientRetryInitialSleepTimeMs = 100;
1✔
889
      private long clientRetryMaxSleepTimeMs = 10000;
1✔
890

891
      private int coreClientNumForEachNode = DefaultProperty.CORE_CLIENT_NUM_FOR_EACH_NODE;
1✔
892

893
      private int maxClientNumForEachNode = DefaultProperty.MAX_CLIENT_NUM_FOR_EACH_NODE;
1✔
894

895
      public Client build() {
896
        return new Client(
1✔
897
            clientRequestTimeoutMillis,
898
            clientMaxRetryAttempt,
899
            clientRetryInitialSleepTimeMs,
900
            clientRetryMaxSleepTimeMs,
901
            coreClientNumForEachNode,
902
            maxClientNumForEachNode);
903
      }
904

905
      public Builder setClientRequestTimeoutMillis(long clientRequestTimeoutMillis) {
906
        this.clientRequestTimeoutMillis = clientRequestTimeoutMillis;
1✔
907
        return this;
1✔
908
      }
909

910
      public Builder setClientMaxRetryAttempt(int clientMaxRetryAttempt) {
911
        this.clientMaxRetryAttempt = clientMaxRetryAttempt;
1✔
912
        return this;
1✔
913
      }
914

915
      public Builder setClientRetryInitialSleepTimeMs(long clientRetryInitialSleepTimeMs) {
916
        this.clientRetryInitialSleepTimeMs = clientRetryInitialSleepTimeMs;
1✔
917
        return this;
1✔
918
      }
919

920
      public Builder setClientRetryMaxSleepTimeMs(long clientRetryMaxSleepTimeMs) {
921
        this.clientRetryMaxSleepTimeMs = clientRetryMaxSleepTimeMs;
1✔
922
        return this;
1✔
923
      }
924

925
      public Builder setCoreClientNumForEachNode(int coreClientNumForEachNode) {
926
        this.coreClientNumForEachNode = coreClientNumForEachNode;
1✔
927
        return this;
1✔
928
      }
929

930
      public Builder setMaxClientNumForEachNode(int maxClientNumForEachNode) {
931
        this.maxClientNumForEachNode = maxClientNumForEachNode;
1✔
932
        return this;
1✔
933
      }
934
    }
935
  }
936

937
  public static class Impl {
938

939
    private final int retryTimesMax;
940
    private final long retryWaitMillis;
941

942
    private final long triggerSnapshotTime;
943
    private final long triggerSnapshotFileSize;
944

945
    public Impl(
946
        int retryTimesMax,
947
        long retryWaitMillis,
948
        long triggerSnapshotTime,
949
        long triggerSnapshotFileSize) {
1✔
950
      this.retryTimesMax = retryTimesMax;
1✔
951
      this.retryWaitMillis = retryWaitMillis;
1✔
952
      this.triggerSnapshotTime = triggerSnapshotTime;
1✔
953
      this.triggerSnapshotFileSize = triggerSnapshotFileSize;
1✔
954
    }
1✔
955

956
    public int getRetryTimesMax() {
957
      return retryTimesMax;
1✔
958
    }
959

960
    public long getRetryWaitMillis() {
961
      return retryWaitMillis;
1✔
962
    }
963

964
    public long getTriggerSnapshotTime() {
965
      return triggerSnapshotTime;
1✔
966
    }
967

968
    public long getTriggerSnapshotFileSize() {
969
      return triggerSnapshotFileSize;
1✔
970
    }
971

972
    public static Impl.Builder newBuilder() {
973
      return new Builder();
1✔
974
    }
975

976
    public static class Builder {
1✔
977

978
      private int retryTimesMax = 3;
1✔
979
      private long retryWaitMillis = 500;
1✔
980

981
      // 120s
982
      private long triggerSnapshotTime = 120;
1✔
983
      // 20GB
984
      private long triggerSnapshotFileSize = 20L << 30;
1✔
985

986
      public Impl build() {
987
        return new Impl(
1✔
988
            retryTimesMax, retryWaitMillis, triggerSnapshotTime, triggerSnapshotFileSize);
989
      }
990

991
      public Impl.Builder setRetryTimesMax(int retryTimesMax) {
992
        this.retryTimesMax = retryTimesMax;
×
993
        return this;
×
994
      }
995

996
      public Impl.Builder setRetryWaitMillis(long retryWaitMillis) {
997
        this.retryWaitMillis = retryWaitMillis;
×
998
        return this;
×
999
      }
1000

1001
      public Impl.Builder setTriggerSnapshotTime(long triggerSnapshotTime) {
1002
        this.triggerSnapshotTime = triggerSnapshotTime;
1✔
1003
        return this;
1✔
1004
      }
1005

1006
      public Impl.Builder setTriggerSnapshotFileSize(long triggerSnapshotFileSize) {
1007
        this.triggerSnapshotFileSize = triggerSnapshotFileSize;
1✔
1008
        return this;
1✔
1009
      }
1010
    }
1011
  }
1012

1013
  public static class LeaderLogAppender {
1014

1015
    private final SizeInBytes bufferByteLimit;
1016
    private final SizeInBytes snapshotChunkSizeMax;
1017
    private final boolean installSnapshotEnabled;
1018

1019
    private LeaderLogAppender(
1020
        SizeInBytes bufferByteLimit,
1021
        SizeInBytes snapshotChunkSizeMax,
1022
        boolean installSnapshotEnabled) {
1✔
1023
      this.bufferByteLimit = bufferByteLimit;
1✔
1024
      this.snapshotChunkSizeMax = snapshotChunkSizeMax;
1✔
1025
      this.installSnapshotEnabled = installSnapshotEnabled;
1✔
1026
    }
1✔
1027

1028
    public SizeInBytes getBufferByteLimit() {
1029
      return bufferByteLimit;
1✔
1030
    }
1031

1032
    public SizeInBytes getSnapshotChunkSizeMax() {
1033
      return snapshotChunkSizeMax;
1✔
1034
    }
1035

1036
    public boolean isInstallSnapshotEnabled() {
1037
      return installSnapshotEnabled;
1✔
1038
    }
1039

1040
    public static LeaderLogAppender.Builder newBuilder() {
1041
      return new LeaderLogAppender.Builder();
1✔
1042
    }
1043

1044
    public static class Builder {
1✔
1045

1046
      private SizeInBytes bufferByteLimit =
1✔
1047
          RaftServerConfigKeys.Log.Appender.BUFFER_BYTE_LIMIT_DEFAULT;
1048
      private SizeInBytes snapshotChunkSizeMax =
1✔
1049
          RaftServerConfigKeys.Log.Appender.SNAPSHOT_CHUNK_SIZE_MAX_DEFAULT;
1050
      private boolean installSnapshotEnabled =
1✔
1051
          RaftServerConfigKeys.Log.Appender.INSTALL_SNAPSHOT_ENABLED_DEFAULT;
1052

1053
      public LeaderLogAppender build() {
1054
        return new LeaderLogAppender(bufferByteLimit, snapshotChunkSizeMax, installSnapshotEnabled);
1✔
1055
      }
1056

1057
      public LeaderLogAppender.Builder setBufferByteLimit(long bufferByteLimit) {
1058
        this.bufferByteLimit = SizeInBytes.valueOf(bufferByteLimit);
1✔
1059
        return this;
1✔
1060
      }
1061

1062
      public LeaderLogAppender.Builder setSnapshotChunkSizeMax(long snapshotChunkSizeMax) {
1063
        this.snapshotChunkSizeMax = SizeInBytes.valueOf(snapshotChunkSizeMax);
×
1064
        return this;
×
1065
      }
1066

1067
      public LeaderLogAppender.Builder setInstallSnapshotEnabled(boolean installSnapshotEnabled) {
1068
        this.installSnapshotEnabled = installSnapshotEnabled;
×
1069
        return this;
×
1070
      }
1071
    }
1072
  }
1073

1074
  public static class Read {
1075
    public enum Option {
1✔
1076
      DEFAULT,
1✔
1077
      LINEARIZABLE
1✔
1078
    }
1079

1080
    private final Read.Option readOption;
1081
    private final TimeDuration readTimeout;
1082

1083
    private Read(Read.Option readOption, TimeDuration readTimeout) {
1✔
1084
      this.readOption = readOption;
1✔
1085
      this.readTimeout = readTimeout;
1✔
1086
    }
1✔
1087

1088
    public Option getReadOption() {
1089
      return readOption;
1✔
1090
    }
1091

1092
    public TimeDuration getReadTimeout() {
1093
      return readTimeout;
1✔
1094
    }
1095

1096
    public static Read.Builder newBuilder() {
1097
      return new Read.Builder();
1✔
1098
    }
1099

1100
    public static class Builder {
1✔
1101
      private Read.Option readOption = Option.LINEARIZABLE;
1✔
1102
      private TimeDuration readTimeout = TimeDuration.valueOf(10, TimeUnit.SECONDS);
1✔
1103

1104
      public Read.Builder setReadOption(Read.Option readOption) {
1105
        this.readOption = readOption;
×
1106
        return this;
×
1107
      }
1108

1109
      public Read.Builder setReadTimeout(TimeDuration timeout) {
1110
        this.readTimeout = timeout;
1✔
1111
        return this;
1✔
1112
      }
1113

1114
      public Read build() {
1115
        return new Read(readOption, readTimeout);
1✔
1116
      }
1117
    }
1118
  }
1119

1120
  public static class Utils {
1121

1122
    private final int sleepDeviationThresholdMs;
1123

1124
    private Utils(int sleepDeviationThresholdMs) {
1✔
1125
      this.sleepDeviationThresholdMs = sleepDeviationThresholdMs;
1✔
1126
    }
1✔
1127

1128
    public int getSleepDeviationThresholdMs() {
1129
      return sleepDeviationThresholdMs;
1✔
1130
    }
1131

1132
    public static Utils.Builder newBuilder() {
1133
      return new Utils.Builder();
1✔
1134
    }
1135

1136
    public static class Builder {
1✔
1137

1138
      private int sleepDeviationThresholdMs = 4 * 1000;
1✔
1139

1140
      public Utils build() {
1141
        return new Utils(sleepDeviationThresholdMs);
1✔
1142
      }
1143

1144
      public void setSleepDeviationThresholdMs(int sleepDeviationThresholdMs) {
1145
        this.sleepDeviationThresholdMs = sleepDeviationThresholdMs;
×
1146
      }
×
1147
    }
1148
  }
1149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc