示例#1
0
  /**
   * Rename the files. This works around some limitations of both FileContext (no s3n support) and
   * NativeS3FileSystem.rename which will not overwrite
   *
   * @param outputFS The output fs
   * @param indexZipFilePath The original file path
   * @param finalIndexZipFilePath The to rename the original file to
   * @return False if a rename failed, true otherwise (rename success or no rename needed)
   */
  private static boolean renameIndexFiles(
      final FileSystem outputFS, final Path indexZipFilePath, final Path finalIndexZipFilePath) {
    try {
      return RetryUtils.retry(
          new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
              final boolean needRename;

              if (outputFS.exists(finalIndexZipFilePath)) {
                // NativeS3FileSystem.rename won't overwrite, so we might need to delete the old
                // index first
                final FileStatus zipFile = outputFS.getFileStatus(indexZipFilePath);
                final FileStatus finalIndexZipFile = outputFS.getFileStatus(finalIndexZipFilePath);

                if (zipFile.getModificationTime() >= finalIndexZipFile.getModificationTime()
                    || zipFile.getLen() != finalIndexZipFile.getLen()) {
                  log.info(
                      "File[%s / %s / %sB] existed, but wasn't the same as [%s / %s / %sB]",
                      finalIndexZipFile.getPath(),
                      new DateTime(finalIndexZipFile.getModificationTime()),
                      finalIndexZipFile.getLen(),
                      zipFile.getPath(),
                      new DateTime(zipFile.getModificationTime()),
                      zipFile.getLen());
                  outputFS.delete(finalIndexZipFilePath, false);
                  needRename = true;
                } else {
                  log.info(
                      "File[%s / %s / %sB] existed and will be kept",
                      finalIndexZipFile.getPath(),
                      new DateTime(finalIndexZipFile.getModificationTime()),
                      finalIndexZipFile.getLen());
                  needRename = false;
                }
              } else {
                needRename = true;
              }

              if (needRename) {
                log.info(
                    "Attempting rename from [%s] to [%s]", indexZipFilePath, finalIndexZipFilePath);
                return outputFS.rename(indexZipFilePath, finalIndexZipFilePath);
              } else {
                return true;
              }
            }
          },
          FileUtils.IS_EXCEPTION,
          NUM_RETRIES);
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
示例#2
0
 public <T> T retryTransaction(
     final TransactionCallback<T> callback, final int quietTries, final int maxTries) {
   final Callable<T> call =
       new Callable<T>() {
         @Override
         public T call() throws Exception {
           return getDBI().inTransaction(callback);
         }
       };
   try {
     return RetryUtils.retry(call, shouldRetry, quietTries, maxTries);
   } catch (Exception e) {
     throw Throwables.propagate(e);
   }
 }
示例#3
0
 public <T> T retryWithHandle(
     final HandleCallback<T> callback, final Predicate<Throwable> myShouldRetry) {
   final Callable<T> call =
       new Callable<T>() {
         @Override
         public T call() throws Exception {
           return getDBI().withHandle(callback);
         }
       };
   try {
     return RetryUtils.retry(call, myShouldRetry, DEFAULT_MAX_TRIES);
   } catch (Exception e) {
     throw Throwables.propagate(e);
   }
 }