Skip to content

Commit

Permalink
Merge pull request #1746 from tursodatabase/lucio/fix-pitr
Browse files Browse the repository at this point in the history
sqld: fix pitr and revert back to NaiveDateTime
  • Loading branch information
LucioFranco authored Sep 18, 2024
2 parents b03db2d + aeb495f commit 5129424
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions libsql-server/src/http/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::extract::{FromRef, Path, State};
use axum::middleware::Next;
use axum::routing::delete;
use axum::Json;
use chrono::{DateTime, Utc};
use chrono::NaiveDateTime;
use futures::{SinkExt, StreamExt, TryStreamExt};
use hyper::{Body, Request, StatusCode};
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
Expand Down Expand Up @@ -427,7 +427,7 @@ async fn handle_create_namespace<C: Connector>(

#[derive(Debug, Deserialize)]
struct ForkNamespaceReq {
timestamp: DateTime<Utc>,
timestamp: NaiveDateTime,
}

async fn handle_fork_namespace<C>(
Expand Down
7 changes: 4 additions & 3 deletions libsql-server/src/namespace/configurator/libsql_primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use chrono::{DateTime, Utc};
use futures::prelude::Future;
use libsql_sys::name::NamespaceResolver;
use libsql_sys::wal::either::Either;
Expand Down Expand Up @@ -270,7 +269,7 @@ impl ConfigureNamespace for LibsqlPrimaryConfigurator {
_from_config: MetaStoreHandle,
_to_ns: NamespaceName,
_to_config: MetaStoreHandle,
timestamp: Option<DateTime<Utc>>,
timestamp: Option<chrono::prelude::NaiveDateTime>,
_store: NamespaceStore,
) -> Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>> {
Box::pin(async move {
Expand All @@ -284,7 +283,9 @@ impl ConfigureNamespace for LibsqlPrimaryConfigurator {
.find_segment(
&s.backend().default_config(),
&ns,
libsql_wal::storage::backend::FindSegmentReq::Timestamp(ts),
libsql_wal::storage::backend::FindSegmentReq::Timestamp(
ts.and_utc(),
),
)
.await
.unwrap();
Expand Down
3 changes: 1 addition & 2 deletions libsql-server/src/namespace/configurator/libsql_replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;

use chrono::{DateTime, Utc};
use hyper::Uri;
use libsql_replication::injector::LibsqlInjector;
use libsql_replication::replicator::Replicator;
Expand Down Expand Up @@ -266,7 +265,7 @@ impl ConfigureNamespace for LibsqlReplicaConfigurator {
_from_config: MetaStoreHandle,
_to_ns: NamespaceName,
_to_config: MetaStoreHandle,
_timestamp: Option<DateTime<Utc>>,
_timestamp: Option<chrono::prelude::NaiveDateTime>,
_store: NamespaceStore,
) -> Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>> {
Box::pin(std::future::ready(Err(crate::Error::Fork(
Expand Down
24 changes: 16 additions & 8 deletions libsql-server/src/namespace/configurator/libsql_schema.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::path::Path;
use std::sync::Arc;

use chrono::{DateTime, Utc};
use futures::prelude::Future;
use libsql_sys::name::NamespaceResolver;
use libsql_wal::io::StdIO;
Expand Down Expand Up @@ -160,13 +159,22 @@ impl ConfigureNamespace for LibsqlSchemaConfigurator {

fn fork<'a>(
&'a self,
_from_ns: &'a Namespace,
_from_config: MetaStoreHandle,
_to_ns: NamespaceName,
_to_config: MetaStoreHandle,
_timestamp: Option<DateTime<Utc>>,
_store: NamespaceStore,
from_ns: &'a Namespace,
from_config: MetaStoreHandle,
to_ns: NamespaceName,
to_config: MetaStoreHandle,
timestamp: Option<chrono::prelude::NaiveDateTime>,
store: NamespaceStore,
) -> std::pin::Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>> {
todo!()
Box::pin(super::fork::fork(
from_ns,
from_config,
to_ns,
to_config,
timestamp,
store,
&self.primary_config,
self.base.base_path.clone(),
))
}
}
4 changes: 2 additions & 2 deletions libsql-server/src/namespace/configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::sync::Arc;
use std::time::Duration;

use chrono::{DateTime, Utc};
use chrono::NaiveDateTime;
use futures::Future;
use libsql_sys::EncryptionConfig;
use tokio::sync::Semaphore;
Expand Down Expand Up @@ -139,7 +139,7 @@ pub trait ConfigureNamespace {
from_config: MetaStoreHandle,
to_ns: NamespaceName,
to_config: MetaStoreHandle,
timestamp: Option<DateTime<Utc>>,
timestamp: Option<NaiveDateTime>,
store: NamespaceStore,
) -> Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>>;
}
5 changes: 2 additions & 3 deletions libsql-server/src/namespace/configurator/primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use chrono::{DateTime, Utc};
use futures::prelude::Future;
use libsql_sys::EncryptionConfig;
use tokio::task::JoinSet;
Expand Down Expand Up @@ -185,15 +184,15 @@ impl ConfigureNamespace for PrimaryConfigurator {
from_config: MetaStoreHandle,
to_ns: NamespaceName,
to_config: MetaStoreHandle,
timestamp: Option<DateTime<Utc>>,
timestamp: Option<chrono::prelude::NaiveDateTime>,
store: NamespaceStore,
) -> Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>> {
Box::pin(super::fork::fork(
from_ns,
from_config,
to_ns,
to_config,
timestamp.map(|d| d.naive_utc()),
timestamp,
store,
&self.primary_config,
self.base.base_path.clone(),
Expand Down
3 changes: 1 addition & 2 deletions libsql-server/src/namespace/configurator/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::pin::Pin;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;

use chrono::{DateTime, Utc};
use futures::Future;
use hyper::Uri;
use libsql_replication::rpc::replication::log_offset::WalFlavor;
Expand Down Expand Up @@ -256,7 +255,7 @@ impl ConfigureNamespace for ReplicaConfigurator {
_from_config: MetaStoreHandle,
_to_ns: NamespaceName,
_to_config: MetaStoreHandle,
_timestamp: Option<DateTime<Utc>>,
_timestamp: Option<chrono::NaiveDateTime>,
_store: NamespaceStore,
) -> Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>> {
Box::pin(std::future::ready(Err(crate::Error::Fork(
Expand Down
5 changes: 2 additions & 3 deletions libsql-server/src/namespace/configurator/schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::{atomic::AtomicBool, Arc};

use chrono::{DateTime, Utc};
use futures::prelude::Future;
use tokio::task::JoinSet;

Expand Down Expand Up @@ -121,15 +120,15 @@ impl ConfigureNamespace for SchemaConfigurator {
from_config: MetaStoreHandle,
to_ns: NamespaceName,
to_config: MetaStoreHandle,
timestamp: Option<DateTime<Utc>>,
timestamp: Option<chrono::prelude::NaiveDateTime>,
store: NamespaceStore,
) -> std::pin::Pin<Box<dyn Future<Output = crate::Result<Namespace>> + Send + 'a>> {
Box::pin(super::fork::fork(
from_ns,
from_config,
to_ns,
to_config,
timestamp.map(|ts| ts.naive_utc()),
timestamp,
store,
&self.primary_config,
self.base.base_path.clone(),
Expand Down
4 changes: 2 additions & 2 deletions libsql-server/src/namespace/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use async_lock::RwLock;
use chrono::{DateTime, Utc};
use chrono::NaiveDateTime;
use futures::TryFutureExt;
use moka::future::Cache;
use once_cell::sync::OnceCell;
Expand Down Expand Up @@ -219,7 +219,7 @@ impl NamespaceStore {
from: NamespaceName,
to: NamespaceName,
to_config: DatabaseConfig,
timestamp: Option<DateTime<Utc>>,
timestamp: Option<NaiveDateTime>,
) -> crate::Result<()> {
if self.inner.has_shutdown.load(Ordering::Relaxed) {
return Err(Error::NamespaceStoreShutdown);
Expand Down

0 comments on commit 5129424

Please sign in to comment.