Skip to content

Commit 6fd307a

Browse files
committed
Make ScyllaDB replication factor configurable
1 parent f476e61 commit 6fd307a

File tree

16 files changed

+85
-31
lines changed

16 files changed

+85
-31
lines changed

Diff for: docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ COPY --from=binaries \
115115
COPY --chmod=755 \
116116
docker/server-entrypoint.sh \
117117
docker/server-init.sh \
118+
docker/proxy-entrypoint.sh \
118119
docker/proxy-init.sh \
119120
docker/compose-server-entrypoint.sh \
120121
docker/compose-proxy-entrypoint.sh \

Diff for: docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ services:
4242
shard-init:
4343
image: "${LINERA_IMAGE:-linera}"
4444
container_name: shard-init
45-
command: [ "./compose-server-init.sh" ]
45+
command: [ "./compose-server-init.sh", "1"]
4646
volumes:
4747
- .:/config
4848
depends_on:

Diff for: docker/proxy-entrypoint.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
storage_replication_factor=$1
4+
5+
exec ./linera-proxy \
6+
--storage scylladb:tcp:scylla-client.scylla.svc.cluster.local:9042 \
7+
--genesis /config/genesis.json \
8+
--storage-replication-factor $storage_replication_factor \
9+
/config/server.json

Diff for: docker/server-entrypoint.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/bin/sh
22

3+
storage_replication_factor=$1
4+
35
# Extract the ordinal number from the pod hostname
46
ORDINAL="${HOSTNAME##*-}"
57

68
exec ./linera-server run \
79
--storage scylladb:tcp:scylla-client.scylla.svc.cluster.local:9042 \
810
--server /config/server.json \
911
--shard $ORDINAL \
10-
--genesis /config/genesis.json
12+
--genesis /config/genesis.json \
13+
--storage-replication-factor $storage_replication_factor

Diff for: docker/server-init.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh
22

3+
storage_replication_factor=$1
34
while true; do
45
./linera storage check-existence --storage "scylladb:tcp:scylla-client.scylla.svc.cluster.local:9042"
56
status=$?
@@ -11,7 +12,8 @@ while true; do
1112
echo "Database does not exist, attempting to initialize..."
1213
if ./linera-server initialize \
1314
--storage scylladb:tcp:scylla-client.scylla.svc.cluster.local:9042 \
14-
--genesis /config/genesis.json; then
15+
--genesis /config/genesis.json \
16+
--storage-replication-factor $storage_replication_factor; then
1517
echo "Initialization successful."
1618
exit 0
1719
else

Diff for: kubernetes/linera-validator/helmfile.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ releases:
4242
- scylla-manager/scylla-manager
4343
- scylla-operator/scylla-operator
4444
values:
45-
- {{ env "LINERA_HELMFILE_VALUES_SCYLLA" | default "scylla.values.yaml" }}
45+
- {{ env "LINERA_HELMFILE_VALUES_SCYLLA" | default "scylla.values.yaml.gotmpl" }}
4646
- name: scylla-manager
4747
version: v1.13.0
4848
namespace: scylla-manager

Diff for: kubernetes/linera-validator/scylla.values.yaml renamed to kubernetes/linera-validator/scylla.values.yaml.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sysctls:
44
datacenter: validator
55
racks:
66
- name: rack-1
7-
members: 1
7+
members: {{ env "LINERA_HELMFILE_SET_SCYLLA_REPLICATION_FACTOR" | default 1 }}
88
scyllaConfig: "scylla-config"
99
storage:
1010
capacity: 2Gi

Diff for: kubernetes/linera-validator/templates/proxy.yaml

+1-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,7 @@ spec:
6969
name: linera-port
7070
- containerPort: 20100
7171
name: linera-port-int
72-
command:
73-
[
74-
"./linera-proxy",
75-
"--storage",
76-
"scylladb:tcp:scylla-client.scylla.svc.cluster.local:9042",
77-
"--genesis",
78-
"/config/genesis.json",
79-
]
80-
args: ["/config/server.json"]
72+
command: ["./proxy-entrypoint.sh", {{ .Values.storageReplicationFactor | quote }}]
8173
env:
8274
- name: RUST_LOG
8375
value: {{ .Values.logLevel }}

Diff for: kubernetes/linera-validator/templates/shards.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ spec:
3535
- name: linera-server-initializer
3636
image: {{ .Values.lineraImage }}
3737
imagePullPolicy: {{ .Values.lineraImagePullPolicy }}
38-
command: ["./server-init.sh"]
38+
command: ["./server-init.sh", {{ .Values.storageReplicationFactor | quote }}]
3939
env:
4040
- name: RUST_LOG
4141
value: {{ .Values.logLevel }}
@@ -49,7 +49,7 @@ spec:
4949
- name: linera-server
5050
image: {{ .Values.lineraImage }}
5151
imagePullPolicy: {{ .Values.lineraImagePullPolicy }}
52-
command: ["./server-entrypoint.sh"]
52+
command: ["./server-entrypoint.sh", {{ .Values.storageReplicationFactor | quote }}]
5353
env:
5454
- name: RUST_LOG
5555
value: {{ .Values.logLevel }}

Diff for: kubernetes/linera-validator/values-local.yaml.gotmpl

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ logLevel: "debug"
77
proxyPort: 19100
88
metricsPort: 21100
99
numShards: {{ env "LINERA_HELMFILE_SET_NUM_SHARDS" | default 10 }}
10+
storageReplicationFactor: {{ env "LINERA_HELMFILE_SET_STORAGE_REPLICATION_FACTOR" | default 1 }}
1011

1112
# Loki
1213
loki-stack:

Diff for: linera-indexer/lib/src/scylla_db.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct ScyllaDbConfig {
4141
/// The maximal number of entries in the storage cache.
4242
#[arg(long, default_value = "1000")]
4343
pub max_cache_entries: usize,
44+
45+
/// The replication factor for the keyspace
46+
#[arg(long, default_value = "1")]
47+
pub replication_factor: u32,
4448
}
4549

4650
pub type ScyllaDbRunner = Runner<ScyllaDbStore, ScyllaDbConfig>;
@@ -59,7 +63,11 @@ impl ScyllaDbRunner {
5963
storage_cache_config,
6064
};
6165
let namespace = config.client.table.clone();
62-
let store_config = ScyllaDbStoreConfig::new(config.client.uri.clone(), common_config);
66+
let store_config = ScyllaDbStoreConfig::new(
67+
config.client.uri.clone(),
68+
common_config,
69+
config.client.replication_factor,
70+
);
6371
let store = ScyllaDbStore::connect(&store_config, &namespace).await?;
6472
Self::new(config, store).await
6573
}

Diff for: linera-service/src/linera/main.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,10 @@ struct ClientOptions {
13151315
/// Subcommand.
13161316
#[command(subcommand)]
13171317
command: ClientCommand,
1318+
1319+
/// The replication factor for the keyspace
1320+
#[arg(long, default_value = "1")]
1321+
storage_replication_factor: u32,
13181322
}
13191323

13201324
impl ClientOptions {
@@ -1339,7 +1343,7 @@ impl ClientOptions {
13391343
let storage_config = self.storage_config()?;
13401344
debug!("Running command using storage configuration: {storage_config}");
13411345
let store_config = storage_config
1342-
.add_common_config(self.common_config())
1346+
.add_common_config(self.common_config(), self.storage_replication_factor)
13431347
.await?;
13441348
let genesis_config = self.wallet().await?.genesis_config().clone();
13451349
let output = Box::pin(store_config.run_with_storage(
@@ -1355,7 +1359,7 @@ impl ClientOptions {
13551359
let storage_config = self.storage_config()?;
13561360
debug!("Running command using storage configuration: {storage_config}");
13571361
let store_config = storage_config
1358-
.add_common_config(self.common_config())
1362+
.add_common_config(self.common_config(), self.storage_replication_factor)
13591363
.await?;
13601364
let output = Box::pin(store_config.run_with_store(job)).await?;
13611365
Ok(output)
@@ -1365,7 +1369,7 @@ impl ClientOptions {
13651369
let storage_config = self.storage_config()?;
13661370
debug!("Initializing storage using configuration: {storage_config}");
13671371
let store_config = storage_config
1368-
.add_common_config(self.common_config())
1372+
.add_common_config(self.common_config(), self.storage_replication_factor)
13691373
.await?;
13701374
let wallet = self.wallet().await?;
13711375
store_config.initialize(wallet.genesis_config()).await?;

Diff for: linera-service/src/proxy/main.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ pub struct ProxyOptions {
9595
/// Path to the file describing the initial user chains (aka genesis state)
9696
#[arg(long = "genesis")]
9797
genesis_config_path: PathBuf,
98+
99+
/// The replication factor for the keyspace
100+
#[arg(long, default_value = "1")]
101+
storage_replication_factor: u32,
98102
}
99103

100104
/// A Linera Proxy, either gRPC or over 'Simple Transport', meaning TCP or UDP.
@@ -410,7 +414,10 @@ impl ProxyOptions {
410414
storage_cache_config,
411415
};
412416
let genesis_config: GenesisConfig = util::read_json(&self.genesis_config_path)?;
413-
let store_config = self.storage_config.add_common_config(common_config).await?;
417+
let store_config = self
418+
.storage_config
419+
.add_common_config(common_config, self.storage_replication_factor)
420+
.await?;
414421
store_config
415422
.run_with_storage(&genesis_config, None, ProxyContext::from_options(self)?)
416423
.boxed()

Diff for: linera-service/src/server.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ enum ServerCommand {
382382
/// The maximal number of entries in the storage cache.
383383
#[arg(long, default_value = "1000")]
384384
max_cache_entries: usize,
385+
386+
/// The replication factor for the storage.
387+
#[arg(long, default_value = "1")]
388+
storage_replication_factor: u32,
385389
},
386390

387391
/// Act as a trusted third-party and generate all server configurations
@@ -431,6 +435,10 @@ enum ServerCommand {
431435
/// The maximal number of entries in the storage cache.
432436
#[arg(long, default_value = "1000")]
433437
max_cache_entries: usize,
438+
439+
/// The replication factor for the storage.
440+
#[arg(long, default_value = "1")]
441+
storage_replication_factor: u32,
434442
},
435443

436444
/// Replaces the configurations of the shards by following the given template.
@@ -533,6 +541,7 @@ async fn run(options: ServerOptions) {
533541
max_cache_size,
534542
max_entry_size,
535543
max_cache_entries,
544+
storage_replication_factor,
536545
} => {
537546
linera_version::VERSION_INFO.log();
538547

@@ -561,7 +570,7 @@ async fn run(options: ServerOptions) {
561570
storage_cache_config,
562571
};
563572
let store_config = storage_config
564-
.add_common_config(common_config)
573+
.add_common_config(common_config, storage_replication_factor)
565574
.await
566575
.unwrap();
567576
store_config
@@ -621,6 +630,7 @@ async fn run(options: ServerOptions) {
621630
max_cache_size,
622631
max_entry_size,
623632
max_cache_entries,
633+
storage_replication_factor,
624634
} => {
625635
let genesis_config: GenesisConfig =
626636
util::read_json(&genesis_config_path).expect("Failed to read initial chain config");
@@ -635,7 +645,7 @@ async fn run(options: ServerOptions) {
635645
storage_cache_config,
636646
};
637647
let store_config = storage_config
638-
.add_common_config(common_config)
648+
.add_common_config(common_config, storage_replication_factor)
639649
.await
640650
.unwrap();
641651
tracing::info!(

Diff for: linera-service/src/storage.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ impl StorageConfigNamespace {
388388
pub async fn add_common_config(
389389
&self,
390390
common_config: CommonStoreConfig,
391+
_replication_factor: u32,
391392
) -> Result<StoreConfig, anyhow::Error> {
392393
let namespace = self.namespace.clone();
393394
match &self.storage_config {
@@ -424,7 +425,8 @@ impl StorageConfigNamespace {
424425
}
425426
#[cfg(feature = "scylladb")]
426427
StorageConfig::ScyllaDb { uri } => {
427-
let config = ScyllaDbStoreConfig::new(uri.to_string(), common_config);
428+
let config =
429+
ScyllaDbStoreConfig::new(uri.to_string(), common_config, _replication_factor);
428430
Ok(StoreConfig::ScyllaDb(config, namespace))
429431
}
430432
#[cfg(all(feature = "rocksdb", feature = "scylladb"))]
@@ -438,7 +440,8 @@ impl StorageConfigNamespace {
438440
path_with_guard.clone(),
439441
common_config.clone(),
440442
);
441-
let second_config = ScyllaDbStoreConfig::new(uri.to_string(), common_config);
443+
let second_config =
444+
ScyllaDbStoreConfig::new(uri.to_string(), common_config, _replication_factor);
442445
let config = DualStoreConfig {
443446
first_config,
444447
second_config,

Diff for: linera-views/src/backends/scylla_db.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ pub struct ScyllaDbStoreInternalConfig {
632632
pub uri: String,
633633
/// The common configuration of the key value store
634634
common_config: CommonStoreInternalConfig,
635+
/// The replication factor for the keyspace
636+
pub replication_factor: u32,
635637
}
636638

637639
impl AdminKeyValueStore for ScyllaDbStoreInternal {
@@ -811,10 +813,13 @@ impl AdminKeyValueStore for ScyllaDbStoreInternal {
811813
.boxed()
812814
.await?;
813815
// Create a keyspace if it doesn't exist
814-
let query = "CREATE KEYSPACE IF NOT EXISTS kv WITH REPLICATION = { \
815-
'class' : 'SimpleStrategy', \
816-
'replication_factor' : 1 \
817-
}";
816+
let query = format!(
817+
"CREATE KEYSPACE IF NOT EXISTS kv WITH REPLICATION = {{ \
818+
'class' : 'SimpleStrategy', \
819+
'replication_factor' : {} \
820+
}}",
821+
config.replication_factor
822+
);
818823

819824
// Execute the query
820825
let prepared = session.prepare(query).await?;
@@ -890,7 +895,11 @@ impl TestKeyValueStore for JournalingKeyValueStore<ScyllaDbStoreInternal> {
890895
max_concurrent_queries: Some(TEST_SCYLLA_DB_MAX_CONCURRENT_QUERIES),
891896
max_stream_queries: TEST_SCYLLA_DB_MAX_STREAM_QUERIES,
892897
};
893-
Ok(ScyllaDbStoreInternalConfig { uri, common_config })
898+
Ok(ScyllaDbStoreInternalConfig {
899+
uri,
900+
common_config,
901+
replication_factor: 1,
902+
})
894903
}
895904
}
896905

@@ -914,10 +923,15 @@ pub type ScyllaDbStoreConfig = LruCachingConfig<ScyllaDbStoreInternalConfig>;
914923

915924
impl ScyllaDbStoreConfig {
916925
/// Creates a `ScyllaDbStoreConfig` from the inputs.
917-
pub fn new(uri: String, common_config: crate::store::CommonStoreConfig) -> ScyllaDbStoreConfig {
926+
pub fn new(
927+
uri: String,
928+
common_config: crate::store::CommonStoreConfig,
929+
replication_factor: u32,
930+
) -> ScyllaDbStoreConfig {
918931
let inner_config = ScyllaDbStoreInternalConfig {
919932
uri,
920933
common_config: common_config.reduced(),
934+
replication_factor,
921935
};
922936
ScyllaDbStoreConfig {
923937
inner_config,

0 commit comments

Comments
 (0)