Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Lance format Lance Dataset Restore

From Leeroopedia


Knowledge Sources
Domains Data_Engineering, Version_Control
Last Updated 2026-02-08 19:00 GMT

Overview

Concrete tool for promoting a previously committed dataset version to become the new latest version, provided by the Lance library.

Description

Dataset::restore() creates a new version of the dataset whose content is identical to the version the dataset is currently checked out at. It fetches the latest manifest to determine the current head, constructs a Transaction with Operation::Restore { version }, and delegates to the standard apply_commit() path. The internal restore_old_manifest() function reads the old manifest from storage, updates its timestamp, ensures the max_fragment_id does not decrease, and produces the manifest that will be committed as the new version.

Prerequisite: The dataset must be checked out at the version you want to restore before calling restore(). Use checkout_version() first.

Usage

Use this method to roll back a Lance dataset to a previous state after a bad write, accidental deletion, or failed schema migration. The operation is non-destructive: it appends a new version rather than removing intermediate versions.

Code Reference

Source Location

  • Repository: Lance
  • File (method): rust/lance/src/dataset.rs
  • Lines (method): L1131-L1147
  • File (restore_old_manifest): rust/lance/src/dataset/transaction.rs
  • Lines (restore_old_manifest): L1525-L1545

Signature

restore method:

impl Dataset {
    /// Restore the currently checked out version of the dataset as the latest version.
    pub async fn restore(&mut self) -> Result<()>
}

restore_old_manifest (internal):

impl Transaction {
    pub(crate) async fn restore_old_manifest(
        object_store: &ObjectStore,
        commit_handler: &dyn CommitHandler,
        base_path: &Path,
        version: u64,
        config: &ManifestWriteConfig,
        tx_path: &str,
        current_manifest: &Manifest,
    ) -> Result<(Manifest, Vec<IndexMetadata>)>
}

Import

use lance::Dataset;

I/O Contract

Inputs

Name Type Required Description
self &mut Dataset Yes The dataset handle, which must be checked out at the version to restore. The method uses self.manifest.version as the restore target.

Outputs

Name Type Description
Ok () The restore was committed successfully. The dataset handle is updated to the new latest version.
Err Error A CommitConflict if the commit fails after retries, or an I/O error if the old manifest cannot be read.

Internal: restore_old_manifest Inputs

Name Type Required Description
object_store &ObjectStore Yes Object store for reading the old manifest.
commit_handler &dyn CommitHandler Yes Handler to resolve the old version's manifest location.
base_path &Path Yes Base path of the dataset.
version u64 Yes The version number to restore.
config &ManifestWriteConfig Yes Write configuration (provides the timestamp for the new manifest).
tx_path &str Yes Path to the transaction file for this commit.
current_manifest &Manifest Yes The current (latest) manifest, used to ensure max_fragment_id does not decrease.

Internal: restore_old_manifest Outputs

Name Type Description
Ok (Manifest, Vec<IndexMetadata>) The restored manifest (with updated timestamp and max_fragment_id) and its associated index metadata.
Err Error An error if the old manifest cannot be read or deserialized.

Usage Examples

use lance::Dataset;

async fn restore_to_version(uri: &str, target_version: u64) -> lance::Result<()> {
    // Step 1: Open the dataset (loads the latest version)
    let dataset = Dataset::open(uri).await?;
    println!("Current version: {}", dataset.version().version);

    // Step 2: Check out the version to restore
    let mut checked_out = dataset.checkout_version(target_version).await?;
    println!("Checked out version: {}", checked_out.version().version);

    // Step 3: Restore -- creates a new version with the same content
    checked_out.restore().await?;
    println!("Restored. New latest version: {}", checked_out.version().version);

    // The dataset now has a new version (latest + 1) whose data
    // matches the target_version. All intermediate versions remain
    // accessible for inspection.
    Ok(())
}

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment