Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/extensions-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:

jobs:
c-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
defaults:
run:
working-directory: libsql-sqlite3
Expand All @@ -41,7 +41,7 @@ jobs:
make test

rs-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
defaults:
run:
working-directory: libsql-sqlite3
Expand All @@ -61,7 +61,7 @@ jobs:
cargo test --features=loadable_extension

extensions-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Extensions Tests

steps:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/golang-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
jobs:
golang-bindings:

runs-on: ubuntu-latest
runs-on: ubuntu-24.04

services:
sqld:
Expand All @@ -37,7 +37,9 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '>=1.21'
# 1.27.4 rejects the LTO section in the static lib built above (".llvmbc" in
# #cgo LDFLAGS); 1.27.3 is the last version that builds go-libsql.
go-version: '1.27.3'
- name: get TCL
run: sudo apt-get install -y tcl8.6-dev

Expand Down
91 changes: 81 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bottomless-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ aws-sdk-s3 = "1"
aws-smithy-types = "1"
bottomless = { version = "0", path = "../bottomless" }
bytes = "1"
chrono = "0.4.23"
jiff = "1"
clap = { version = "4.0.29", features = ["derive"] }
libsql-sys = { path = "../libsql-sys" }
tokio = { version = "1.23.0", features = ["macros", "rt", "rt-multi-thread"] }
Expand Down
23 changes: 14 additions & 9 deletions bottomless-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use aws_sdk_s3::Client;
use bytes::Bytes;
use chrono::NaiveDateTime;
use clap::{Parser, Subcommand};
use jiff::civil::{Date, DateTime};
use libsql_sys::{connection::NO_AUTOCHECKPOINT, wal::Sqlite3WalManager};
use rusqlite::params;
use std::path::PathBuf;
Expand Down Expand Up @@ -59,15 +59,17 @@ enum Commands {
#[clap(
long,
conflicts_with = "generation",
long_help = "List only generations older than given date"
long_help = "List only generations older than given date",
value_parser = bottomless::replicator::parse_date
)]
older_than: Option<chrono::NaiveDate>,
older_than: Option<Date>,
#[clap(
long,
conflicts_with = "generation",
long_help = "List only generations newer than given date"
long_help = "List only generations newer than given date",
value_parser = bottomless::replicator::parse_date
)]
newer_than: Option<chrono::NaiveDate>,
newer_than: Option<Date>,
#[clap(
long,
short,
Expand All @@ -89,7 +91,8 @@ enum Commands {
conflicts_with = "generation",
long_help = "UTC timestamp which is an upper bound for the transactions to be restored."
)]
utc_time: Option<NaiveDateTime>,
#[clap(value_parser = bottomless::replicator::parse_utc_datetime)]
utc_time: Option<DateTime>,
#[clap(long, short, conflicts_with_all = ["generation", "utc_time"], long_help = "Restore from a local directory")]
from_dir: Option<PathBuf>,
},
Expand All @@ -107,7 +110,8 @@ enum Commands {
conflicts_with = "generation",
long_help = "UTC timestamp which is an upper bound for the transactions to be verified."
)]
utc_time: Option<NaiveDateTime>,
#[clap(value_parser = bottomless::replicator::parse_utc_datetime)]
utc_time: Option<DateTime>,
},
#[clap(about = "Remove given generation from remote storage")]
Rm {
Expand All @@ -116,9 +120,10 @@ enum Commands {
#[clap(
long,
conflicts_with = "generation",
long_help = "Remove generations older than given date"
long_help = "Remove generations older than given date",
value_parser = bottomless::replicator::parse_date
)]
older_than: Option<chrono::NaiveDate>,
older_than: Option<Date>,
#[clap(long, short)]
verbose: bool,
},
Expand Down
50 changes: 34 additions & 16 deletions bottomless-cli/src/replicator_extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use aws_sdk_s3::error::SdkError;
use aws_sdk_s3::types::ObjectAttributes;
use aws_sdk_s3::Client;
use aws_smithy_types::date_time::Format;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use jiff::civil::{Date, DateTime};
use jiff::tz::TimeZone;
use jiff::Timestamp;
use tokio::io::BufReader;

pub(crate) struct Replicator {
Expand All @@ -24,15 +26,18 @@ impl std::ops::DerefMut for Replicator {
}
}

fn uuid_to_datetime(uuid: &uuid::Uuid) -> chrono::NaiveDateTime {
fn uuid_to_datetime(uuid: &uuid::Uuid) -> DateTime {
let timestamp = bottomless::replicator::Replicator::generation_to_timestamp(uuid);
let (seconds, _) = timestamp
.as_ref()
.map(uuid::Timestamp::to_unix)
.unwrap_or_default();
chrono::DateTime::from_timestamp_millis((seconds * 1000) as i64)
.unwrap()
.naive_utc()
TimeZone::UTC.to_datetime(Timestamp::from_second(seconds as i64).unwrap_or(Timestamp::MAX))
}

/// `2026-11-30 12:00:00`, as the listings have always printed a UTC datetime.
fn fmt_datetime(datetime: &DateTime) -> String {
datetime.strftime("%Y-%m-%d %H:%M:%S").to_string()
}

pub(crate) async fn detect_db(client: &Client, bucket: &str, namespace: &str) -> Option<String> {
Expand Down Expand Up @@ -95,8 +100,8 @@ impl Replicator {
pub(crate) async fn list_generations(
&self,
limit: Option<u64>,
older_than: Option<chrono::NaiveDate>,
newer_than: Option<chrono::NaiveDate>,
older_than: Option<Date>,
newer_than: Option<Date>,
verbose: bool,
) -> Result<()> {
let mut next_marker = None;
Expand Down Expand Up @@ -130,19 +135,23 @@ impl Replicator {
let prefix = &prefix[self.db_name.len() + 1..prefix.len() - 1];
let uuid = uuid::Uuid::try_parse(prefix)?;
let datetime = uuid_to_datetime(&uuid);
if datetime.date() < newer_than.unwrap_or(chrono::NaiveDate::MIN) {
if datetime.date() < newer_than.unwrap_or(Date::MIN) {
continue;
}
if datetime.date() > older_than.unwrap_or(chrono::NaiveDate::MAX) {
if datetime.date() > older_than.unwrap_or(Date::MAX) {
continue;
}
println!("{} (created: {})", uuid, datetime.and_utc().to_rfc3339());
println!(
"{} (created: {})",
uuid,
datetime.strftime("%Y-%m-%dT%H:%M:%S+00:00")
);
if verbose {
let counter = self.get_remote_change_counter(&uuid).await?;
let consistent_frame = self.get_last_consistent_frame(&uuid).await?;
let m = self.get_metadata(&uuid).await?;
let parent = self.get_dependency(&uuid).await?;
println!("\tcreated at (UTC): {datetime}");
println!("\tcreated at (UTC): {}", fmt_datetime(&datetime));
println!("\tchange counter: {counter:?}");
println!("\tconsistent WAL frame: {consistent_frame}");
if let Some((page_size, crc)) = m {
Expand All @@ -169,17 +178,23 @@ impl Replicator {
}
}

pub(crate) async fn remove_many(&self, older_than: NaiveDate, verbose: bool) -> Result<()> {
let older_than = NaiveDateTime::new(older_than, NaiveTime::MIN);
pub(crate) async fn remove_many(&self, older_than: Date, verbose: bool) -> Result<()> {
let older_than = older_than.to_datetime(jiff::civil::Time::midnight());
let delete_all = self.inner.delete_all(Some(older_than)).await?;
if verbose {
println!("Tombstoned {} at {}", self.inner.db_path, older_than);
println!(
"Tombstoned {} at {}",
self.inner.db_path,
fmt_datetime(&older_than)
);
}
let removed_generations = delete_all.commit().await?;
if verbose {
println!(
"Removed {} generations of {} up to {}",
removed_generations, self.inner.db_path, older_than
removed_generations,
self.inner.db_path,
fmt_datetime(&older_than)
);
}
Ok(())
Expand Down Expand Up @@ -253,7 +268,10 @@ impl Replicator {
let meta = self.get_metadata(&generation).await?;
let dep = self.get_dependency(&generation).await?;
println!("Generation {} for {}", generation, self.db_name);
println!("\tcreated at: {}", uuid_to_datetime(&generation));
println!(
"\tcreated at: {}",
fmt_datetime(&uuid_to_datetime(&generation))
);
println!("\tchange counter: {counter:?}");
println!("\tconsistent WAL frame: {consistent_frame}");
if let Some((page_size, crc)) = meta {
Expand Down
Loading
Loading