You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/08/28 23:59:29 UTC

[GitHub] sohami commented on a change in pull request #1296: DRILL-5365: Prevent plugin config from changing default fs. Make DrillFileSystem Immutable.

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

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/DrillFileSystem.java
 ##########
 @@ -79,32 +77,56 @@
 
   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);
-    this.codecFactory = new CompressionCodecFactory(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);
+    this.underlyingFs = FileSystem.get(this.fsConf);
+    this.codecFactory = new CompressionCodecFactory(this.fsConf);
     this.operatorStats = operatorStats;
+    this.initialized = true;
+  }
+
+  private void throwUnsupported() {
+    throw new UnsupportedOperationException(DrillFileSystem.class.getCanonicalName() + " is immutable and should not be changed after creation.");
   }
 
+  /**
+   * This method should never be used on {@link DrillFileSystem} since {@link DrillFileSystem} is immutable.
+   * {@inheritDoc}
+   * @throws UnsupportedOperationException when called.
+   */
   @Override
   public void setConf(Configuration conf) {
-    // Guard against setConf(null) call that is called as part of superclass constructor (Configured) of the
-    // DrillFileSystem, at which point underlyingFs is null.
-    if (conf != null && underlyingFs != null) {
-      underlyingFs.setConf(conf);
+    if (!initialized) {
 
 Review comment:
   We can still use `(underlyingFs != null)` check and get rid of the `initialized` flag. New check can be:
   
   ```
   if (underlyingFs != null) {
      throwUnsupported();
   }
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services