Repository navigation
Conversation
A pipeline at 16 workers ran out of file descriptors in storage, but process_open_fds does not say how many of them storage holds, or when. The new files_open gauge counts the storage files that the process has open: one for each file being written and one for each file being read. Issue: #8173 Signed-off-by: Ben Pfaff <blp@feldera.com>
A checkpoint collects a committer for each of its files, for every spine in every worker, and keeps them all until commit_all. Each committer was the file's reader, so each kept its file descriptor: the 2 metadata files of each spine, the copy on storage of each batch in memory, and any batch on storage that a merge replaced before the commit. A large program at 16 workers passed the 1,048,576 descriptor limit, and then a merge failed with "too many open files". Under syncfs, which commits every file with one system call, the checkpoint does not need the committers at all. Now StorageBackend::commit_set() returns a CommitSet, a trait object that all of the threads that write a checkpoint share, and that makes the files durable in CommitSet::commit(). It replaces commit_all() and sync_files(). Under syncfs, the POSIX backend's set only counts its files and drops each one as it is added, which closes the file unless a batch still uses it. Under per-file sync, the set keeps the files until the commit, as before. Issue: #8173 Signed-off-by: Ben Pfaff <blp@feldera.com>
…sync. Under per-file sync, a checkpoint keeps each of its files open until it commits, because the committer of each file is its reader. A large program at 16 workers passed the 1,048,576 descriptor limit this way. Closing each file and opening it again to fsync it would bound the open files, but it can lose a write error: the kernel records the error in the file's inode, and once nothing keeps the file open, it can evict the inode, so that the later fsync reports success. Now the per-file CommitSet makes its files durable each time it has collected 1,024 of them, and keeps them open until then. It makes one group durable at a time, and a thread that fills a group waits for its turn before it writes more files, so at most about one group for each worker thread is open. The time it records for the checkpoint is the time that passed. Issue: #8173 Signed-off-by: Ben Pfaff <blp@feldera.com>
| } | ||
|
|
||
| impl StorageBackend for MemoryBackend { | ||
| /// A [MemoryReader] needs nothing to become durable. |
There was a problem hiding this comment.
bug (medium, CI): this breaks the cargo-doc pre-commit hook (RUSTDOCFLAGS="-D warnings" cargo doc --document-private-items): public documentation for commit_set links to private item MemoryReader (rustdoc::private-intra-doc-links). Drop the link, e.g.:
| /// A [MemoryReader] needs nothing to become durable. | |
| /// A memory file needs nothing to become durable. |
|
Review: shared What I ran (debug build):
test diff#[cfg(test)]
mod commit_set_tests {
use super::*;
use std::sync::atomic::{AtomicUsize, Ordering};
static COMMITTED: AtomicUsize = AtomicUsize::new(0);
#[derive(Debug)]
struct Fake(StoragePath, bool);
impl FileRw for Fake {
fn file_id(&self) -> FileId { FileId::new() }
fn path(&self) -> &StoragePath { &self.0 }
}
impl FileCommitter for Fake {
fn commit(&self) -> Result<(), StorageError> {
if self.1 { return Err(StorageError::stdio(ErrorKind::Other, "fsync", "x")); }
COMMITTED.fetch_add(1, Ordering::Relaxed);
Ok(())
}
}
#[test]
fn concurrent_adds_and_errors() {
let set = Arc::new(PerFileCommitSet::new(commit_each).with_group_files(7));
let hs: Vec<_> = (0..8).map(|_| { let set = set.clone(); std::thread::spawn(move || {
for i in 0..1000 {
set.add(Arc::new(Fake(format!("f{i}").into(), false))).unwrap();
assert!(set.pending() <= 7);
}
})}).collect();
hs.into_iter().for_each(|h| h.join().unwrap());
set.commit().unwrap();
assert_eq!(COMMITTED.load(Ordering::Relaxed), 8000);
// A failing file in a full group fails `add`; in the remainder, `commit`.
let set = PerFileCommitSet::new(commit_each).with_group_files(2);
set.add(Arc::new(Fake("a".into(), true))).unwrap();
assert!(set.add(Arc::new(Fake("b".into(), false))).is_err());
set.add(Arc::new(Fake("c".into(), true))).unwrap();
assert!(set.commit().is_err());
}
}Everything else checks out. The design is sound: syncfs on Linux 5.8 or later reports writeback errors through the superblock, so it is safe to close files early, and the per-file path keeps each file open until it is durable. The |
A checkpoint kept one file descriptor open for each file that it wrote, until the commit. The number of open descriptors grew with workers × checkpointed operators. At 16 workers, a large program passed the 1,048,576 limit, and a merge panicked with "too many open files".
Issue: #8173
files_opengauge: the storage files that the process has open.StorageBackend::commit_set()returns aCommitSetthat the checkpoint threads share. It replacescommit_all()andsync_files(). Under syncfs, the POSIX set only counts the files and keeps none open. The memory backend uses the newNoopCommitSet.Open files during a checkpoint:
storage_commit_all_latency_secondsstill has one observation for each checkpoint. Under per-file sync, the observation includes the groups that were made durable before the commit.No changelog entry: this is an internal fix and a new metric.
Later work, not in this PR:
ObjectBackendcan useNoopCommitSet.commit_set, so that each backend supplies its own set.Testing
crates/dbsp/tests/open_files.rsandcrates/dbsp/tests/checkpoint_sync.rscheckfiles_openand the sync and commit counts for each sync mode. They also check a secondcommit, with groups and without.per_file_commit_set_syncs_in_groups(POSIX) andcommit_set_keeps_no_files(memory).cargo test: dbsp storage, spine, checkpoint andlazy_input_upserttests, all dbsp integration tests,feldera-storage, and static-connectorsstorage::tests pass. Clippy is clean.Written by Claude