/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.drill.exec.store.sys.local;

import java.io.File;
import java.io.IOException;

import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.store.sys.PStore;
import org.apache.drill.exec.store.sys.PStoreConfig;
import org.apache.drill.exec.store.sys.PStoreProvider;
import org.apache.drill.exec.store.sys.PStoreRegistry;

/**
 * A really simple provider that stores data in the local file system, one value per file.
 */
public class LocalPStoreProvider implements PStoreProvider{
  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LocalPStoreProvider.class);

  private File path;
  private final boolean enableWrite;

  public LocalPStoreProvider(DrillConfig config) {
    path = new File(config.getString(ExecConstants.SYS_STORE_PROVIDER_LOCAL_PATH));
    enableWrite = config.getBoolean(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE);
  }

  public LocalPStoreProvider(PStoreRegistry registry) {
    this(registry.getConfig());
  }

  @Override
  public void close() {
  }

  @Override
  public <V> PStore<V> getPStore(PStoreConfig<V> storeConfig) throws IOException {
    if(enableWrite){
      return new LocalPStore<V>(path, storeConfig);
    }else{
      return new NoWriteLocalPStore<V>();
    }
  }

  @Override
  public void start() {
  }

}

@@ -892,16 +892,59 @@
 ception;
+%0Aimport java.util.concurrent.ConcurrentMap;
 %0A%0Aimport
@@ -1243,16 +1243,56 @@
 istry;%0A%0A
+import com.google.common.collect.Maps;%0A%0A
 /**%0A * A
@@ -1603,16 +1603,77 @@
 leWrite;
+%0A  private ConcurrentMap%3CPStoreConfig%3C?%3E, PStore%3C?%3E%3E pstores;
 %0A%0A  publ
@@ -1891,16 +1891,85 @@
 WRITE);%0A
+    if(!enableWrite)%7B%0A      pstores = Maps.newConcurrentMap();%0A    %7D%0A
   %7D%0A%0A  p
@@ -2280,30 +2280,37 @@
 else%7B%0A      
-return
+PStore%3CV%3E p =
  new NoWrite
@@ -2323,24 +2323,142 @@
 Store%3CV%3E();%0A
+      PStore%3C?%3E p2 = pstores.putIfAbsent(storeConfig, p);%0A      if(p2 != null) return (PStore%3CV%3E) p2;%0A      return p;%0A
     %7D%0A  %7D%0A%0A 

Update local pstore provider to hold data when running in write disabled mode. Allows use of web guy for profile viewing while debugging.