iceberg-cpp
Loading...
Searching...
No Matches
update_snapshot_reference.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#include <unordered_map>
25
27#include "iceberg/result.h"
28#include "iceberg/type_fwd.h"
30
32
33namespace iceberg {
34
39class ICEBERG_EXPORT UpdateSnapshotReference : public PendingUpdate {
40 public:
42 std::shared_ptr<TransactionContext> ctx);
43
44 ~UpdateSnapshotReference() override;
45
51 UpdateSnapshotReference& CreateBranch(const std::string& name, int64_t snapshot_id);
52
58 UpdateSnapshotReference& CreateTag(const std::string& name, int64_t snapshot_id);
59
64 UpdateSnapshotReference& RemoveBranch(const std::string& name);
65
70 UpdateSnapshotReference& RemoveTag(const std::string& name);
71
77 UpdateSnapshotReference& RenameBranch(const std::string& name,
78 const std::string& new_name);
79
85 UpdateSnapshotReference& ReplaceBranch(const std::string& name, int64_t snapshot_id);
86
92 UpdateSnapshotReference& ReplaceBranch(const std::string& from, const std::string& to);
93
102 UpdateSnapshotReference& FastForward(const std::string& from, const std::string& to);
103
109 UpdateSnapshotReference& ReplaceTag(const std::string& name, int64_t snapshot_id);
110
117 int32_t min_snapshots_to_keep);
118
125 int64_t max_snapshot_age_ms);
126
132 UpdateSnapshotReference& SetMaxRefAgeMs(const std::string& name,
133 int64_t max_ref_age_ms);
134
135 Kind kind() const final { return Kind::kUpdateSnapshotReference; }
136
142 bool IsRetryable() const override { return false; }
143
144 struct ApplyResult {
146 std::vector<std::pair<std::string, std::shared_ptr<SnapshotRef>>> to_set;
148 std::vector<std::string> to_remove;
149 };
150
153
154 private:
155 explicit UpdateSnapshotReference(std::shared_ptr<TransactionContext> ctx);
156
157 UpdateSnapshotReference& ReplaceBranchInternal(const std::string& from,
158 const std::string& to,
159 bool fast_forward);
160
161 std::unordered_map<std::string, std::shared_ptr<SnapshotRef>> updated_refs_;
162};
163
164} // namespace iceberg
Base class for all kinds of table metadata updates.
Definition pending_update.h:41
Updates snapshot references.
Definition update_snapshot_reference.h:39
Kind kind() const final
Return the kind of this pending update.
Definition update_snapshot_reference.h:135
UpdateSnapshotReference & SetMaxRefAgeMs(const std::string &name, int64_t max_ref_age_ms)
Set the maximum reference age in milliseconds.
UpdateSnapshotReference & FastForward(const std::string &from, const std::string &to)
Fast-forward a branch to another reference's snapshot ID.
UpdateSnapshotReference & ReplaceBranch(const std::string &name, int64_t snapshot_id)
Replace a branch reference with a new snapshot ID.
UpdateSnapshotReference & SetMaxSnapshotAgeMs(const std::string &name, int64_t max_snapshot_age_ms)
Set the maximum snapshot age in milliseconds for a branch.
bool IsRetryable() const override
Snapshot reference updates are not retryable.
Definition update_snapshot_reference.h:142
UpdateSnapshotReference & RemoveTag(const std::string &name)
Remove a tag reference.
UpdateSnapshotReference & CreateBranch(const std::string &name, int64_t snapshot_id)
Create a branch reference.
UpdateSnapshotReference & RemoveBranch(const std::string &name)
Remove a branch reference.
UpdateSnapshotReference & ReplaceBranch(const std::string &from, const std::string &to)
Replace a branch reference with another reference's snapshot ID.
UpdateSnapshotReference & ReplaceTag(const std::string &name, int64_t snapshot_id)
Replace a tag reference with a new snapshot ID.
UpdateSnapshotReference & RenameBranch(const std::string &name, const std::string &new_name)
Rename a branch reference.
UpdateSnapshotReference & SetMinSnapshotsToKeep(const std::string &name, int32_t min_snapshots_to_keep)
Set the minimum number of snapshots to keep for a branch.
Result< ApplyResult > Apply()
Apply the pending changes and return the updated and removed references.
UpdateSnapshotReference & CreateTag(const std::string &name, int64_t snapshot_id)
Create a tag reference.
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.
Definition update_snapshot_reference.h:144
std::vector< std::string > to_remove
Reference names to remove.
Definition update_snapshot_reference.h:148
std::vector< std::pair< std::string, std::shared_ptr< SnapshotRef > > > to_set
References to set or update (name, ref pairs)
Definition update_snapshot_reference.h:146