Skip to content

Deprecate TableMetadata.removeSnapshotsIf in favor of metadata builder #3900

Closed

Activity

  1. amogh-jahagirdar commented on Jan 20, 2022

    @amogh-jahagirdar
    Contributor

    After #3883 gets closed, I'll raise a PR for this that I have ready. I am planning on deprecating the existing TableMetadata#removeSnapshotsIf and adding the a new removeSnapshots method which simply accepts a set of snapshot ids to remove. It will do validation that the set of snapshot ids passed in does not contain the latest snapshot id. Something like the following.

    public TableMetadata removeSnapshots(Set<Long> snapshotIdsToRemove) {
        Preconditions.checkArgument(snapshotIdsToRemove != null,
            "Snapshot ids to remove cannot be null");
        ValidationException.check(!snapshotIdsToRemove.contains(currentSnapshotId),
            String.format("Cannot remove the latest snapshot id: %d", currentSnapshotId));
        return new Builder(this)
            .removeSnapshots(snapshotIdsToRemove)
            .build();
      }
    
    

    Then in a later PR to address updating the expiration logic to account for references, we would start calling removeSnapshots along with replaceRefs. @jackye1995 thoughts on this?

  2. amogh-jahagirdar commented on Jan 20, 2022

    @amogh-jahagirdar
    Contributor

    As a follow up, I think in the scope of the API we should also make sure we are cleaning up any references as well, as to prevent a "corrupt" state of TableMetadata. So if snapshot 2 is to be removed and there are references to snapshot 2, within this API we should also remove those references. This way we don't have any dangling references. We could also filter and not remove any snapshots which have references in this method, and then force callers to remove references first and then the snapshot ids. This seems like too much work for callers, and to me is not as intuitive. Let me know your thoughts.

  3. jackye1995 commented on Jan 21, 2022

    @jackye1995
    ContributorAuthor

    Overall there are 3 use cases:

    1. filter snapshots with ref and skip removal of those
    2. throw exception if a snapshot to remove has ref
    3. directly remove snapshot and its associated refs

    Consider the use case if this method, it is basically used for snapshot expiration and nothing else. The logic is:

        TableMetadata updateMeta = base.removeSnapshotsIf(snapshot ->
            idsToRemove.contains(snapshot.snapshotId()) ||
            (snapshot.timestampMillis() < expireOlderThan && !idsToRetain.contains(snapshot.snapshotId())));

    When we add branching and tagging, we will have a much more complex if statement to filter out snapshots, and we should be sure that the snapshots passed into the method are the ones we truly want to remove. The snapshot might have associated refs, but removing the refs along the way seems like the correct choice, so that we don't need to have another operation like RemoveSnapshotRef to clean those things up.

    Based on this, I think option 3 makes sense to me at this point of time based on the use case.

    This is also not a one way door, we can always add a flag to achieve 1 or 2 in the future if that is absolutely needed, but it should be simpler to enforce that requirement before the information is passed into the method.

  4. github-actions commented on Aug 22, 2022

    @github-actions

    This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

  5. github-actions commented on Sep 5, 2022

    @github-actions

    This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions