kellen commented on code in PR #29537:
URL: https://github.com/apache/beam/pull/29537#discussion_r1406748127


##########
sdks/java/io/hadoop-common/src/main/java/org/apache/beam/sdk/io/hadoop/SerializableConfiguration.java:
##########
@@ -49,34 +52,40 @@ public SerializableConfiguration(Configuration conf) {
     if (conf == null) {
       throw new NullPointerException("Configuration must not be null.");
     }
+    this.confMutated = true;
     this.conf = conf;
   }
 
   public Configuration get() {
-    if (serializationCache != null) {
-      serializationCache = null;
-    }
+    // get() call returns the original conf, which is mutable by caller
+    confMutated = true;
     return conf;
   }
 
   @Override
   public void writeExternal(ObjectOutput out) throws IOException {
-    if (serializationCache == null) {
-      ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
-      try (DataOutputStream dos = new DataOutputStream(baos)) {
-        conf.write(dos);
-        serializationCache = baos.toByteArray();
+    String canonicalName;
+    synchronized (this) {
+      canonicalName = conf.getClass().getCanonicalName();
+      if (confMutated) {
+        confMutated = false;
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
+        try (DataOutputStream dos = new DataOutputStream(baos)) {
+          // this call is slow.
+          conf.write(dos);
+          serializationCache = baos.toByteArray();

Review Comment:
   Actually with this implementation, synchronization is not required unless 
`conf.write` will explode if there is some concurrent modification. 



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

Reply via email to