/** Returns all index paths. */
 public Path[] indexPaths(Index index) {
   assert assertEnvIsLocked();
   Path[] indexPaths = new Path[nodePaths.length];
   for (int i = 0; i < nodePaths.length; i++) {
     indexPaths[i] = nodePaths[i].indicesPath.resolve(index.name());
   }
   return indexPaths;
 }
Exemplo n.º 2
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);
   }
 }
 /**
  * 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 Settings indexSettings)
     throws IOException {
   // This is to ensure someone doesn't use Settings.EMPTY
   assert indexSettings != Settings.EMPTY;
   final Path[] indexPaths = indexPaths(index);
   logger.trace(
       "deleting index {} directory, paths({}): [{}]", index, indexPaths.length, indexPaths);
   IOUtils.rm(indexPaths);
   if (hasCustomDataPath(indexSettings)) {
     Path customLocation = resolveCustomLocation(indexSettings, index.name());
     logger.trace("deleting custom index {} directory [{}]", index, customLocation);
     IOUtils.rm(customLocation);
   }
 }
  protected BlobStoreIndexGateway(
      Index index, @IndexSettings Settings indexSettings, Gateway gateway) {
    super(index, indexSettings);

    if (gateway.type().equals(NoneGateway.TYPE)) {
      logger.warn(
          "index gateway is configured, but no cluster level gateway configured, cluster level metadata will be lost on full shutdown");
    }

    this.gateway = (BlobStoreGateway) gateway;
    this.blobStore = this.gateway.blobStore();

    this.chunkSize = componentSettings.getAsBytesSize("chunk_size", this.gateway.chunkSize());

    this.indexPath = this.gateway.basePath().add("indices").add(index.name());
  }
 /**
  * Tries to find all allocated shards for the given index on the current node. NOTE: This methods
  * is prone to race-conditions on the filesystem layer since it might not see directories created
  * concurrently or while it's traversing.
  *
  * @param index the index to filter shards
  * @return a set of shard IDs
  * @throws IOException if an IOException occurs
  */
 public Set<ShardId> findAllShardIds(final Index index) throws IOException {
   assert index != null;
   if (nodePaths == null || locks == null) {
     throw new IllegalStateException("node is not configured to store local location");
   }
   assert assertEnvIsLocked();
   final Set<ShardId> shardIds = Sets.newHashSet();
   String indexName = index.name();
   for (final NodePath nodePath : nodePaths) {
     Path location = nodePath.indicesPath;
     if (Files.isDirectory(location)) {
       try (DirectoryStream<Path> indexStream = Files.newDirectoryStream(location)) {
         for (Path indexPath : indexStream) {
           if (indexName.equals(indexPath.getFileName().toString())) {
             shardIds.addAll(findAllShardsForIndex(indexPath));
           }
         }
       }
     }
   }
   return shardIds;
 }
 /** Resolves the given indexes directory against this NodePath */
 public Path resolve(Index index) {
   return indicesPath.resolve(index.name());
 }