S3Guard { public static void putWithTtl(MetadataStore ms, DirListingMetadata dirMeta, final List<Path> unchangedEntries, final ITtlTimeProvider timeProvider, @Nullable final BulkOperationState operationState) throws IOException { long now = timeProvider.getNow(); dirMeta.setLastUpdated(now); dirMeta.getListing() .forEach(pm -> pm.setLastUpdated(now)); ms.put(dirMeta, unchangedEntries, operationState); } private  S3Guard(); @Retries.OnceTranslated static MetadataStore getMetadataStore(FileSystem fs,
      ITtlTimeProvider ttlTimeProvider); @RetryTranslated static boolean refreshEntry(
      MetadataStore metadataStore,
      PathMetadata pm,
      S3AFileStatus s3AFileStatus,
      ITtlTimeProvider timeProvider); @RetryTranslated static S3AFileStatus putAndReturn(MetadataStore ms,
      S3AFileStatus status,
      ITtlTimeProvider timeProvider); @RetryTranslated static S3AFileStatus putAndReturn(
      final MetadataStore ms,
      final S3AFileStatus status,
      final ITtlTimeProvider timeProvider,
      @Nullable final BulkOperationState operationState); @RetryTranslated static void putAuthDirectoryMarker(
      final MetadataStore ms,
      final S3AFileStatus status,
      final ITtlTimeProvider timeProvider,
      @Nullable final BulkOperationState operationState); static BulkOperationState initiateBulkWrite(
      @Nullable final MetadataStore metastore,
      final BulkOperationState.OperationType operation,
      final Path path); static S3AFileStatus[] dirMetaToStatuses(DirListingMetadata dirMeta); static RemoteIterator<S3AFileStatus> dirListingUnion(
          MetadataStore ms, Path path,
          RemoteIterator<S3AFileStatus> backingStatuses,
          DirListingMetadata dirMeta, boolean isAuthoritative,
          ITtlTimeProvider timeProvider,
          Function<S3AFileStatus[], RemoteIterator<S3AFileStatus>> toStatusItr); static boolean isNullMetadataStore(MetadataStore ms); @Deprecated @Retries.OnceExceptionsSwallowed static void makeDirsOrdered(MetadataStore ms, List<Path> dirs,
      String owner, boolean authoritative, ITtlTimeProvider timeProvider); static void addMoveDir(MetadataStore ms, Collection<Path> srcPaths,
      Collection<PathMetadata> dstMetas, Path srcPath, Path dstPath,
      String owner); static void addMoveFile(MetadataStore ms, Collection<Path> srcPaths,
      Collection<PathMetadata> dstMetas, Path srcPath, Path dstPath,
      long size, long blockSize, String owner, String eTag, String versionId); static void addMoveAncestors(MetadataStore ms,
      Collection<Path> srcPaths, Collection<PathMetadata> dstMetas,
      Path srcRoot, Path srcPath, Path dstPath, String owner); @Retries.RetryTranslated static void addAncestors(
      final MetadataStore metadataStore,
      final Path qualifiedPath,
      final ITtlTimeProvider timeProvider,
      @Nullable final BulkOperationState operationState); static void assertQualified(Path p); static void assertQualified(Path...paths); static void putWithTtl(MetadataStore ms,
      DirListingMetadata dirMeta,
      final List<Path> unchangedEntries,
      final ITtlTimeProvider timeProvider,
      @Nullable final BulkOperationState operationState); static void putWithTtl(MetadataStore ms, PathMetadata fileMeta,
      @Nullable ITtlTimeProvider timeProvider,
      @Nullable final BulkOperationState operationState); static void putWithTtl(MetadataStore ms,
      Collection<? extends PathMetadata> fileMetas,
      @Nullable ITtlTimeProvider timeProvider,
      @Nullable final BulkOperationState operationState); static PathMetadata getWithTtl(MetadataStore ms, Path path,
      @Nullable ITtlTimeProvider timeProvider,
      final boolean needEmptyDirectoryFlag,
      final boolean allowAuthoritative); @RetryTranslated static DirListingMetadata listChildrenWithTtl(MetadataStore ms,
      Path path,
      @Nullable ITtlTimeProvider timeProvider,
      boolean allowAuthoritative); static Collection<String> getAuthoritativePaths(S3AFileSystem fs); static boolean allowAuthoritative(Path p, S3AFileSystem fs,
      boolean authMetadataStore, Collection<String> authPaths); static void logS3GuardDisabled(Logger logger, String warnLevelStr,
      String bucket); @InterfaceAudience.Private
  @InterfaceStability.Unstable
  @VisibleForTesting
  static final String S3GUARD_DDB_CLIENT_FACTORY_IMPL; @VisibleForTesting
  static final boolean DIR_MERGE_UPDATES_ALL_RECORDS_NONAUTH; @VisibleForTesting
  static final String DISABLED_LOG_MSG; static final String UNKNOWN_WARN_LEVEL; }
@Test public void testPutWithTtlDirListingMeta() throws Exception { DirListingMetadata dlm = new DirListingMetadata(new Path("/"), null, false); MetadataStore ms = spy(MetadataStore.class); ITtlTimeProvider timeProvider = mock(ITtlTimeProvider.class); when(timeProvider.getNow()).thenReturn(100L); S3Guard.putWithTtl(ms, dlm, Collections.emptyList(), timeProvider, null); assertEquals("last update in " + dlm, 100L, dlm.getLastUpdated()); verify(timeProvider, times(1)).getNow(); verify(ms, times(1)).put(dlm, Collections.emptyList(), null); }
@Test public void testPutWithTtlFileMeta() throws Exception { S3AFileStatus fileStatus = mock(S3AFileStatus.class); when(fileStatus.getPath()).thenReturn(new Path("/")); PathMetadata pm = new PathMetadata(fileStatus); MetadataStore ms = spy(MetadataStore.class); ITtlTimeProvider timeProvider = mock(ITtlTimeProvider.class); when(timeProvider.getNow()).thenReturn(100L); S3Guard.putWithTtl(ms, pm, timeProvider, null); assertEquals("last update in " + pm, 100L, pm.getLastUpdated()); verify(timeProvider, times(1)).getNow(); verify(ms, times(1)).put(pm, null); }
@Test public void testPutWithTtlCollection() throws Exception { S3AFileStatus fileStatus = mock(S3AFileStatus.class); when(fileStatus.getPath()).thenReturn(new Path("/")); Collection<PathMetadata> pmCollection = new ArrayList<>(); for (int i = 0; i < 10; i++) { pmCollection.add(new PathMetadata(fileStatus)); } MetadataStore ms = spy(MetadataStore.class); ITtlTimeProvider timeProvider = mock(ITtlTimeProvider.class); when(timeProvider.getNow()).thenReturn(100L); S3Guard.putWithTtl(ms, pmCollection, timeProvider, null); pmCollection.forEach( pm -> assertEquals(100L, pm.getLastUpdated()) ); verify(timeProvider, times(1)).getNow(); verify(ms, times(1)).put(pmCollection, null); }