forked from voldemort/voldemort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientConfig.java
1116 lines (954 loc) · 41.9 KB
/
ClientConfig.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
/*
* Copyright 2008-2010 LinkedIn, Inc
*
* Licensed 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 voldemort.client;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import voldemort.client.protocol.RequestFormatType;
import voldemort.cluster.Zone;
import voldemort.cluster.failuredetector.BannagePeriodFailureDetector;
import voldemort.cluster.failuredetector.FailureDetectorConfig;
import voldemort.cluster.failuredetector.ThresholdFailureDetector;
import voldemort.common.VoldemortOpCode;
import voldemort.serialization.DefaultSerializerFactory;
import voldemort.serialization.SerializerFactory;
import voldemort.utils.ConfigurationException;
import voldemort.utils.Props;
import voldemort.utils.ReflectUtils;
import voldemort.utils.Utils;
/**
* A configuration object that holds configuration parameters for the client.
*
*
*/
public class ClientConfig {
private volatile int maxConnectionsPerNode = 50;
private volatile long connectionTimeoutMs = 500;
private volatile long socketTimeoutMs = 5000;
private volatile boolean socketKeepAlive = false;
private volatile int selectors = 8;
private volatile long routingTimeoutMs = 5000;
private volatile TimeoutConfig timeoutConfig = new TimeoutConfig(routingTimeoutMs, false);
private volatile int socketBufferSize = 64 * 1024;
private volatile SerializerFactory serializerFactory = new DefaultSerializerFactory();
private volatile List<String> bootstrapUrls = null;
private volatile RequestFormatType requestFormatType = RequestFormatType.VOLDEMORT_V1;
private volatile RoutingTier routingTier = RoutingTier.CLIENT;
private volatile boolean enableLazy = true;
private volatile boolean enablePipelineRoutedStore = true;
private volatile int clientZoneId = Zone.DEFAULT_ZONE_ID;
/*
* The following are only used with a non pipe line routed, i.e non NIO
* based client
*/
@Deprecated
private volatile int maxTotalConnections = 500;
@Deprecated
private volatile int maxThreads = 5;
@Deprecated
private volatile int maxQueuedRequests = 50;
@Deprecated
private volatile long threadIdleMs = 100000;
private volatile boolean useDefaultClient = true;
private volatile String failureDetectorImplementation = FailureDetectorConfig.DEFAULT_IMPLEMENTATION_CLASS_NAME;
private volatile long failureDetectorBannagePeriod = FailureDetectorConfig.DEFAULT_BANNAGE_PERIOD;
private volatile int failureDetectorThreshold = FailureDetectorConfig.DEFAULT_THRESHOLD;
private volatile int failureDetectorThresholdCountMinimum = FailureDetectorConfig.DEFAULT_THRESHOLD_COUNT_MINIMUM;
private volatile long failureDetectorThresholdIntervalMs = FailureDetectorConfig.DEFAULT_THRESHOLD_INTERVAL;
private volatile long failureDetectorAsyncRecoveryIntervalMs = FailureDetectorConfig.DEFAULT_ASYNC_RECOVERY_INTERVAL;
private volatile List<String> failureDetectorCatastrophicErrorTypes = FailureDetectorConfig.DEFAULT_CATASTROPHIC_ERROR_TYPES;
private long failureDetectorRequestLengthThreshold = socketTimeoutMs;
private volatile int maxBootstrapRetries = 2;
private volatile String clientContextName = "";
/* 5 second check interval, in ms */
private volatile long asyncCheckMetadataIntervalInMs = 5000;
/* 12 hr refresh internval, in seconds */
private volatile int clientRegistryRefreshIntervalInSecs = 3600 * 12;
private volatile int asyncJobThreadPoolSize = 2;
/* SystemStore client config */
private volatile int sysMaxConnectionsPerNode = 2;
private volatile int sysRoutingTimeoutMs = 5000;
private volatile int sysSocketTimeoutMs = 5000;
private volatile int sysConnectionTimeoutMs = 1500;
private volatile boolean sysEnableJmx = false;
private volatile boolean sysEnablePipelineRoutedStore = true;
/* Voldemort client component config */
private volatile boolean enableJmx = true;
private volatile boolean enableCompressionLayer = true;
private volatile boolean enableSerializationLayer = true;
private volatile boolean enableInconsistencyResolvingLayer = true;
public ClientConfig() {}
/* Propery names for propery-based configuration */
public static final String MAX_CONNECTIONS_PER_NODE_PROPERTY = "max_connections";
public static final String MAX_TOTAL_CONNECTIONS_PROPERTY = "max_total_connections";
public static final String MAX_THREADS_PROPERTY = "max_threads";
public static final String MAX_QUEUED_REQUESTS_PROPERTY = "max_queued_requests";
public static final String THREAD_IDLE_MS_PROPERTY = "thread_idle_ms";
public static final String CONNECTION_TIMEOUT_MS_PROPERTY = "connection_timeout_ms";
public static final String SOCKET_TIMEOUT_MS_PROPERTY = "socket_timeout_ms";
public static final String SOCKET_KEEPALIVE_PROPERTY = "socket_keepalive";
public static final String SELECTORS_PROPERTY = "selectors";
public static final String ROUTING_TIMEOUT_MS_PROPERTY = "routing_timeout_ms";
public static final String GETALL_ROUTING_TIMEOUT_MS_PROPERTY = "getall_routing_timeout_ms";
public static final String PUT_ROUTING_TIMEOUT_MS_PROPERTY = "put_routing_timeout_ms";
public static final String GET_ROUTING_TIMEOUT_MS_PROPERTY = "get_routing_timeout_ms";
public static final String GET_VERSIONS_ROUTING_TIMEOUT_MS_PROPERTY = "getversions_routing_timeout_ms";
public static final String DELETE_ROUTING_TIMEOUT_MS_PROPERTY = "delete_routing_timeout_ms";
public static final String ALLOW_PARTIAL_GETALLS_PROPERTY = "allow_partial_getalls";
public static final String NODE_BANNAGE_MS_PROPERTY = "node_bannage_ms";
public static final String SOCKET_BUFFER_SIZE_PROPERTY = "socket_buffer_size";
public static final String SERIALIZER_FACTORY_CLASS_PROPERTY = "serializer_factory_class";
public static final String BOOTSTRAP_URLS_PROPERTY = "bootstrap_urls";
public static final String REQUEST_FORMAT_PROPERTY = "request_format";
public static final String ENABLE_JMX_PROPERTY = "enable_jmx";
public static final String ENABLE_PIPELINE_ROUTED_STORE_PROPERTY = "enable_pipeline_routed_store";
public static final String ENABLE_HINTED_HANDOFF_PROPERTY = "enable_hinted_handoff";
public static final String ENABLE_LAZY_PROPERTY = "enable-lazy";
public static final String CLIENT_ZONE_ID = "client_zone_id";
public static final String FAILUREDETECTOR_IMPLEMENTATION_PROPERTY = "failuredetector_implementation";
public static final String FAILUREDETECTOR_BANNAGE_PERIOD_PROPERTY = "failuredetector_bannage_period";
public static final String FAILUREDETECTOR_THRESHOLD_PROPERTY = "failuredetector_threshold";
public static final String FAILUREDETECTOR_THRESHOLD_INTERVAL_PROPERTY = "failuredetector_threshold_interval";
public static final String FAILUREDETECTOR_THRESHOLD_COUNTMINIMUM_PROPERTY = "failuredetector_threshold_countminimum";
public static final String FAILUREDETECTOR_ASYNCRECOVERY_INTERVAL_PROPERTY = "failuredetector_asyncscan_interval";
public static final String FAILUREDETECTOR_CATASTROPHIC_ERROR_TYPES_PROPERTY = "failuredetector_catastrophic_error_types";
public static final String FAILUREDETECTOR_REQUEST_LENGTH_THRESHOLD_PROPERTY = "failuredetector_request_length_threshold";
public static final String MAX_BOOTSTRAP_RETRIES = "max_bootstrap_retries";
public static final String CLIENT_CONTEXT_NAME = "voldemort_client_context_name";
public static final String ASYNC_CHECK_METADATA_INTERVAL = "check_metadata_interval_ms";
public static final String USE_DEFAULT_CLIENT = "use_default_client";
public static final String CLIENT_REGISTRY_REFRESH_INTERVAL = "client_registry_refresh_interval_seconds";
public static final String ASYNC_JOB_THREAD_POOL_SIZE = "async_job_thread_pool_size";
public static final String SYS_MAX_CONNECTIONS_PER_NODE = "sys_max_connections_per_node";
public static final String SYS_ROUTING_TIMEOUT_MS = "sys_routing_timeout_ms";
public static final String SYS_CONNECTION_TIMEOUT_MS = "sys_connection_timeout_ms";
public static final String SYS_SOCKET_TIMEOUT_MS = "sys_socket_timeout_ms";
public static final String SYS_ENABLE_JMX = "sys_enable_jmx";
public static final String SYS_ENABLE_PIPELINE_ROUTED_STORE = "sys_enable_pipeline_routed_store";
public static final String ENABLE_COMPRESSION_LAYER = "enable_compression_layer";
public static final String ENABLE_SERIALIZATION_LAYER = "enable_serialization_layer";
public static final String ENABLE_INCONSISTENCY_RESOLVING_LAYER = "enable_inconsistency_resolving_layer";
/**
* Instantiate the client config using a properties file
*
* @param propertyFile Properties file
*/
public ClientConfig(File propertyFile) {
Properties properties = new Properties();
InputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(propertyFile.getAbsolutePath()));
properties.load(input);
} catch(IOException e) {
throw new ConfigurationException(e);
} finally {
IOUtils.closeQuietly(input);
}
setProperties(properties);
}
/**
* Initiate the client config from a set of properties. This is useful for
* wiring from Spring or for externalizing client properties to a properties
* file
*
* @param properties The properties to use
*/
public ClientConfig(Properties properties) {
setProperties(properties);
}
private void setProperties(Properties properties) {
Props props = new Props(properties);
if(props.containsKey(MAX_CONNECTIONS_PER_NODE_PROPERTY))
this.setMaxConnectionsPerNode(props.getInt(MAX_CONNECTIONS_PER_NODE_PROPERTY));
if(props.containsKey(MAX_TOTAL_CONNECTIONS_PROPERTY))
this.setMaxTotalConnections(props.getInt(MAX_TOTAL_CONNECTIONS_PROPERTY));
if(props.containsKey(MAX_THREADS_PROPERTY))
this.setMaxThreads(props.getInt(MAX_THREADS_PROPERTY));
if(props.containsKey(MAX_QUEUED_REQUESTS_PROPERTY))
this.setMaxQueuedRequests(props.getInt(MAX_QUEUED_REQUESTS_PROPERTY));
if(props.containsKey(THREAD_IDLE_MS_PROPERTY))
this.setThreadIdleTime(props.getLong(THREAD_IDLE_MS_PROPERTY), TimeUnit.MILLISECONDS);
if(props.containsKey(CONNECTION_TIMEOUT_MS_PROPERTY))
this.setConnectionTimeout(props.getInt(CONNECTION_TIMEOUT_MS_PROPERTY),
TimeUnit.MILLISECONDS);
if(props.containsKey(SOCKET_TIMEOUT_MS_PROPERTY))
this.setSocketTimeout(props.getInt(SOCKET_TIMEOUT_MS_PROPERTY), TimeUnit.MILLISECONDS);
if(props.containsKey(SOCKET_KEEPALIVE_PROPERTY))
this.setSocketKeepAlive(props.getBoolean(SOCKET_KEEPALIVE_PROPERTY));
if(props.containsKey(SELECTORS_PROPERTY))
this.setSelectors(props.getInt(SELECTORS_PROPERTY));
if(props.containsKey(ROUTING_TIMEOUT_MS_PROPERTY))
this.setRoutingTimeout(props.getInt(ROUTING_TIMEOUT_MS_PROPERTY), TimeUnit.MILLISECONDS);
// By default, make all the timeouts equal to routing timeout
timeoutConfig = new TimeoutConfig(routingTimeoutMs, false);
if(props.containsKey(GETALL_ROUTING_TIMEOUT_MS_PROPERTY))
timeoutConfig.setOperationTimeout(VoldemortOpCode.GET_ALL_OP_CODE,
props.getInt(GETALL_ROUTING_TIMEOUT_MS_PROPERTY));
if(props.containsKey(GET_ROUTING_TIMEOUT_MS_PROPERTY))
timeoutConfig.setOperationTimeout(VoldemortOpCode.GET_OP_CODE,
props.getInt(GET_ROUTING_TIMEOUT_MS_PROPERTY));
if(props.containsKey(PUT_ROUTING_TIMEOUT_MS_PROPERTY)) {
long putTimeoutMs = props.getInt(PUT_ROUTING_TIMEOUT_MS_PROPERTY);
timeoutConfig.setOperationTimeout(VoldemortOpCode.PUT_OP_CODE, putTimeoutMs);
// By default, use the same thing for getVersions() also
timeoutConfig.setOperationTimeout(VoldemortOpCode.GET_VERSION_OP_CODE, putTimeoutMs);
}
// of course, if someone overrides it, we will respect that
if(props.containsKey(GET_VERSIONS_ROUTING_TIMEOUT_MS_PROPERTY))
timeoutConfig.setOperationTimeout(VoldemortOpCode.GET_VERSION_OP_CODE,
props.getInt(GET_VERSIONS_ROUTING_TIMEOUT_MS_PROPERTY));
if(props.containsKey(DELETE_ROUTING_TIMEOUT_MS_PROPERTY))
timeoutConfig.setOperationTimeout(VoldemortOpCode.DELETE_OP_CODE,
props.getInt(DELETE_ROUTING_TIMEOUT_MS_PROPERTY));
if(props.containsKey(ALLOW_PARTIAL_GETALLS_PROPERTY))
timeoutConfig.setPartialGetAllAllowed(props.getBoolean(ALLOW_PARTIAL_GETALLS_PROPERTY));
if(props.containsKey(SOCKET_BUFFER_SIZE_PROPERTY))
this.setSocketBufferSize(props.getInt(SOCKET_BUFFER_SIZE_PROPERTY));
if(props.containsKey(SERIALIZER_FACTORY_CLASS_PROPERTY)) {
Class<?> factoryClass = ReflectUtils.loadClass(props.getString(SERIALIZER_FACTORY_CLASS_PROPERTY));
SerializerFactory factory = (SerializerFactory) ReflectUtils.callConstructor(factoryClass,
new Object[] {});
this.setSerializerFactory(factory);
}
if(props.containsKey(BOOTSTRAP_URLS_PROPERTY))
this.setBootstrapUrls(props.getList(BOOTSTRAP_URLS_PROPERTY));
if(props.containsKey(REQUEST_FORMAT_PROPERTY))
this.setRequestFormatType(RequestFormatType.fromCode(props.getString(REQUEST_FORMAT_PROPERTY)));
if(props.containsKey(ENABLE_JMX_PROPERTY))
this.setEnableJmx(props.getBoolean(ENABLE_JMX_PROPERTY));
if(props.containsKey(ENABLE_LAZY_PROPERTY))
this.setEnableLazy(props.getBoolean(ENABLE_LAZY_PROPERTY));
if(props.containsKey(ENABLE_PIPELINE_ROUTED_STORE_PROPERTY))
this.setEnablePipelineRoutedStore(props.getBoolean(ENABLE_PIPELINE_ROUTED_STORE_PROPERTY));
if(props.containsKey(CLIENT_ZONE_ID))
this.setClientZoneId(props.getInt(CLIENT_ZONE_ID));
if(props.containsKey(USE_DEFAULT_CLIENT))
this.enableDefaultClient(props.getBoolean(USE_DEFAULT_CLIENT));
if(props.containsKey(FAILUREDETECTOR_IMPLEMENTATION_PROPERTY))
this.setFailureDetectorImplementation(props.getString(FAILUREDETECTOR_IMPLEMENTATION_PROPERTY));
// We're changing the property from "node_bannage_ms" to
// "failuredetector_bannage_period" so if we have the old one, migrate
// it over.
if(props.containsKey(NODE_BANNAGE_MS_PROPERTY)
&& !props.containsKey(FAILUREDETECTOR_BANNAGE_PERIOD_PROPERTY)) {
props.put(FAILUREDETECTOR_BANNAGE_PERIOD_PROPERTY, props.get(NODE_BANNAGE_MS_PROPERTY));
}
if(props.containsKey(FAILUREDETECTOR_BANNAGE_PERIOD_PROPERTY))
this.setFailureDetectorBannagePeriod(props.getLong(FAILUREDETECTOR_BANNAGE_PERIOD_PROPERTY));
if(props.containsKey(FAILUREDETECTOR_THRESHOLD_PROPERTY))
this.setFailureDetectorThreshold(props.getInt(FAILUREDETECTOR_THRESHOLD_PROPERTY));
if(props.containsKey(FAILUREDETECTOR_THRESHOLD_COUNTMINIMUM_PROPERTY))
this.setFailureDetectorThresholdCountMinimum(props.getInt(FAILUREDETECTOR_THRESHOLD_COUNTMINIMUM_PROPERTY));
if(props.containsKey(FAILUREDETECTOR_THRESHOLD_INTERVAL_PROPERTY))
this.setFailureDetectorThresholdInterval(props.getLong(FAILUREDETECTOR_THRESHOLD_INTERVAL_PROPERTY));
if(props.containsKey(FAILUREDETECTOR_ASYNCRECOVERY_INTERVAL_PROPERTY))
this.setFailureDetectorAsyncRecoveryInterval(props.getLong(FAILUREDETECTOR_ASYNCRECOVERY_INTERVAL_PROPERTY));
if(props.containsKey(FAILUREDETECTOR_CATASTROPHIC_ERROR_TYPES_PROPERTY))
this.setFailureDetectorCatastrophicErrorTypes(props.getList(FAILUREDETECTOR_CATASTROPHIC_ERROR_TYPES_PROPERTY));
if(props.containsKey(FAILUREDETECTOR_REQUEST_LENGTH_THRESHOLD_PROPERTY))
this.setFailureDetectorRequestLengthThreshold(props.getLong(FAILUREDETECTOR_REQUEST_LENGTH_THRESHOLD_PROPERTY));
else
this.setFailureDetectorRequestLengthThreshold(getSocketTimeout(TimeUnit.MILLISECONDS));
if(props.containsKey(MAX_BOOTSTRAP_RETRIES))
this.setMaxBootstrapRetries(props.getInt(MAX_BOOTSTRAP_RETRIES));
if(props.containsKey(CLIENT_CONTEXT_NAME)) {
this.setClientContextName(props.getString(CLIENT_CONTEXT_NAME));
}
if(props.containsKey(ASYNC_CHECK_METADATA_INTERVAL)) {
this.setAsyncMetadataRefreshInMs(props.getLong(ASYNC_CHECK_METADATA_INTERVAL));
}
if(props.containsKey(CLIENT_REGISTRY_REFRESH_INTERVAL)) {
this.setClientRegistryUpdateIntervalInSecs(props.getInt(CLIENT_REGISTRY_REFRESH_INTERVAL));
}
if(props.containsKey(ASYNC_JOB_THREAD_POOL_SIZE)) {
this.setAsyncJobThreadPoolSize(props.getInt(ASYNC_JOB_THREAD_POOL_SIZE));
}
/* Check for system store paramaters if any */
if(props.containsKey(SYS_MAX_CONNECTIONS_PER_NODE)) {
this.setSysMaxConnectionsPerNode(props.getInt(SYS_MAX_CONNECTIONS_PER_NODE));
}
if(props.containsKey(SYS_ROUTING_TIMEOUT_MS)) {
this.setSysRoutingTimeout(props.getInt(SYS_ROUTING_TIMEOUT_MS));
}
if(props.containsKey(SYS_SOCKET_TIMEOUT_MS)) {
this.setSysSocketTimeout(props.getInt(SYS_SOCKET_TIMEOUT_MS));
}
if(props.containsKey(SYS_CONNECTION_TIMEOUT_MS)) {
this.setSysConnectionTimeout(props.getInt(SYS_CONNECTION_TIMEOUT_MS));
}
if(props.containsKey(SYS_ENABLE_JMX)) {
this.setSysEnableJmx(props.getBoolean(SYS_ENABLE_JMX));
}
if(props.containsKey(SYS_ENABLE_PIPELINE_ROUTED_STORE)) {
this.setSysEnablePipelineRoutedStore(props.getBoolean(SYS_ENABLE_PIPELINE_ROUTED_STORE));
}
if(props.containsKey(ENABLE_COMPRESSION_LAYER)) {
this.setEnableCompressionLayer(props.getBoolean(ENABLE_COMPRESSION_LAYER));
}
if(props.containsKey(ENABLE_SERIALIZATION_LAYER)) {
this.setEnableSerializationLayer(props.getBoolean(ENABLE_SERIALIZATION_LAYER));
}
if(props.containsKey(ENABLE_INCONSISTENCY_RESOLVING_LAYER)) {
this.setEnableInconsistencyResolvingLayer(props.getBoolean(ENABLE_INCONSISTENCY_RESOLVING_LAYER));
}
}
/**
* Sets the maximum number of connections a system store client will create
* to a voldemort server
*
* @param maxConnectionsPerNode
* @return
*/
private ClientConfig setSysMaxConnectionsPerNode(int maxConnectionsPerNode) {
if(maxConnectionsPerNode <= 0)
throw new IllegalArgumentException("Value must be greater than zero.");
this.sysMaxConnectionsPerNode = maxConnectionsPerNode;
return this;
}
public int getSysMaxConnectionsPerNode() {
return this.sysMaxConnectionsPerNode;
}
/**
* Sets the routing layer timeout for the system store client.
*
* @param sysRoutingTimeout
* @return
*/
private ClientConfig setSysRoutingTimeout(int sysRoutingTimeoutMs) {
if(sysRoutingTimeoutMs <= 0)
throw new IllegalArgumentException("Value must be greater than zero.");
this.sysRoutingTimeoutMs = sysRoutingTimeoutMs;
return this;
}
public int getSysRoutingTimeout() {
return this.sysRoutingTimeoutMs;
}
/**
* Sets the socket timeout (at the java.net layer) for the system store
* client
*
* @param sysSocketTimeout
* @return
*/
private ClientConfig setSysSocketTimeout(int sysSocketTimeoutMs) {
if(sysSocketTimeoutMs <= 0)
throw new IllegalArgumentException("Value must be greater than zero.");
this.sysSocketTimeoutMs = sysSocketTimeoutMs;
return this;
}
public int getSysSocketTimeout() {
return this.sysSocketTimeoutMs;
}
/**
* Amount of time in ms spent trying to establish a connection to voldemort
* servers, from the system store client
*
* @param sysConnectionTimeoutMs
* @return
*/
private ClientConfig setSysConnectionTimeout(int sysConnectionTimeoutMs) {
if(sysConnectionTimeoutMs <= 0)
throw new IllegalArgumentException("Value must be greater than zero.");
this.sysConnectionTimeoutMs = sysConnectionTimeoutMs;
return this;
}
public int getSysConnectionTimeout() {
return this.sysConnectionTimeoutMs;
}
/**
* Whether or not JMX monitoring is enabled for the system store
*
* @param sysEnableJmx
* @return
*/
public ClientConfig setSysEnableJmx(boolean sysEnableJmx) {
this.sysEnableJmx = sysEnableJmx;
return this;
}
public boolean getSysEnableJmx() {
return this.sysEnableJmx;
}
/**
* Should pipleline store be used by the system store client?
*
* @param sysEnablePipelineRoutedStore
* @return
*/
public ClientConfig setSysEnablePipelineRoutedStore(boolean sysEnablePipelineRoutedStore) {
this.sysEnablePipelineRoutedStore = sysEnablePipelineRoutedStore;
return this;
}
public boolean getSysEnablePipelineRoutedStore() {
return this.sysEnablePipelineRoutedStore;
}
public int getMaxConnectionsPerNode() {
return maxConnectionsPerNode;
}
/**
* Set the maximum number of connections allowed to each voldemort node.
* Play with this value to determine how many connections are enough for
* your workload. Without high enough connections, you may not be able to
* throw enough traffic at the servers
*
* @param maxConnectionsPerNode The maximum number of connections
*/
public ClientConfig setMaxConnectionsPerNode(int maxConnectionsPerNode) {
if(maxConnectionsPerNode <= 0)
throw new IllegalArgumentException("Value must be greater than zero.");
this.maxConnectionsPerNode = maxConnectionsPerNode;
return this;
}
public int getSocketTimeout(TimeUnit unit) {
return toInt(unit.convert(socketTimeoutMs, TimeUnit.MILLISECONDS));
}
/**
* Set the SO_TIMEOUT for the socket if using HTTP or socket based network
* communication. This is the maximum amount of time the socket will block
* waiting for network activity.
*
* @param socketTimeout The socket timeout
* @param unit The time unit of the timeout value
*/
public ClientConfig setSocketTimeout(int socketTimeout, TimeUnit unit) {
this.socketTimeoutMs = unit.toMillis(socketTimeout);
return this;
}
public boolean getSocketKeepAlive() {
return socketKeepAlive;
}
/**
* Enabled/disable SO_KEEPALIVE on the connection created with the voldemort
* servers
*
* @param socketKeepAlive
* @return
*/
public ClientConfig setSocketKeepAlive(boolean socketKeepAlive) {
this.socketKeepAlive = socketKeepAlive;
return this;
}
public int getSelectors() {
return selectors;
}
/**
* Number of NIO selector threads to use, to handle communication with the
* server.Typically, this is same as the number of cores in the client
* machine
*
* @param selectors
* @return
*/
public ClientConfig setSelectors(int selectors) {
this.selectors = selectors;
return this;
}
public int getRoutingTimeout(TimeUnit unit) {
return toInt(unit.convert(routingTimeoutMs, TimeUnit.MILLISECONDS));
}
/**
* Set the timeout for all blocking operations to complete on all nodes. The
* number of blocking operations can be configured using the preferred-reads
* and preferred-writes configuration for the store.
*
* See {@link #GETALL_ROUTING_TIMEOUT_MS_PROPERTY},
* {@link #GET_ROUTING_TIMEOUT_MS_PROPERTY},
* {@link #PUT_ROUTING_TIMEOUT_MS_PROPERTY},
* {@link #DELETE_ROUTING_TIMEOUT_MS_PROPERTY} to override timeouts for
* specific operations
*
* @param routingTimeout The timeout for all operations to complete.
* @param unit The time unit of the timeout value
*/
public ClientConfig setRoutingTimeout(int routingTimeout, TimeUnit unit) {
this.routingTimeoutMs = unit.toMillis(routingTimeout);
return this;
}
/**
* Set the timeout configuration for the voldemort operations
*
* @param tConfig
* @return
*/
public ClientConfig setTimeoutConfig(TimeoutConfig tConfig) {
this.timeoutConfig = tConfig;
return this;
}
/**
* Get the timeouts for voldemort operations
*
* @return
*/
public TimeoutConfig getTimeoutConfig() {
return timeoutConfig;
}
/**
* @deprecated Use {@link #getFailureDetectorBannagePeriod()} instead
*/
@Deprecated
public int getNodeBannagePeriod(TimeUnit unit) {
return toInt(unit.convert(failureDetectorBannagePeriod, TimeUnit.MILLISECONDS));
}
/**
* The period of time to ban a node that gives an error on an operation.
*
* @param nodeBannagePeriod The period of time to ban the node
* @param unit The time unit of the given value
*
* @deprecated Use {@link #setFailureDetectorBannagePeriod(long)} instead
*/
@Deprecated
public ClientConfig setNodeBannagePeriod(int nodeBannagePeriod, TimeUnit unit) {
this.failureDetectorBannagePeriod = unit.toMillis(nodeBannagePeriod);
return this;
}
public int getConnectionTimeout(TimeUnit unit) {
return (int) Math.min(unit.convert(connectionTimeoutMs, TimeUnit.MILLISECONDS),
Integer.MAX_VALUE);
}
/**
* Set the maximum allowable time to block waiting for a free connection
*
* @param connectionTimeout The connection timeout
* @param unit The time unit of the given value
*/
public ClientConfig setConnectionTimeout(int connectionTimeout, TimeUnit unit) {
this.connectionTimeoutMs = unit.toMillis(connectionTimeout);
return this;
}
public int getSocketBufferSize() {
return socketBufferSize;
}
/**
* Set the size of the socket buffer to use for both socket reads and socket
* writes
*
* @param socketBufferSize The size of the socket buffer in bytes
*/
public ClientConfig setSocketBufferSize(int socketBufferSize) {
this.socketBufferSize = socketBufferSize;
return this;
}
public SerializerFactory getSerializerFactory() {
return serializerFactory;
}
/**
* Set the SerializerFactory used to serialize and deserialize values
*/
public ClientConfig setSerializerFactory(SerializerFactory serializerFactory) {
this.serializerFactory = Utils.notNull(serializerFactory);
return this;
}
public String[] getBootstrapUrls() {
if(this.bootstrapUrls == null)
throw new IllegalStateException("No bootstrap urls have been set.");
return this.bootstrapUrls.toArray(new String[this.bootstrapUrls.size()]);
}
/**
* Set the bootstrap urls from which to attempt a connection
*
* @param bootstrapUrls The urls to bootstrap from
*/
public ClientConfig setBootstrapUrls(List<String> bootstrapUrls) {
this.bootstrapUrls = Utils.notNull(bootstrapUrls);
if(this.bootstrapUrls.size() <= 0)
throw new IllegalArgumentException("Must provide at least one bootstrap URL.");
return this;
}
/**
* Set the bootstrap urls from which to attempt a connection
*
* @param bootstrapUrls The urls to bootstrap from
*/
public ClientConfig setBootstrapUrls(String... bootstrapUrls) {
this.bootstrapUrls = Arrays.asList(Utils.notNull(bootstrapUrls));
if(this.bootstrapUrls.size() <= 0)
throw new IllegalArgumentException("Must provide at least one bootstrap URL.");
return this;
}
public RequestFormatType getRequestFormatType() {
return requestFormatType;
}
/**
* Set the request format type used for network communications (for example
* protocol buffers)
*
* @param requestFormatType The type of the network protocol
*/
public ClientConfig setRequestFormatType(RequestFormatType requestFormatType) {
this.requestFormatType = Utils.notNull(requestFormatType);
return this;
}
public RoutingTier getRoutingTier() {
return routingTier;
}
/**
* Set the tier at which routing occurs. Client-side routing occurs on the
* client, and server-side routing on the server.
*
* NOTE : Server side routing is not used, as yet. The java client only
* supports client-side routing.
*
* @param routingTier The routing tier to use for routing requests
*/
public ClientConfig setRoutingTier(RoutingTier routingTier) {
this.routingTier = Utils.notNull(routingTier);
return this;
}
public int getMaxThreads() {
return maxThreads;
}
/**
* Set the maximum number of client threads
*
* @param maxThreads The maximum number of client threads
*/
public ClientConfig setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
return this;
}
@Deprecated
public int getMaxTotalConnections() {
return maxTotalConnections;
}
@Deprecated
public int getThreadIdleTime(TimeUnit unit) {
return toInt(unit.convert(threadIdleMs, TimeUnit.MILLISECONDS));
}
/**
* The amount of time to keep an idle client thread alive
*
* @param threadIdleTime
*/
@Deprecated
public ClientConfig setThreadIdleTime(long threadIdleTime, TimeUnit unit) {
this.threadIdleMs = unit.toMillis(threadIdleTime);
return this;
}
public int getMaxQueuedRequests() {
return maxQueuedRequests;
}
/**
* Set the maximum number of queued node operations before client actions
* will be blocked
*
* @param maxQueuedRequests The maximum number of queued requests
*/
public ClientConfig setMaxQueuedRequests(int maxQueuedRequests) {
this.maxQueuedRequests = maxQueuedRequests;
return this;
}
/**
* Set the maximum number of connections allowed to all voldemort nodes.
* Note: This has no effect when using NIO based pipeline routing
*
* @param maxTotalConnections The maximum total number of connections
*/
@Deprecated
public ClientConfig setMaxTotalConnections(int maxTotalConnections) {
if(maxTotalConnections <= 0)
throw new IllegalArgumentException("Value must be greater than zero.");
this.maxTotalConnections = maxTotalConnections;
return this;
}
public int toInt(long l) {
return (int) Math.min(l, Integer.MAX_VALUE);
}
public boolean isJmxEnabled() {
return this.enableJmx;
}
/**
* Enable JMX monitoring of the clients?
*
* @param enableJmx If true JMX monitoring of the clients will be enabled
*/
public ClientConfig setEnableJmx(boolean enableJmx) {
this.enableJmx = enableJmx;
return this;
}
public boolean isLazyEnabled() {
return this.enableLazy;
}
/**
* Enable lazy initialization of clients?
*
* @param enableLazy If true clients will be lazily initialized
*/
public ClientConfig setEnableLazy(boolean enableLazy) {
this.enableLazy = enableLazy;
return this;
}
/**
* Sets the zone the client belongs to. This is very important in zoned
* configurations since the client always has an "affinity" towards the
* servers in its zone.
*
* Default : zone 0
*
* @param clientZoneId
* @return
*/
public ClientConfig setClientZoneId(int clientZoneId) {
this.clientZoneId = clientZoneId;
return this;
}
public int getClientZoneId() {
return this.clientZoneId;
}
/**
* Whether or not a {@link ZenStoreClient} is created as opposed to a
* {@link DefaultStoreClient}
*
* true = DefaultStoreClient and false = ZenStoreClient
*
* @param enableDefault
* @return
*/
public ClientConfig enableDefaultClient(boolean enableDefault) {
this.useDefaultClient = enableDefault;
return this;
}
public boolean isDefaultClientEnabled() {
return this.useDefaultClient;
}
public boolean isPipelineRoutedStoreEnabled() {
return enablePipelineRoutedStore;
}
/**
* Whether or not to use the Pipeline routing which is much more resource
* efficient by employing Java NIO to handle communication with the server
*
* @param enablePipelineRoutedStore
* @return
*/
public ClientConfig setEnablePipelineRoutedStore(boolean enablePipelineRoutedStore) {
this.enablePipelineRoutedStore = enablePipelineRoutedStore;
return this;
}
public String getFailureDetectorImplementation() {
return failureDetectorImplementation;
}
/**
* FailureDetector to use. Its highly recommended to use
* {@link ThresholdFailureDetector} as opposed to using
* {@link BannagePeriodFailureDetector}
*
* @param failureDetectorImplementation
* @return
*/
public ClientConfig setFailureDetectorImplementation(String failureDetectorImplementation) {
this.failureDetectorImplementation = failureDetectorImplementation;
return this;
}
public long getFailureDetectorBannagePeriod() {
return failureDetectorBannagePeriod;
}
public ClientConfig setFailureDetectorBannagePeriod(long failureDetectorBannagePeriod) {
this.failureDetectorBannagePeriod = failureDetectorBannagePeriod;
return this;
}
public int getFailureDetectorThreshold() {
return failureDetectorThreshold;
}
/**
* Set the percentage of exceptions that tolerated in a given failure
* detector window. If the client experiences more exceptions than this
* threshold, it will mark the erring server down
*
* @param failureDetectorThreshold
* @return
*/
public ClientConfig setFailureDetectorThreshold(int failureDetectorThreshold) {
this.failureDetectorThreshold = failureDetectorThreshold;
return this;
}
public int getFailureDetectorThresholdCountMinimum() {
return failureDetectorThresholdCountMinimum;
}
/**
* Sets the minimum number of failures (exceptions/slow responses) in a
* given failure detector window, for a server to be marked down. Guards
* against a very small number of exceptions tripping the Failure detector
* due to low activity
*
* @param failureDetectorThresholdCountMinimum
* @return
*/
public ClientConfig setFailureDetectorThresholdCountMinimum(int failureDetectorThresholdCountMinimum) {
this.failureDetectorThresholdCountMinimum = failureDetectorThresholdCountMinimum;
return this;
}
public long getFailureDetectorThresholdInterval() {
return failureDetectorThresholdIntervalMs;
}
/**
* Time window in ms, over which the failure detector accounts the failures
* and successes
*
* @param failureDetectorThresholdIntervalMs
* @return
*/
public ClientConfig setFailureDetectorThresholdInterval(long failureDetectorThresholdIntervalMs) {
this.failureDetectorThresholdIntervalMs = failureDetectorThresholdIntervalMs;
return this;
}
public long getFailureDetectorAsyncRecoveryInterval() {
return failureDetectorAsyncRecoveryIntervalMs;
}
/**
* Number of milliseconds, to try to check if a marked down server has come
* back up again
*
* @param failureDetectorAsyncRecoveryInterval
* @return
*/
public ClientConfig setFailureDetectorAsyncRecoveryInterval(long failureDetectorAsyncRecoveryInterval) {
this.failureDetectorAsyncRecoveryIntervalMs = failureDetectorAsyncRecoveryInterval;
return this;
}
public List<String> getFailureDetectorCatastrophicErrorTypes() {
return failureDetectorCatastrophicErrorTypes;
}
/**
* Sets the exception types that should be treated as catastrophic,by the
* failure detector, resulting in the server being immediately considered
* down. Input string list should be populated by something like
* ConnectException.class.getName()
*
* @param failureDetectorCatastrophicErrorTypes
* @return
*/
public ClientConfig setFailureDetectorCatastrophicErrorTypes(List<String> failureDetectorCatastrophicErrorTypes) {
this.failureDetectorCatastrophicErrorTypes = failureDetectorCatastrophicErrorTypes;
return this;
}
public long getFailureDetectorRequestLengthThreshold() {
return failureDetectorRequestLengthThreshold;
}
/**
* Sets the maximum amount of time a request is allowed to take, to be not
* considered as a "slow" request and count against the server, in terms of
* failure detection
*
* @param failureDetectorRequestLengthThreshold
* @return
*/
public ClientConfig setFailureDetectorRequestLengthThreshold(long failureDetectorRequestLengthThreshold) {
this.failureDetectorRequestLengthThreshold = failureDetectorRequestLengthThreshold;
return this;