Skip to content
Open
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
47 changes: 47 additions & 0 deletions kernel/src/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,53 @@ impl Committer for FileSystemCommitter {
}
}

/// Marker trait to pass arbitrary context to the StagedCommitter.
pub trait Context: std::fmt::Debug + AsAny {}

#[derive(Debug)]
pub struct StagedCommitter {
catalog_committer: Box<dyn CatalogCommitter>,
context: Box<dyn Context>,
}

impl StagedCommitter {
pub fn new(catalog_committer: Box<dyn CatalogCommitter>, context: Box<dyn Context>) -> Self {
Self {
catalog_committer,
context,
}
}
}

pub trait CatalogCommitter: Send + AsAny + std::fmt::Debug {
fn commit_request(
&self,
engine: &dyn Engine,
staged_commit_path: &Url,
context: &dyn Context,
) -> DeltaResult<CommitResponse>;
}

impl Committer for StagedCommitter {
fn commit(
&self,
engine: &dyn Engine,
actions: Box<dyn Iterator<Item = DeltaResult<FilteredEngineData>> + Send + '_>,
commit_metadata: CommitMetadata,
) -> DeltaResult<CommitResponse> {
let staged_commit_path = commit_metadata.staged_commit_path()?;
engine
.json_handler()
.write_json_file(&staged_commit_path, Box::new(actions), false)?;

let committed = engine.storage_handler().head(&staged_commit_path)?;
Comment on lines +205 to +210
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is the point of StagedCommitter just to allow reuse of these lines of code here that write the staged commit file?

I wonder if this is worth the overhead / potential complexity?

We can always add this later -- and I do think that just copying these few lines of code, or exposing, if you'd like, a public utility that makes this 1 line (I still prefer just these 4, since it's so simple) could be a better alternative in the short term?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that a c/c++ engine cannot just paste these lines of rust code. This utility is almost entirely targeted at ffi engines that don't have an easy way to "just write the data" because they don't have access to all the rust default engine machinery.

That said, @zachschuermann , would it be simpler from an FFI perspective to just provide a write_actions utility that duckdb could call to write the staged file? I think in the end the amount of code would be similar, but it might circumvent the context problem?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nick. Can we schedule some time (or point me to some resources) to help me learn more about FFI and non-rust-engine complexity ?

For example: If a C++ Connector already has a C++ Engine implementation (not saying that is a trivial task) -- is it then easy for them to use the UC Committer?

Actually, to back up further, would a C++ Connector us the rust-UC-Committer (via FFI bindings) or would it have to build its own UC-Committer?

tracing::debug!("wrote staged commit file: {:?}", committed);

self.catalog_committer
.commit_request(engine, &staged_commit_path, self.context.as_ref())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand: is the commit_metadata passed into the catalog_committer::commit_request method?

}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading