Perform workspace reindexing
@param dropExisting
@param nThreads
428739
protected boolean doReindexing(boolean dropExisting, int nThreads) {
    boolean successful = false;
    Integer oldPoolSize = ((SearchIndex) handler).getIndexingThreadPoolSize();
    String newIndexPath = null;

    hotReindexingState = "Running. Started at " + LocalDateTime.now().format(sdf);
    try {

      isResponsibleForResuming.set(true);

      //hot async reindexing with drop exiting index data
      // set offline index state
      if (dropExisting) {
        // set offline cluster wide (will make merger disposed and volatile flushed)
        if (rpcService != null && changesFilter.isShared()) {
          rpcService.executeCommandOnAllNodes(changeIndexState, true, false, false);
        } else {
          handler.setOnline(false, false, true);
        }
      }
      // launch reindexing thread safely, resume nodes if any exception occurs
      if (handler instanceof SearchIndex) {
        if (dropExisting) {
          ((SearchIndex) handler).getIndex().reindex(itemMgr);
        } else {
          String oldIndexPath = ((SearchIndex) handler).getPath();
          newIndexPath = oldIndexPath + SUFFIX_ASYNC_REINDEXING;

          //try remove new index directory if already exist
          cleanIndexDirectory(oldIndexPath + SUFFIX_ASYNC_REINDEXING);

          //hot async reindexing without remove old index
          //create new index and register it
          MultiIndex newIndex = ((SearchIndex) handler).createNewIndex(SUFFIX_ASYNC_REINDEXING);
          ErrorLog errorLog = ((SearchIndex) handler).doInitErrorLog(newIndexPath);
          ((SearchIndex) handler).getIndexRegister().register(newIndex, errorLog);
          ((SearchIndex) handler).setIndexingThreadPoolSize(nThreads > 1 ? nThreads : 1);

          //set offline the new index
          newIndex.setOnline(false, true, false);

          //start create new index
          newIndex.reindex(itemMgr);

          //set  online to flush offline index
          newIndex.setOnline(true, true, false);

          //Suspend component, on cluster mode stop all index nodes
          //All the working threads will be suspended until the resume operation is performed.
          suspend();
          ((SearchIndex) handler).getIndexRegister().unregister(newIndex);

          final File indexDir = new File(oldIndexPath);
          final File newIndexDir = new File(oldIndexPath + SUFFIX_ASYNC_REINDEXING);

          //try remove old index directory
          LOG.info("Try to clean old lucene indexes of the workspace '" + workspaceName + "'");
          cleanIndexDirectory(oldIndexPath);

          //try rename new index folder .new
          LOG.info("try to rename new lucene indexes of the workspace '" + workspaceName + "'");
          SecurityHelper.doPrivilegedIOExceptionAction((PrivilegedExceptionAction<Void>) () -> {
            DirectoryHelper.renameFile(newIndexDir, indexDir);
            return null;
          });

          // Resume all the working threads that have been previously suspended.
          resume();
        }

        successful = true;
      } else {
        LOG.error("This kind of QuerHandler class doesn't support hot reindxing.");
      }
    } catch (RepositoryException e) {
      LOG.error("Error while reindexing the workspace", e);
    } catch (SecurityException e) {
      LOG.error("Can't change state to offline.", e);
    } catch (RPCException e) {
      LOG.error("Can't change state to offline.", e);
    } catch (IOException e) {
      LOG.error("Error while reindexing the workspace", e);
    }
    // safely change state back
    catch (SuspendException e) {
      LOG.error("Can't suspend SearchIndex component, " +
              "impossible to switch to newly created index, the old index still used", e);

    } catch (ResumeException e) {
      LOG.error("Can't resume SearchIndex component, impossible to set the index online", e);
    } finally {
      if (dropExisting) {
        // finish, setting indexes back online
        if (rpcService != null && changesFilter.isShared()) {
          try {
            // if dropExisting, then queries are no allowed
            rpcService.executeCommandOnAllNodes(changeIndexState, true, true, true);
          } catch (SecurityException e) {
            LOG.error("Error setting index back online in a cluster", e);
          } catch (RPCException e) {
            LOG.error("Error setting index back online in a cluster", e);
          }
        } else {
          try {
            handler.setOnline(true, true, true);
          } catch (IOException e) {
            LOG.error("Error setting index back online locally");
          }
        }
      } else {
        ((SearchIndex) handler).setIndexingThreadPoolSize(oldPoolSize);
      }
      if (successful) {
        hotReindexingState = "Finished at " + LocalDateTime.now().format(sdf);
        LOG.info("Reindexing finished successfully.");
      } else {
        hotReindexingState = "Stopped with errors at " + LocalDateTime.now().format(sdf);
        LOG.info("Reindexing halted with errors.");
        if (!dropExisting) {
          try {
            if (newIndexPath != null)
              cleanIndexDirectory(newIndexPath);
          } catch (IOException e) {
            LOG.error("Error while removing the folder of the index used for the hot reindexing", e);

          }
        }
      }
      isResponsibleForResuming.set(false);

      return successful;
    }
  }
217179
public void setBackupThreadCount( final int backupThreadCount ) {
        final int oldBackupThreadCount = _backupThreadCount;
        _backupThreadCount = backupThreadCount;
        if ( _manager.isInitialized() ) {
            _log.info( "Changed backupThreadCount from " + oldBackupThreadCount + " to " + _backupThreadCount + "." +
                    " Reloading configuration..." );
            reloadMemcachedConfig( _memcachedNodes, _failoverNodes );
            _log.info( "Finished reloading configuration." );
        }
    }
636562
public static ExecutorService newBlockingFixedThreadPoolExecutor(int nThreads, int queueSize) {
        BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(queueSize);
        RejectedExecutionHandler blockingRejectedExecutionHandler = new RejectedExecutionHandler() {
            @Override
            public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {
                try {
                    executor.getQueue().put(task);
                } catch (InterruptedException e) {
                }
            }

        };

        return new ThreadPoolExecutor(nThreads, nThreads,
                0L, TimeUnit.MILLISECONDS, blockingQueue,
                blockingRejectedExecutionHandler);
    }
262926
protected void workspaceAdded( String workspaceName ) {
        String workspaceKey = NodeKey.keyForWorkspaceName(workspaceName);
        if (systemWorkspaceKey.equals(workspaceKey)) {
            // No sequencers for the system workspace!
            return;
        }
        Collection<SequencingConfiguration> configs = new LinkedList<SequencingConfiguration>();
        // Go through the sequencers to see which apply to this workspace ...
        for (Sequencer sequencer : sequencersById.values()) {
            boolean updated = false;
            for (SequencerPathExpression expression : pathExpressionsBySequencerId.get(sequencer.getUniqueId())) {
                if (expression.appliesToWorkspace(workspaceName)) {
                    updated = true;
                    configs.add(new SequencingConfiguration(expression, sequencer));
                }
            }
            if (DEBUG && updated) {
                LOGGER.debug("Updated sequencer '{0}' (id={1}) configuration due to new workspace '{2}' in repository '{3}'",
                             sequencer.getName(), sequencer.getUniqueId(), workspaceName, repository.name());
            }
        }
        if (configs.isEmpty()) return;
        // Otherwise, update the configs by workspace key ...
        try {
            configChangeLock.lock();
            // Make a copy of the existing map ...
            Map<String, Collection<SequencingConfiguration>> configByWorkspaceName = new HashMap<String, Collection<SequencingConfiguration>>(
                                                                                                                                              this.configByWorkspaceName);
            // Insert the new information ...
            configByWorkspaceName.put(workspaceName, configs);
            // Replace the exisiting map (which is used without a lock) ...
            this.configByWorkspaceName = configByWorkspaceName;
        } finally {
            configChangeLock.unlock();
        }
    }
1363228
@Override
    public void destroyWorkspace() {
        ensureThreadExistense();

        MemoryWorkspace workspace = backingMap.get().get(MemoryWorkspace.DEFAULT_ID);
        //if (workspace != null)
        //workspace.destroyWorkspace();

        backingMap.get().remove(MemoryWorkspace.DEFAULT_ID);
    }
322047
public void setRebootWorkspaceRequests(java.util.Collection<RebootRequest> rebootWorkspaceRequests) {
        if (rebootWorkspaceRequests == null) {
            this.rebootWorkspaceRequests = null;
            return;
        }

        this.rebootWorkspaceRequests = new com.amazonaws.internal.SdkInternalList<RebootRequest>(rebootWorkspaceRequests);
    }
1154461
private void remove(Thread t) {
        synchronized (this) {
            if (destroyed) {
                return;
            }
            for (int i = 0 ; i < nthreads ; i++) {
                if (threads[i] == t) {
                    System.arraycopy(threads, i + 1, threads, i, --nthreads - i);
                    // Zap dangling reference to the dead thread so that
                    // the garbage collector will collect it.
                    threads[nthreads] = null;
                    break;
                }
            }
        }
    }
949580
@Override
    protected void nibble(Queue<DuplicationMorsel> queue) {
        DuplicationMorsel morsel = queue.poll();
        String account = morsel.getAccount();
        String spaceId = morsel.getSpaceId();
        DuplicationStorePolicy storePolicy = morsel.getStorePolicy();

        //get all items from source
        StorageProvider sourceProvider =
            getStorageProvider(account, storePolicy.getSrcStoreId());
        StorageProvider destProvider =
            getStorageProvider(account, storePolicy.getDestStoreId());

        if (!morsel.isDeletePerformed()) {
            addDuplicationTasksForContentNotInSource(account,
                                                     spaceId,
                                                     storePolicy,
                                                     sourceProvider,
                                                     destProvider);
            morsel.setDeletePerformed(true);
        }

        int maxTaskQueueSize = getMaxTaskQueueSize();
        int taskQueueSize = getTaskQueue().size();
        if (taskQueueSize >= maxTaskQueueSize) {
            log.info("Task queue size ({}) has reached or exceeded max size ({}).",
                     taskQueueSize, maxTaskQueueSize);
            addToReloadList(morsel);
        } else {
            if (addDuplicationTasksFromSource(morsel, sourceProvider, 1000)) {
                log.info("All tasks that could be created were created for account={}, spaceId={}, storePolicy={}. " +
                         "getTaskQueue().size = {}", account, spaceId, storePolicy, getTaskQueue().size());
                log.info("morsel completely nibbled. No reload necessary in this round.", morsel);
            } else {
                log.info("morsel nibbled a bit: {}", morsel);
                addToReloadList(morsel);
            }

        }
    }
1179852
@Override
  public void removeNamespace(final MongoNamespace namespace) {
    this.instanceLock.writeLock().lock();
    try {
      if (!this.nsStreamers.containsKey(namespace)) {
        return;
      }
      final NamespaceChangeStreamListener streamer = this.nsStreamers.get(namespace);
      streamer.stop();
      this.nsStreamers.remove(namespace);
    } finally {
      this.instanceLock.writeLock().unlock();
    }
  }
424817
@Override
    public final void dropCatalog(ClusterName targetCluster, CatalogName name) throws UnsupportedException,

            ExecutionException {

        try {
            connectionHandler.startJob(targetCluster.getName());

            if (logger.isDebugEnabled()) {
                logger.debug("Dropping catalog [" + name.getName() + "] in cluster [" + targetCluster.getName() + "]");
            }

            dropCatalog(name, connectionHandler.getConnection(targetCluster.getName()));
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Catalog [" + name.getName() + "] has been drepped successfully in cluster [" + targetCluster
                                .getName() + "]");
            }
        } finally {
            connectionHandler.endJob(targetCluster.getName());
        }

    }
1124020
private void reindexContent( boolean includeSystemContent,
                                 IndexWriter indexes ) {
        if (indexes.canBeSkipped()) return;
        // The node type schemata changes every time a node type is (un)registered, so get the snapshot that we'll use throughout
        RepositoryCache repoCache = runningState.repositoryCache();

        logger.debug(JcrI18n.reindexAll.text(runningState.name()));

        if (includeSystemContent) {
            String systemWorkspaceName = repoCache.getSystemWorkspaceName();
            updateIndexesStatus(systemWorkspaceName, IndexManager.IndexStatus.ENABLED, IndexManager.IndexStatus.REINDEXING);
            NodeCache systemWorkspaceCache = repoCache.getWorkspaceCache(systemWorkspaceName);
            CachedNode rootNode = systemWorkspaceCache.getNode(repoCache.getSystemKey());
            // Index the system content ...
            logger.debug("Starting reindex of system content in '{0}' repository.", runningState.name());
            if (reindexSystemContent(rootNode, Integer.MAX_VALUE, indexes)) {
                commitChanges(systemWorkspaceName);
            }
            logger.debug("Completed reindex of system content in '{0}' repository.", runningState.name());
            updateIndexesStatus(systemWorkspaceName, IndexManager.IndexStatus.REINDEXING, IndexManager.IndexStatus.ENABLED);
        }

        // Index the non-system workspaces ...
        for (String workspaceName : repoCache.getWorkspaceNames()) {
            // change the status of the indexes to reindexing
            updateIndexesStatus(workspaceName, IndexManager.IndexStatus.ENABLED, IndexManager.IndexStatus.REINDEXING);
            NodeCache workspaceCache = repoCache.getWorkspaceCache(workspaceName);
            CachedNode rootNode = workspaceCache.getNode(workspaceCache.getRootKey());
            logger.debug("Starting reindex of workspace '{0}' content in '{1}' repository.", runningState.name(), workspaceName);
            if (reindexContent(workspaceName, workspaceCache, rootNode, Integer.MAX_VALUE, false, indexes)) {
                commitChanges(workspaceName);
            }
            logger.debug("Completed reindex of workspace '{0}' content in '{1}' repository.", runningState.name(), workspaceName);
            updateIndexesStatus(workspaceName, IndexManager.IndexStatus.REINDEXING, IndexManager.IndexStatus.ENABLED);
        }
    }
946752
private void consumeCompaction(CompactionUpdateBatch updateBatch) throws Exception {
        int ignoreCount = 0;
        int updateCount = updateBatch.size();
        int totalIgnoreBytes = 0;
        int totalUpdateBytes = updateBatch.getDataSizeTotal();
        
        /* Using lwMark is to guarantee that redo logs from compaction will not increase
         * the hwMark of the underlying array file. If hwMark is being used, the current
         * redo entry is discarded upon crash. Upon restart, the hwMark from the underlying
         * array file may prevent updates in the lost redo entry from being resent.   
         */
        long updateScn = _addressArray.getLWMark();
        Segment segTarget = updateBatch.getTargetSegment();
        
        for(int i = 0; i < updateCount; i++) {
            int index = updateBatch.getUpdateIndex(i);
            long origAddr = updateBatch.getOriginDataAddr(i);
            long currAddr = getAddress(index);
            
            if(currAddr == 0 ||      /* data at the given index is deleted by writer */ 
               currAddr != origAddr  /* data at the given index is updated by writer */) {
                /*
                 * The address generated by the compactor is obsolete.
                 */
                int updateBytes = updateBatch.getUpdateDataSize(i);
                totalIgnoreBytes += updateBytes;
                ignoreCount++;
            } else {
                /*
                 * The address generated by the compactor has not been touched by the writer.
                 * Update the address array directly.
                 */ 
                setCompactionAddress(index, updateBatch.getUpdateDataAddr(i), updateScn);
            }
        }
        
        int consumeCount = updateCount - ignoreCount;
        int totalConsumeBytes = totalUpdateBytes - totalIgnoreBytes;
        
        if(_log.isTraceEnabled()) {
            _log.trace("consumed compaction batch " +
                       updateBatch.getDescriptiveId() +
                       " updates " + consumeCount + "/" + updateCount +
                       " bytes " + totalConsumeBytes + "/" + totalUpdateBytes);
        }
        
        // Update segment load size
        segTarget.decrLoadSize(totalIgnoreBytes);
    }
295524
private void pruneTracks(SetTrackInfo<Desc> info, GrowQueue_I32 unassociated) {
		if( unassociated.size > maxInactiveTracks ) {
			// make the first N elements the ones which will be dropped
			int numDrop = unassociated.size-maxInactiveTracks;
			for (int i = 0; i < numDrop; i++) {
				int selected = rand.nextInt(unassociated.size-i)+i;
				int a = unassociated.get(i);
				unassociated.data[i] = unassociated.data[selected];
				unassociated.data[selected] = a;
			}
			List<PointTrack> dropList = new ArrayList<>();
			for (int i = 0; i < numDrop; i++) {
				dropList.add( info.tracks.get(unassociated.get(i)) );
			}
			for (int i = 0; i < dropList.size(); i++) {
				dropTrack(dropList.get(i));
			}
		}
	}
1279311
public Future<Boolean> reindexContentAsync( final JcrWorkspace workspace ) {
        return indexingExecutorService.submit(() -> {
            reindexContent(workspace);
            return Boolean.TRUE;
        });
    }
932605
def flushIndexes(self) :
		""
		for n in self.getIndexes(rabaOnly = True) :
			self.dropIndexByName(n[1])
318573
public void setStartWorkspaceRequests(java.util.Collection<StartRequest> startWorkspaceRequests) {
        if (startWorkspaceRequests == null) {
            this.startWorkspaceRequests = null;
            return;
        }

        this.startWorkspaceRequests = new com.amazonaws.internal.SdkInternalList<StartRequest>(startWorkspaceRequests);
    }
361750
protected void purgeZeroObject(Long bucketId, Long objectId, AllocationPoint point, boolean copyback) {
        allocationsMap.remove(objectId);

        memoryHandler.purgeZeroObject(bucketId, objectId, point, copyback);

        getFlowController().getEventsProvider().storeEvent(point.getLastWriteEvent());
        getFlowController().getEventsProvider().storeEvent(point.getLastReadEvent());
    }