amogh-jahagirdar commented on a change in pull request #4071:
URL: https://github.com/apache/iceberg/pull/4071#discussion_r837008625



##########
File path: 
core/src/main/java/org/apache/iceberg/UpdateSnapshotReferencesOperation.java
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+class UpdateSnapshotReferencesOperation implements PendingUpdate<Map<String, 
SnapshotRef>> {
+
+  private final TableOperations ops;
+  private final Map<String, SnapshotRef> updatedRefs;
+  private TableMetadata base;
+
+  UpdateSnapshotReferencesOperation(TableOperations ops) {
+    this.ops = ops;
+    this.base = ops.current();
+    this.updatedRefs = Maps.newHashMap(base.refs());
+  }
+
+  @Override
+  public Map<String, SnapshotRef> apply() {
+    return refDiff(base.refs(), updatedRefs);
+  }
+
+  @Override
+  public void commit() {
+    TableMetadata updated = internalApply();

Review comment:
       Currently since UpdateSnapshotReferenceOperation is contained within a 
transaction, we need to commit the transaction table operations even if there 
are no changes (to advance the hasLastOpCommited flag). This is because we have 
started  a transaction and the table operations last operation has not 
committed; when the overall transaction goes to commit, it validates if the 
last operation has committed and fails if it's not the case. Since this is 
transaction table operations and we're not updating the new pointer to the 
metadata until the transaction commits, I don't think there's any performance 
issue since we do not attempt to update the catalog pointer until the overall 
transaction commits. 
   
   let me know if I am missing something!
   
   Another way I was thinking to handle this was in BaseTransaction.commit, if 
there are no  intermediate snapshots produced and if the metadata changes is 
empty, it's a noop commit, but we advance hasLastOpCommitted flag? 
   
   
https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/BaseTransaction.java#L502




-- 
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]

Reply via email to