ilooner commented on a change in pull request #1296: DRILL-5365: Prevent plugin 
config from changing default fs. Make DrillFileSystem Immutable.
URL: https://github.com/apache/drill/pull/1296#discussion_r203902329
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/DrillFileSystem.java
 ##########
 @@ -65,46 +62,105 @@
 import com.google.common.collect.Maps;
 
 /**
- * DrillFileSystem is the wrapper around the actual FileSystem implementation.
+ * DrillFileSystem is the wrapper around the actual FileSystem implementation. 
The {@link DrillFileSystem} is
+ * immutable.
  *
  * If {@link org.apache.drill.exec.ops.OperatorStats} are provided it returns 
an instrumented FSDataInputStream to
  * measure IO wait time and tracking file open/close operations.
  */
 public class DrillFileSystem extends FileSystem implements OpenFileTracker {
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillFileSystem.class);
   private final static boolean TRACKING_ENABLED = 
AssertionUtil.isAssertionsEnabled();
+  private final static DrillFileSystemCache CACHE = new DrillFileSystemCache();
 
+  public static final String FS_DEFAULT_NAME = "fs.default.name";
   public static final String UNDERSCORE_PREFIX = "_";
   public static final String DOT_PREFIX = ".";
 
   private final ConcurrentMap<DrillFSDataInputStream, DebugStackTrace> 
openedFiles = Maps.newConcurrentMap();
 
+  private final Configuration fsConf;
   private final FileSystem underlyingFs;
   private final OperatorStats operatorStats;
   private final CompressionCodecFactory codecFactory;
 
+  private boolean initialized = false;
+
   public DrillFileSystem(Configuration fsConf) throws IOException {
     this(fsConf, null);
   }
 
   public DrillFileSystem(Configuration fsConf, OperatorStats operatorStats) 
throws IOException {
-    this.underlyingFs = FileSystem.get(fsConf);
+    // Configuration objects are mutable, and the underlying FileSystem object 
may directly use a passed in Configuration.
+    // In order to avoid scenarios where a Configuration can change after a 
DrillFileSystem is created, we make a copy
+    // of the Configuration.
+    this.fsConf = new Configuration(fsConf);
+    normalize(fsConf);
 
 Review comment:
   Thanks for showing me this, never knew about it. 
   
   I think setDeprecateProperties does some of what we need, but would still 
have a problem. Consider the following input and output mappings for 
setDeprecateProperties.
   
   (fs.default.name: val1 ) -> (fs.default.name: val1 )
   (fs.default.name: val1, fs.defaultFS: val2 ) -> (fs.default.name: val1, 
fs.defaultFS: val2 )
   (fs.default.name: val1, fs.defaultFS: val1 ) -> (fs.default.name: val1, 
fs.defaultFS: val1 )
   
   Ideally we would want all this outputs to be the same and we would want a 
warning if our given config has different values for fs.default.name and 
fs.defaultFS.
   
   The normalize method handles this cases. I am trying to think of a way to 
use setDeprecateProperties to replace some of the existing code in normalize. 
But I can't think of a way to use setDeprecateProperties with the extra case 
handling to make the code any simpler than what it is now. 
   
   If you have any ideas on a way we could use setDeprecateProperties and 
handle the other cases described above more simply than the current normalize 
method, let me know and I will do it. Otherwise if we can't think of anything 
now, I'd prefer to keep the normalize method as is. 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to