test_class.declarator: tempFolder = new TemporaryFolder(new File("target"))
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public TemporaryFolder tempFolder = new TemporaryFolder(new File("target"));
test_class.type: TemporaryFolder
test_class.var_name: tempFolder
test_class.declarator: builderProvider = new DocumentMKBuilderProvider()
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider();
test_class.type: DocumentMKBuilderProvider
test_class.var_name: builderProvider
test_class.declarator: rnd = new Random()
test_class.modifier: private
test_class.original_string: private Random rnd = new Random();
test_class.type: Random
test_class.var_name: rnd
test_class.declarator: copier
test_class.modifier: private
test_class.original_string: private IndexCopier copier;
test_class.type: IndexCopier
test_class.var_name: copier
test_class.declarator: executor
test_class.modifier: private
test_class.original_string: private ExecutorService executor;
test_class.type: ExecutorService
test_class.var_name: executor
test_class.declarator: ns
test_class.modifier: private
test_class.original_string: private DocumentNodeStore ns;
test_class.type: DocumentNodeStore
test_class.var_name: ns
test_class.file: oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/CopyOnWriteDirectoryTest.java
test_class.identifier: CopyOnWriteDirectoryTest
test_case.body: @Test
      public void copyOnWrite() throws Exception {
          LuceneIndexDefinition def = new LuceneIndexDefinition(ns.getRoot(), ns.getRoot(), "/foo");
          NodeBuilder builder = ns.getRoot().builder();
          Directory dir = new DefaultDirectoryFactory(copier, null).newInstance(def, builder.child("foo"), INDEX_DATA_CHILD_NAME, false);
          addFiles(dir);
          writeTree(builder);
          dir.close();
          ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
      }
test_case.class_method_signature: CopyOnWriteDirectoryTest.copyOnWrite()
test_case.full_signature: @Test public void copyOnWrite()
test_case.identifier: copyOnWrite
test_case.invocations: getRoot getRoot builder getRoot newInstance child addFiles writeTree close merge
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void copyOnWrite()
focal_class.declarator: log = LoggerFactory.getLogger(CopyOnWriteDirectory.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(CopyOnWriteDirectory.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: PERF_LOGGER = new PerfLogger(LoggerFactory.getLogger(log.getName() + ".perf"))
focal_class.modifier: private static final
focal_class.original_string: private static final PerfLogger PERF_LOGGER = new PerfLogger(LoggerFactory.getLogger(log.getName() + ".perf"));
focal_class.type: PerfLogger
focal_class.var_name: PERF_LOGGER
focal_class.declarator: indexCopier
focal_class.modifier: private final
focal_class.original_string: private final IndexCopier indexCopier;
focal_class.type: IndexCopier
focal_class.var_name: indexCopier
focal_class.declarator: STOP = new Callable<Void>() {
          @Override
          public Void call() throws Exception {
              return null;
          }
      }
focal_class.modifier: private final
focal_class.original_string: private final Callable<Void> STOP = new Callable<Void>() {
          @Override
          public Void call() throws Exception {
              return null;
          }
      };
focal_class.type: Callable<Void>
focal_class.var_name: STOP
focal_class.declarator: remote
focal_class.modifier: private final
focal_class.original_string: private final Directory remote;
focal_class.type: Directory
focal_class.var_name: remote
focal_class.declarator: local
focal_class.modifier: private final
focal_class.original_string: private final Directory local;
focal_class.type: Directory
focal_class.var_name: local
focal_class.declarator: executor
focal_class.modifier: private final
focal_class.original_string: private final Executor executor;
focal_class.type: Executor
focal_class.var_name: executor
focal_class.declarator: fileMap = newConcurrentMap()
focal_class.modifier: private final
focal_class.original_string: private final ConcurrentMap<String, COWFileReference> fileMap = newConcurrentMap();
focal_class.type: ConcurrentMap<String, COWFileReference>
focal_class.var_name: fileMap
focal_class.declarator: deletedFilesLocal = Sets.newConcurrentHashSet()
focal_class.modifier: private final
focal_class.original_string: private final Set<String> deletedFilesLocal = Sets.newConcurrentHashSet();
focal_class.type: Set<String>
focal_class.var_name: deletedFilesLocal
focal_class.declarator: skippedFiles = Sets.newConcurrentHashSet()
focal_class.modifier: private final
focal_class.original_string: private final Set<String> skippedFiles = Sets.newConcurrentHashSet();
focal_class.type: Set<String>
focal_class.var_name: skippedFiles
focal_class.declarator: queue = new LinkedBlockingQueue<Callable<Void>>()
focal_class.modifier: private final
focal_class.original_string: private final BlockingQueue<Callable<Void>> queue = new LinkedBlockingQueue<Callable<Void>>();
focal_class.type: BlockingQueue<Callable<Void>>
focal_class.var_name: queue
focal_class.declarator: errorInCopy = new AtomicReference<Throwable>()
focal_class.modifier: private final
focal_class.original_string: private final AtomicReference<Throwable> errorInCopy = new AtomicReference<Throwable>();
focal_class.type: AtomicReference<Throwable>
focal_class.var_name: errorInCopy
focal_class.declarator: copyDone = new CountDownLatch(1)
focal_class.modifier: private final
focal_class.original_string: private final CountDownLatch copyDone = new CountDownLatch(1);
focal_class.type: CountDownLatch
focal_class.var_name: copyDone
focal_class.declarator: reindexMode
focal_class.modifier: private final
focal_class.original_string: private final boolean reindexMode;
focal_class.type: boolean
focal_class.var_name: reindexMode
focal_class.declarator: indexPath
focal_class.modifier: private final
focal_class.original_string: private final String indexPath;
focal_class.type: String
focal_class.var_name: indexPath
focal_class.declarator: closed
focal_class.modifier: private
focal_class.original_string: private boolean closed;
focal_class.type: boolean
focal_class.var_name: closed
focal_class.declarator: currentTask =  NotifyingFutureTask.completed()
focal_class.modifier: private volatile
focal_class.original_string: private volatile NotifyingFutureTask currentTask =  NotifyingFutureTask.completed();
focal_class.type: NotifyingFutureTask
focal_class.var_name: currentTask
focal_class.declarator: completionHandler = new Runnable() {
          Callable<Void> task = new Callable<Void>() {
              @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
              @Override
              public Void call() throws Exception {
                  try {
                      Callable<Void> task = queue.poll();
                      if (task != null && task != STOP) {
                          if (errorInCopy.get() != null) {
                              log.trace("[COW][{}] Skipping task {} as some exception occurred in previous run",
                                      indexPath, task);
                          } else {
                              task.call();
                          }
                          currentTask.onComplete(completionHandler);
                      }
  
                      //Signal that all tasks completed
                      if (task == STOP){
                          copyDone.countDown();
                      }
                  } catch (Throwable t) {
                      errorInCopy.set(t);
                      log.debug("[COW][{}] Error occurred while copying files. Further processing would " +
                              "be skipped", indexPath, t);
                      currentTask.onComplete(completionHandler);
                  }
                  return null;
              }
          };
  
          @Override
          public void run() {
              currentTask = new NotifyingFutureTask(task);
              try {
                  executor.execute(currentTask);
              } catch (RejectedExecutionException e){
                  checkIfClosed(false);
                  throw e;
              }
          }
      }
focal_class.modifier: private final
focal_class.original_string: private final Runnable completionHandler = new Runnable() {
          Callable<Void> task = new Callable<Void>() {
              @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
              @Override
              public Void call() throws Exception {
                  try {
                      Callable<Void> task = queue.poll();
                      if (task != null && task != STOP) {
                          if (errorInCopy.get() != null) {
                              log.trace("[COW][{}] Skipping task {} as some exception occurred in previous run",
                                      indexPath, task);
                          } else {
                              task.call();
                          }
                          currentTask.onComplete(completionHandler);
                      }
  
                      //Signal that all tasks completed
                      if (task == STOP){
                          copyDone.countDown();
                      }
                  } catch (Throwable t) {
                      errorInCopy.set(t);
                      log.debug("[COW][{}] Error occurred while copying files. Further processing would " +
                              "be skipped", indexPath, t);
                      currentTask.onComplete(completionHandler);
                  }
                  return null;
              }
          };
  
          @Override
          public void run() {
              currentTask = new NotifyingFutureTask(task);
              try {
                  executor.execute(currentTask);
              } catch (RejectedExecutionException e){
                  checkIfClosed(false);
                  throw e;
              }
          }
      };
focal_class.type: Runnable
focal_class.var_name: completionHandler
focal_class.file: oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/CopyOnWriteDirectory.java
focal_class.identifier: CopyOnWriteDirectory
focal_class.class_method_signature: CopyOnWriteDirectory.CopyOnWriteDirectory(IndexCopier indexCopier, Directory remote, Directory local, boolean reindexMode,
                                  String indexPath, Executor executor)
focal_class.full_signature: public  CopyOnWriteDirectory(IndexCopier indexCopier, Directory remote, Directory local, boolean reindexMode,
                                  String indexPath, Executor executor)
focal_class.identifier: CopyOnWriteDirectory
focal_class.modifiers: public
focal_class.parameters: (IndexCopier indexCopier, Directory remote, Directory local, boolean reindexMode,
                                  String indexPath, Executor executor)
focal_class.signature:  CopyOnWriteDirectory(IndexCopier indexCopier, Directory remote, Directory local, boolean reindexMode,
                                  String indexPath, Executor executor)
focal_class.class_method_signature: CopyOnWriteDirectory.listAll()
focal_class.full_signature: @Override public String[] listAll()
focal_class.identifier: listAll
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String[]
focal_class.signature: String[] listAll()
focal_class.class_method_signature: CopyOnWriteDirectory.fileExists(String name)
focal_class.full_signature: @Override public boolean fileExists(String name)
focal_class.identifier: fileExists
focal_class.modifiers: @Override public
focal_class.parameters: (String name)
focal_class.return: boolean
focal_class.signature: boolean fileExists(String name)
focal_class.class_method_signature: CopyOnWriteDirectory.deleteFile(String name)
focal_class.full_signature: @Override public void deleteFile(String name)
focal_class.identifier: deleteFile
focal_class.modifiers: @Override public
focal_class.parameters: (String name)
focal_class.return: void
focal_class.signature: void deleteFile(String name)
focal_class.class_method_signature: CopyOnWriteDirectory.fileLength(String name)
focal_class.full_signature: @Override public long fileLength(String name)
focal_class.identifier: fileLength
focal_class.modifiers: @Override public
focal_class.parameters: (String name)
focal_class.return: long
focal_class.signature: long fileLength(String name)
focal_class.class_method_signature: CopyOnWriteDirectory.createOutput(String name, IOContext context)
focal_class.full_signature: @Override public IndexOutput createOutput(String name, IOContext context)
focal_class.identifier: createOutput
focal_class.modifiers: @Override public
focal_class.parameters: (String name, IOContext context)
focal_class.return: IndexOutput
focal_class.signature: IndexOutput createOutput(String name, IOContext context)
focal_class.class_method_signature: CopyOnWriteDirectory.sync(Collection<String> names)
focal_class.full_signature: @Override public void sync(Collection<String> names)
focal_class.identifier: sync
focal_class.modifiers: @Override public
focal_class.parameters: (Collection<String> names)
focal_class.return: void
focal_class.signature: void sync(Collection<String> names)
focal_class.class_method_signature: CopyOnWriteDirectory.openInput(String name, IOContext context)
focal_class.full_signature: @Override public IndexInput openInput(String name, IOContext context)
focal_class.identifier: openInput
focal_class.modifiers: @Override public
focal_class.parameters: (String name, IOContext context)
focal_class.return: IndexInput
focal_class.signature: IndexInput openInput(String name, IOContext context)
focal_class.class_method_signature: CopyOnWriteDirectory.isClosed()
focal_class.full_signature: public boolean isClosed()
focal_class.identifier: isClosed
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isClosed()
focal_class.class_method_signature: CopyOnWriteDirectory.close()
focal_class.full_signature: @Override public void close()
focal_class.identifier: close
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void close()
focal_class.class_method_signature: CopyOnWriteDirectory.toString()
focal_class.full_signature: @Override public String toString()
focal_class.identifier: toString
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String toString()
focal_class.class_method_signature: CopyOnWriteDirectory.getSkippedFilesSize()
focal_class.full_signature: private long getSkippedFilesSize()
focal_class.identifier: getSkippedFilesSize
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long getSkippedFilesSize()
focal_class.class_method_signature: CopyOnWriteDirectory.deleteLocalFile(String fileName)
focal_class.full_signature: private void deleteLocalFile(String fileName)
focal_class.identifier: deleteLocalFile
focal_class.modifiers: private
focal_class.parameters: (String fileName)
focal_class.return: void
focal_class.signature: void deleteLocalFile(String fileName)
focal_class.class_method_signature: CopyOnWriteDirectory.initialize()
focal_class.full_signature: private void initialize()
focal_class.identifier: initialize
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void initialize()
focal_class.class_method_signature: CopyOnWriteDirectory.addCopyTask(final String name)
focal_class.full_signature: private void addCopyTask(final String name)
focal_class.identifier: addCopyTask
focal_class.modifiers: private
focal_class.parameters: (final String name)
focal_class.return: void
focal_class.signature: void addCopyTask(final String name)
focal_class.class_method_signature: CopyOnWriteDirectory.addDeleteTask(final String name)
focal_class.full_signature: private void addDeleteTask(final String name)
focal_class.identifier: addDeleteTask
focal_class.modifiers: private
focal_class.parameters: (final String name)
focal_class.return: void
focal_class.signature: void addDeleteTask(final String name)
focal_class.class_method_signature: CopyOnWriteDirectory.addTask(Callable<Void> task)
focal_class.full_signature: private void addTask(Callable<Void> task)
focal_class.identifier: addTask
focal_class.modifiers: private
focal_class.parameters: (Callable<Void> task)
focal_class.return: void
focal_class.signature: void addTask(Callable<Void> task)
focal_class.class_method_signature: CopyOnWriteDirectory.checkIfClosed(boolean throwException)
focal_class.full_signature: private void checkIfClosed(boolean throwException)
focal_class.identifier: checkIfClosed
focal_class.modifiers: private
focal_class.parameters: (boolean throwException)
focal_class.return: void
focal_class.signature: void checkIfClosed(boolean throwException)
focal_class.superclass: extends FilterDirectory
focal_method.body: @Override
      public void close() throws IOException {
          if (isClosed()) {
              return;
          }
  
          int pendingCopies = queue.size();
          addTask(STOP);
  
          //Wait for all pending copy task to finish
          try {
              long start = PERF_LOGGER.start();
  
              //Loop untill queue finished or IndexCopier
              //found to be closed. Doing it with timeout to
              //prevent any bug causing the thread to wait indefinitely
              while (!copyDone.await(10, TimeUnit.SECONDS)) {
                  if (indexCopier.isClosed()) {
                      throw new IndexCopierClosedException("IndexCopier found to be closed " +
                              "while processing copy task for" + remote.toString());
                  }
              }
              PERF_LOGGER.end(start, -1, "[COW][{}] Completed pending copying task {}", indexPath, pendingCopies);
          } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
              throw new IOException(e);
          }
  
          Throwable t = errorInCopy.get();
          if (t != null){
              throw new IOException("Error occurred while copying files for " + indexPath, t);
          }
  
          //Sanity check
          checkArgument(queue.isEmpty(), "Copy queue still " +
                  "has pending task left [%d]. %s", queue.size(), queue);
  
          long skippedFilesSize = getSkippedFilesSize();
  
          for (String fileName : deletedFilesLocal){
              deleteLocalFile(fileName);
          }
  
          indexCopier.skippedUpload(skippedFilesSize);
  
          String msg = "[COW][{}] CopyOnWrite stats : Skipped copying {} files with total size {}";
          if ((reindexMode && skippedFilesSize > 0) || skippedFilesSize > 10 * FileUtils.ONE_MB){
              log.info(msg, indexPath, skippedFiles.size(), humanReadableByteCount(skippedFilesSize));
          } else {
              log.debug(msg, indexPath, skippedFiles.size(), humanReadableByteCount(skippedFilesSize));
          }
  
          if (log.isTraceEnabled()){
              log.trace("[COW][{}] File listing - Upon completion {}", indexPath, Arrays.toString(remote.listAll()));
          }
  
          local.close();
          remote.close();
  
          closed = true;
      }
focal_method.class_method_signature: CopyOnWriteDirectory.close()
focal_method.full_signature: @Override public void close()
focal_method.identifier: close
focal_method.invocations: isClosed size addTask start await isClosed toString end interrupt currentThread get checkArgument isEmpty size getSkippedFilesSize deleteLocalFile skippedUpload info size humanReadableByteCount debug size humanReadableByteCount isTraceEnabled trace toString listAll close close
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void close()