use crate::api::rest_api::RESTApi;
use crate::catalog::Identifier;
use crate::spec::{PartitionStatistics, Snapshot};
use crate::table::SnapshotManager;
use crate::Result;
use async_trait::async_trait;
use std::sync::Arc;
#[async_trait]
pub trait SnapshotCommit: Send + Sync {
async fn commit(&self, snapshot: &Snapshot, statistics: &[PartitionStatistics])
-> Result<bool>;
}
pub struct RenamingSnapshotCommit {
snapshot_manager: SnapshotManager,
}
impl RenamingSnapshotCommit {
pub fn new(snapshot_manager: SnapshotManager) -> Self {
Self { snapshot_manager }
}
}
#[async_trait]
impl SnapshotCommit for RenamingSnapshotCommit {
async fn commit(
&self,
snapshot: &Snapshot,
_statistics: &[PartitionStatistics],
) -> Result<bool> {
self.snapshot_manager.commit_snapshot(snapshot).await
}
}
pub struct RESTSnapshotCommit {
api: Arc<RESTApi>,
identifier: Identifier,
uuid: String,
}
impl RESTSnapshotCommit {
pub fn new(api: Arc<RESTApi>, identifier: Identifier, uuid: String) -> Self {
Self {
api,
identifier,
uuid,
}
}
}
#[async_trait]
impl SnapshotCommit for RESTSnapshotCommit {
async fn commit(
&self,
snapshot: &Snapshot,
statistics: &[PartitionStatistics],
) -> Result<bool> {
self.api
.commit_snapshot(&self.identifier, &self.uuid, snapshot, statistics)
.await
}
}