vectordotdev/vector · error

cannot extend a file through the truncation API

Error message

cannot extend a file through the truncation API

What it means

The disk v2 buffer writer's truncate_current_data_file shrinks the active data file (e.g. after acknowledging consumed records). This error is raised when the requested size exceeds the writer's tracked current_data_file_size, because the truncation API cannot grow a file. The check uses the writer's in-memory size tracker instead of live metadata.

Solutions

  1. Fix the caller to clamp the truncation size to current_data_file_size before calling.
  2. Verify acknowledgement/checkpoint bookkeeping so retained sizes never exceed the tracked file size.
  3. If triggered after recovery, rebuild the buffer directory state or discard the corrupt buffer.

Example fix

// before
writer.truncate_current_data_file(acked_size).await?;
// after
let size = acked_size.min(writer.current_data_file_size);
writer.truncate_current_data_file(size).await?;
Defensive patterns

Strategy: validation

Validate before calling

// clamp acknowledged size to the tracked data file size
fn clamp_truncate_size(acked: u64, tracked: u64) -> u64 {
    acked.min(tracked)
}

Try / catch

match writer.truncate_current_data_file(size).await {
    Err(e) if e.kind() == io::ErrorKind::InvalidInput => {
        // stale size accounting: resync with writer.current_data_file_size
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling truncate_current_data_file with a size larger than current_data_file_size; acknowledged offsets pointing beyond the tracked data file size due to stale bookkeeping or a checkpoint/checkpoint mismatch after recovery.

Common situations: Replaying acknowledgements from an old checkpoint against a newer data file; a bug in offset/size accounting in the buffer; concurrent compaction and acknowledgement processing.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/086d467859a7140d. Report an issue: GitHub.

Appendix: source

Thrown at lib/vector-buffers/src/variants/disk_v2/writer.rs:1240

                        WriterCheckpointScanAction::Continue => {}
                        WriterCheckpointScanAction::Stop => break,
                    }
                }
            }
        }

        // Windows does not permit truncating a file while the scan's read handle remains open.
        drop(reader);
        self.apply_writer_checkpoint_scan(scan).await
    }

    async fn truncate_current_data_file(&mut self, size: u64) -> io::Result<()> {
        let writer = self
            .writer
            .as_mut()
            .expect("writer should exist after `ensure_ready_for_write`");
        if size > writer.current_data_file_size {
            return Err(io::Error::new(
                io::ErrorKind::InvalidInput,
                "cannot extend a file through the truncation API",
            ));
        }
        writer.writer.flush().await?;

        let data_file_path = self.ledger.get_current_writer_data_file_path();
        self.ledger
            .filesystem()
            .truncate_file(&data_file_path, size)
            .await?;

        writer.current_data_file_size = size;
        self.data_file_size = size;

        Ok(())
    }

View on GitHub (pinned to bdb87aeaa4)