rdblue commented on code in PR #15583:
URL: https://github.com/apache/iceberg/pull/15583#discussion_r2920244066
##########
core/src/main/java/org/apache/iceberg/hadoop/SerializableConfiguration.java:
##########
@@ -18,33 +18,34 @@
*/
package org.apache.iceberg.hadoop;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.SerializableMap;
+import org.apache.iceberg.util.SerializableSupplier;
/** Wraps a {@link Configuration} object in a {@link Serializable} layer. */
-public class SerializableConfiguration implements Serializable {
-
- private transient Configuration hadoopConf;
+public class SerializableConfiguration implements
SerializableSupplier<Configuration> {
+ private final SerializableMap<String, String> confAsMap;
+ private transient volatile Configuration hadoopConf = null;
public SerializableConfiguration(Configuration hadoopConf) {
- this.hadoopConf = hadoopConf;
- }
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- hadoopConf.write(out);
- }
-
- private void readObject(ObjectInputStream in) throws ClassNotFoundException,
IOException {
- in.defaultReadObject();
- hadoopConf = new Configuration(false);
- hadoopConf.readFields(in);
+ this.confAsMap =
SerializableMap.copyOf(Maps.newHashMapWithExpectedSize(hadoopConf.size()));
Review Comment:
This is a little strange. The old version just used a map directly. It's
alright to use `SerializableMap`, I guess. But this will also allocate a map,
then throw it away to immediately copy it.
It would be better to not make the code more complicated or to construct
`SerializableMap` so that it doesn't do unnecessary allocation and copying.
--
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]