iceberg-cpp
Loading...
Searching...
No Matches
snapshot_manager.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <memory>
23#include <string>
24
26#include "iceberg/result.h"
27#include "iceberg/type_fwd.h"
29
32
33namespace iceberg {
34
50class ICEBERG_EXPORT SnapshotManager : public ErrorCollector {
51 public:
53 static Result<std::shared_ptr<SnapshotManager>> Make(std::shared_ptr<Table> table);
54
59 std::shared_ptr<Transaction> transaction);
60
61 ~SnapshotManager() override;
62
68 SnapshotManager& Cherrypick(int64_t snapshot_id);
69
74 SnapshotManager& SetCurrentSnapshot(int64_t snapshot_id);
75
80 SnapshotManager& RollbackToTime(int64_t timestamp_ms);
81
87 SnapshotManager& RollbackTo(int64_t snapshot_id);
88
95 SnapshotManager& CreateBranch(const std::string& name);
96
102 SnapshotManager& CreateBranch(const std::string& name, int64_t snapshot_id);
103
109 SnapshotManager& CreateTag(const std::string& name, int64_t snapshot_id);
110
115 SnapshotManager& RemoveBranch(const std::string& name);
116
121 SnapshotManager& RemoveTag(const std::string& name);
122
128 SnapshotManager& ReplaceTag(const std::string& name, int64_t snapshot_id);
129
135 SnapshotManager& ReplaceBranch(const std::string& name, int64_t snapshot_id);
136
144 SnapshotManager& ReplaceBranch(const std::string& from, const std::string& to);
145
154 SnapshotManager& FastForwardBranch(const std::string& from, const std::string& to);
155
161 SnapshotManager& RenameBranch(const std::string& name, const std::string& new_name);
162
168 SnapshotManager& SetMinSnapshotsToKeep(const std::string& branch_name,
169 int32_t min_snapshots_to_keep);
170
176 SnapshotManager& SetMaxSnapshotAgeMs(const std::string& branch_name,
177 int64_t max_snapshot_age_ms);
178
184 SnapshotManager& SetMaxRefAgeMs(const std::string& name, int64_t max_ref_age_ms);
185
187 Status Commit();
188
189 private:
190 SnapshotManager(std::shared_ptr<Transaction> transaction, bool is_external_transaction);
191
193 Result<std::shared_ptr<UpdateSnapshotReference>> UpdateSnapshotReferencesOperation();
194
196 Status CommitIfRefUpdatesExist();
197
198 std::shared_ptr<Transaction> transaction_;
199 const bool is_external_transaction_;
200 std::shared_ptr<UpdateSnapshotReference> update_snap_refs_;
201};
202
203} // namespace iceberg
Base class for collecting errors in the builder pattern.
Definition error_collector.h:93
API for managing snapshots.
Definition snapshot_manager.h:50
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,...
SnapshotManager & RollbackToTime(int64_t timestamp_ms)
Roll this table's data back to the last snapshot before the given timestamp.
SnapshotManager & SetMaxSnapshotAgeMs(const std::string &branch_name, int64_t max_snapshot_age_ms)
Update the max snapshot age for a branch.
SnapshotManager & RemoveTag(const std::string &name)
Remove the tag with the given name.
static Result< std::shared_ptr< SnapshotManager > > Make(std::shared_ptr< Transaction > transaction)
Create a SnapshotManager from an existing transaction.
SnapshotManager & ReplaceTag(const std::string &name, int64_t snapshot_id)
Replace the tag with the given name to point to the specified snapshot.
SnapshotManager & CreateBranch(const std::string &name, int64_t snapshot_id)
Create a new branch pointing to the given snapshot id.
Status Commit()
Commit all pending changes.
SnapshotManager & SetCurrentSnapshot(int64_t snapshot_id)
Roll this table's data back to a specific snapshot identified by id.
SnapshotManager & SetMaxRefAgeMs(const std::string &name, int64_t max_ref_age_ms)
Update the retention policy for a reference.
SnapshotManager & CreateBranch(const std::string &name)
Create a new branch. The branch will point to current snapshot if the current snapshot is not NULL....
SnapshotManager & RenameBranch(const std::string &name, const std::string &new_name)
Rename a branch.
static Result< std::shared_ptr< SnapshotManager > > Make(std::shared_ptr< Table > table)
Create a SnapshotManager that owns its own transaction.
SnapshotManager & Cherrypick(int64_t snapshot_id)
Apply supported changes in given snapshot and create a new snapshot which will be set as the current ...
SnapshotManager & ReplaceBranch(const std::string &name, int64_t snapshot_id)
Replace the branch with the given name to point to the specified snapshot.
SnapshotManager & RollbackTo(int64_t snapshot_id)
Rollback table's state to a specific snapshot identified by id.
SnapshotManager & RemoveBranch(const std::string &name)
Remove a branch by name.
SnapshotManager & CreateTag(const std::string &name, int64_t snapshot_id)
Create a new tag pointing to the given snapshot id.
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'....
SnapshotManager & SetMinSnapshotsToKeep(const std::string &branch_name, int32_t min_snapshots_to_keep)
Update the minimum number of snapshots to keep for a branch.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.