You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/12/22 07:49:17 UTC

[GitHub] [iceberg] CodingCat commented on a change in pull request #3663: fix data loss in multi-threading append with HadoopTable

CodingCat commented on a change in pull request #3663:
URL: https://github.com/apache/iceberg/pull/3663#discussion_r773648676



##########
File path: aws/src/integration/java/org/apache/iceberg/aws/glue/TestDynamoLockManager.java
##########
@@ -153,9 +153,9 @@ public void testAcquireSingleProcess() throws Exception {
   @Test
   public void testAcquireMultiProcessAllSucceed() throws Exception {
     lockManager.initialize(ImmutableMap.of(
-        CatalogProperties.LOCK_ACQUIRE_INTERVAL_MS, "500",
-        CatalogProperties.LOCK_ACQUIRE_TIMEOUT_MS, "100000000",
-        CatalogProperties.LOCK_TABLE, lockTableName
+        LockManagerProperties.LOCK_ACQUIRE_INTERVAL_MS, "500",
+        LockManagerProperties.LOCK_ACQUIRE_TIMEOUT_MS, "100000000",
+        LockManagerProperties.LOCK_TABLE, lockTableName

Review comment:
       hmmm...not necessarily? users can create HadoopTables directly and then create HadoopTableOperations (assuming we agree on the current parameter passing mechanism that users pass in via Hadoop Configurations)

##########
File path: core/src/test/java/org/apache/iceberg/util/TestInMemoryLockManager.java
##########
@@ -1,23 +1,18 @@
 /*
- * 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
+ * Licensed 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
+ *     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.
+ * 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.

Review comment:
       ah, sorry, seems intelliJ added this somehow

##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java
##########
@@ -353,8 +346,12 @@ int findVersion() {
    * @param src the source file
    * @param dst the destination file
    */
-  private void renameToFinal(FileSystem fs, Path src, Path dst) {
+  private void renameToFinal(FileSystem fs, Path src, Path dst, int nextVersion) {
     try {
+      lockManager.acquire(dst.toString(), Thread.currentThread().getName());
+      if (fs.exists(dst)) {
+        throw new CommitFailedException("Version %d already exists: %s", nextVersion, dst);
+      }

Review comment:
       done

##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java
##########
@@ -194,8 +203,24 @@ TableOperations newTableOps(String location) {
     if (location.contains(METADATA_JSON)) {
       return new StaticTableOperations(location, new HadoopFileIO(conf));
     } else {
-      return new HadoopTableOperations(new Path(location), new HadoopFileIO(conf), conf);
+      return new HadoopTableOperations(new Path(location), new HadoopFileIO(conf), conf,
+              createOrGetLockManager(location));
+    }
+  }
+
+  private LockManager createOrGetLockManager(String location) {
+    Map<String, String> properties = new HashMap<>();
+    Iterator<Map.Entry<String, String>> configEntries = this.conf.iterator();

Review comment:
       done

##########
File path: core/src/main/java/org/apache/iceberg/util/LockManagerProperties.java
##########
@@ -0,0 +1,42 @@
+/*
+ * Licensed 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.

Review comment:
       as said above, with HadoopTables, users can directly create a HadoopTables object by passing in lock configurations, so it is not exclusively a catalog config anymore?

##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java
##########
@@ -194,8 +203,24 @@ TableOperations newTableOps(String location) {
     if (location.contains(METADATA_JSON)) {
       return new StaticTableOperations(location, new HadoopFileIO(conf));
     } else {
-      return new HadoopTableOperations(new Path(location), new HadoopFileIO(conf), conf);
+      return new HadoopTableOperations(new Path(location), new HadoopFileIO(conf), conf,
+              createOrGetLockManager(location));

Review comment:
       hmmm...the consideration here is actually users can pass different configurations of LockManager for different tables 

##########
File path: core/src/test/java/org/apache/iceberg/util/TestLockManagers.java
##########
@@ -1,26 +1,20 @@
 /*
- * 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
+ * Licensed 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
+ *     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.
+ * 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.

Review comment:
       done

##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
##########
@@ -105,6 +108,8 @@ public void initialize(String name, Map<String, String> properties) {
     this.fileIO = fileIOImpl == null ? new HadoopFileIO(conf) : CatalogUtil.loadFileIO(fileIOImpl, properties, conf);
 
     this.suppressPermissionError = Boolean.parseBoolean(properties.get(HADOOP_SUPPRESS_PERMISSION_ERROR));
+
+    this.lockManager = LockManagers.from(properties);

Review comment:
       done




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org