arnaudbriche commented on code in PR #401:
URL: https://github.com/apache/iceberg-go/pull/401#discussion_r2174396326
##########
table/transaction.go:
##########
@@ -142,6 +143,121 @@ func (t *Transaction) SetProperties(props
iceberg.Properties) error {
return nil
}
+type expireSnapshotsCfg struct {
+ minSnapshotsToKeep *int
+ maxSnapshotAgeMs *int64
+}
+
+type ExpireSnapshotsOpt func(*expireSnapshotsCfg)
+
+func WithRetainLast(n int) ExpireSnapshotsOpt {
+ return func(cfg *expireSnapshotsCfg) {
+ cfg.minSnapshotsToKeep = &n
+ }
+}
+
+func WithOlderThan(t time.Duration) ExpireSnapshotsOpt {
+ return func(cfg *expireSnapshotsCfg) {
+ n := t.Milliseconds()
+ cfg.maxSnapshotAgeMs = &n
+ }
+}
+
+func (t *Transaction) ExpireSnapshots(opts ...ExpireSnapshotsOpt) error {
+ var (
+ cfg expireSnapshotsCfg
+ updates []Update
+ snapsToKeep = make(map[int64]struct{})
+ refsToDelete = make(map[string]struct{})
+ nowMs = time.Now().UnixMilli()
+ )
+
+ for _, opt := range opts {
+ opt(&cfg)
+ }
+
+ for refName, ref := range t.meta.refs {
+ if refName == MainBranch {
+ continue
+ }
+
+ snap, err := t.meta.SnapshotByID(ref.SnapshotID)
+ if err != nil {
+ return err
+ }
+
+ maxRefAgeMs := internal.Coalesce(ref.MaxRefAgeMs,
cfg.maxSnapshotAgeMs)
+ if maxRefAgeMs == nil {
+ return errors.New("cannot find a valid value for
maxRefAgeMs")
+ }
Review Comment:
Indeed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]