10
10
import org .apache .cassandra .config .ParameterizedClass ;
11
11
import org .apache .cassandra .exceptions .ConfigurationException ;
12
12
13
- public class CassandraEmbeddedProperties implements CassandraEmbeddedConfiguration
13
+ public class CassandraEmbeddedProperties
14
+ implements CassandraEmbeddedConfiguration
14
15
{
15
16
16
17
private volatile static CassandraEmbeddedProperties instance ;
@@ -33,60 +34,162 @@ private CassandraEmbeddedProperties(String storageFolder,
33
34
Objects .isNull (instance );
34
35
35
36
Config configLocal = new Config ();
37
+
38
+ // ------------------------
39
+ // Generic configuration
40
+ // ------------------------
36
41
configLocal .cluster_name = "Test Cluster" ;
37
- configLocal .hinted_handoff_enabled = true ;
38
- configLocal .max_hint_window_in_ms = 10800000 ; // 3 hours
39
- configLocal .hinted_handoff_throttle_in_kb = 1024 ;
40
- configLocal .max_hints_delivery_threads = 2 ;
41
- configLocal .hints_directory = String .format ("%s/cassandra/hints" , storageFolder );
42
+ configLocal .snapshot_before_compaction = false ;
43
+ configLocal .auto_snapshot = false ;
44
+
45
+ // ------------------------
46
+ // Security
47
+ // ------------------------
42
48
configLocal .authenticator = "PasswordAuthenticator" ;
43
49
configLocal .authorizer = "AllowAllAuthorizer" ;
44
50
configLocal .permissions_validity_in_ms = 2000 ;
45
- configLocal .partitioner = "org.apache.cassandra.dht.Murmur3Partitioner" ;
46
- configLocal .data_file_directories = new String [] { String .format ("%s/cassandra/data" , storageFolder ) };
47
- configLocal .commitlog_directory = String .format ("%s/cassandra/commitlog" , storageFolder );
48
- configLocal .cdc_raw_directory = String .format ("%s/cassandra/cdc" , storageFolder );
49
- configLocal .disk_failure_policy = DiskFailurePolicy .stop ;
50
- configLocal .key_cache_save_period = 14400 ;
51
- configLocal .row_cache_size_in_mb = 0 ;
52
- configLocal .row_cache_save_period = 0 ;
53
- configLocal .saved_caches_directory = String .format ("%s/cassandra/saved_caches" , storageFolder );
54
- configLocal .commitlog_sync = CommitLogSync .periodic ;
55
- configLocal .commitlog_sync_period_in_ms = 10000 ;
56
- configLocal .commitlog_segment_size_in_mb = 8 ;
57
- configLocal .max_mutation_size_in_kb = 4096 ;
58
- configLocal .seed_provider = new ParameterizedClass ("org.apache.cassandra.locator.SimpleSeedProvider" ,
59
- Collections .singletonMap ("seeds" , "127.0.0.1" ));
60
- configLocal .concurrent_reads = 32 ;
61
- configLocal .concurrent_writes = 32 ;
62
- configLocal .trickle_fsync = false ;
63
- configLocal .trickle_fsync_interval_in_kb = 10240 ;
51
+
52
+ // ------------------------
53
+ // Network
54
+ // ------------------------
55
+ configLocal .start_rpc = false ; // disable thrift - it's deprecated and should not be used!
56
+ configLocal .listen_address = "127.0.0.1" ;
64
57
configLocal .storage_port = 7010 ;
65
58
configLocal .ssl_storage_port = 7011 ;
66
- configLocal .listen_address = "127.0.0.1" ;
67
-
68
59
configLocal .start_native_transport = true ;
69
60
configLocal .native_transport_port = port ;
61
+ configLocal .native_transport_max_threads = 256 ;
70
62
71
- configLocal .start_rpc = false ;
72
- configLocal .incremental_backups = false ;
73
- configLocal .snapshot_before_compaction = false ;
74
- configLocal .auto_snapshot = false ;
75
- configLocal .column_index_size_in_kb = 64 ;
76
- configLocal .compaction_throughput_mb_per_sec = 16 ;
63
+ // Coordinator related
77
64
configLocal .read_request_timeout_in_ms = 5000 ;
78
65
configLocal .range_request_timeout_in_ms = 10000 ;
79
66
configLocal .write_request_timeout_in_ms = 2000 ;
80
67
configLocal .cas_contention_timeout_in_ms = 1000 ;
81
68
configLocal .truncate_request_timeout_in_ms = 60000 ;
82
69
configLocal .request_timeout_in_ms = 10000 ;
83
70
configLocal .cross_node_timeout = false ;
71
+
72
+ // Addresses of hosts that are deemed contact points.
73
+ // Cassandra nodes use this list of hosts to find each other and learn
74
+ // the topology of the ring. You must change this if you are running multiple nodes!
75
+ // - seeds is actually a comma-delimited list of addresses.
76
+ // Ex: "seeds: <ip1>,<ip2>,<ip3>"
77
+ configLocal .seed_provider = new ParameterizedClass ("org.apache.cassandra.locator.SimpleSeedProvider" ,
78
+ Collections .singletonMap ("seeds" , "127.0.0.1" ));
79
+
80
+ // ------------------------
81
+ // Storage locations
82
+ // ------------------------
83
+ configLocal .data_file_directories = new String []{ String .format ("%s/cassandra/data" , storageFolder ) };
84
+ configLocal .saved_caches_directory = String .format ("%s/cassandra/saved_caches" , storageFolder );
85
+ configLocal .commitlog_directory = String .format ("%s/cassandra/commitlog" , storageFolder );
86
+ // CommitLogSegments are moved to this directory on flush if cdc_enabled: true and the segment contains
87
+ // mutations for a CDC-enabled table. This should be placed on a separate spindle than the data directories.
88
+ // If not set, the default directory is $CASSANDRA_HOME/data/cdc_raw.
89
+ configLocal .cdc_raw_directory = String .format ("%s/cassandra/cdc" , storageFolder );
90
+ configLocal .hints_directory = String .format ("%s/cassandra/hints" , storageFolder );
91
+
92
+ // ------------------------
93
+ // Disk
94
+ // ------------------------
95
+ configLocal .disk_optimization_strategy = Config .DiskOptimizationStrategy .ssd ;
96
+ configLocal .disk_failure_policy = DiskFailurePolicy .stop ;
97
+ configLocal .trickle_fsync = true ; // good on SSDs, probably bad on hdd
98
+ configLocal .trickle_fsync_interval_in_kb = 10240 ; // default: 10240
99
+ configLocal .concurrent_compactors = 2 ;
100
+ configLocal .compaction_throughput_mb_per_sec = 128 ; // 128+ for SSD, 16 for hdd;
101
+ // - Usually (16 × number_of_drives)
102
+ configLocal .concurrent_reads = 32 ;
103
+ // - Writes in Cassandra are rarely I/O bound, so the ideal number of concurrent writes depends on the number
104
+ // of CPU cores on the node. The recommended value is 8 × number_of_cpu_cores.
105
+ configLocal .concurrent_writes = 16 ;
106
+ // - Counter writes read the current values before incrementing and writing them back.
107
+ // The recommended value is (16 × number_of_drives).
108
+ configLocal .concurrent_counter_writes = 32 ;
109
+ // - Limit on the number of concurrent materialized view writes. Set this to the lesser of concurrent reads or
110
+ // concurrent writes, because there is a read involved in each materialized view write. (Default: 32)
111
+ configLocal .concurrent_materialized_view_writes = 32 ;
112
+
113
+ // - (Default 1024KB ) Total maximum throttle for replaying hints. Throttling is reduced proportionally to
114
+ // the number of nodes in the cluster.
115
+ //configLocal.batchlog_replay_throttle_in_kb = 1024;
116
+
117
+ // Cache and index settings
118
+ // - (Default: 64) Granularity of the index of rows within a partition. For huge rows, decrease this setting to
119
+ // improve seek time. If you use key cache, be careful not to make this setting too large because key cache
120
+ // will be overwhelmed. If you're unsure of the size of the rows, it's best to use the default setting.
121
+ configLocal .column_index_size_in_kb = 32 ; // default 64
122
+ configLocal .column_index_cache_size_in_kb = 1024 ;
123
+
124
+ // Memtable (in-memory structures where Cassandra buffers writes)
125
+ // https://cassandra.apache.org/doc/latest/architecture/storage_engine.html#memtables
126
+ configLocal .memtable_allocation_type = Config .MemtableAllocationType .offheap_objects ;
127
+ // - Smaller of number of disks or number of cores with a minimum of 2 and a maximum of 8
128
+ // If your data directories are backed by SSDs, increase this setting to the number of cores.
129
+ configLocal .memtable_flush_writers = 2 ;
130
+ // - The compaction process opens SSTables before they are completely written and uses them in place of
131
+ // the prior SSTables for any range previously written. This setting helps to smoothly transfer reads
132
+ // between the SSTables by reducing page cache churn and keeps hot rows hot.
133
+ configLocal .sstable_preemptive_open_interval_in_mb = 64 ; // default 50
134
+
135
+ // Enable / disable CDC functionality on a per-node basis. This modifies the logic used for write path allocation rejection
136
+ // (standard: never reject. cdc: reject Mutation containing a CDC-enabled table if at space limit in cdc_raw_directory).
137
+ configLocal .cdc_enabled = false ;
138
+
139
+ // The default option is “periodic” where writes may be ack'ed immediately and the CommitLog is simply synced
140
+ // every commitlog_sync_period_in_ms milliseconds. What this means, is the commit is
141
+ configLocal .commitlog_sync = CommitLogSync .periodic ;
142
+ configLocal .commitlog_sync_period_in_ms = 3000 ; // sync log every 5s.
143
+ configLocal .commitlog_total_space_in_mb = 32 ;
144
+ configLocal .commitlog_segment_size_in_mb = 32 ;
145
+ configLocal .max_mutation_size_in_kb = (configLocal .commitlog_segment_size_in_mb * 1024 ) / 2 ;
146
+ // configLocal.ideal_consistency_level = ConsistencyLevel.LOCAL_QUORUM; // available in cassandra 4
147
+
148
+ // ------------------------
149
+ // Replication
150
+ // ------------------------
151
+
152
+ // A partitioner determines how data is distributed across the nodes in the cluster (including replicas).
153
+ // Basically, a partitioner is a function for deriving a token representing a row from its partition key,
154
+ // typically by hashing. Each row of data is then distributed across the cluster by the value of the token.
155
+ //
156
+ // Default: Murmur3Partitioner using MurmurHash which uses 64-bit hashing function and allows for possible
157
+ // range of hash values is from -2^63 to +2^63-1.
158
+ // WARNING: You cannot change the partitioner in existing clusters that use a different partitioner.
159
+ //
160
+ configLocal .partitioner = org .apache .cassandra .dht .Murmur3Partitioner .class .getName ();
161
+
162
+ // hinted_handoff is used to optimize cluster consistency process and anti-entropy (the synchronization of
163
+ // replica data on nodes to ensure that the data is fresh) when a replica-owning node is not available to accept
164
+ // the write operation (i.e. network issues/etc). This operation DOES NOT guarantee successful write operations,
165
+ // except when a client application uses consistency level of `ANY`.
166
+ // WARNING: This MUST be enabled for HA setups! It's currently disabled, because we're using single nodes setups.
167
+ configLocal .hinted_handoff_enabled = false ;
168
+
169
+ // Endpoint snitch
170
+ // This teaches Cassandra enough about your network's topology so it can route requests efficiently and spread
171
+ // replicas by grouping machines nto `data centers` and `racks`.
172
+ // WARNING: Switching this option CAN CAUSE DATA LOSS (read manual)
173
+ // Default: SimpleSnitch (leave it as is for now)
84
174
configLocal .endpoint_snitch = "SimpleSnitch" ;
85
175
configLocal .dynamic_snitch_update_interval_in_ms = 100 ;
86
176
configLocal .dynamic_snitch_reset_interval_in_ms = 600000 ;
87
177
configLocal .dynamic_snitch_badness_threshold = 0.1 ;
88
- configLocal .request_scheduler = "org.apache.cassandra.scheduler.NoScheduler" ;
89
- configLocal .index_interval = 128 ;
178
+
179
+ // Back-pressure settings # If enabled, the coordinator will apply the back-pressure strategy specified below to
180
+ // each mutation sent to replicas, with the aim of reducing pressure on overloaded replicas.
181
+ // Should be configured usually for cluster setup.
182
+ configLocal .back_pressure_enabled = false ;
183
+ //configLocal.back_pressure_strategy = RateBasedBackPressure.withDefaultParams();
184
+
185
+ // internode_compression controls whether traffic between nodes is compressed
186
+ // all - all traffic is compressed
187
+ // dc - traffic between nodes is compressed
188
+ // none - no compression (suitable for single nodes)
189
+ configLocal .internode_compression = Config .InternodeCompression .none ;
190
+
191
+ // Wanr for GC pauses longer than 500ms (usually means heap is near limit)
192
+ configLocal .gc_warn_threshold_in_ms = 500 ;
90
193
91
194
this .config = configLocal ;
92
195
}
@@ -99,24 +202,27 @@ public Integer getPort()
99
202
@ Override
100
203
public String getCassandraConfigLoaderClassName ()
101
204
{
102
- return "org.strongbox.db.server.CassandraEmbeddedProperties$CassandraEmbeddedPropertiesLoader" ;
205
+ return CassandraEmbeddedPropertiesLoader . class . getName () ;
103
206
}
104
207
105
208
public String getStorageFolder ()
106
209
{
107
210
return config .data_file_directories [0 ].replace ("/cassandra/data" , "" );
108
211
}
109
212
110
- public static class CassandraEmbeddedPropertiesLoader implements ConfigurationLoader
213
+ public static class CassandraEmbeddedPropertiesLoader
214
+ implements ConfigurationLoader
111
215
{
216
+
112
217
@ Override
113
218
public Config loadConfig ()
114
- throws ConfigurationException
219
+ throws ConfigurationException
115
220
{
116
221
Objects .nonNull (instance );
117
222
118
223
return instance .config ;
119
224
}
120
225
121
226
}
227
+
122
228
}
0 commit comments