/**
  * Acquires, then releases, all {@code write.lock} files in the given shard paths. The
  * "write.lock" file is assumed to be under the shard path's "index" directory as used by
  * Elasticsearch.
  *
  * @throws LockObtainFailedException if any of the locks could not be acquired
  */
 public static void acquireFSLockForPaths(IndexSettings indexSettings, Path... shardPaths)
     throws IOException {
   Lock[] locks = new Lock[shardPaths.length];
   Directory[] dirs = new Directory[shardPaths.length];
   try {
     for (int i = 0; i < shardPaths.length; i++) {
       // resolve the directory the shard actually lives in
       Path p = shardPaths[i].resolve("index");
       // open a directory (will be immediately closed) on the shard's location
       dirs[i] =
           new SimpleFSDirectory(
               p, indexSettings.getValue(FsDirectoryService.INDEX_LOCK_FACTOR_SETTING));
       // create a lock for the "write.lock" file
       try {
         locks[i] = dirs[i].obtainLock(IndexWriter.WRITE_LOCK_NAME);
       } catch (IOException ex) {
         throw new LockObtainFailedException(
             "unable to acquire " + IndexWriter.WRITE_LOCK_NAME + " for " + p, ex);
       }
     }
   } finally {
     IOUtils.closeWhileHandlingException(locks);
     IOUtils.closeWhileHandlingException(dirs);
   }
 }