You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2020/04/30 00:51:11 UTC

[incubator-iceberg] branch master updated: Suppress exceptions while unlocking tables in HiveTableOperations (#987)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 189ea23  Suppress exceptions while unlocking tables in HiveTableOperations (#987)
189ea23 is described below

commit 189ea232bfbe0b4a01dda0419cf24a2ebff5dfe1
Author: Anton Okolnychyi <ao...@apple.com>
AuthorDate: Wed Apr 29 17:51:01 2020 -0700

    Suppress exceptions while unlocking tables in HiveTableOperations (#987)
---
 .../apache/iceberg/hive/HiveTableOperations.java   | 15 +++--
 .../org/apache/iceberg/hive/TestHiveCommits.java   | 69 ++++++++++++++++++++++
 2 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java b/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
index 0823184..e6d33b9 100644
--- a/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
+++ b/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
@@ -296,13 +296,18 @@ public class HiveTableOperations extends BaseMetastoreTableOperations {
   private void unlock(Optional<Long> lockId) {
     if (lockId.isPresent()) {
       try {
-        metaClients.run(client -> {
-          client.unlock(lockId.get());
-          return null;
-        });
+        doUnlock(lockId.get());
       } catch (Exception e) {
-        throw new RuntimeException(String.format("Failed to unlock %s.%s", database, tableName), e);
+        LOG.warn("Failed to unlock {}.{}", database, tableName, e);
       }
     }
   }
+
+  // visible for testing
+  protected void doUnlock(long lockId) throws TException, InterruptedException {
+    metaClients.run(client -> {
+      client.unlock(lockId);
+      return null;
+    });
+  }
 }
diff --git a/hive/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java b/hive/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java
new file mode 100644
index 0000000..81ac504
--- /dev/null
+++ b/hive/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java
@@ -0,0 +1,69 @@
+/*
+ * 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.hive;
+
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.types.Types;
+import org.apache.thrift.TException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+
+public class TestHiveCommits extends HiveTableBaseTest {
+
+  @Test
+  public void testSuppressUnlockExceptions() throws TException, InterruptedException {
+    Table table = catalog.loadTable(TABLE_IDENTIFIER);
+    HiveTableOperations ops = (HiveTableOperations) ((HasTableOperations) table).operations();
+
+    TableMetadata metadataV1 = ops.current();
+
+    table.updateSchema()
+        .addColumn("n", Types.IntegerType.get())
+        .commit();
+
+    ops.refresh();
+
+    TableMetadata metadataV2 = ops.current();
+
+    Assert.assertEquals(2, ops.current().schema().columns().size());
+
+    HiveTableOperations spyOps = spy(ops);
+
+    ArgumentCaptor<Long> lockId = ArgumentCaptor.forClass(Long.class);
+    doThrow(new RuntimeException()).when(spyOps).doUnlock(lockId.capture());
+
+    try {
+      spyOps.commit(metadataV2, metadataV1);
+    } finally {
+      ops.doUnlock(lockId.getValue());
+    }
+
+    ops.refresh();
+
+    // the commit must succeed
+    Assert.assertEquals(1, ops.current().schema().columns().size());
+  }
+}