/
ClientConfiguration.java
2039 lines (1850 loc) · 68.4 KB
/
ClientConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.bookkeeper.conf;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.bookkeeper.util.BookKeeperConstants.FEATURE_DISABLE_ENSEMBLE_CHANGE;
import io.netty.buffer.ByteBuf;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.apache.bookkeeper.client.BookKeeper.DigestType;
import org.apache.bookkeeper.client.EnsemblePlacementPolicy;
import org.apache.bookkeeper.client.LedgerHandle;
import org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy;
import org.apache.bookkeeper.client.api.BookKeeperBuilder;
import org.apache.bookkeeper.common.util.ReflectionUtils;
import org.apache.bookkeeper.discover.RegistrationClient;
import org.apache.bookkeeper.discover.ZKRegistrationClient;
import org.apache.bookkeeper.replication.Auditor;
import org.apache.commons.configuration.ConfigurationException;
/**
* Configuration settings for client side.
*/
public class ClientConfiguration extends AbstractConfiguration<ClientConfiguration> {
// Throttle value
protected static final String THROTTLE = "throttle";
// Digest Type
protected static final String DIGEST_TYPE = "digestType";
protected static final String ENABLE_DIGEST_TYPE_AUTODETECTION = "enableDigestTypeAutodetection";
// Passwd
protected static final String PASSWD = "passwd";
// Client TLS (@deprecated since 4.7.0)
/**
* @deprecated Use {@link #TLS_KEYSTORE_TYPE}
*/
@Deprecated
protected static final String CLIENT_TLS_KEYSTORE_TYPE = "clientKeyStoreType";
/**
* @deprecated Use {@link #TLS_KEYSTORE}
*/
@Deprecated
protected static final String CLIENT_TLS_KEYSTORE = "clientKeyStore";
/**
* @deprecated Use {@link #TLS_KEYSTORE_PASSWORD_PATH}
*/
@Deprecated
protected static final String CLIENT_TLS_KEYSTORE_PASSWORD_PATH = "clientKeyStorePasswordPath";
/**
* @deprecated Use {@link #TLS_TRUSTSTORE_TYPE}
*/
@Deprecated
protected static final String CLIENT_TLS_TRUSTSTORE_TYPE = "clientTrustStoreType";
/**
* @deprecated Use {@link #TLS_TRUSTSTORE}
*/
@Deprecated
protected static final String CLIENT_TLS_TRUSTSTORE = "clientTrustStore";
/**
* @deprecated Use {@link #TLS_TRUSTSTORE_PASSWORD_PATH}
*/
@Deprecated
protected static final String CLIENT_TLS_TRUSTSTORE_PASSWORD_PATH = "clientTrustStorePasswordPath";
// NIO Parameters
protected static final String CLIENT_TCP_NODELAY = "clientTcpNoDelay";
protected static final String CLIENT_SOCK_KEEPALIVE = "clientSockKeepalive";
protected static final String CLIENT_SENDBUFFER_SIZE = "clientSendBufferSize";
protected static final String CLIENT_RECEIVEBUFFER_SIZE = "clientReceiveBufferSize";
protected static final String CLIENT_WRITEBUFFER_LOW_WATER_MARK = "clientWriteBufferLowWaterMark";
protected static final String CLIENT_WRITEBUFFER_HIGH_WATER_MARK = "clientWriteBufferHighWaterMark";
protected static final String CLIENT_CONNECT_TIMEOUT_MILLIS = "clientConnectTimeoutMillis";
protected static final String CLIENT_TCP_USER_TIMEOUT_MILLIS = "clientTcpUserTimeoutMillis";
protected static final String NUM_CHANNELS_PER_BOOKIE = "numChannelsPerBookie";
protected static final String USE_V2_WIRE_PROTOCOL = "useV2WireProtocol";
protected static final String NETTY_USE_POOLED_BUFFERS = "nettyUsePooledBuffers";
// Read Parameters
protected static final String READ_TIMEOUT = "readTimeout";
protected static final String SPECULATIVE_READ_TIMEOUT = "speculativeReadTimeout";
protected static final String FIRST_SPECULATIVE_READ_TIMEOUT = "firstSpeculativeReadTimeout";
protected static final String MAX_SPECULATIVE_READ_TIMEOUT = "maxSpeculativeReadTimeout";
protected static final String SPECULATIVE_READ_TIMEOUT_BACKOFF_MULTIPLIER =
"speculativeReadTimeoutBackoffMultiplier";
protected static final String FIRST_SPECULATIVE_READ_LAC_TIMEOUT = "firstSpeculativeReadLACTimeout";
protected static final String MAX_SPECULATIVE_READ_LAC_TIMEOUT = "maxSpeculativeReadLACTimeout";
protected static final String SPECULATIVE_READ_LAC_TIMEOUT_BACKOFF_MULTIPLIER =
"speculativeReadLACTimeoutBackoffMultiplier";
protected static final String ENABLE_PARALLEL_RECOVERY_READ = "enableParallelRecoveryRead";
protected static final String RECOVERY_READ_BATCH_SIZE = "recoveryReadBatchSize";
protected static final String REORDER_READ_SEQUENCE_ENABLED = "reorderReadSequenceEnabled";
protected static final String STICKY_READS_ENABLED = "stickyReadSEnabled";
// Add Parameters
protected static final String OPPORTUNISTIC_STRIPING = "opportunisticStriping";
protected static final String DELAY_ENSEMBLE_CHANGE = "delayEnsembleChange";
protected static final String MAX_ALLOWED_ENSEMBLE_CHANGES = "maxNumEnsembleChanges";
// Timeout Setting
protected static final String ADD_ENTRY_TIMEOUT_SEC = "addEntryTimeoutSec";
protected static final String ADD_ENTRY_QUORUM_TIMEOUT_SEC = "addEntryQuorumTimeoutSec";
protected static final String READ_ENTRY_TIMEOUT_SEC = "readEntryTimeoutSec";
protected static final String TIMEOUT_MONITOR_INTERVAL_SEC = "timeoutMonitorIntervalSec";
protected static final String TIMEOUT_TASK_INTERVAL_MILLIS = "timeoutTaskIntervalMillis";
protected static final String EXPLICIT_LAC_INTERVAL = "explicitLacInterval";
protected static final String PCBC_TIMEOUT_TIMER_TICK_DURATION_MS = "pcbcTimeoutTimerTickDurationMs";
protected static final String PCBC_TIMEOUT_TIMER_NUM_TICKS = "pcbcTimeoutTimerNumTicks";
protected static final String TIMEOUT_TIMER_TICK_DURATION_MS = "timeoutTimerTickDurationMs";
protected static final String TIMEOUT_TIMER_NUM_TICKS = "timeoutTimerNumTicks";
// backpressure configuration
protected static final String WAIT_TIMEOUT_ON_BACKPRESSURE = "waitTimeoutOnBackpressureMs";
// Bookie health check settings
protected static final String BOOKIE_HEALTH_CHECK_ENABLED = "bookieHealthCheckEnabled";
protected static final String BOOKIE_HEALTH_CHECK_INTERVAL_SECONDS = "bookieHealthCheckIntervalSeconds";
protected static final String BOOKIE_ERROR_THRESHOLD_PER_INTERVAL = "bookieErrorThresholdPerInterval";
protected static final String BOOKIE_QUARANTINE_TIME_SECONDS = "bookieQuarantineTimeSeconds";
protected static final String BOOKIE_QUARANTINE_RATIO = "bookieQuarantineRatio";
// Bookie info poll interval
protected static final String DISK_WEIGHT_BASED_PLACEMENT_ENABLED = "diskWeightBasedPlacementEnabled";
protected static final String GET_BOOKIE_INFO_INTERVAL_SECONDS = "getBookieInfoIntervalSeconds";
protected static final String GET_BOOKIE_INFO_RETRY_INTERVAL_SECONDS = "getBookieInfoRetryIntervalSeconds";
protected static final String BOOKIE_MAX_MULTIPLE_FOR_WEIGHTED_PLACEMENT =
"bookieMaxMultipleForWeightBasedPlacement";
protected static final String GET_BOOKIE_INFO_TIMEOUT_SECS = "getBookieInfoTimeoutSecs";
protected static final String START_TLS_TIMEOUT_SECS = "startTLSTimeoutSecs";
protected static final String TLS_HOSTNAME_VERIFICATION_ENABLED = "tlsHostnameVerificationEnabled";
// Number of Threads
protected static final String NUM_WORKER_THREADS = "numWorkerThreads";
protected static final String NUM_IO_THREADS = "numIOThreads";
// Ensemble Placement Policy
public static final String ENSEMBLE_PLACEMENT_POLICY = "ensemblePlacementPolicy";
protected static final String NETWORK_TOPOLOGY_STABILIZE_PERIOD_SECONDS = "networkTopologyStabilizePeriodSeconds";
protected static final String READ_REORDER_THRESHOLD_PENDING_REQUESTS = "readReorderThresholdPendingRequests";
protected static final String ENSEMBLE_PLACEMENT_POLICY_ORDER_SLOW_BOOKIES =
"ensemblePlacementPolicyOrderSlowBookies";
// Stats
protected static final String ENABLE_TASK_EXECUTION_STATS = "enableTaskExecutionStats";
protected static final String TASK_EXECUTION_WARN_TIME_MICROS = "taskExecutionWarnTimeMicros";
// Failure History Settings
protected static final String ENABLE_BOOKIE_FAILURE_TRACKING = "enableBookieFailureTracking";
protected static final String BOOKIE_FAILURE_HISTORY_EXPIRATION_MS = "bookieFailureHistoryExpirationMSec";
// Discovery
protected static final String FOLLOW_BOOKIE_ADDRESS_TRACKING = "enableBookieAddressTracking";
// Names of dynamic features
protected static final String DISABLE_ENSEMBLE_CHANGE_FEATURE_NAME = "disableEnsembleChangeFeatureName";
// Role of the client
protected static final String CLIENT_ROLE = "clientRole";
/**
* This client will act as a standard client.
*/
public static final String CLIENT_ROLE_STANDARD = "standard";
/**
* This client will act as a system client, like the {@link Auditor}.
*/
public static final String CLIENT_ROLE_SYSTEM = "system";
// Client auth provider factory class name. It must be configured on Bookies to for the Auditor
protected static final String CLIENT_AUTH_PROVIDER_FACTORY_CLASS = "clientAuthProviderFactoryClass";
// Registration Client
protected static final String REGISTRATION_CLIENT_CLASS = "registrationClientClass";
// Logs
protected static final String CLIENT_CONNECT_BOOKIE_UNAVAILABLE_LOG_THROTTLING =
"clientConnectBookieUnavailableLogThrottling";
/**
* Construct a default client-side configuration.
*/
public ClientConfiguration() {
super();
}
/**
* Construct a client-side configuration using a base configuration.
*
* @param conf
* Base configuration
*/
public ClientConfiguration(AbstractConfiguration conf) {
super();
loadConf(conf);
}
/**
* Get throttle value.
*
* @return throttle value
* @see #setThrottleValue
*/
public int getThrottleValue() {
return this.getInt(THROTTLE, 5000);
}
/**
* Set throttle value.
*
* <p>Since BookKeeper process requests in asynchronous way, it will holds
* those pending request in queue. You may easily run it out of memory
* if producing too many requests than the capability of bookie servers can handle.
* To prevent that from happening, you can set a throttle value here.
*
* <p>Setting the throttle value to 0, will disable any throttling.
*
* @param throttle
* Throttle Value
* @return client configuration
*/
public ClientConfiguration setThrottleValue(int throttle) {
this.setProperty(THROTTLE, Integer.toString(throttle));
return this;
}
/**
* Get autodetection of digest type.
*
* <p>Ignores provided digestType, if enabled and uses one from ledger metadata instead.
* Incompatible with ledger created by bookie versions < 4.2
*
* <p>It is turned on by default since 4.7.
*
* @return flag to enable/disable autodetection of digest type.
*/
public boolean getEnableDigestTypeAutodetection() {
return getBoolean(ENABLE_DIGEST_TYPE_AUTODETECTION, true);
}
/**
* Enable autodetection of digest type.
* Ignores provided digestType, if enabled and uses one from ledger metadata instead.
* Incompatible with ledger created by bookie versions < 4.2
*
* @return client configuration.
*/
public ClientConfiguration setEnableDigestTypeAutodetection(boolean enable) {
this.setProperty(ENABLE_DIGEST_TYPE_AUTODETECTION, enable);
return this;
}
/**
* Get digest type used in bookkeeper admin.
*
* @return digest type
* @see #setBookieRecoveryDigestType
*/
public DigestType getBookieRecoveryDigestType() {
return DigestType.valueOf(this.getString(DIGEST_TYPE, DigestType.CRC32.toString()));
}
/**
* Set digest type used in bookkeeper admin.
*
* <p>Digest Type and Passwd used to open ledgers for admin tool
* For now, assume that all ledgers were created with the same DigestType
* and password. In the future, this admin tool will need to know for each
* ledger, what was the DigestType and password used to create it before it
* can open it. These values will come from System properties, though fixed
* defaults are defined here.
*
* @param digestType
* Digest Type
* @return client configuration
*/
public ClientConfiguration setBookieRecoveryDigestType(DigestType digestType) {
this.setProperty(DIGEST_TYPE, digestType.toString());
return this;
}
/**
* Get passwd used in bookkeeper admin.
*
* @return password
* @see #setBookieRecoveryPasswd
*/
public byte[] getBookieRecoveryPasswd() {
return this.getString(PASSWD, "").getBytes(UTF_8);
}
/**
* Set passwd used in bookkeeper admin.
*
* <p>Digest Type and Passwd used to open ledgers for admin tool
* For now, assume that all ledgers were created with the same DigestType
* and password. In the future, this admin tool will need to know for each
* ledger, what was the DigestType and password used to create it before it
* can open it. These values will come from System properties, though fixed
* defaults are defined here.
*
* @param passwd
* Password
* @return client configuration
*/
public ClientConfiguration setBookieRecoveryPasswd(byte[] passwd) {
setProperty(PASSWD, new String(passwd, UTF_8));
return this;
}
/**
* Is tcp connection no delay.
*
* @return tcp socket nodelay setting
* @see #setClientTcpNoDelay
*/
public boolean getClientTcpNoDelay() {
return getBoolean(CLIENT_TCP_NODELAY, true);
}
/**
* Set socket nodelay setting.
*
* <p>This settings is used to enabled/disabled Nagle's algorithm, which is a means of
* improving the efficiency of TCP/IP networks by reducing the number of packets
* that need to be sent over the network. If you are sending many small messages,
* such that more than one can fit in a single IP packet, setting client.tcpnodelay
* to false to enable Nagle algorithm can provide better performance.
* <br>
* Default value is true.
*
* @param noDelay
* NoDelay setting
* @return client configuration
*/
public ClientConfiguration setClientTcpNoDelay(boolean noDelay) {
setProperty(CLIENT_TCP_NODELAY, Boolean.toString(noDelay));
return this;
}
/**
* get socket keepalive.
*
* @return socket keepalive setting
*/
public boolean getClientSockKeepalive() {
return getBoolean(CLIENT_SOCK_KEEPALIVE, true);
}
/**
* Set socket keepalive setting.
*
* <p>This setting is used to send keep-alive messages on connection-oriented sockets.
*
* @param keepalive
* KeepAlive setting
* @return client configuration
*/
public ClientConfiguration setClientSockKeepalive(boolean keepalive) {
setProperty(CLIENT_SOCK_KEEPALIVE, Boolean.toString(keepalive));
return this;
}
/**
* Get client netty channel send buffer size.
*
* @return client netty channel send buffer size
*/
public int getClientSendBufferSize() {
return getInt(CLIENT_SENDBUFFER_SIZE, 1 * 1024 * 1024);
}
/**
* Set client netty channel send buffer size.
*
* @param bufferSize
* client netty channel send buffer size.
* @return client configuration.
*/
public ClientConfiguration setClientSendBufferSize(int bufferSize) {
setProperty(CLIENT_SENDBUFFER_SIZE, bufferSize);
return this;
}
/**
* Get client netty channel receive buffer size.
*
* @return client netty channel receive buffer size.
*/
public int getClientReceiveBufferSize() {
return getInt(CLIENT_RECEIVEBUFFER_SIZE, 1 * 1024 * 1024);
}
/**
* Set client netty channel receive buffer size.
*
* @param bufferSize
* netty channel receive buffer size.
* @return client configuration.
*/
public ClientConfiguration setClientReceiveBufferSize(int bufferSize) {
setProperty(CLIENT_RECEIVEBUFFER_SIZE, bufferSize);
return this;
}
/**
* Get client netty channel write buffer low water mark.
*
* @return netty channel write buffer low water mark.
*/
public int getClientWriteBufferLowWaterMark() {
return getInt(CLIENT_WRITEBUFFER_LOW_WATER_MARK, 384 * 1024);
}
/**
* Set client netty channel write buffer low water mark.
*
* @param waterMark
* netty channel write buffer low water mark.
* @return client configuration.
*/
public ClientConfiguration setClientWriteBufferLowWaterMark(int waterMark) {
setProperty(CLIENT_WRITEBUFFER_LOW_WATER_MARK, waterMark);
return this;
}
/**
* Get client netty channel write buffer high water mark.
*
* @return netty channel write buffer high water mark.
*/
public int getClientWriteBufferHighWaterMark() {
return getInt(CLIENT_WRITEBUFFER_HIGH_WATER_MARK, 512 * 1024);
}
/**
* Set client netty channel write buffer high water mark.
*
* @param waterMark
* netty channel write buffer high water mark.
* @return client configuration.
*/
public ClientConfiguration setClientWriteBufferHighWaterMark(int waterMark) {
setProperty(CLIENT_WRITEBUFFER_HIGH_WATER_MARK, waterMark);
return this;
}
/**
* Get the tick duration in milliseconds that used for timeout timer.
*
* @return tick duration in milliseconds
*/
public long getTimeoutTimerTickDurationMs() {
return getLong(TIMEOUT_TIMER_TICK_DURATION_MS, 100);
}
/**
* Set the tick duration in milliseconds that used for timeout timer.
*
* @param tickDuration
* tick duration in milliseconds.
* @return client configuration.
*/
public ClientConfiguration setTimeoutTimerTickDurationMs(long tickDuration) {
setProperty(TIMEOUT_TIMER_TICK_DURATION_MS, tickDuration);
return this;
}
/**
* Get number of ticks that used for timeout timer.
*
* @return number of ticks that used for timeout timer.
*/
public int getTimeoutTimerNumTicks() {
return getInt(TIMEOUT_TIMER_NUM_TICKS, 1024);
}
/**
* Set number of ticks that used for timeout timer.
*
* @param numTicks
* number of ticks that used for timeout timer.
* @return client configuration.
*/
public ClientConfiguration setTimeoutTimerNumTicks(int numTicks) {
setProperty(TIMEOUT_TIMER_NUM_TICKS, numTicks);
return this;
}
/**
* Get client netty connect timeout in millis.
*
* @return client netty connect timeout in millis.
*/
public int getClientConnectTimeoutMillis() {
// 10 seconds as netty default value.
return getInt(CLIENT_CONNECT_TIMEOUT_MILLIS, 10000);
}
/**
* Set client netty connect timeout in millis.
*
* @param connectTimeoutMillis
* client netty connect timeout in millis.
* @return client configuration.
*/
public ClientConfiguration setClientConnectTimeoutMillis(int connectTimeoutMillis) {
setProperty(CLIENT_CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis);
return this;
}
/**
* Get client netty TCP user timeout in millis (only for Epoll channels).
*
* @return client netty Epoll user tcp timeout in millis.
* @throws NoSuchElementException if the property is not set.
*/
public int getTcpUserTimeoutMillis() {
return getInt(CLIENT_TCP_USER_TIMEOUT_MILLIS);
}
/**
* Set client netty TCP user timeout in millis (only for Epoll channels).
*
* @param tcpUserTimeoutMillis
* client netty TCP user timeout in millis.
* @return client configuration.
*/
public ClientConfiguration setTcpUserTimeoutMillis(int tcpUserTimeoutMillis) {
setProperty(CLIENT_TCP_USER_TIMEOUT_MILLIS, tcpUserTimeoutMillis);
return this;
}
/**
* Get num channels per bookie.
*
* @return num channels per bookie.
*/
public int getNumChannelsPerBookie() {
return getInt(NUM_CHANNELS_PER_BOOKIE, 1);
}
/**
* Set num channels per bookie.
*
* @param numChannelsPerBookie
* num channels per bookie.
* @return client configuration.
*/
public ClientConfiguration setNumChannelsPerBookie(int numChannelsPerBookie) {
setProperty(NUM_CHANNELS_PER_BOOKIE, numChannelsPerBookie);
return this;
}
/**
* Use older Bookkeeper wire protocol (no protobuf).
*
* @return whether or not to use older Bookkeeper wire protocol (no protobuf)
*/
public boolean getUseV2WireProtocol() {
return getBoolean(USE_V2_WIRE_PROTOCOL, false);
}
/**
* Set whether or not to use older Bookkeeper wire protocol (no protobuf).
*
* @param useV2WireProtocol
* whether or not to use older Bookkeeper wire protocol (no protobuf)
* @return client configuration.
*/
public ClientConfiguration setUseV2WireProtocol(boolean useV2WireProtocol) {
setProperty(USE_V2_WIRE_PROTOCOL, useV2WireProtocol);
return this;
}
/**
* Get the socket read timeout. This is the number of
* seconds we wait without hearing a response from a bookie
* before we consider it failed.
*
* <p>The default is 5 seconds.
*
* @return the current read timeout in seconds
* @deprecated use {@link #getReadEntryTimeout()} or {@link #getAddEntryTimeout()} instead
*/
@Deprecated
public int getReadTimeout() {
return getInt(READ_TIMEOUT, 5);
}
/**
* Set the socket read timeout.
* @see #getReadTimeout()
* @param timeout The new read timeout in seconds
* @return client configuration
* @deprecated use {@link #setReadEntryTimeout(int)} or {@link #setAddEntryTimeout(int)} instead
*/
@Deprecated
public ClientConfiguration setReadTimeout(int timeout) {
setProperty(READ_TIMEOUT, Integer.toString(timeout));
return this;
}
/**
* Get the timeout for add request. This is the number of seconds we wait without hearing
* a response for add request from a bookie before we consider it failed.
*
* <p>The default value is 5 second for backwards compatibility.
*
* @return add entry timeout.
*/
@SuppressWarnings("deprecation")
public int getAddEntryTimeout() {
return getInt(ADD_ENTRY_TIMEOUT_SEC, getReadTimeout());
}
/**
* Set timeout for add entry request.
* @see #getAddEntryTimeout()
*
* @param timeout
* The new add entry timeout in seconds.
* @return client configuration.
*/
public ClientConfiguration setAddEntryTimeout(int timeout) {
setProperty(ADD_ENTRY_TIMEOUT_SEC, timeout);
return this;
}
/**
* Get the timeout for top-level add request. That is, the amount of time we should spend
* waiting for ack quorum.
*
* @return add entry ack quorum timeout.
*/
public int getAddEntryQuorumTimeout() {
return getInt(ADD_ENTRY_QUORUM_TIMEOUT_SEC, -1);
}
/**
* Set timeout for top-level add entry request.
* @see #getAddEntryQuorumTimeout()
*
* @param timeout
* The new add entry ack quorum timeout in seconds.
* @return client configuration.
*/
public ClientConfiguration setAddEntryQuorumTimeout(int timeout) {
setProperty(ADD_ENTRY_QUORUM_TIMEOUT_SEC, timeout);
return this;
}
/**
* Get the timeout for read entry. This is the number of seconds we wait without hearing
* a response for read entry request from a bookie before we consider it failed. By default,
* we use socket timeout specified at {@link #getReadTimeout()}.
*
* @return read entry timeout.
*/
@SuppressWarnings("deprecation")
public int getReadEntryTimeout() {
return getInt(READ_ENTRY_TIMEOUT_SEC, getReadTimeout());
}
/**
* Set the timeout for read entry request.
* @see #getReadEntryTimeout()
*
* @param timeout
* The new read entry timeout in seconds.
* @return client configuration.
*/
public ClientConfiguration setReadEntryTimeout(int timeout) {
setProperty(READ_ENTRY_TIMEOUT_SEC, timeout);
return this;
}
/**
* Get the interval between successive executions of the operation timeout monitor. This value is in seconds.
*
* @see #setTimeoutMonitorIntervalSec(long)
* @return the interval at which request timeouts will be checked
*/
public long getTimeoutMonitorIntervalSec() {
int minTimeout = Math.min(Math.min(getAddEntryQuorumTimeout(),
getAddEntryTimeout()), getReadEntryTimeout());
return getLong(TIMEOUT_MONITOR_INTERVAL_SEC, Math.max(minTimeout / 2, 1));
}
/**
* Set the interval between successive executions of the operation timeout monitor. The value in seconds.
* Every X seconds, all outstanding add and read operations are checked to see if they have been running
* for longer than their configured timeout. Any that have been will be errored out.
*
* <p>This timeout should be set to a value which is a fraction of the values of
* {@link #getAddEntryQuorumTimeout}, {@link #getAddEntryTimeout} and {@link #getReadEntryTimeout},
* so that these timeouts run in a timely fashion.
*
* @param timeoutInterval The timeout monitor interval, in seconds
* @return client configuration
*/
public ClientConfiguration setTimeoutMonitorIntervalSec(long timeoutInterval) {
setProperty(TIMEOUT_MONITOR_INTERVAL_SEC, Long.toString(timeoutInterval));
return this;
}
/**
* Get the interval between successive executions of the PerChannelBookieClient's TimeoutTask. This value is in
* milliseconds. Every X milliseconds, the timeout task will be executed and it will error out entries that have
* timed out.
*
* <p>We do it more aggressive to not accumulate pending requests due to slow responses.
*
* @return the interval at which request timeouts will be checked
*/
@Deprecated
public long getTimeoutTaskIntervalMillis() {
return getLong(TIMEOUT_TASK_INTERVAL_MILLIS,
TimeUnit.SECONDS.toMillis(Math.min(getAddEntryTimeout(), getReadEntryTimeout())) / 2);
}
@Deprecated
public ClientConfiguration setTimeoutTaskIntervalMillis(long timeoutMillis) {
setProperty(TIMEOUT_TASK_INTERVAL_MILLIS, Long.toString(timeoutMillis));
return this;
}
/**
* Get the configured interval between explicit LACs to bookies.
* Generally LACs are piggy-backed on writes, and user can configure
* the interval between these protocol messages. A value of '0' disables
* sending any explicit LACs.
*
* @return interval between explicit LACs
*/
public int getExplictLacInterval() {
return getInt(EXPLICIT_LAC_INTERVAL, 0);
}
/**
* Set the interval to check the need for sending an explicit LAC.
* @param interval
* Number of milli seconds between checking the need for sending an explict LAC.
* @return Client configuration.
*/
public ClientConfiguration setExplictLacInterval(int interval) {
setProperty(EXPLICIT_LAC_INTERVAL, interval);
return this;
}
/**
* Get the tick duration in milliseconds that used for the
* HashedWheelTimer that used by PCBC to timeout
* requests.
*
* @return tick duration in milliseconds
*/
@Deprecated
public long getPCBCTimeoutTimerTickDurationMs() {
return getLong(PCBC_TIMEOUT_TIMER_TICK_DURATION_MS, 100);
}
/**
* Set the tick duration in milliseconds that used for
* HashedWheelTimer that used by PCBC to timeout
* requests. Be aware of HashedWheelTimer if you
* are going to modify this setting.
*
* @see #getPCBCTimeoutTimerTickDurationMs()
*
* @param tickDuration
* tick duration in milliseconds.
* @return client configuration.
*/
@Deprecated
public ClientConfiguration setPCBCTimeoutTimerTickDurationMs(long tickDuration) {
setProperty(PCBC_TIMEOUT_TIMER_TICK_DURATION_MS, tickDuration);
return this;
}
/**
* Get number of ticks that used for
* HashedWheelTimer that used by PCBC to timeout
* requests.
*
* @return number of ticks that used for timeout timer.
*/
@Deprecated
public int getPCBCTimeoutTimerNumTicks() {
return getInt(PCBC_TIMEOUT_TIMER_NUM_TICKS, 1024);
}
/**
* Set number of ticks that used for
* HashedWheelTimer that used by PCBC to timeout request.
* Be aware of HashedWheelTimer if you are going to modify
* this setting.
*
* @see #getPCBCTimeoutTimerNumTicks()
*
* @param numTicks
* number of ticks that used for timeout timer.
* @return client configuration.
*/
@Deprecated
public ClientConfiguration setPCBCTimeoutTimerNumTicks(int numTicks) {
setProperty(PCBC_TIMEOUT_TIMER_NUM_TICKS, numTicks);
return this;
}
/**
* Timeout controlling wait on request send in case of unresponsive bookie(s)
* (i.e. bookie in long GC etc.)
*
* @return timeout value
* negative value disables the feature
* 0 to allow request to fail immediately
* Default is -1 (disabled)
*/
public long getWaitTimeoutOnBackpressureMillis() {
return getLong(WAIT_TIMEOUT_ON_BACKPRESSURE, -1);
}
/**
* Timeout controlling wait on request send in case of unresponsive bookie(s)
* (i.e. bookie in long GC etc.)
*
* @param value
* negative value disables the feature
* 0 to allow request to fail immediately
* Default is -1 (disabled)
* @return client configuration.
*/
public ClientConfiguration setWaitTimeoutOnBackpressureMillis(long value) {
setProperty(WAIT_TIMEOUT_ON_BACKPRESSURE, value);
return this;
}
/**
* Get the number of worker threads. This is the number of
* worker threads used by bookkeeper client to submit operations.
*
* @return the number of worker threads
*/
public int getNumWorkerThreads() {
return getInt(NUM_WORKER_THREADS, Runtime.getRuntime().availableProcessors());
}
/**
* Set the number of worker threads.
*
* <p>
* NOTE: setting the number of worker threads after BookKeeper object is constructed
* will not take any effect on the number of threads in the pool.
* </p>
*
* @see #getNumWorkerThreads()
* @param numThreads number of worker threads used for bookkeeper
* @return client configuration
*/
public ClientConfiguration setNumWorkerThreads(int numThreads) {
setProperty(NUM_WORKER_THREADS, numThreads);
return this;
}
/**
* Get the number of IO threads. This is the number of
* threads used by Netty to handle TCP connections.
*
* @return the number of IO threads
*/
public int getNumIOThreads() {
return getInt(NUM_IO_THREADS, 2 * Runtime.getRuntime().availableProcessors());
}
/**
* Set the number of IO threads.
*
* <p>
* This is the number of threads used by Netty to handle TCP connections.
* </p>
*
* <p>
* NOTE: setting the number of IO threads after BookKeeper object is constructed
* will not take any effect on the number of threads in the pool.
* </p>
*
* @see #getNumIOThreads()
* @param numThreads number of IO threads used for bookkeeper
* @return client configuration
*/
public ClientConfiguration setNumIOThreads(int numThreads) {
setProperty(NUM_IO_THREADS, numThreads);
return this;
}
/**
* Get the period of time after which a speculative entry read should be triggered.
* A speculative entry read is sent to the next replica bookie before
* an error or response has been received for the previous entry read request.
*
* <p>A speculative entry read is only sent if we have not heard from the current
* replica bookie during the entire read operation which may comprise of many entries.
*
* <p>Speculative reads allow the client to avoid having to wait for the connect timeout
* in the case that a bookie has failed. It induces higher load on the network and on
* bookies. This should be taken into account before changing this configuration value.
*
* @see org.apache.bookkeeper.client.LedgerHandle#asyncReadEntries
* @return the speculative read timeout in milliseconds. Default 2000.
*/
public int getSpeculativeReadTimeout() {
return getInt(SPECULATIVE_READ_TIMEOUT, 2000);
}
/**
* Set the speculative read timeout. A lower timeout will reduce read latency in the
* case of a failed bookie, while increasing the load on bookies and the network.
*
* <p>The default is 2000 milliseconds. A value of 0 will disable speculative reads
* completely.
*
* @see #getSpeculativeReadTimeout()
* @param timeout the timeout value, in milliseconds
* @return client configuration
*/
public ClientConfiguration setSpeculativeReadTimeout(int timeout) {
setProperty(SPECULATIVE_READ_TIMEOUT, timeout);
return this;
}
/**
* Get the first speculative read timeout.
*
* @return first speculative read timeout.
*/
public int getFirstSpeculativeReadTimeout() {
return getInt(FIRST_SPECULATIVE_READ_TIMEOUT, getSpeculativeReadTimeout());
}
/**
* Set the first speculative read timeout.
*
* @param timeout
* first speculative read timeout.
* @return client configuration.
*/
public ClientConfiguration setFirstSpeculativeReadTimeout(int timeout) {
setProperty(FIRST_SPECULATIVE_READ_TIMEOUT, timeout);
return this;
}
/**
* Multipler to use when determining time between successive speculative read requests.
*
* @return speculative read timeout backoff multiplier.
*/
public float getSpeculativeReadTimeoutBackoffMultiplier() {
return getFloat(SPECULATIVE_READ_TIMEOUT_BACKOFF_MULTIPLIER, 2.0f);
}
/**
* Set the multipler to use when determining time between successive speculative read requests.
*
* @param speculativeReadTimeoutBackoffMultiplier
* multipler to use when determining time between successive speculative read requests.
* @return client configuration.
*/
public ClientConfiguration setSpeculativeReadTimeoutBackoffMultiplier(
float speculativeReadTimeoutBackoffMultiplier) {
setProperty(SPECULATIVE_READ_TIMEOUT_BACKOFF_MULTIPLIER, speculativeReadTimeoutBackoffMultiplier);
return this;
}
/**
* Multipler to use when determining time between successive speculative read LAC requests.
*