You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "amogh-jahagirdar (via GitHub)" <gi...@apache.org> on 2023/02/18 17:01:20 UTC

[GitHub] [iceberg] amogh-jahagirdar commented on a diff in pull request #6857: Core,AWS: Init ObjectMapper with AtomicReference

amogh-jahagirdar commented on code in PR #6857:
URL: https://github.com/apache/iceberg/pull/6857#discussion_r1111060602


##########
aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3ObjectMapper.java:
##########
@@ -42,26 +43,24 @@
 
 public class S3ObjectMapper {
 
-  private static final JsonFactory FACTORY = new JsonFactory();
-  private static final ObjectMapper MAPPER = new ObjectMapper(FACTORY);
-  private static volatile boolean isInitialized = false;
+  private static final AtomicReference<ObjectMapper> REFERENCE = new AtomicReference<>();
 
   private S3ObjectMapper() {}
 
   static ObjectMapper mapper() {
-    if (!isInitialized) {
-      synchronized (S3ObjectMapper.class) {
-        if (!isInitialized) {
-          MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
-          MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-          MAPPER.setPropertyNamingStrategy(PropertyNamingStrategies.KebabCaseStrategy.INSTANCE);
-          MAPPER.registerModule(initModule());
-          isInitialized = true;
-        }
-      }
+    if (null == REFERENCE.get()) {

Review Comment:
   Yeah it's a good question. It really is more of a cleanliness thing imo, it just felt a bit unnecessary to have double check locking when atomic reference already encapsulates a few of the aspects we care about. 
   
   For avoiding the unnecessary work being done by one thread in the situation you described, could we make the mapper() method itself synchronized? That way two threads cannot init at the same time anyways, and the second thread will see the atomic reference is set and not do any work.



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