Ejemplo n.º 1
0
 /**
  * Deletes an indexes data directory recursively. Note: this method assumes that the shard lock is
  * acquired
  *
  * @param index the index to delete
  * @param indexSettings settings for the index being deleted
  */
 public void deleteIndexDirectoryUnderLock(Index index, IndexSettings indexSettings)
     throws IOException {
   final Path[] indexPaths = indexPaths(index);
   logger.trace(
       "deleting index {} directory, paths({}): [{}]", index, indexPaths.length, indexPaths);
   IOUtils.rm(indexPaths);
   if (indexSettings.hasCustomDataPath()) {
     Path customLocation = resolveCustomLocation(indexSettings, index.name());
     logger.trace("deleting custom index {} directory [{}]", index, customLocation);
     IOUtils.rm(customLocation);
   }
 }
Ejemplo n.º 2
0
 /**
  * Deletes a shard data directory. Note: this method assumes that the shard lock is acquired. This
  * method will also attempt to acquire the write locks for the shard's paths before deleting the
  * data, but this is best effort, as the lock is released before the deletion happens in order to
  * allow the folder to be deleted
  *
  * @param lock the shards lock
  * @throws IOException if an IOException occurs
  * @throws ElasticsearchException if the write.lock is not acquirable
  */
 public void deleteShardDirectoryUnderLock(ShardLock lock, IndexSettings indexSettings)
     throws IOException {
   final ShardId shardId = lock.getShardId();
   assert isShardLocked(shardId) : "shard " + shardId + " is not locked";
   final Path[] paths = availableShardPaths(shardId);
   logger.trace("acquiring locks for {}, paths: [{}]", shardId, paths);
   acquireFSLockForPaths(indexSettings, paths);
   IOUtils.rm(paths);
   if (indexSettings.hasCustomDataPath()) {
     Path customLocation = resolveCustomLocation(indexSettings, shardId);
     logger.trace("acquiring lock for {}, custom path: [{}]", shardId, customLocation);
     acquireFSLockForPaths(indexSettings, customLocation);
     logger.trace("deleting custom shard {} directory [{}]", shardId, customLocation);
     IOUtils.rm(customLocation);
   }
   logger.trace("deleted shard {} directory, paths: [{}]", shardId, paths);
   assert FileSystemUtils.exists(paths) == false;
 }
 /**
  * Renames <code>indexFolderName</code> index folders found in node paths and custom path iff
  * {@link #needsUpgrade(Index, String)} is true. Index folder in custom paths are renamed first
  * followed by index folders in each node path.
  */
 void upgrade(final String indexFolderName) throws IOException {
   for (NodeEnvironment.NodePath nodePath : nodeEnv.nodePaths()) {
     final Path indexFolderPath = nodePath.indicesPath.resolve(indexFolderName);
     final IndexMetaData indexMetaData =
         IndexMetaData.FORMAT.loadLatestState(logger, indexFolderPath);
     if (indexMetaData != null) {
       final Index index = indexMetaData.getIndex();
       if (needsUpgrade(index, indexFolderName)) {
         logger.info("{} upgrading [{}] to new naming convention", index, indexFolderPath);
         final IndexSettings indexSettings = new IndexSettings(indexMetaData, settings);
         if (indexSettings.hasCustomDataPath()) {
           // we rename index folder in custom path before renaming them in any node path
           // to have the index state under a not-yet-upgraded index folder, which we use to
           // continue renaming after a incomplete upgrade.
           final Path customLocationSource =
               nodeEnv.resolveBaseCustomLocation(indexSettings).resolve(indexFolderName);
           final Path customLocationTarget = customLocationSource.resolveSibling(index.getUUID());
           // we rename the folder in custom path only the first time we encounter a state
           // in a node path, which needs upgrading, it is a no-op for subsequent node paths
           if (Files.exists(
                   customLocationSource) // might not exist if no data was written for this index
               && Files.exists(customLocationTarget) == false) {
             upgrade(index, customLocationSource, customLocationTarget);
           } else {
             logger.info("[{}] no upgrade needed - already upgraded", customLocationTarget);
           }
         }
         upgrade(index, indexFolderPath, indexFolderPath.resolveSibling(index.getUUID()));
       } else {
         logger.debug("[{}] no upgrade needed - already upgraded", indexFolderPath);
       }
     } else {
       logger.warn("[{}] no index state found - ignoring", indexFolderPath);
     }
   }
 }