Skip to content

Commit 22b7bdf

Browse files
committed
configure stall protection grace period through env var
1 parent d42e05a commit 22b7bdf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

bottomless/src/replicator.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use anyhow::{anyhow, bail};
77
use arc_swap::ArcSwapOption;
88
use async_compression::tokio::write::{GzipEncoder, ZstdEncoder};
99
use aws_config::BehaviorVersion;
10-
use aws_sdk_s3::config::{Credentials, Region, SharedCredentialsProvider};
10+
use aws_sdk_s3::config::{
11+
Credentials, Region, SharedCredentialsProvider, StalledStreamProtectionConfig,
12+
};
1113
use aws_sdk_s3::error::SdkError;
1214
use aws_sdk_s3::operation::get_object::builders::GetObjectFluentBuilder;
1315
use aws_sdk_s3::operation::get_object::GetObjectError;
@@ -125,6 +127,8 @@ pub struct Options {
125127
pub skip_snapshot: bool,
126128
/// Skip uploading snapshots on shutdown
127129
pub skip_shutdown_upload: bool,
130+
/// Stall protection grace period duration for AWS S3 client
131+
pub stall_protection_grace_period: std::time::Duration,
128132
}
129133

130134
impl Options {
@@ -145,8 +149,13 @@ impl Options {
145149
"LIBSQL_BOTTOMLESS_AWS_SECRET_ACCESS_KEY was not set"
146150
))?;
147151
let session_token: Option<String> = self.session_token.clone();
152+
153+
let mut stall_protection = StalledStreamProtectionConfig::enabled();
154+
stall_protection.set_grace_period(Some(self.stall_protection_grace_period));
155+
148156
let conf = loader
149157
.behavior_version(BehaviorVersion::latest())
158+
.stalled_stream_protection(stall_protection.build())
150159
.region(Region::new(region))
151160
.credentials_provider(SharedCredentialsProvider::new(Credentials::new(
152161
access_key_id,
@@ -245,6 +254,11 @@ impl Options {
245254
let skip_shutdown_upload =
246255
env_var_or("LIBSQL_BOTTOMLESS_SKIP_SHUTDOWN_UPLOAD", false).parse::<bool>()?;
247256

257+
let stall_protection_grace_period_sec =
258+
env_var_or("LIBSQL_S3_STALL_PROTECTION_GRACE_PERIOD_SEC", 20).parse::<u64>()?;
259+
let stall_protection_grace_period =
260+
std::time::Duration::from_secs(stall_protection_grace_period_sec);
261+
248262
Ok(Options {
249263
db_id,
250264
create_bucket_if_not_exists: true,
@@ -263,6 +277,7 @@ impl Options {
263277
s3_max_retries,
264278
skip_snapshot,
265279
skip_shutdown_upload,
280+
stall_protection_grace_period,
266281
})
267282
}
268283
}

0 commit comments

Comments
 (0)