iceberg-cpp
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
iceberg::SnapshotManager Class Reference

API for managing snapshots. More...

#include <snapshot_manager.h>

Inheritance diagram for iceberg::SnapshotManager:
iceberg::ErrorCollector

Public Member Functions

SnapshotManagerCherrypick (int64_t snapshot_id)
 Apply supported changes in given snapshot and create a new snapshot which will be set as the current snapshot on commit.
 
SnapshotManagerSetCurrentSnapshot (int64_t snapshot_id)
 Roll this table's data back to a specific snapshot identified by id.
 
SnapshotManagerRollbackToTime (int64_t timestamp_ms)
 Roll this table's data back to the last snapshot before the given timestamp.
 
SnapshotManagerRollbackTo (int64_t snapshot_id)
 Rollback table's state to a specific snapshot identified by id.
 
SnapshotManagerCreateBranch (const std::string &name)
 Create a new branch. The branch will point to current snapshot if the current snapshot is not NULL. Otherwise, the branch will point to a newly created empty snapshot.
 
SnapshotManagerCreateBranch (const std::string &name, int64_t snapshot_id)
 Create a new branch pointing to the given snapshot id.
 
SnapshotManagerCreateTag (const std::string &name, int64_t snapshot_id)
 Create a new tag pointing to the given snapshot id.
 
SnapshotManagerRemoveBranch (const std::string &name)
 Remove a branch by name.
 
SnapshotManagerRemoveTag (const std::string &name)
 Remove the tag with the given name.
 
SnapshotManagerReplaceTag (const std::string &name, int64_t snapshot_id)
 Replace the tag with the given name to point to the specified snapshot.
 
SnapshotManagerReplaceBranch (const std::string &name, int64_t snapshot_id)
 Replace the branch with the given name to point to the specified snapshot.
 
SnapshotManagerReplaceBranch (const std::string &from, const std::string &to)
 Replace the 'from' branch to point to the 'to' snapshot. The 'to' will remain unchanged, and 'from' branch will retain its retention properties. If the 'from' branch does not exist, it will be created with default retention properties.
 
SnapshotManagerFastForwardBranch (const std::string &from, const std::string &to)
 Perform a fast-forward of 'from' up to the 'to' snapshot if 'from' is an ancestor of 'to'. The 'to' will remain unchanged, and 'from' will retain its retention properties. If the 'from' branch does not exist, it will be created with default retention properties.
 
SnapshotManagerRenameBranch (const std::string &name, const std::string &new_name)
 Rename a branch.
 
SnapshotManagerSetMinSnapshotsToKeep (const std::string &branch_name, int32_t min_snapshots_to_keep)
 Update the minimum number of snapshots to keep for a branch.
 
SnapshotManagerSetMaxSnapshotAgeMs (const std::string &branch_name, int64_t max_snapshot_age_ms)
 Update the max snapshot age for a branch.
 
SnapshotManagerSetMaxRefAgeMs (const std::string &name, int64_t max_ref_age_ms)
 Update the retention policy for a reference.
 
Status Commit ()
 Commit all pending changes.
 
- Public Member Functions inherited from iceberg::ErrorCollector
 ErrorCollector (ErrorCollector &&)=default
 
ErrorCollectoroperator= (ErrorCollector &&)=default
 
 ErrorCollector (const ErrorCollector &)=default
 
ErrorCollectoroperator= (const ErrorCollector &)=default
 
template<typename... Args>
auto & AddError (this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args)
 Add a specific error and return reference to derived class.
 
auto & AddError (this auto &self, Error err)
 Add an existing error object and return reference to derived class.
 
auto & AddError (this auto &self, std::unexpected< Error > err)
 Add an unexpected result's error and return reference to derived class.
 
bool has_errors () const
 Check if any errors have been collected.
 
size_t error_count () const
 Get the number of errors collected.
 
Status CheckErrors () const
 Check for accumulated errors and return them if any exist.
 
void ClearErrors ()
 Clear all accumulated errors.
 
const std::vector< Error > & errors () const
 Get read-only access to all collected errors.
 

Static Public Member Functions

static Result< std::shared_ptr< SnapshotManager > > Make (std::shared_ptr< Table > table)
 Create a SnapshotManager that owns its own transaction.
 
static Result< std::shared_ptr< SnapshotManager > > Make (std::shared_ptr< Transaction > transaction)
 Create a SnapshotManager from an existing transaction.
 

Additional Inherited Members

- Protected Attributes inherited from iceberg::ErrorCollector
std::vector< Errorerrors_
 

Detailed Description

API for managing snapshots.

Allows rolling table data back to a stated at an older table snapshot.

Rollback: This API does not allow conflicting calls to SetCurrentSnapshot and RollbackToTime. When committing, these changes will be applied to the current table metadata. Commit conflicts will not be resolved and will result in a

Cherrypick: In an audit workflow, new data is written to an orphan snapshot that is not committed as the table's current state until it is audited. After auditing a change, it may need to be applied or cherry-picked on top of the latest snapshot instead of the one that was current when the audited changes were created. This class adds support for cherry-picking the changes from an orphan snapshot by applying them to the current snapshot. The output of the operation is a new snapshot with the changes from cherry-picked snapshot.

Member Function Documentation

◆ Cherrypick()

SnapshotManager & iceberg::SnapshotManager::Cherrypick ( int64_t  snapshot_id)

Apply supported changes in given snapshot and create a new snapshot which will be set as the current snapshot on commit.

Parameters
snapshot_ida Snapshot ID whose changes to apply
Returns
Reference to this for method chaining

◆ CreateBranch() [1/2]

SnapshotManager & iceberg::SnapshotManager::CreateBranch ( const std::string &  name)

Create a new branch. The branch will point to current snapshot if the current snapshot is not NULL. Otherwise, the branch will point to a newly created empty snapshot.

Parameters
namebranch name
Returns
Reference to this for method chaining

◆ CreateBranch() [2/2]

SnapshotManager & iceberg::SnapshotManager::CreateBranch ( const std::string &  name,
int64_t  snapshot_id 
)

Create a new branch pointing to the given snapshot id.

Parameters
namebranch name
snapshot_idid of the snapshot which will be the head of the branch
Returns
Reference to this for method chaining

◆ CreateTag()

SnapshotManager & iceberg::SnapshotManager::CreateTag ( const std::string &  name,
int64_t  snapshot_id 
)

Create a new tag pointing to the given snapshot id.

Parameters
nametag name
snapshot_idsnapshot id for the head of the new tag
Returns
Reference to this for method chaining

◆ FastForwardBranch()

SnapshotManager & iceberg::SnapshotManager::FastForwardBranch ( const std::string &  from,
const std::string &  to 
)

Perform a fast-forward of 'from' up to the 'to' snapshot if 'from' is an ancestor of 'to'. The 'to' will remain unchanged, and 'from' will retain its retention properties. If the 'from' branch does not exist, it will be created with default retention properties.

Parameters
frombranch to fast-forward
toref for the 'from' branch to be fast forwarded to
Returns
Reference to this for method chaining

◆ Make()

Result< std::shared_ptr< SnapshotManager > > iceberg::SnapshotManager::Make ( std::shared_ptr< Transaction transaction)
static

Create a SnapshotManager from an existing transaction.

Note
The caller is responsible for committing the transaction.

◆ RemoveBranch()

SnapshotManager & iceberg::SnapshotManager::RemoveBranch ( const std::string &  name)

Remove a branch by name.

Parameters
namebranch name
Returns
Reference to this for method chaining

◆ RemoveTag()

SnapshotManager & iceberg::SnapshotManager::RemoveTag ( const std::string &  name)

Remove the tag with the given name.

Parameters
nametag name
Returns
Reference to this for method chaining

◆ RenameBranch()

SnapshotManager & iceberg::SnapshotManager::RenameBranch ( const std::string &  name,
const std::string &  new_name 
)

Rename a branch.

Parameters
namename of branch to rename
new_namethe desired new name of the branch
Returns
Reference to this for method chaining

◆ ReplaceBranch() [1/2]

SnapshotManager & iceberg::SnapshotManager::ReplaceBranch ( const std::string &  from,
const std::string &  to 
)

Replace the 'from' branch to point to the 'to' snapshot. The 'to' will remain unchanged, and 'from' branch will retain its retention properties. If the 'from' branch does not exist, it will be created with default retention properties.

Parameters
frombranch to replace
tothe branch 'from' should be replaced with
Returns
Reference to this for method chaining

◆ ReplaceBranch() [2/2]

SnapshotManager & iceberg::SnapshotManager::ReplaceBranch ( const std::string &  name,
int64_t  snapshot_id 
)

Replace the branch with the given name to point to the specified snapshot.

Parameters
namebranch to replace
snapshot_idnew snapshot id for the given branch
Returns
Reference to this for method chaining

◆ ReplaceTag()

SnapshotManager & iceberg::SnapshotManager::ReplaceTag ( const std::string &  name,
int64_t  snapshot_id 
)

Replace the tag with the given name to point to the specified snapshot.

Parameters
nametag to replace
snapshot_idnew snapshot id for the given tag
Returns
Reference to this for method chaining

◆ RollbackTo()

SnapshotManager & iceberg::SnapshotManager::RollbackTo ( int64_t  snapshot_id)

Rollback table's state to a specific snapshot identified by id.

Parameters
snapshot_idlong id of snapshot to roll back table to. Must be an ancestor of the current snapshot
Returns
Reference to this for method chaining

◆ RollbackToTime()

SnapshotManager & iceberg::SnapshotManager::RollbackToTime ( int64_t  timestamp_ms)

Roll this table's data back to the last snapshot before the given timestamp.

Parameters
timestamp_msa long timestamp in milliseconds
Returns
Reference to this for method chaining

◆ SetCurrentSnapshot()

SnapshotManager & iceberg::SnapshotManager::SetCurrentSnapshot ( int64_t  snapshot_id)

Roll this table's data back to a specific snapshot identified by id.

Parameters
snapshot_idlong id of the snapshot to roll back table data to
Returns
Reference to this for method chaining

◆ SetMaxRefAgeMs()

SnapshotManager & iceberg::SnapshotManager::SetMaxRefAgeMs ( const std::string &  name,
int64_t  max_ref_age_ms 
)

Update the retention policy for a reference.

Parameters
namebranch name
max_ref_age_msretention age in milliseconds of the tag reference itself
Returns
Reference to this for method chaining

◆ SetMaxSnapshotAgeMs()

SnapshotManager & iceberg::SnapshotManager::SetMaxSnapshotAgeMs ( const std::string &  branch_name,
int64_t  max_snapshot_age_ms 
)

Update the max snapshot age for a branch.

Parameters
branch_namebranch name
max_snapshot_age_msmaximum snapshot age in milliseconds to retain on branch
Returns
Reference to this for method chaining

◆ SetMinSnapshotsToKeep()

SnapshotManager & iceberg::SnapshotManager::SetMinSnapshotsToKeep ( const std::string &  branch_name,
int32_t  min_snapshots_to_keep 
)

Update the minimum number of snapshots to keep for a branch.

Parameters
branch_namebranch name
min_snapshots_to_keepminimum number of snapshots to retain on the branch
Returns
Reference to this for method chaining

The documentation for this class was generated from the following files: