Skip to content

Commit 0a6dacf

Browse files
avinasshMarinPostma
authored andcommitted
Make snapshot at shutdown opt in
1 parent cd949d8 commit 0a6dacf

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

libsql-server/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub struct DbConfig {
124124
pub max_total_response_size: u64,
125125
pub snapshot_exec: Option<String>,
126126
pub checkpoint_interval: Option<Duration>,
127+
pub snapshot_at_shutdown: bool,
127128
}
128129

129130
impl Default for DbConfig {
@@ -139,6 +140,7 @@ impl Default for DbConfig {
139140
max_total_response_size: bytesize::mb(10u64),
140141
snapshot_exec: None,
141142
checkpoint_interval: None,
143+
snapshot_at_shutdown: false,
142144
}
143145
}
144146
}

libsql-server/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ where
526526
disable_namespace: self.disable_namespaces,
527527
};
528528
let factory = PrimaryNamespaceMaker::new(conf);
529-
let namespaces = NamespaceStore::new(factory, false);
529+
let namespaces = NamespaceStore::new(factory, false, self.db_config.snapshot_at_shutdown);
530530

531531
// eagerly load the default namespace when namespaces are disabled
532532
if self.disable_namespaces {
@@ -614,7 +614,7 @@ impl<C: Connector> Replica<C> {
614614
max_total_response_size: self.db_config.max_total_response_size,
615615
};
616616
let factory = ReplicaNamespaceMaker::new(conf);
617-
let namespaces = NamespaceStore::new(factory, true);
617+
let namespaces = NamespaceStore::new(factory, true, false);
618618
let replication_service = ReplicationLogProxyService::new(channel.clone(), uri.clone());
619619
let proxy_service = ReplicaProxyService::new(channel, uri, self.auth.clone());
620620

libsql-server/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ struct Cli {
191191
/// the default namespace.
192192
#[clap(long)]
193193
enable_namespaces: bool,
194+
195+
/// Enable snapshot at shutdown
196+
#[clap(long)]
197+
snapshot_at_shutdown: bool,
194198
}
195199

196200
#[derive(clap::Subcommand, Debug)]
@@ -296,6 +300,7 @@ fn make_db_config(config: &Cli) -> anyhow::Result<DbConfig> {
296300
max_total_response_size: config.max_total_response_size.as_u64(),
297301
snapshot_exec: config.snapshot_exec.clone(),
298302
checkpoint_interval: config.checkpoint_interval_s.map(Duration::from_secs),
303+
snapshot_at_shutdown: config.snapshot_at_shutdown,
299304
})
300305
}
301306

libsql-server/src/namespace/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,18 @@ struct NamespaceStoreInner<M: MakeNamespace> {
351351
make_namespace: M,
352352
allow_lazy_creation: bool,
353353
has_shutdown: AtomicBool,
354+
snapshot_at_shutdown: bool,
354355
}
355356

356357
impl<M: MakeNamespace> NamespaceStore<M> {
357-
pub fn new(make_namespace: M, allow_lazy_creation: bool) -> Self {
358+
pub fn new(make_namespace: M, allow_lazy_creation: bool, snapshot_at_shutdown: bool) -> Self {
358359
Self {
359360
inner: Arc::new(NamespaceStoreInner {
360361
store: Default::default(),
361362
make_namespace,
362363
allow_lazy_creation,
363364
has_shutdown: AtomicBool::new(false),
365+
snapshot_at_shutdown,
364366
}),
365367
}
366368
}
@@ -598,7 +600,7 @@ impl<M: MakeNamespace> NamespaceStore<M> {
598600
self.inner.has_shutdown.store(true, Ordering::Relaxed);
599601
let mut lock = self.inner.store.write().await;
600602
for (name, ns) in lock.drain() {
601-
ns.shutdown().await?;
603+
ns.shutdown(self.inner.snapshot_at_shutdown).await?;
602604
trace!("shutdown namespace: `{}`", name);
603605
}
604606
Ok(())
@@ -645,9 +647,11 @@ impl<T: Database> Namespace<T> {
645647
Ok(())
646648
}
647649

648-
async fn shutdown(mut self) -> anyhow::Result<()> {
650+
async fn shutdown(mut self, should_checkpoint: bool) -> anyhow::Result<()> {
649651
self.tasks.shutdown().await;
650-
self.checkpoint().await?;
652+
if should_checkpoint {
653+
self.checkpoint().await?;
654+
}
651655
self.db.shutdown().await?;
652656
Ok(())
653657
}

libsql-server/src/test/bottomless.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ async fn configure_server(
5050
max_total_response_size: 10000000 * 4096,
5151
snapshot_exec: None,
5252
checkpoint_interval: Some(Duration::from_secs(3)),
53+
snapshot_at_shutdown: false,
5354
},
5455
admin_api_config: None,
5556
disable_namespaces: true,

0 commit comments

Comments
 (0)