Skip to content

feat!(runtime): Support custom Runtime in Catalog#2308

Open
CTTY wants to merge 9 commits intoapache:mainfrom
CTTY:ctty/runtime-api
Open

feat!(runtime): Support custom Runtime in Catalog#2308
CTTY wants to merge 9 commits intoapache:mainfrom
CTTY:ctty/runtime-api

Conversation

@CTTY
Copy link
Copy Markdown
Collaborator

@CTTY CTTY commented Apr 2, 2026

Which issue does this PR close?

What changes are included in this PR?

  • Introduced RuntimeHandle
  • Refactored Runtime to compose two RuntimeHandles: one for IO-bound work (io()) and one for CPU-bound work (cpu()).
  • Added with_runtime to CatalogBuilder trait

Are these changes tested?

Yes

.metadata(metadata)
.metadata_location(metadata_location)
.identifier(table_ident)
.file_io(file_io.clone())
Copy link
Copy Markdown
Collaborator Author

@CTTY CTTY Apr 13, 2026

Choose a reason for hiding this comment

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

I think we should pass runtime here as well, need to revisit

We can add a builder to IcebergTableProviderFactory and add with_runtime there. But I feel like this can be a separate effort

Comment thread crates/iceberg/src/runtime/mod.rs Outdated
Comment thread crates/iceberg/src/runtime/mod.rs Outdated
@CTTY CTTY changed the title feat(runtime): Support custom Runtime in Catalog feat!(runtime): Support custom Runtime in Catalog Apr 13, 2026
@CTTY CTTY marked this pull request as ready for review April 13, 2026 23:49
Copy link
Copy Markdown
Contributor

@blackmwk blackmwk left a comment

Choose a reason for hiding this comment

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

Thanks @CTTY , generally looks good!

Comment thread crates/iceberg/src/runtime/mod.rs Outdated
pub struct RuntimeHandle {
/// Keeps the tokio runtime alive when we own it (`Runtime::new`).
/// `None` when borrowing an existing runtime via `Handle::try_current()`.
_owned: Option<Arc<tokio::runtime::Runtime>>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I still don't understand why we need to keep this field, even if it's created from Runtime, I think keeping a handle would be enough?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the problem if it's not complete? If you are worring about some actions may fail in the middle of executions, then this is not the right way to guarantee that. There are many ways to crash the program, and storing Arc<Runtime> doesn't help much and our design should not rely on it.

The problem with this design is that it makes difficult for user to understand the subtle difference between these two api. We should either always ask user to provide Arc<Runtime>, or always always only store Handle.

Comment thread crates/iceberg/src/runtime/mod.rs Outdated
use tracing::warn;

/// Wrapper around tokio's JoinHandle that panics on task failure.
pub struct JoinHandle<T>(task::JoinHandle<T>);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The error handling would be rather painful. tokio's JoinHandle's Output is Result<tokio's T, JoinError>: https://github.com/tokio-rs/tokio/blob/master/tokio/src/runtime/task/join.rs#L325

without the wrapper, we will need to handle the JoinError directly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this case I think it's reasonable to keep it, but we should not panic when error happens, we should convert it to iceberg's error.

@CTTY CTTY force-pushed the ctty/runtime-api branch from 001b61b to 2ab8d46 Compare April 29, 2026 23:57
T: Send + 'static,
{
JoinHandle(task::spawn_blocking(f))
impl Default for Runtime {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, we should not implement Default

pub struct RuntimeHandle {
/// Keeps the tokio runtime alive when we own it (`Runtime::new`).
/// `None` when borrowing an existing runtime via `Handle::try_current()`.
_owned: Option<Arc<tokio::runtime::Runtime>>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the problem if it's not complete? If you are worring about some actions may fail in the middle of executions, then this is not the right way to guarantee that. There are many ways to crash the program, and storing Arc<Runtime> doesn't help much and our design should not rely on it.

The problem with this design is that it makes difficult for user to understand the subtle difference between these two api. We should either always ask user to provide Arc<Runtime>, or always always only store Handle.

use tracing::warn;

/// Wrapper around tokio's JoinHandle that panics on task failure.
pub struct JoinHandle<T>(task::JoinHandle<T>);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this case I think it's reasonable to keep it, but we should not panic when error happens, we should convert it to iceberg's error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DISCUSSION] Runtime support enhancement

2 participants