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;
    }
  }
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 ) ; if ( dropExisting ) { if ( rpcService != null && changesFilter . isShared ( ) ) { rpcService . executeCommandOnAllNodes ( changeIndexState , true , false , false ) ; } else { handler . setOnline ( false , false , true ) ; } } if ( handler instanceof SearchIndex ) { if ( dropExisting ) { ( ( SearchIndex ) handler ) . getIndex ( ) . reindex ( itemMgr ) ; } else { String oldIndexPath = ( ( SearchIndex ) handler ) . getPath ( ) ; newIndexPath = oldIndexPath + SUFFIX_ASYNC_REINDEXING ; cleanIndexDirectory ( oldIndexPath + SUFFIX_ASYNC_REINDEXING ) ; 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 ) ; newIndex . setOnline ( false , true , false ) ; newIndex . reindex ( itemMgr ) ; newIndex . setOnline ( true , true , false ) ; suspend ( ) ; ( ( SearchIndex ) handler ) . getIndexRegister ( ) . unregister ( newIndex ) ; final File indexDir = new File ( oldIndexPath ) ; final File newIndexDir = new File ( oldIndexPath + SUFFIX_ASYNC_REINDEXING ) ; LOG . info ( "Try to clean old lucene indexes of the workspace '" + workspaceName + "'" ) ; cleanIndexDirectory ( oldIndexPath ) ; LOG . info ( "try to rename new lucene indexes of the workspace '" + workspaceName + "'" ) ; SecurityHelper . doPrivilegedIOExceptionAction ( ( PrivilegedExceptionAction < Void > ) ( ) -> { DirectoryHelper . renameFile ( newIndexDir , indexDir ) ; return null ; } ) ; 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 ) ; } 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 ) { if ( rpcService != null && changesFilter . isShared ( ) ) { try { 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 ; } }
Perform workspace reindexing
@param dropExisting
@param nThreads