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

apache / iotdb / #9666

pending completion
#9666

push

travis_ci

web-flow
[IOTDB-5557] [RatisConsensus] Support linearizable read during recovery (#10597)

53 of 53 new or added lines in 4 files covered. (100.0%)

79130 of 165784 relevant lines covered (47.73%)

0.48 hits per line

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

84.1
/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

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

68
  public Rpc getRpc() {
69
    return rpc;
1✔
70
  }
71

72
  public LeaderElection getLeaderElection() {
73
    return leaderElection;
1✔
74
  }
75

76
  public Snapshot getSnapshot() {
77
    return snapshot;
1✔
78
  }
79

80
  public ThreadPool getThreadPool() {
81
    return threadPool;
1✔
82
  }
83

84
  public Log getLog() {
85
    return log;
1✔
86
  }
87

88
  public Grpc getGrpc() {
89
    return grpc;
1✔
90
  }
91

92
  public Client getClient() {
93
    return client;
1✔
94
  }
95

96
  public Impl getImpl() {
97
    return impl;
1✔
98
  }
99

100
  public LeaderLogAppender getLeaderLogAppender() {
101
    return leaderLogAppender;
1✔
102
  }
103

104
  public Read getRead() {
105
    return read;
1✔
106
  }
107

108
  public static Builder newBuilder() {
109
    return new Builder();
1✔
110
  }
111

112
  public static class Builder {
1✔
113

114
    private Rpc rpc;
115
    private LeaderElection leaderElection;
116
    private Snapshot snapshot;
117
    private ThreadPool threadPool;
118
    private Log log;
119
    private Grpc grpc;
120

121
    private Client client;
122
    private Impl impl;
123
    private LeaderLogAppender leaderLogAppender;
124
    private Read read;
125

126
    public RatisConfig build() {
127
      return new RatisConfig(
1✔
128
          Optional.ofNullable(rpc).orElseGet(() -> Rpc.newBuilder().build()),
1✔
129
          Optional.ofNullable(leaderElection).orElseGet(() -> LeaderElection.newBuilder().build()),
1✔
130
          Optional.ofNullable(snapshot).orElseGet(() -> Snapshot.newBuilder().build()),
1✔
131
          Optional.ofNullable(threadPool).orElseGet(() -> ThreadPool.newBuilder().build()),
1✔
132
          Optional.ofNullable(log).orElseGet(() -> Log.newBuilder().build()),
1✔
133
          Optional.ofNullable(grpc).orElseGet(() -> Grpc.newBuilder().build()),
1✔
134
          Optional.ofNullable(client).orElseGet(() -> Client.newBuilder().build()),
1✔
135
          Optional.ofNullable(impl).orElseGet(() -> Impl.newBuilder().build()),
1✔
136
          Optional.ofNullable(leaderLogAppender)
1✔
137
              .orElseGet(() -> LeaderLogAppender.newBuilder().build()),
1✔
138
          Optional.ofNullable(read).orElseGet(() -> Read.newBuilder().build()));
1✔
139
    }
140

141
    public Builder setRpc(Rpc rpc) {
142
      this.rpc = rpc;
1✔
143
      return this;
1✔
144
    }
145

146
    public Builder setLeaderElection(LeaderElection leaderElection) {
147
      this.leaderElection = leaderElection;
×
148
      return this;
×
149
    }
150

151
    public Builder setSnapshot(Snapshot snapshot) {
152
      this.snapshot = snapshot;
1✔
153
      return this;
1✔
154
    }
155

156
    public Builder setThreadPool(ThreadPool threadPool) {
157
      this.threadPool = threadPool;
×
158
      return this;
×
159
    }
160

161
    public Builder setLog(Log log) {
162
      this.log = log;
1✔
163
      return this;
1✔
164
    }
165

166
    public Builder setGrpc(Grpc grpc) {
167
      this.grpc = grpc;
1✔
168
      return this;
1✔
169
    }
170

171
    public Builder setClient(Client client) {
172
      this.client = client;
1✔
173
      return this;
1✔
174
    }
175

176
    public Builder setImpl(Impl impl) {
177
      this.impl = impl;
1✔
178
      return this;
1✔
179
    }
180

181
    public Builder setLeaderLogAppender(LeaderLogAppender leaderLogAppender) {
182
      this.leaderLogAppender = leaderLogAppender;
1✔
183
      return this;
1✔
184
    }
185

186
    public Builder setRead(Read read) {
187
      this.read = read;
1✔
188
      return this;
1✔
189
    }
190
  }
191

192
  /** server rpc timeout related. */
193
  public static class Rpc {
194

195
    private final TimeDuration timeoutMin;
196
    private final TimeDuration timeoutMax;
197
    private final TimeDuration requestTimeout;
198
    private final TimeDuration sleepTime;
199
    private final TimeDuration slownessTimeout;
200
    private final TimeDuration firstElectionTimeoutMin;
201
    private final TimeDuration firstElectionTimeoutMax;
202

203
    private Rpc(
204
        TimeDuration timeoutMin,
205
        TimeDuration timeoutMax,
206
        TimeDuration requestTimeout,
207
        TimeDuration sleepTime,
208
        TimeDuration slownessTimeout,
209
        TimeDuration firstElectionTimeoutMin,
210
        TimeDuration firstElectionTimeoutMax) {
1✔
211
      this.timeoutMin = timeoutMin;
1✔
212
      this.timeoutMax = timeoutMax;
1✔
213
      this.requestTimeout = requestTimeout;
1✔
214
      this.sleepTime = sleepTime;
1✔
215
      this.slownessTimeout = slownessTimeout;
1✔
216
      this.firstElectionTimeoutMin = firstElectionTimeoutMin;
1✔
217
      this.firstElectionTimeoutMax = firstElectionTimeoutMax;
1✔
218
    }
1✔
219

220
    public TimeDuration getTimeoutMin() {
221
      return timeoutMin;
1✔
222
    }
223

224
    public TimeDuration getTimeoutMax() {
225
      return timeoutMax;
1✔
226
    }
227

228
    public TimeDuration getRequestTimeout() {
229
      return requestTimeout;
1✔
230
    }
231

232
    public TimeDuration getSleepTime() {
233
      return sleepTime;
1✔
234
    }
235

236
    public TimeDuration getSlownessTimeout() {
237
      return slownessTimeout;
1✔
238
    }
239

240
    public TimeDuration getFirstElectionTimeoutMin() {
241
      return firstElectionTimeoutMin;
1✔
242
    }
243

244
    public TimeDuration getFirstElectionTimeoutMax() {
245
      return firstElectionTimeoutMax;
1✔
246
    }
247

248
    public static Rpc.Builder newBuilder() {
249
      return new Rpc.Builder();
1✔
250
    }
251

252
    public static class Builder {
1✔
253

254
      private TimeDuration timeoutMin = TimeDuration.valueOf(2, TimeUnit.SECONDS);
1✔
255
      private TimeDuration timeoutMax = TimeDuration.valueOf(4, TimeUnit.SECONDS);
1✔
256
      private TimeDuration requestTimeout = TimeDuration.valueOf(20, TimeUnit.SECONDS);
1✔
257
      private TimeDuration sleepTime = TimeDuration.valueOf(1, TimeUnit.SECONDS);
1✔
258
      private TimeDuration slownessTimeout = TimeDuration.valueOf(10, TimeUnit.MINUTES);
1✔
259

260
      private TimeDuration firstElectionTimeoutMin =
1✔
261
          TimeDuration.valueOf(50, TimeUnit.MILLISECONDS);
1✔
262

263
      private TimeDuration firstElectionTimeoutMax =
1✔
264
          TimeDuration.valueOf(150, TimeUnit.MILLISECONDS);
1✔
265

266
      public Rpc build() {
267
        return new Rpc(
1✔
268
            timeoutMin,
269
            timeoutMax,
270
            requestTimeout,
271
            sleepTime,
272
            slownessTimeout,
273
            firstElectionTimeoutMin,
274
            firstElectionTimeoutMax);
275
      }
276

277
      public Rpc.Builder setTimeoutMin(TimeDuration timeoutMin) {
278
        this.timeoutMin = timeoutMin;
1✔
279
        return this;
1✔
280
      }
281

282
      public Rpc.Builder setTimeoutMax(TimeDuration timeoutMax) {
283
        this.timeoutMax = timeoutMax;
1✔
284
        return this;
1✔
285
      }
286

287
      public Rpc.Builder setRequestTimeout(TimeDuration requestTimeout) {
288
        this.requestTimeout = requestTimeout;
1✔
289
        return this;
1✔
290
      }
291

292
      public Rpc.Builder setSleepTime(TimeDuration sleepTime) {
293
        this.sleepTime = sleepTime;
×
294
        return this;
×
295
      }
296

297
      public Rpc.Builder setSlownessTimeout(TimeDuration slownessTimeout) {
298
        this.slownessTimeout = slownessTimeout;
×
299
        return this;
×
300
      }
301

302
      public Rpc.Builder setFirstElectionTimeoutMax(TimeDuration firstElectionTimeoutMax) {
303
        this.firstElectionTimeoutMax = firstElectionTimeoutMax;
1✔
304
        return this;
1✔
305
      }
306

307
      public Rpc.Builder setFirstElectionTimeoutMin(TimeDuration firstElectionTimeoutMin) {
308
        this.firstElectionTimeoutMin = firstElectionTimeoutMin;
1✔
309
        return this;
1✔
310
      }
311
    }
312
  }
313

314
  public static class LeaderElection {
315

316
    private final TimeDuration leaderStepDownWaitTimeKey;
317
    private final boolean preVote;
318

319
    private LeaderElection(TimeDuration leaderStepDownWaitTimeKey, boolean preVote) {
1✔
320
      this.leaderStepDownWaitTimeKey = leaderStepDownWaitTimeKey;
1✔
321
      this.preVote = preVote;
1✔
322
    }
1✔
323

324
    public TimeDuration getLeaderStepDownWaitTimeKey() {
325
      return leaderStepDownWaitTimeKey;
1✔
326
    }
327

328
    public boolean isPreVote() {
329
      return preVote;
1✔
330
    }
331

332
    public static LeaderElection.Builder newBuilder() {
333
      return new LeaderElection.Builder();
1✔
334
    }
335

336
    public static class Builder {
1✔
337

338
      private TimeDuration leaderStepDownWaitTimeKey = TimeDuration.valueOf(30, TimeUnit.SECONDS);
1✔
339
      private boolean preVote = RaftServerConfigKeys.LeaderElection.PRE_VOTE_DEFAULT;
1✔
340

341
      public LeaderElection build() {
342
        return new LeaderElection(leaderStepDownWaitTimeKey, preVote);
1✔
343
      }
344

345
      public LeaderElection.Builder setLeaderStepDownWaitTimeKey(
346
          TimeDuration leaderStepDownWaitTimeKey) {
347
        this.leaderStepDownWaitTimeKey = leaderStepDownWaitTimeKey;
×
348
        return this;
×
349
      }
350

351
      public LeaderElection.Builder setPreVote(boolean preVote) {
352
        this.preVote = preVote;
×
353
        return this;
×
354
      }
355
    }
356
  }
357

358
  public static class Snapshot {
359

360
    private final boolean autoTriggerEnabled;
361
    private final long creationGap;
362
    private final long autoTriggerThreshold;
363
    private final int retentionFileNum;
364

365
    private Snapshot(
366
        boolean autoTriggerEnabled,
367
        long creationGap,
368
        long autoTriggerThreshold,
369
        int retentionFileNum) {
1✔
370
      this.autoTriggerEnabled = autoTriggerEnabled;
1✔
371
      this.creationGap = creationGap;
1✔
372
      this.autoTriggerThreshold = autoTriggerThreshold;
1✔
373
      this.retentionFileNum = retentionFileNum;
1✔
374
    }
1✔
375

376
    public boolean isAutoTriggerEnabled() {
377
      return autoTriggerEnabled;
1✔
378
    }
379

380
    public long getCreationGap() {
381
      return creationGap;
1✔
382
    }
383

384
    public long getAutoTriggerThreshold() {
385
      return autoTriggerThreshold;
1✔
386
    }
387

388
    public int getRetentionFileNum() {
389
      return retentionFileNum;
1✔
390
    }
391

392
    public static Snapshot.Builder newBuilder() {
393
      return new Snapshot.Builder();
1✔
394
    }
395

396
    public static class Builder {
1✔
397

398
      private boolean autoTriggerEnabled = true;
1✔
399
      private long creationGap = RaftServerConfigKeys.Snapshot.CREATION_GAP_DEFAULT;
1✔
400
      private long autoTriggerThreshold =
1✔
401
          RaftServerConfigKeys.Snapshot.AUTO_TRIGGER_THRESHOLD_DEFAULT;
402
      private int retentionFileNum = RaftServerConfigKeys.Snapshot.RETENTION_FILE_NUM_DEFAULT;
1✔
403

404
      public Snapshot build() {
405
        return new Snapshot(
1✔
406
            autoTriggerEnabled, creationGap, autoTriggerThreshold, retentionFileNum);
407
      }
408

409
      public Snapshot.Builder setAutoTriggerEnabled(boolean autoTriggerEnabled) {
410
        this.autoTriggerEnabled = autoTriggerEnabled;
×
411
        return this;
×
412
      }
413

414
      public Snapshot.Builder setCreationGap(long creationGap) {
415
        this.creationGap = creationGap;
1✔
416
        return this;
1✔
417
      }
418

419
      public Snapshot.Builder setAutoTriggerThreshold(long autoTriggerThreshold) {
420
        this.autoTriggerThreshold = autoTriggerThreshold;
1✔
421
        return this;
1✔
422
      }
423

424
      public Snapshot.Builder setRetentionFileNum(int retentionFileNum) {
425
        this.retentionFileNum = retentionFileNum;
×
426
        return this;
×
427
      }
428
    }
429
  }
430

431
  public static class ThreadPool {
432

433
    private final boolean proxyCached;
434
    private final int proxySize;
435
    private final boolean serverCached;
436
    private final int serverSize;
437
    private final boolean clientCached;
438
    private final int clientSize;
439

440
    private ThreadPool(
441
        boolean proxyCached,
442
        int proxySize,
443
        boolean serverCached,
444
        int serverSize,
445
        boolean clientCached,
446
        int clientSize) {
1✔
447
      this.proxyCached = proxyCached;
1✔
448
      this.proxySize = proxySize;
1✔
449
      this.serverCached = serverCached;
1✔
450
      this.serverSize = serverSize;
1✔
451
      this.clientCached = clientCached;
1✔
452
      this.clientSize = clientSize;
1✔
453
    }
1✔
454

455
    public boolean isProxyCached() {
456
      return proxyCached;
1✔
457
    }
458

459
    public int getProxySize() {
460
      return proxySize;
1✔
461
    }
462

463
    public boolean isServerCached() {
464
      return serverCached;
1✔
465
    }
466

467
    public int getServerSize() {
468
      return serverSize;
1✔
469
    }
470

471
    public boolean isClientCached() {
472
      return clientCached;
1✔
473
    }
474

475
    public int getClientSize() {
476
      return clientSize;
1✔
477
    }
478

479
    public static ThreadPool.Builder newBuilder() {
480
      return new ThreadPool.Builder();
1✔
481
    }
482

483
    public static class Builder {
1✔
484

485
      private boolean proxyCached = RaftServerConfigKeys.ThreadPool.PROXY_CACHED_DEFAULT;
1✔
486
      private int proxySize = RaftServerConfigKeys.ThreadPool.PROXY_SIZE_DEFAULT;
1✔
487
      private boolean serverCached = RaftServerConfigKeys.ThreadPool.SERVER_CACHED_DEFAULT;
1✔
488
      private int serverSize = RaftServerConfigKeys.ThreadPool.SERVER_SIZE_DEFAULT;
1✔
489
      private boolean clientCached = RaftServerConfigKeys.ThreadPool.CLIENT_CACHED_DEFAULT;
1✔
490
      private int clientSize = RaftServerConfigKeys.ThreadPool.CLIENT_SIZE_DEFAULT;
1✔
491

492
      public ThreadPool build() {
493
        return new ThreadPool(
1✔
494
            proxyCached, proxySize, serverCached, serverSize, clientCached, clientSize);
495
      }
496

497
      public ThreadPool.Builder setProxyCached(boolean proxyCached) {
498
        this.proxyCached = proxyCached;
×
499
        return this;
×
500
      }
501

502
      public ThreadPool.Builder setProxySize(int proxySize) {
503
        this.proxySize = proxySize;
×
504
        return this;
×
505
      }
506

507
      public ThreadPool.Builder setServerCached(boolean serverCached) {
508
        this.serverCached = serverCached;
×
509
        return this;
×
510
      }
511

512
      public ThreadPool.Builder setServerSize(int serverSize) {
513
        this.serverSize = serverSize;
×
514
        return this;
×
515
      }
516

517
      public ThreadPool.Builder setClientCached(boolean clientCached) {
518
        this.clientCached = clientCached;
×
519
        return this;
×
520
      }
521

522
      public ThreadPool.Builder setClientSize(int clientSize) {
523
        this.clientSize = clientSize;
×
524
        return this;
×
525
      }
526
    }
527
  }
528

529
  public static class Log {
530

531
    private final boolean useMemory;
532
    private final int queueElementLimit;
533
    private final SizeInBytes queueByteLimit;
534
    private final int purgeGap;
535
    private final boolean purgeUptoSnapshotIndex;
536
    private final long preserveNumsWhenPurge;
537
    private final SizeInBytes segmentSizeMax;
538
    private final int segmentCacheNumMax;
539
    private final SizeInBytes segmentCacheSizeMax;
540
    private final SizeInBytes preallocatedSize;
541
    private final SizeInBytes writeBufferSize;
542
    private final int forceSyncNum;
543
    private final boolean unsafeFlushEnabled;
544

545
    private Log(
546
        boolean useMemory,
547
        int queueElementLimit,
548
        SizeInBytes queueByteLimit,
549
        int purgeGap,
550
        boolean purgeUptoSnapshotIndex,
551
        long preserveNumsWhenPurge,
552
        SizeInBytes segmentSizeMax,
553
        int segmentCacheNumMax,
554
        SizeInBytes segmentCacheSizeMax,
555
        SizeInBytes preallocatedSize,
556
        SizeInBytes writeBufferSize,
557
        int forceSyncNum,
558
        boolean unsafeFlushEnabled) {
1✔
559
      this.useMemory = useMemory;
1✔
560
      this.queueElementLimit = queueElementLimit;
1✔
561
      this.queueByteLimit = queueByteLimit;
1✔
562
      this.purgeGap = purgeGap;
1✔
563
      this.purgeUptoSnapshotIndex = purgeUptoSnapshotIndex;
1✔
564
      this.preserveNumsWhenPurge = preserveNumsWhenPurge;
1✔
565
      this.segmentSizeMax = segmentSizeMax;
1✔
566
      this.segmentCacheNumMax = segmentCacheNumMax;
1✔
567
      this.segmentCacheSizeMax = segmentCacheSizeMax;
1✔
568
      this.preallocatedSize = preallocatedSize;
1✔
569
      this.writeBufferSize = writeBufferSize;
1✔
570
      this.forceSyncNum = forceSyncNum;
1✔
571
      this.unsafeFlushEnabled = unsafeFlushEnabled;
1✔
572
    }
1✔
573

574
    public boolean isUseMemory() {
575
      return useMemory;
1✔
576
    }
577

578
    public int getQueueElementLimit() {
579
      return queueElementLimit;
1✔
580
    }
581

582
    public SizeInBytes getQueueByteLimit() {
583
      return queueByteLimit;
1✔
584
    }
585

586
    public int getPurgeGap() {
587
      return purgeGap;
1✔
588
    }
589

590
    public boolean isPurgeUptoSnapshotIndex() {
591
      return purgeUptoSnapshotIndex;
1✔
592
    }
593

594
    public SizeInBytes getSegmentSizeMax() {
595
      return segmentSizeMax;
1✔
596
    }
597

598
    public int getSegmentCacheNumMax() {
599
      return segmentCacheNumMax;
1✔
600
    }
601

602
    public SizeInBytes getSegmentCacheSizeMax() {
603
      return segmentCacheSizeMax;
1✔
604
    }
605

606
    public SizeInBytes getPreallocatedSize() {
607
      return preallocatedSize;
1✔
608
    }
609

610
    public SizeInBytes getWriteBufferSize() {
611
      return writeBufferSize;
1✔
612
    }
613

614
    public int getForceSyncNum() {
615
      return forceSyncNum;
1✔
616
    }
617

618
    public boolean isUnsafeFlushEnabled() {
619
      return unsafeFlushEnabled;
1✔
620
    }
621

622
    public long getPreserveNumsWhenPurge() {
623
      return preserveNumsWhenPurge;
1✔
624
    }
625

626
    public static Log.Builder newBuilder() {
627
      return new Log.Builder();
1✔
628
    }
629

630
    public static class Builder {
1✔
631

632
      private boolean useMemory = false;
1✔
633
      private int queueElementLimit = 4096;
1✔
634
      private SizeInBytes queueByteLimit = SizeInBytes.valueOf("64MB");
1✔
635
      private int purgeGap = 1024;
1✔
636
      private boolean purgeUptoSnapshotIndex = true;
1✔
637
      private long preserveNumsWhenPurge = 1000;
1✔
638
      private SizeInBytes segmentSizeMax = SizeInBytes.valueOf("24MB");
1✔
639
      private int segmentCacheNumMax = 2;
1✔
640
      private SizeInBytes segmentCacheSizeMax = SizeInBytes.valueOf("200MB");
1✔
641
      private SizeInBytes preallocatedSize = SizeInBytes.valueOf("4MB");
1✔
642
      private SizeInBytes writeBufferSize = SizeInBytes.valueOf("64KB");
1✔
643
      private int forceSyncNum = 128;
1✔
644
      private boolean unsafeFlushEnabled = true;
1✔
645

646
      public Log build() {
647
        return new Log(
1✔
648
            useMemory,
649
            queueElementLimit,
650
            queueByteLimit,
651
            purgeGap,
652
            purgeUptoSnapshotIndex,
653
            preserveNumsWhenPurge,
654
            segmentSizeMax,
655
            segmentCacheNumMax,
656
            segmentCacheSizeMax,
657
            preallocatedSize,
658
            writeBufferSize,
659
            forceSyncNum,
660
            unsafeFlushEnabled);
661
      }
662

663
      public Log.Builder setUseMemory(boolean useMemory) {
664
        this.useMemory = useMemory;
×
665
        return this;
×
666
      }
667

668
      public Log.Builder setQueueElementLimit(int queueElementLimit) {
669
        this.queueElementLimit = queueElementLimit;
×
670
        return this;
×
671
      }
672

673
      public Log.Builder setQueueByteLimit(SizeInBytes queueByteLimit) {
674
        this.queueByteLimit = queueByteLimit;
×
675
        return this;
×
676
      }
677

678
      public Log.Builder setPurgeGap(int purgeGap) {
679
        this.purgeGap = purgeGap;
1✔
680
        return this;
1✔
681
      }
682

683
      public Log.Builder setPurgeUptoSnapshotIndex(boolean purgeUptoSnapshotIndex) {
684
        this.purgeUptoSnapshotIndex = purgeUptoSnapshotIndex;
1✔
685
        return this;
1✔
686
      }
687

688
      public Log.Builder setPreserveNumsWhenPurge(long preserveNumsWhenPurge) {
689
        this.preserveNumsWhenPurge = preserveNumsWhenPurge;
1✔
690
        return this;
1✔
691
      }
692

693
      public Log.Builder setSegmentSizeMax(SizeInBytes segmentSizeMax) {
694
        this.segmentSizeMax = segmentSizeMax;
1✔
695
        return this;
1✔
696
      }
697

698
      public Log.Builder setSegmentCacheNumMax(int segmentCacheNumMax) {
699
        this.segmentCacheNumMax = segmentCacheNumMax;
×
700
        return this;
×
701
      }
702

703
      public Log.Builder setSegmentCacheSizeMax(SizeInBytes segmentCacheSizeMax) {
704
        this.segmentCacheSizeMax = segmentCacheSizeMax;
×
705
        return this;
×
706
      }
707

708
      public Log.Builder setPreallocatedSize(SizeInBytes preallocatedSize) {
709
        this.preallocatedSize = preallocatedSize;
×
710
        return this;
×
711
      }
712

713
      public Log.Builder setWriteBufferSize(SizeInBytes writeBufferSize) {
714
        this.writeBufferSize = writeBufferSize;
×
715
        return this;
×
716
      }
717

718
      public Log.Builder setForceSyncNum(int forceSyncNum) {
719
        this.forceSyncNum = forceSyncNum;
1✔
720
        return this;
1✔
721
      }
722

723
      public Log.Builder setUnsafeFlushEnabled(boolean unsafeFlushEnabled) {
724
        this.unsafeFlushEnabled = unsafeFlushEnabled;
1✔
725
        return this;
1✔
726
      }
727
    }
728
  }
729

730
  public static class Grpc {
731

732
    private final SizeInBytes messageSizeMax;
733
    private final SizeInBytes flowControlWindow;
734
    private final boolean asyncRequestThreadPoolCached;
735
    private final int asyncRequestThreadPoolSize;
736
    private final int leaderOutstandingAppendsMax;
737

738
    private Grpc(
739
        SizeInBytes messageSizeMax,
740
        SizeInBytes flowControlWindow,
741
        boolean asyncRequestThreadPoolCached,
742
        int asyncRequestThreadPoolSize,
743
        int leaderOutstandingAppendsMax) {
1✔
744
      this.messageSizeMax = messageSizeMax;
1✔
745
      this.flowControlWindow = flowControlWindow;
1✔
746
      this.asyncRequestThreadPoolCached = asyncRequestThreadPoolCached;
1✔
747
      this.asyncRequestThreadPoolSize = asyncRequestThreadPoolSize;
1✔
748
      this.leaderOutstandingAppendsMax = leaderOutstandingAppendsMax;
1✔
749
    }
1✔
750

751
    public SizeInBytes getMessageSizeMax() {
752
      return messageSizeMax;
1✔
753
    }
754

755
    public SizeInBytes getFlowControlWindow() {
756
      return flowControlWindow;
1✔
757
    }
758

759
    public boolean isAsyncRequestThreadPoolCached() {
760
      return asyncRequestThreadPoolCached;
1✔
761
    }
762

763
    public int getAsyncRequestThreadPoolSize() {
764
      return asyncRequestThreadPoolSize;
1✔
765
    }
766

767
    public int getLeaderOutstandingAppendsMax() {
768
      return leaderOutstandingAppendsMax;
1✔
769
    }
770

771
    public static Grpc.Builder newBuilder() {
772
      return new Grpc.Builder();
1✔
773
    }
774

775
    public static class Builder {
1✔
776

777
      private SizeInBytes messageSizeMax = SizeInBytes.valueOf("512MB");
1✔
778
      private SizeInBytes flowControlWindow = SizeInBytes.valueOf("4MB");
1✔
779
      private boolean asyncRequestThreadPoolCached =
1✔
780
          Server.ASYNC_REQUEST_THREAD_POOL_CACHED_DEFAULT;
781
      private int asyncRequestThreadPoolSize = Server.ASYNC_REQUEST_THREAD_POOL_SIZE_DEFAULT;
1✔
782
      private int leaderOutstandingAppendsMax = Server.LEADER_OUTSTANDING_APPENDS_MAX_DEFAULT;
1✔
783

784
      public Grpc build() {
785
        return new Grpc(
1✔
786
            messageSizeMax,
787
            flowControlWindow,
788
            asyncRequestThreadPoolCached,
789
            asyncRequestThreadPoolSize,
790
            leaderOutstandingAppendsMax);
791
      }
792

793
      public Grpc.Builder setMessageSizeMax(SizeInBytes messageSizeMax) {
794
        this.messageSizeMax = messageSizeMax;
×
795
        return this;
×
796
      }
797

798
      public Grpc.Builder setFlowControlWindow(SizeInBytes flowControlWindow) {
799
        this.flowControlWindow = flowControlWindow;
1✔
800
        return this;
1✔
801
      }
802

803
      public Grpc.Builder setAsyncRequestThreadPoolCached(boolean asyncRequestThreadPoolCached) {
804
        this.asyncRequestThreadPoolCached = asyncRequestThreadPoolCached;
×
805
        return this;
×
806
      }
807

808
      public Grpc.Builder setAsyncRequestThreadPoolSize(int asyncRequestThreadPoolSize) {
809
        this.asyncRequestThreadPoolSize = asyncRequestThreadPoolSize;
×
810
        return this;
×
811
      }
812

813
      public Grpc.Builder setLeaderOutstandingAppendsMax(int leaderOutstandingAppendsMax) {
814
        this.leaderOutstandingAppendsMax = leaderOutstandingAppendsMax;
1✔
815
        return this;
1✔
816
      }
817
    }
818
  }
819

820
  public static class Client {
821

822
    private final long clientRequestTimeoutMillis;
823
    private final int clientMaxRetryAttempt;
824
    private final long clientRetryInitialSleepTimeMs;
825
    private final long clientRetryMaxSleepTimeMs;
826
    private final int coreClientNumForEachNode;
827
    private final int maxClientNumForEachNode;
828

829
    public Client(
830
        long clientRequestTimeoutMillis,
831
        int clientMaxRetryAttempt,
832
        long clientRetryInitialSleepTimeMs,
833
        long clientRetryMaxSleepTimeMs,
834
        int coreClientNumForEachNode,
835
        int maxClientNumForEachNode) {
1✔
836
      this.clientRequestTimeoutMillis = clientRequestTimeoutMillis;
1✔
837
      this.clientMaxRetryAttempt = clientMaxRetryAttempt;
1✔
838
      this.clientRetryInitialSleepTimeMs = clientRetryInitialSleepTimeMs;
1✔
839
      this.clientRetryMaxSleepTimeMs = clientRetryMaxSleepTimeMs;
1✔
840
      this.coreClientNumForEachNode = coreClientNumForEachNode;
1✔
841
      this.maxClientNumForEachNode = maxClientNumForEachNode;
1✔
842
    }
1✔
843

844
    public long getClientRequestTimeoutMillis() {
845
      return clientRequestTimeoutMillis;
×
846
    }
847

848
    public int getClientMaxRetryAttempt() {
849
      return clientMaxRetryAttempt;
1✔
850
    }
851

852
    public long getClientRetryInitialSleepTimeMs() {
853
      return clientRetryInitialSleepTimeMs;
1✔
854
    }
855

856
    public long getClientRetryMaxSleepTimeMs() {
857
      return clientRetryMaxSleepTimeMs;
1✔
858
    }
859

860
    public int getCoreClientNumForEachNode() {
861
      return coreClientNumForEachNode;
1✔
862
    }
863

864
    public int getMaxClientNumForEachNode() {
865
      return maxClientNumForEachNode;
1✔
866
    }
867

868
    public static Client.Builder newBuilder() {
869
      return new Builder();
1✔
870
    }
871

872
    public static class Builder {
1✔
873

874
      private long clientRequestTimeoutMillis = 10000;
1✔
875
      private int clientMaxRetryAttempt = 10;
1✔
876
      private long clientRetryInitialSleepTimeMs = 100;
1✔
877
      private long clientRetryMaxSleepTimeMs = 10000;
1✔
878

879
      private int coreClientNumForEachNode = DefaultProperty.CORE_CLIENT_NUM_FOR_EACH_NODE;
1✔
880

881
      private int maxClientNumForEachNode = DefaultProperty.MAX_CLIENT_NUM_FOR_EACH_NODE;
1✔
882

883
      public Client build() {
884
        return new Client(
1✔
885
            clientRequestTimeoutMillis,
886
            clientMaxRetryAttempt,
887
            clientRetryInitialSleepTimeMs,
888
            clientRetryMaxSleepTimeMs,
889
            coreClientNumForEachNode,
890
            maxClientNumForEachNode);
891
      }
892

893
      public Builder setClientRequestTimeoutMillis(long clientRequestTimeoutMillis) {
894
        this.clientRequestTimeoutMillis = clientRequestTimeoutMillis;
1✔
895
        return this;
1✔
896
      }
897

898
      public Builder setClientMaxRetryAttempt(int clientMaxRetryAttempt) {
899
        this.clientMaxRetryAttempt = clientMaxRetryAttempt;
1✔
900
        return this;
1✔
901
      }
902

903
      public Builder setClientRetryInitialSleepTimeMs(long clientRetryInitialSleepTimeMs) {
904
        this.clientRetryInitialSleepTimeMs = clientRetryInitialSleepTimeMs;
1✔
905
        return this;
1✔
906
      }
907

908
      public Builder setClientRetryMaxSleepTimeMs(long clientRetryMaxSleepTimeMs) {
909
        this.clientRetryMaxSleepTimeMs = clientRetryMaxSleepTimeMs;
1✔
910
        return this;
1✔
911
      }
912

913
      public Builder setCoreClientNumForEachNode(int coreClientNumForEachNode) {
914
        this.coreClientNumForEachNode = coreClientNumForEachNode;
1✔
915
        return this;
1✔
916
      }
917

918
      public Builder setMaxClientNumForEachNode(int maxClientNumForEachNode) {
919
        this.maxClientNumForEachNode = maxClientNumForEachNode;
1✔
920
        return this;
1✔
921
      }
922
    }
923
  }
924

925
  public static class Impl {
926

927
    private final int retryTimesMax;
928
    private final long retryWaitMillis;
929

930
    private final long triggerSnapshotTime;
931
    private final long triggerSnapshotFileSize;
932

933
    public Impl(
934
        int retryTimesMax,
935
        long retryWaitMillis,
936
        long triggerSnapshotTime,
937
        long triggerSnapshotFileSize) {
1✔
938
      this.retryTimesMax = retryTimesMax;
1✔
939
      this.retryWaitMillis = retryWaitMillis;
1✔
940
      this.triggerSnapshotTime = triggerSnapshotTime;
1✔
941
      this.triggerSnapshotFileSize = triggerSnapshotFileSize;
1✔
942
    }
1✔
943

944
    public int getRetryTimesMax() {
945
      return retryTimesMax;
1✔
946
    }
947

948
    public long getRetryWaitMillis() {
949
      return retryWaitMillis;
1✔
950
    }
951

952
    public long getTriggerSnapshotTime() {
953
      return triggerSnapshotTime;
1✔
954
    }
955

956
    public long getTriggerSnapshotFileSize() {
957
      return triggerSnapshotFileSize;
1✔
958
    }
959

960
    public static Impl.Builder newBuilder() {
961
      return new Builder();
1✔
962
    }
963

964
    public static class Builder {
1✔
965

966
      private int retryTimesMax = 3;
1✔
967
      private long retryWaitMillis = 500;
1✔
968

969
      // 120s
970
      private long triggerSnapshotTime = 120;
1✔
971
      // 20GB
972
      private long triggerSnapshotFileSize = 20L << 30;
1✔
973

974
      public Impl build() {
975
        return new Impl(
1✔
976
            retryTimesMax, retryWaitMillis, triggerSnapshotTime, triggerSnapshotFileSize);
977
      }
978

979
      public Impl.Builder setRetryTimesMax(int retryTimesMax) {
980
        this.retryTimesMax = retryTimesMax;
×
981
        return this;
×
982
      }
983

984
      public Impl.Builder setRetryWaitMillis(long retryWaitMillis) {
985
        this.retryWaitMillis = retryWaitMillis;
×
986
        return this;
×
987
      }
988

989
      public Impl.Builder setTriggerSnapshotTime(long triggerSnapshotTime) {
990
        this.triggerSnapshotTime = triggerSnapshotTime;
1✔
991
        return this;
1✔
992
      }
993

994
      public Impl.Builder setTriggerSnapshotFileSize(long triggerSnapshotFileSize) {
995
        this.triggerSnapshotFileSize = triggerSnapshotFileSize;
1✔
996
        return this;
1✔
997
      }
998
    }
999
  }
1000

1001
  public static class LeaderLogAppender {
1002

1003
    private final SizeInBytes bufferByteLimit;
1004
    private final SizeInBytes snapshotChunkSizeMax;
1005
    private final boolean installSnapshotEnabled;
1006

1007
    private LeaderLogAppender(
1008
        SizeInBytes bufferByteLimit,
1009
        SizeInBytes snapshotChunkSizeMax,
1010
        boolean installSnapshotEnabled) {
1✔
1011
      this.bufferByteLimit = bufferByteLimit;
1✔
1012
      this.snapshotChunkSizeMax = snapshotChunkSizeMax;
1✔
1013
      this.installSnapshotEnabled = installSnapshotEnabled;
1✔
1014
    }
1✔
1015

1016
    public SizeInBytes getBufferByteLimit() {
1017
      return bufferByteLimit;
1✔
1018
    }
1019

1020
    public SizeInBytes getSnapshotChunkSizeMax() {
1021
      return snapshotChunkSizeMax;
1✔
1022
    }
1023

1024
    public boolean isInstallSnapshotEnabled() {
1025
      return installSnapshotEnabled;
1✔
1026
    }
1027

1028
    public static LeaderLogAppender.Builder newBuilder() {
1029
      return new LeaderLogAppender.Builder();
1✔
1030
    }
1031

1032
    public static class Builder {
1✔
1033

1034
      private SizeInBytes bufferByteLimit =
1✔
1035
          RaftServerConfigKeys.Log.Appender.BUFFER_BYTE_LIMIT_DEFAULT;
1036
      private SizeInBytes snapshotChunkSizeMax =
1✔
1037
          RaftServerConfigKeys.Log.Appender.SNAPSHOT_CHUNK_SIZE_MAX_DEFAULT;
1038
      private boolean installSnapshotEnabled =
1✔
1039
          RaftServerConfigKeys.Log.Appender.INSTALL_SNAPSHOT_ENABLED_DEFAULT;
1040

1041
      public LeaderLogAppender build() {
1042
        return new LeaderLogAppender(bufferByteLimit, snapshotChunkSizeMax, installSnapshotEnabled);
1✔
1043
      }
1044

1045
      public LeaderLogAppender.Builder setBufferByteLimit(long bufferByteLimit) {
1046
        this.bufferByteLimit = SizeInBytes.valueOf(bufferByteLimit);
1✔
1047
        return this;
1✔
1048
      }
1049

1050
      public LeaderLogAppender.Builder setSnapshotChunkSizeMax(long snapshotChunkSizeMax) {
1051
        this.snapshotChunkSizeMax = SizeInBytes.valueOf(snapshotChunkSizeMax);
×
1052
        return this;
×
1053
      }
1054

1055
      public LeaderLogAppender.Builder setInstallSnapshotEnabled(boolean installSnapshotEnabled) {
1056
        this.installSnapshotEnabled = installSnapshotEnabled;
×
1057
        return this;
×
1058
      }
1059
    }
1060
  }
1061

1062
  public static class Read {
1063
    public enum Option {
1✔
1064
      DEFAULT,
1✔
1065
      LINEARIZABLE
1✔
1066
    }
1067

1068
    private final Read.Option readOption;
1069
    private final TimeDuration readTimeout;
1070

1071
    private Read(Read.Option readOption, TimeDuration readTimeout) {
1✔
1072
      this.readOption = readOption;
1✔
1073
      this.readTimeout = readTimeout;
1✔
1074
    }
1✔
1075

1076
    public Option getReadOption() {
1077
      return readOption;
1✔
1078
    }
1079

1080
    public TimeDuration getReadTimeout() {
1081
      return readTimeout;
1✔
1082
    }
1083

1084
    public static Read.Builder newBuilder() {
1085
      return new Read.Builder();
1✔
1086
    }
1087

1088
    public static class Builder {
1✔
1089
      private Read.Option readOption = Option.LINEARIZABLE;
1✔
1090
      private TimeDuration readTimeout = TimeDuration.valueOf(10, TimeUnit.SECONDS);
1✔
1091

1092
      public Read.Builder setReadOption(Read.Option readOption) {
1093
        this.readOption = readOption;
×
1094
        return this;
×
1095
      }
1096

1097
      public Read.Builder setReadTimeout(TimeDuration timeout) {
1098
        this.readTimeout = timeout;
1✔
1099
        return this;
1✔
1100
      }
1101

1102
      public Read build() {
1103
        return new Read(readOption, readTimeout);
1✔
1104
      }
1105
    }
1106
  }
1107
}
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

© 2026 Coveralls, Inc