difin commented on code in PR #5712:
URL: https://github.com/apache/hive/pull/5712#discussion_r2015395118


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/writer/WriterRegistry.java:
##########
@@ -36,13 +36,10 @@ public static Map<String, List<HiveIcebergWriter>> 
removeWriters(TaskAttemptID t
   }
 
   public static void registerWriter(TaskAttemptID taskAttemptID, String 
tableName, HiveIcebergWriter writer) {
-    writers.putIfAbsent(taskAttemptID, Maps.newConcurrentMap());
+    Map<String, List<HiveIcebergWriter>> outputWriters =
+        writers.computeIfAbsent(taskAttemptID, k -> Maps.newConcurrentMap());
 
-    Map<String, List<HiveIcebergWriter>> writersOfTableMap = 
writers.get(taskAttemptID);
-    writersOfTableMap.putIfAbsent(tableName, Lists.newArrayList());
-
-    List<HiveIcebergWriter> writerList = writersOfTableMap.get(tableName);
-    writerList.add(writer);
+    outputWriters.computeIfAbsent(tableName, k -> new 
CopyOnWriteArrayList<>()).add(writer);

Review Comment:
   Looks good for making the list of writers thread safe. 
   
   Was the race condition occurring in this `registerWriter` method itself when 
adding a writer to the list of outputWriters or was it occurring later when 
some concurrent threads were working with the list of outputWriters after 
getting them via `removeWriters` ?



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