68 static Result<std::shared_ptr<ExpireSnapshots>> Make(
69 std::shared_ptr<TransactionContext> ctx);
74 std::vector<std::string> refs_to_remove;
75 std::vector<int64_t> snapshot_ids_to_remove;
76 std::vector<int32_t> partition_spec_ids_to_remove;
77 std::unordered_set<int32_t> schema_ids_to_remove;
78 std::shared_ptr<const TableMetadata> metadata_before_expiration;
119 ExpireSnapshots& DeleteWith(std::function<
void(
const std::string&)> delete_func);
142 Kind
kind() const final {
return Kind::kExpireSnapshots; }
147 Result<ApplyResult> Apply();
158 Status Finalize(Result<const TableMetadata*> commit_result)
override;
163 using SnapshotToRef = std::unordered_map<std::string, std::shared_ptr<SnapshotRef>>;
165 Result<SnapshotToRef> ComputeRetainedRefs(
const SnapshotToRef& refs)
const;
167 Result<std::unordered_set<int64_t>> ComputeBranchSnapshotsToRetain(
168 int64_t snapshot_id, TimePointMs expire_snapshot_older_than,
169 int32_t min_snapshots_to_keep)
const;
171 Result<std::unordered_set<int64_t>> ComputeAllBranchSnapshotIdsToRetain(
172 const SnapshotToRef& refs)
const;
174 Result<std::unordered_set<int64_t>> UnreferencedSnapshotIdsToRetain(
175 const SnapshotToRef& refs)
const;
177 const TimePointMs current_time_ms_;
178 const int64_t default_max_ref_age_ms_;
179 int32_t default_min_num_snapshots_;
180 TimePointMs default_expire_older_than_;
181 std::function<void(
const std::string&)> delete_func_;
182 std::vector<int64_t> snapshot_ids_to_expire_;
183 enum CleanupLevel cleanup_level_ { CleanupLevel::kAll };
184 bool clean_expired_metadata_{
false};
185 bool specified_snapshot_id_{
false};
188 std::optional<ApplyResult> apply_result_;