This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 421e6125 feat(c): support cross-process commit messages (#1257)
421e6125 is described below
commit 421e6125d41c767483ab265260c848a8d205d143
Author: QuakeWang <[email protected]>
AuthorDate: Sat Oct 31 11:45:40 2026 +0800
feat(c): support cross-process commit messages (#1257)
---
Cargo.lock | 1 +
bindings/c/Cargo.toml | 1 +
bindings/c/src/result.rs | 6 +
bindings/c/src/tests.rs | 2 +
bindings/c/src/tests/commit_messages.rs | 620 ++++++++++++++++++++++++++++++++
bindings/c/src/types.rs | 6 +-
bindings/c/src/write.rs | 142 +++++++-
docs/src/c-binding.md | 75 +++-
8 files changed, 847 insertions(+), 6 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 01748f3c..41ea5cf2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4743,6 +4743,7 @@ dependencies = [
"arrow-array",
"arrow-schema",
"async-trait",
+ "base64 0.22.1",
"bytes",
"futures",
"opendal-core",
diff --git a/bindings/c/Cargo.toml b/bindings/c/Cargo.toml
index a62c2c36..ddccb891 100644
--- a/bindings/c/Cargo.toml
+++ b/bindings/c/Cargo.toml
@@ -48,6 +48,7 @@ async-trait = "0.1.81"
bytes = "1.7.1"
[dev-dependencies]
+base64 = "0.22"
opendal = { package = "opendal-core", version = "0.58.0" }
# Test-only: the vector-search integration tests build a real primary-key
vindex
# IVF-flat ANN segment fixture in-process. Versions match crates/paimon.
diff --git a/bindings/c/src/result.rs b/bindings/c/src/result.rs
index bf1f0c4b..27446b56 100644
--- a/bindings/c/src/result.rs
+++ b/bindings/c/src/result.rs
@@ -194,6 +194,12 @@ pub struct paimon_result_prepare_commit {
pub error: *mut paimon_error,
}
+#[repr(C)]
+pub struct paimon_result_bytes_array {
+ pub bytes: paimon_bytes_array,
+ pub error: *mut paimon_error,
+}
+
#[repr(C)]
pub struct paimon_result_postpone_fixed_bucket_write_builder {
pub write_builder: *mut paimon_postpone_fixed_bucket_write_builder,
diff --git a/bindings/c/src/tests.rs b/bindings/c/src/tests.rs
index f445de6c..108078d4 100644
--- a/bindings/c/src/tests.rs
+++ b/bindings/c/src/tests.rs
@@ -26,6 +26,8 @@
//! must NOT wrap C FFI calls inside another `block_on`. Use the global
//! runtime only for Rust-API setup (write_data_rust, setup_table_dirs).
+mod commit_messages;
+
use std::collections::HashMap;
use std::ffi::{c_void, CString};
use std::mem::ManuallyDrop;
diff --git a/bindings/c/src/tests/commit_messages.rs
b/bindings/c/src/tests/commit_messages.rs
new file mode 100644
index 00000000..ac2905c3
--- /dev/null
+++ b/bindings/c/src/tests/commit_messages.rs
@@ -0,0 +1,620 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::*;
+use base64::Engine;
+
+// Java CommitMessageSerializer v14 fixtures also used by the core codec tests:
+// an empty increment, an index increment, and an index with DV/global
metadata.
+const JAVA_BODIES: [&str; 3] = [
+
"AAAADAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABw==",
+
"AAAADAAAAAAAAAAAAAAAAAAAAAMBAAAABQAAAAAAAAAAAAAAAAAAAAEAAABAAHAAAAAAAABJAAAAAAAAgWluZGV4AACFCQAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABw==",
+
"AAAADAAAAAAAAAAAAAAAAAAAAAMBAAAABQAAAAAAAAAAAAAAAAAAAAEAAADgAAAAAAAAAABEVgAAAAAAgmluZGV4AACFCQAAAAAAAAACAAAAAAAAAEgAAABAAAAACwAAAIgAAABIAAAAmAAAAAEAAAAAAAAAOAAAABAAAAAAAAAAAAAAAAwAAAAoAAAAAwAAAAAAAAAMAAAAAAAAAAIAAAAAAAAAZGF0YS5wYXJxdWV0AAAAAGZpbGU6L2luZGV4AAAAAAAAAAAAAAAAAAoAAAAAAAAAFAAAAAAAAAADAAAAAAAAABAAAAA4AAAAAQIAAAAAAIIDAAAAAAAAgQIAAAAAAAAAAQAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAc=",
+];
+
+fn java_bodies() -> Vec<Vec<u8>> {
+ JAVA_BODIES
+ .iter()
+ .map(|body| {
+ base64::engine::general_purpose::STANDARD
+ .decode(body)
+ .unwrap()
+ })
+ .collect()
+}
+
+fn slices(bodies: &[Vec<u8>]) -> Vec<paimon_byte_slice> {
+ bodies
+ .iter()
+ .map(|body| paimon_byte_slice {
+ data: body.as_ptr(),
+ len: body.len(),
+ })
+ .collect()
+}
+
+unsafe fn assert_ok(error: *mut paimon_error) {
+ if !error.is_null() {
+ let message = String::from_utf8_lossy(std::slice::from_raw_parts(
+ (*error).message.data,
+ (*error).message.len,
+ ))
+ .into_owned();
+ paimon_error_free(error);
+ panic!("{message}");
+ }
+}
+
+unsafe fn assert_error(error: *mut paimon_error, code: PaimonErrorCode) {
+ assert!(!error.is_null());
+ let actual = (*error).code;
+ paimon_error_free(error);
+ assert_eq!(actual, code as i32);
+}
+
+unsafe fn new_committer(
+ table: *const paimon_table,
+ user: &str,
+ overwrite: bool,
+) -> *mut paimon_table_commit {
+ let user = CString::new(user).unwrap();
+ let builder = paimon_table_new_write_builder_with_commit_user(table,
user.as_ptr());
+ assert_ok(builder.error);
+ if overwrite {
+ assert_ok(paimon_write_builder_with_overwrite(builder.write_builder));
+ }
+ let result = paimon_write_builder_new_commit(builder.write_builder);
+ paimon_write_builder_free(builder.write_builder);
+ assert_ok(result.error);
+ result.commit
+}
+
+unsafe fn prepare(
+ table: *const paimon_table,
+ user: &str,
+ overwrite: bool,
+ batch: RecordBatch,
+) -> *mut paimon_commit_messages {
+ let user = CString::new(user).unwrap();
+ let builder = paimon_table_new_write_builder_with_commit_user(table,
user.as_ptr());
+ assert_ok(builder.error);
+ if overwrite {
+ assert_ok(paimon_write_builder_with_overwrite(builder.write_builder));
+ }
+ let writer = paimon_write_builder_new_write(builder.write_builder);
+ assert_ok(writer.error);
+ let (array, schema) = export_batch_to_ffi(batch);
+ assert_ok(paimon_table_write_write_arrow_batch(
+ writer.write,
+ (&**array) as *const FFI_ArrowArray as *mut c_void,
+ (&**schema) as *const FFI_ArrowSchema as *mut c_void,
+ ));
+ let result = paimon_table_write_prepare_commit(writer.write);
+ assert_ok(result.error);
+ paimon_table_write_free(writer.write);
+ paimon_write_builder_free(builder.write_builder);
+ result.messages
+}
+
+unsafe fn copy_bodies(array: &paimon_bytes_array) -> Vec<Vec<u8>> {
+ (0..array.len)
+ .map(|index| {
+ let bytes = &*array.data.add(index);
+ std::slice::from_raw_parts(bytes.data, bytes.len).to_vec()
+ })
+ .collect()
+}
+
+unsafe fn import(
+ commit: *const paimon_table_commit,
+ bodies: &[Vec<u8>],
+) -> *mut paimon_commit_messages {
+ let slices = slices(bodies);
+ let result = paimon_commit_messages_deserialize(
+ commit,
+ paimon_commit_messages_serializer_version(),
+ slices.as_ptr(),
+ slices.len(),
+ );
+ assert_ok(result.error);
+ assert!(!result.messages.is_null());
+ result.messages
+}
+
+unsafe fn memory_table(path: &str) -> *mut paimon_table {
+ let file_io = memory_file_io();
+ setup_table_dirs(&file_io, path);
+ wrap_table(Table::new(
+ file_io,
+ Identifier::new("default", "messages"),
+ path.into(),
+ simple_table_schema(),
+ None,
+ ))
+}
+
+#[test]
+fn java_v14_round_trip_owns_buffers_and_context() {
+ assert_eq!(paimon_commit_messages_serializer_version(), 14);
+ unsafe {
+ let table = memory_table("memory:/java_commit_messages");
+ for overwrite in [false, true] {
+ let commit = new_committer(table, "coordinator", overwrite);
+ let bodies = java_bodies();
+ let messages = import(commit, &bodies);
+ drop(bodies);
+ paimon_table_commit_free(commit);
+
+ let state = &*((*messages).inner as *const CommitMessagesState);
+ assert_eq!(state.commit_user, "coordinator");
+ assert_eq!(state.table_location, "memory:/java_commit_messages");
+ assert_eq!(state.overwrite, overwrite);
+ assert_eq!(state.messages[0].bucket, 3);
+ assert_eq!(state.messages[0].check_from_snapshot, Some(7));
+ assert_eq!(state.messages[1].total_buckets, Some(5));
+ assert_eq!(state.messages[1].new_index_files[0].file_name,
"index");
+ let index = &state.messages[2].new_index_files[0];
+ assert_eq!(index.external_path.as_deref(), Some("file:/index"));
+ assert_eq!(index.deletion_vectors_ranges.as_ref().unwrap().len(),
1);
+
+ let result = paimon_commit_messages_serialize(messages);
+ assert_ok(result.error);
+ paimon_commit_messages_free(messages);
+ assert_eq!(copy_bodies(&result.bytes), java_bodies());
+ paimon_bytes_array_free(result.bytes);
+ }
+ unwrap_table(table);
+ }
+}
+
+#[test]
+fn deserialize_rejects_invalid_inputs_without_partial_handles() {
+ unsafe {
+ let table = memory_table("memory:/invalid_commit_messages");
+ let commit = new_committer(table, "coordinator", false);
+ let reject = |target, version, bodies, len, code| {
+ let result = paimon_commit_messages_deserialize(target, version,
bodies, len);
+ assert!(result.messages.is_null());
+ assert_error(result.error, code);
+ };
+ for version in [-1, 0, 13, 15] {
+ reject(
+ commit,
+ version,
+ ptr::null(),
+ 0,
+ PaimonErrorCode::Unsupported,
+ );
+ }
+ reject(
+ ptr::null(),
+ 14,
+ ptr::null(),
+ 0,
+ PaimonErrorCode::InvalidInput,
+ );
+ let uninitialized = paimon_table_commit {
+ inner: ptr::null_mut(),
+ };
+ reject(
+ &uninitialized,
+ 14,
+ ptr::null(),
+ 0,
+ PaimonErrorCode::InvalidInput,
+ );
+ reject(commit, 14, ptr::null(), 1, PaimonErrorCode::InvalidInput);
+ let body = java_bodies().remove(0);
+ let valid = paimon_byte_slice {
+ data: body.as_ptr(),
+ len: body.len(),
+ };
+ reject(
+ commit,
+ 14,
+ &valid,
+ usize::MAX,
+ PaimonErrorCode::InvalidInput,
+ );
+ for (data, len) in [
+ (ptr::null(), 0),
+ (ptr::null(), 1),
+ (body.as_ptr(), 0),
+ (body.as_ptr(), usize::MAX),
+ ] {
+ let invalid = paimon_byte_slice { data, len };
+ reject(commit, 14, &invalid, 1, PaimonErrorCode::InvalidInput);
+ }
+
+ // Every truncation, including after an already-decoded first body,
+ // must return an error rather than a partial message list or a panic.
+ for body in java_bodies() {
+ for len in 0..body.len() {
+ let inputs = [
+ valid,
+ paimon_byte_slice {
+ data: body.as_ptr(),
+ len,
+ },
+ ];
+ reject(
+ commit,
+ 14,
+ inputs.as_ptr(),
+ inputs.len(),
+ PaimonErrorCode::InvalidInput,
+ );
+ }
+ }
+ let mut malformed = Vec::new();
+ let mut trailing = body.clone();
+ trailing.push(0);
+ malformed.push(trailing);
+ for (offset, value) in [(0, -1_i32), (21, -1), (21, i32::MAX)] {
+ let mut bytes = body.clone();
+ bytes[offset..offset + 4].copy_from_slice(&value.to_be_bytes());
+ malformed.push(bytes);
+ }
+ let mut invalid_flag = body.clone();
+ invalid_flag[20] = 2;
+ malformed.push(invalid_flag);
+ for bytes in malformed {
+ let invalid = paimon_byte_slice {
+ data: bytes.as_ptr(),
+ len: bytes.len(),
+ };
+ reject(commit, 14, &invalid, 1, PaimonErrorCode::InvalidInput);
+ }
+ let messages = import(commit, &[body]);
+ paimon_commit_messages_free(messages);
+ paimon_table_commit_free(commit);
+ unwrap_table(table);
+ }
+}
+
+#[test]
+fn empty_messages_and_null_export() {
+ unsafe {
+ for messages in [
+ ptr::null(),
+ &paimon_commit_messages {
+ inner: ptr::null_mut(),
+ },
+ ] {
+ let result = paimon_commit_messages_serialize(messages);
+ assert_error(result.error, PaimonErrorCode::InvalidInput);
+ assert!(result.bytes.data.is_null());
+ assert_eq!(result.bytes.len, 0);
+ paimon_bytes_array_free(result.bytes);
+ }
+ let table = memory_table("memory:/empty_imported_messages");
+ let commit = new_committer(table, "coordinator", false);
+ let result = paimon_commit_messages_deserialize(commit, 14,
ptr::null(), 0);
+ assert_ok(result.error);
+ assert!(!result.messages.is_null());
+ let exported = paimon_commit_messages_serialize(result.messages);
+ assert_ok(exported.error);
+ assert!(exported.bytes.data.is_null());
+ assert_eq!(exported.bytes.len, 0);
+ assert_ok(paimon_table_commit_commit(commit, result.messages));
+ paimon_bytes_array_free(exported.bytes);
+ paimon_commit_messages_free(result.messages);
+ paimon_table_commit_free(commit);
+ unwrap_table(table);
+ }
+}
+
+#[test]
+fn imported_messages_use_target_context_for_commit_merge_and_overwrite() {
+ unsafe {
+ for overwrite in [false, true] {
+ let path = format!("memory:/imported_context_{overwrite}");
+ let table = memory_table(&path);
+ write_data_rust(table_ref(table), &[make_batch(vec![1],
vec!["old"])]);
+ let messages = prepare(table, "worker", overwrite,
make_batch(vec![2], vec!["new"]));
+ let exported = paimon_commit_messages_serialize(messages);
+ assert_ok(exported.error);
+ paimon_commit_messages_free(messages);
+ let commit = new_committer(table, "coordinator", overwrite);
+ let restored = import(commit, ©_bodies(&exported.bytes));
+ paimon_bytes_array_free(exported.bytes);
+ paimon_table_commit_free(commit);
+
+ let other_table = memory_table(&format!("{path}_other"));
+ for wrong in [
+ new_committer(other_table, "coordinator", overwrite),
+ new_committer(table, "other-user", overwrite),
+ new_committer(table, "coordinator", !overwrite),
+ ] {
+ assert_error(
+ paimon_table_commit_commit(wrong, restored),
+ PaimonErrorCode::InvalidInput,
+ );
+ assert_error(
+ paimon_table_commit_abort(wrong, restored),
+ PaimonErrorCode::InvalidInput,
+ );
+ let empty = import(wrong, &[]);
+ assert_error(
+ paimon_commit_messages_merge(restored, empty),
+ PaimonErrorCode::InvalidInput,
+ );
+ paimon_commit_messages_free(empty);
+ paimon_table_commit_free(wrong);
+ }
+ unwrap_table(other_table);
+
+ let commit = new_committer(table, "coordinator", overwrite);
+ if overwrite {
+ assert_error(
+ paimon_table_commit_commit(commit, restored),
+ PaimonErrorCode::InvalidInput,
+ );
+ assert_ok(paimon_table_commit_overwrite_with_identifier(
+ commit, restored, 42,
+ ));
+ } else {
+ assert_error(
+ paimon_table_commit_overwrite(commit, restored),
+ PaimonErrorCode::InvalidInput,
+ );
+ assert_ok(paimon_table_commit_commit_with_identifier(
+ commit, restored, 42,
+ ));
+
assert_ok(paimon_table_commit_filter_and_commit_with_identifier(
+ commit, restored, 42,
+ ));
+ }
+ let expected = if overwrite {
+ vec![(2, "new".into())]
+ } else {
+ vec![(1, "old".into()), (2, "new".into())]
+ };
+ assert_eq!(read_rows_ffi(table), expected);
+ let snapshot = crate::runtime()
+
.block_on(table_ref(table).snapshot_manager().get_latest_snapshot())
+ .unwrap()
+ .unwrap();
+ assert_eq!(snapshot.commit_user(), "coordinator");
+ assert_eq!(snapshot.commit_identifier(), 42);
+ assert_eq!(snapshot.id(), 2);
+ paimon_commit_messages_free(restored);
+ paimon_table_commit_free(commit);
+ unwrap_table(table);
+ }
+ }
+}
+
+#[test]
+fn imported_fixed_bucket_flag_comes_from_target_mode() {
+ unsafe {
+ let table = memory_table("memory:/imported_bucket_mode");
+ let mut message = paimon::table::CommitMessage::new(Vec::new(), 0,
Vec::new());
+ message.total_buckets = Some(1);
+ let bodies = vec![message.serialize().unwrap()];
+ for overwrite in [false, true] {
+ let commit = new_committer(table, "coordinator", overwrite);
+ let messages = import(commit, &bodies);
+ let error = if overwrite {
+ paimon_table_commit_overwrite(commit, messages)
+ } else {
+ paimon_table_commit_commit(commit, messages)
+ };
+ assert_ok(error);
+ paimon_commit_messages_free(messages);
+ paimon_table_commit_free(commit);
+ }
+ unwrap_table(table);
+ }
+}
+
+#[test]
+fn imported_messages_can_abort_prepared_files() {
+ unsafe {
+ let path = "memory:/imported_abort";
+ let table = memory_table(path);
+ let messages = prepare(table, "worker", false, make_batch(vec![1],
vec!["a"]));
+ let state = &*((*messages).inner as *const CommitMessagesState);
+ let message = &state.messages[0];
+ let file = format!(
+ "{path}/bucket-{}/{}",
+ message.bucket, message.new_files[0].file_name
+ );
+ let exported = paimon_commit_messages_serialize(messages);
+ assert_ok(exported.error);
+ paimon_commit_messages_free(messages);
+ let commit = new_committer(table, "coordinator", false);
+ let imported = import(commit, ©_bodies(&exported.bytes));
+ paimon_bytes_array_free(exported.bytes);
+ let io = table_ref(table).file_io();
+ assert!(crate::runtime().block_on(io.exists(&file)).unwrap());
+ assert_ok(paimon_table_commit_abort(commit, imported));
+ assert!(!crate::runtime().block_on(io.exists(&file)).unwrap());
+ paimon_commit_messages_free(imported);
+ paimon_table_commit_free(commit);
+ unwrap_table(table);
+ }
+}
+
+#[test]
+fn format_table_messages_are_unsupported_and_remain_owned_by_caller() {
+ unsafe {
+ let schema = Schema::builder()
+ .column("id", DataType::Int(IntType::new()))
+ .column("name", DataType::VarChar(VarCharType::string_type()))
+ .option("type", "format-table")
+ .option("file.format", "parquet")
+ .build()
+ .unwrap();
+ let table = wrap_table(Table::new(
+ memory_file_io(),
+ Identifier::new("default", "format"),
+ "memory:/format_message_bytes".into(),
+ TableSchema::new(0, &schema),
+ None,
+ ));
+ let messages = prepare(table, "worker", false, make_batch(vec![1],
vec!["a"]));
+ let exported = paimon_commit_messages_serialize(messages);
+ assert_error(exported.error, PaimonErrorCode::Unsupported);
+ assert!(exported.bytes.data.is_null());
+ assert_eq!(exported.bytes.len, 0);
+ paimon_bytes_array_free(exported.bytes);
+ let commit = new_committer(table, "worker", false);
+ let result = paimon_commit_messages_deserialize(commit, 14,
ptr::null(), 0);
+ assert_error(result.error, PaimonErrorCode::Unsupported);
+ assert!(result.messages.is_null());
+ assert_ok(paimon_table_commit_abort(commit, messages));
+ paimon_commit_messages_free(messages);
+ paimon_table_commit_free(commit);
+ unwrap_table(table);
+ }
+}
+
+#[test]
+fn cross_process_commit() {
+ const ROLE: &str = "PAIMON_C_COMMIT_BYTES_ROLE";
+ const ROOT: &str = "PAIMON_C_COMMIT_BYTES_ROOT";
+ let open_catalog = |root: &str| {
+ let mut options = Options::new();
+ options.set("warehouse", root);
+ FileSystemCatalog::new(options).unwrap()
+ };
+ let identifier = Identifier::new("default", "messages");
+ if let Ok(role) = std::env::var(ROLE) {
+ let root = std::env::var(ROOT).unwrap();
+ let catalog = open_catalog(&root);
+ let table = crate::runtime()
+ .block_on(catalog.get_table(&identifier))
+ .unwrap();
+ unsafe {
+ let table = wrap_table(table);
+ if role == "coordinator" {
+ let commit = new_committer(table, "distributed-job", false);
+ let merged = import(commit, &[]);
+ for worker in [1, 2] {
+ let transport =
std::fs::read(format!("{root}/worker-{worker}.json")).unwrap();
+ let (version, bodies): (i32, Vec<Vec<u8>>) =
+ serde_json::from_slice(&transport).unwrap();
+ let inputs = slices(&bodies);
+ let decoded = paimon_commit_messages_deserialize(
+ commit,
+ version,
+ inputs.as_ptr(),
+ inputs.len(),
+ );
+ assert_ok(decoded.error);
+ drop(bodies);
+ assert_ok(paimon_commit_messages_merge(merged,
decoded.messages));
+ paimon_commit_messages_free(decoded.messages);
+ }
+ assert_ok(paimon_table_commit_commit_with_identifier(
+ commit, merged, 42,
+ ));
+ paimon_table_commit_free(commit);
+ let retry = new_committer(table, "distributed-job", false);
+
assert_ok(paimon_table_commit_filter_and_commit_with_identifier(
+ retry, merged, 42,
+ ));
+ paimon_table_commit_free(retry);
+ paimon_commit_messages_free(merged);
+ } else {
+ let worker: i32 = role.parse().unwrap();
+ let messages = prepare(
+ table,
+ "distributed-job",
+ false,
+ make_batch(vec![worker * 2 - 1, worker * 2], vec!["a",
"b"]),
+ );
+ let exported = paimon_commit_messages_serialize(messages);
+ assert_ok(exported.error);
+ assert_eq!(exported.bytes.len, 2, "one body for each
partition");
+ paimon_commit_messages_free(messages);
+ let transport = serde_json::to_vec(&(
+ paimon_commit_messages_serializer_version(),
+ copy_bodies(&exported.bytes),
+ ))
+ .unwrap();
+ paimon_bytes_array_free(exported.bytes);
+ std::fs::write(format!("{root}/worker-{worker}.json"),
transport).unwrap();
+ }
+ unwrap_table(table);
+ }
+ return;
+ }
+
+ let temp = tempfile::tempdir().unwrap();
+ let root = temp.path().to_str().unwrap();
+ let catalog = open_catalog(root);
+ crate::runtime().block_on(async {
+ catalog
+ .create_database("default", false, HashMap::new())
+ .await
+ .unwrap();
+ let schema = Schema::builder()
+ .column("id", DataType::Int(IntType::new()))
+ .column("name", DataType::VarChar(VarCharType::string_type()))
+ .partition_keys(["name"])
+ .build()
+ .unwrap();
+ catalog
+ .create_table(&identifier, schema, false)
+ .await
+ .unwrap();
+ });
+ // Each worker exits before the coordinator starts: only disk bytes and
+ // prepared files survive, never handles, Rust objects or memory storage.
+ for role in ["1", "2", "coordinator"] {
+ let status = Command::new(std::env::current_exe().unwrap())
+ .args([
+ "--exact",
+ "tests::commit_messages::cross_process_commit",
+ "--nocapture",
+ ])
+ .env(ROLE, role)
+ .env(ROOT, root)
+ .status()
+ .unwrap();
+ assert!(status.success(), "{role} process failed");
+ }
+ let table = crate::runtime()
+ .block_on(catalog.get_table(&identifier))
+ .unwrap();
+ let snapshot = crate::runtime()
+ .block_on(table.snapshot_manager().get_latest_snapshot())
+ .unwrap()
+ .unwrap();
+ assert_eq!(
+ snapshot.id(),
+ 1,
+ "all workers publish once and retry is filtered"
+ );
+ assert_eq!(snapshot.commit_user(), "distributed-job");
+ assert_eq!(snapshot.commit_identifier(), 42);
+ unsafe {
+ let table = wrap_table(table);
+ assert_eq!(
+ read_rows_ffi(table),
+ vec![
+ (1, "a".into()),
+ (2, "b".into()),
+ (3, "a".into()),
+ (4, "b".into())
+ ]
+ );
+ unwrap_table(table);
+ }
+}
diff --git a/bindings/c/src/types.rs b/bindings/c/src/types.rs
index 2110d9d0..4dcaefa2 100644
--- a/bindings/c/src/types.rs
+++ b/bindings/c/src/types.rs
@@ -157,7 +157,8 @@ impl paimon_bytes_array {
}
/// # Safety
-/// `array` was returned by `paimon_blob_reader_read_blobs`.
+/// `array` was returned by a Paimon C function and has not been freed.
+/// This frees every buffer and the array itself; do not free elements
separately.
#[no_mangle]
pub unsafe extern "C" fn paimon_bytes_array_free(array: paimon_bytes_array) {
if array.data.is_null() {
@@ -454,6 +455,7 @@ pub(crate) struct PostponeFixedBucketTableWriteState {
pub(crate) struct TableCommitState {
pub commit: TableCommit,
pub overwrite: bool,
+ pub is_format_table: bool,
pub table_location: String,
pub commit_user: String,
}
@@ -494,7 +496,7 @@ pub struct paimon_table_commit {
pub inner: *mut c_void,
}
-/// Opaque container for commit messages and their originating write context.
+/// Opaque container for commit messages and their write or import context.
#[repr(C)]
pub struct paimon_commit_messages {
pub inner: *mut c_void,
diff --git a/bindings/c/src/write.rs b/bindings/c/src/write.rs
index dfb0dddb..9294bb4b 100644
--- a/bindings/c/src/write.rs
+++ b/bindings/c/src/write.rs
@@ -23,11 +23,12 @@ use arrow_array::ffi::{from_ffi, FFI_ArrowArray,
FFI_ArrowSchema};
use arrow_array::{Array, RecordBatch, RecordBatchOptions, StructArray};
use arrow_schema::{DataType as ArrowDataType, Schema as ArrowSchema};
use paimon::resource::ResourceContext;
-use paimon::table::{PostponeBucketPlan, Table};
+use paimon::spec::CoreOptions;
+use paimon::table::{CommitMessage, PostponeBucketPlan, Table,
COMMIT_MESSAGE_SERIALIZER_VERSION};
use crate::error::{check_non_null, paimon_error, validate_cstr,
PaimonErrorCode};
use crate::result::{
- paimon_result_postpone_fixed_bucket_prepare_commit,
+ paimon_result_bytes_array,
paimon_result_postpone_fixed_bucket_prepare_commit,
paimon_result_postpone_fixed_bucket_table_commit,
paimon_result_postpone_fixed_bucket_table_write,
paimon_result_postpone_fixed_bucket_write_builder,
paimon_result_prepare_commit,
@@ -762,6 +763,7 @@ pub unsafe extern "C" fn paimon_write_builder_new_commit(
let inner = Box::into_raw(Box::new(TableCommitState {
commit,
overwrite: state.overwrite,
+ is_format_table:
CoreOptions::new(state.table.schema().options()).is_format_table(),
table_location: state.table.location().to_string(),
commit_user: state.commit_user.clone(),
})) as *mut c_void;
@@ -852,6 +854,133 @@ pub unsafe extern "C" fn
paimon_postpone_fixed_bucket_table_commit_free(
// ======================= CommitMessages ===============================
+/// Version of the Java CommitMessageSerializer bodies exported by this
library.
+/// The version is not embedded in each body; transport it alongside the bytes.
+#[no_mangle]
+pub extern "C" fn paimon_commit_messages_serializer_version() -> i32 {
+ COMMIT_MESSAGE_SERIALIZER_VERSION
+}
+
+/// Export one unframed Java v14 body per message, preserving message order.
+/// Table identity, commit_user and overwrite mode are not part of the bodies.
+/// Format Table messages are unsupported. No postpone-specific handle is
accepted.
+///
+/// The input handle is borrowed. The returned buffers own their bytes and must
+/// be freed with paimon_bytes_array_free, independently of the input handle.
+/// On failure, the returned array is empty and the input remains usable.
+///
+/// # Safety
+/// msgs must be a live standard message handle, or null (returns an error).
+#[no_mangle]
+pub unsafe extern "C" fn paimon_commit_messages_serialize(
+ msgs: *const paimon_commit_messages,
+) -> paimon_result_bytes_array {
+ let encode = || -> Result<Vec<Vec<u8>>, *mut paimon_error> {
+ check_non_null(msgs, "msgs")?;
+ check_non_null((*msgs).inner, "msgs.inner")?;
+ let state = &*((*msgs).inner as *const CommitMessagesState);
+ state
+ .messages
+ .iter()
+ .map(|message|
message.serialize().map_err(paimon_error::from_paimon))
+ .collect()
+ };
+ match encode() {
+ Ok(bytes) => paimon_result_bytes_array {
+ bytes: paimon_bytes_array::new(bytes),
+ error: ptr::null_mut(),
+ },
+ Err(error) => paimon_result_bytes_array {
+ bytes: paimon_bytes_array::empty(),
+ error,
+ },
+ }
+}
+
+/// Import Java v14 bodies and bind them to the target standard committer.
+/// The target supplies table location, commit_user and overwrite mode; the
wire
+/// bodies contain none of these. The caller must route messages to the correct
+/// table and operation. This function cannot authenticate their original
context.
+/// Format Table committers are unsupported.
+///
+/// Input buffers and tc are borrowed only for this call. The returned handle
+/// owns its metadata and a copy of the context; free it with
+/// paimon_commit_messages_free. An empty list is valid. Any error returns a
null
+/// handle, without changing the committer or transferring input ownership.
+///
+/// # Safety
+/// tc must be a live standard committer, or null (returns an error). For
nonzero
+/// bodies_len, bodies must point to that many initialized paimon_byte_slice
+/// values, each referring to readable bytes for this call. Null, empty and
+/// oversized individual buffers return an error.
+#[no_mangle]
+pub unsafe extern "C" fn paimon_commit_messages_deserialize(
+ tc: *const paimon_table_commit,
+ version: i32,
+ bodies: *const paimon_byte_slice,
+ bodies_len: usize,
+) -> paimon_result_prepare_commit {
+ let decode = || -> Result<CommitMessagesState, *mut paimon_error> {
+ check_non_null(tc, "tc")?;
+ check_non_null((*tc).inner, "tc.inner")?;
+ let target = &*((*tc).inner as *const TableCommitState);
+ if target.is_format_table {
+ return Err(paimon_error::new(
+ PaimonErrorCode::Unsupported,
+ "Java CommitMessage bodies cannot be imported for a Format
Table".into(),
+ ));
+ }
+ if version != COMMIT_MESSAGE_SERIALIZER_VERSION {
+ return Err(paimon_error::new(
+ PaimonErrorCode::Unsupported,
+ format!("CommitMessage serializer version {version} is not
supported"),
+ ));
+ }
+ if bodies_len > isize::MAX as usize /
std::mem::size_of::<paimon_byte_slice>() {
+ return Err(invalid_input("oversized CommitMessage body array"));
+ }
+ let bodies = if bodies_len == 0 {
+ &[]
+ } else {
+ check_non_null(bodies, "bodies")?;
+ std::slice::from_raw_parts(bodies, bodies_len)
+ };
+ let mut messages = Vec::new();
+ for body in bodies {
+ if body.data.is_null() || body.len == 0 || body.len > isize::MAX
as usize {
+ return Err(invalid_input("null, empty or oversized
CommitMessage body"));
+ }
+ let mut message = CommitMessage::deserialize(
+ version,
+ std::slice::from_raw_parts(body.data, body.len),
+ )
+ .map_err(|error| invalid_input(error.to_string()))?;
+ if target.overwrite {
+ message.mark_fixed_bucket_overwrite();
+ }
+ messages.push(message);
+ }
+ Ok(CommitMessagesState {
+ messages,
+ overwrite: target.overwrite,
+ table_location: target.table_location.clone(),
+ commit_user: target.commit_user.clone(),
+ })
+ };
+ match decode() {
+ Ok(state) => paimon_result_prepare_commit {
+ messages: Box::into_raw(Box::new(paimon_commit_messages {
+ inner: Box::into_raw(Box::new(state)) as *mut c_void,
+ })),
+ error: ptr::null_mut(),
+ },
+ Err(error) => paimon_result_prepare_commit {
+ messages: ptr::null_mut(),
+ error,
+ },
+ }
+}
+
/// Free standard commit messages.
#[no_mangle]
pub unsafe extern "C" fn paimon_commit_messages_free(msgs: *mut
paimon_commit_messages) {
@@ -1383,6 +1512,15 @@ const _: unsafe extern "C" fn(
) -> *mut paimon_error =
paimon_postpone_fixed_bucket_write_builder_with_bucket_plan;
const _: unsafe extern "C" fn(*mut paimon_table_write) ->
paimon_result_prepare_commit =
paimon_table_write_prepare_commit;
+const _: extern "C" fn() -> i32 = paimon_commit_messages_serializer_version;
+const _: unsafe extern "C" fn(*const paimon_commit_messages) ->
paimon_result_bytes_array =
+ paimon_commit_messages_serialize;
+const _: unsafe extern "C" fn(
+ *const paimon_table_commit,
+ i32,
+ *const paimon_byte_slice,
+ usize,
+) -> paimon_result_prepare_commit = paimon_commit_messages_deserialize;
const _: unsafe extern "C" fn(
*mut paimon_postpone_fixed_bucket_table_write,
) -> paimon_result_postpone_fixed_bucket_prepare_commit =
diff --git a/docs/src/c-binding.md b/docs/src/c-binding.md
index 8cf97b4b..b32a739e 100644
--- a/docs/src/c-binding.md
+++ b/docs/src/c-binding.md
@@ -707,6 +707,75 @@ Writing uses a **write-then-commit** flow:
5. Pass the messages to `paimon_table_commit_commit`.
6. Free the messages, writer, committer, and builder.
+### Cross-process Commit Messages
+
+Workers can prepare files and export their ordinary commit messages for an
+independent coordinator. The coordinator must have access to the same files.
+Use `paimon_table_new_write_builder_with_commit_user` to configure a stable
+logical job identity on workers and the coordinator.
+
+```c
+/* Worker: messages came from paimon_table_write_prepare_commit. */
+int32_t version = paimon_commit_messages_serializer_version();
+paimon_result_bytes_array exported =
paimon_commit_messages_serialize(messages);
+CHECK_RESULT(exported);
+
+/* Send version and each exported.bytes.data[i].data / .len through the
+ application's transport. Preserve the order and boundaries of the bodies.
+ Complete or copy the transport's reads before freeing the buffers. */
+paimon_bytes_array_free(exported.bytes);
+paimon_commit_messages_free(messages);
+```
+
+Each array element is one unframed Java `CommitMessageSerializer` v14 body.
+The version, message count and body lengths are transport metadata, not part
+of those bodies. Do not concatenate bodies or add a header inside a body.
+An empty message list exports an empty array. The buffers are independent of
+the source handle and remain valid after that handle is freed.
+
+On the coordinator, create a standard committer for the intended table and
+operation. Enable overwrite on its builder before creating it if the workers
+prepared an overwrite. Pass the received bodies as borrowed
+`paimon_byte_slice` values:
+
+```c
+paimon_result_prepare_commit restored = paimon_commit_messages_deserialize(
+ committer, received_version, received_bodies, received_count);
+CHECK_RESULT(restored);
+
+/* Input buffers may now be released. Merge the restored handle with other
+ workers' handles using paimon_commit_messages_merge, then commit once. */
+paimon_error *error = paimon_table_commit_commit_with_identifier(
+ committer, restored.messages, checkpoint_id);
+if (error != NULL) {
+ paimon_error_free(error);
+}
+paimon_commit_messages_free(restored.messages);
+```
+
+Deserialization copies the target committer's table location, `commit_user`
+and overwrite mode. These fields are absent from the Java body: the application
+must ensure that the received files belong to the selected table, branch and
+operation. Import does not verify the messages' original identity. Subsequent
+merge, commit and abort calls enforce the copied context. The imported handle
+can outlive both its input buffers and the original committer.
+
+Use `paimon_table_commit_overwrite_with_identifier` for overwrite messages.
+The commit identifier is supplied separately; retain a stable `commit_user`
+and identifier when retrying an uncertain commit. For append retries,
+`paimon_table_commit_filter_and_commit_with_identifier` filters already
+committed identifiers. Merging copies messages and leaves both handles owned
+by the caller; free each handle exactly once. Freeing a handle releases
metadata,
+not prepared files; use `paimon_table_commit_abort` for known uncommitted
files.
+
+Unsupported versions, malformed bodies and invalid pointer/length combinations
+return errors without a partial output handle. `NULL, 0` is a valid empty list;
+an individual empty body is invalid. Format Table message export and import
into
+a Format Table committer are unsupported. These APIs do not accept postpone
+fixed-bucket handles or `CompactTask` / `CompactResult` payloads. Java compact
+increment fields retain the core codec behavior; ordinary commits still reject
+nonempty compact increments.
+
### Shared Writer Memory Reservations
Attach an optional resource context to each write builder before creating its
@@ -738,8 +807,10 @@ count, order, names, and types. A non-nullable table field
must not contain null
values.
!!! warning "Write builder consistency"
- The writer and committer must be created from the same write builder
because
- they share a commit identity. Commit messages must be freed with
+ Local writers and committers must share the table, commit identity and
+ overwrite mode. Use the same builder or set the same explicit identity on
+ separate builders. Imported messages use the target committer's context as
+ described above. Commit messages must be freed with
`paimon_commit_messages_free` even after a successful commit. The caller
retains message ownership and may retry a failed commit.