2424
2525import  java .io .IOException ;
2626import  java .util .ArrayList ;
27+ import  java .util .HashMap ;
2728import  java .util .HashSet ;
2829import  java .util .List ;
30+ import  java .util .Map ;
2931import  java .util .Objects ;
32+ import  java .util .Optional ;
3033import  java .util .Set ;
3134import  java .util .stream .Collectors ;
3235import  org .apache .hadoop .conf .Configuration ;
@@ -230,6 +233,37 @@ public void testExportWithTargetName() throws Exception {
230233    testExportFileSystemState (tableName , snapshotName , targetName , tableNumFiles );
231234  }
232235
236+   @ Test 
237+   public  void  testExportWithResetTtl () throws  Exception  {
238+     String  name  = "testExportWithResetTtl" ;
239+     TableName  tableName  = TableName .valueOf (name );
240+     String  snapshotName  = "snaptb-"  + name ;
241+     Long  ttl  = 100000L ;
242+ 
243+     try  {
244+       // create Table 
245+       createTable (tableName );
246+       SnapshotTestingUtils .loadData (TEST_UTIL , tableName , 50 , FAMILY );
247+       int  tableNumFiles  = admin .getRegions (tableName ).size ();
248+       // take a snapshot with TTL 
249+       Map <String , Object > props  = new  HashMap <>();
250+       props .put ("TTL" , ttl );
251+       admin .snapshot (snapshotName , tableName , props );
252+       Optional <Long > ttlOpt  =
253+         admin .listSnapshots ().stream ().filter (s  -> s .getName ().equals (snapshotName ))
254+           .map (org .apache .hadoop .hbase .client .SnapshotDescription ::getTtl ).findAny ();
255+       assertTrue (ttlOpt .isPresent ());
256+       assertEquals (ttl , ttlOpt .get ());
257+ 
258+       testExportFileSystemState (tableName , snapshotName , snapshotName , tableNumFiles ,
259+         getHdfsDestinationDir (), false , true );
260+     } catch  (Exception  e ) {
261+       throw  e ;
262+     } finally  {
263+       TEST_UTIL .deleteTable (tableName );
264+     }
265+   }
266+ 
233267  private  void  testExportFileSystemState (final  TableName  tableName , final  String  snapshotName ,
234268    final  String  targetName , int  filesExpected ) throws  Exception  {
235269    testExportFileSystemState (tableName , snapshotName , targetName , filesExpected ,
@@ -238,8 +272,15 @@ private void testExportFileSystemState(final TableName tableName, final String s
238272
239273  protected  void  testExportFileSystemState (final  TableName  tableName , final  String  snapshotName ,
240274    final  String  targetName , int  filesExpected , Path  copyDir , boolean  overwrite ) throws  Exception  {
275+     testExportFileSystemState (tableName , snapshotName , targetName , filesExpected , copyDir ,
276+       overwrite , false );
277+   }
278+ 
279+   protected  void  testExportFileSystemState (final  TableName  tableName , final  String  snapshotName ,
280+     final  String  targetName , int  filesExpected , Path  copyDir , boolean  overwrite , boolean  resetTtl )
281+     throws  Exception  {
241282    testExportFileSystemState (TEST_UTIL .getConfiguration (), tableName , snapshotName , targetName ,
242-       filesExpected , TEST_UTIL .getDefaultRootDirPath (), copyDir , overwrite ,
283+       filesExpected , TEST_UTIL .getDefaultRootDirPath (), copyDir , overwrite ,  resetTtl , 
243284      getBypassRegionPredicate (), true );
244285  }
245286
@@ -249,7 +290,8 @@ protected void testExportFileSystemState(final TableName tableName, final String
249290  protected  static  void  testExportFileSystemState (final  Configuration  conf ,
250291    final  TableName  tableName , final  String  snapshotName , final  String  targetName ,
251292    final  int  filesExpected , final  Path  srcDir , Path  rawTgtDir , final  boolean  overwrite ,
252-     final  RegionPredicate  bypassregionPredicate , boolean  success ) throws  Exception  {
293+     final  boolean  resetTtl , final  RegionPredicate  bypassregionPredicate , boolean  success )
294+     throws  Exception  {
253295    FileSystem  tgtFs  = rawTgtDir .getFileSystem (conf );
254296    FileSystem  srcFs  = srcDir .getFileSystem (conf );
255297    Path  tgtDir  = rawTgtDir .makeQualified (tgtFs .getUri (), tgtFs .getWorkingDirectory ());
@@ -267,6 +309,9 @@ protected static void testExportFileSystemState(final Configuration conf,
267309    if  (overwrite ) {
268310      opts .add ("--overwrite" );
269311    }
312+     if  (resetTtl ) {
313+       opts .add ("--reset-ttl" );
314+     }
270315
271316    // Export Snapshot 
272317    int  res  = run (conf , new  ExportSnapshot (), opts .toArray (new  String [opts .size ()]));
@@ -295,7 +340,7 @@ protected static void testExportFileSystemState(final Configuration conf,
295340    final  Path  targetDir  = new  Path (HConstants .SNAPSHOT_DIR_NAME , targetName );
296341    verifySnapshotDir (srcFs , new  Path (srcDir , snapshotDir ), tgtFs , new  Path (tgtDir , targetDir ));
297342    Set <String > snapshotFiles  =
298-       verifySnapshot (conf , tgtFs , tgtDir , tableName , targetName , bypassregionPredicate );
343+       verifySnapshot (conf , tgtFs , tgtDir , tableName , targetName , resetTtl ,  bypassregionPredicate );
299344    assertEquals (filesExpected , snapshotFiles .size ());
300345  }
301346
@@ -312,7 +357,7 @@ protected static void verifySnapshotDir(final FileSystem fs1, final Path root1,
312357   */ 
313358  protected  static  Set <String > verifySnapshot (final  Configuration  conf , final  FileSystem  fs ,
314359    final  Path  rootDir , final  TableName  tableName , final  String  snapshotName ,
315-     final  RegionPredicate  bypassregionPredicate ) throws  IOException  {
360+     final  boolean   resetTtl ,  final   RegionPredicate  bypassregionPredicate ) throws  IOException  {
316361    final  Path  exportedSnapshot  =
317362      new  Path (rootDir , new  Path (HConstants .SNAPSHOT_DIR_NAME , snapshotName ));
318363    final  Set <String > snapshotFiles  = new  HashSet <>();
@@ -354,6 +399,9 @@ private void verifyNonEmptyFile(final Path path) throws IOException {
354399    SnapshotDescription  desc  = SnapshotDescriptionUtils .readSnapshotInfo (fs , exportedSnapshot );
355400    assertTrue (desc .getName ().equals (snapshotName ));
356401    assertTrue (desc .getTable ().equals (tableName .getNameAsString ()));
402+     if  (resetTtl ) {
403+       assertEquals (HConstants .DEFAULT_SNAPSHOT_TTL , desc .getTtl ());
404+     }
357405    return  snapshotFiles ;
358406  }
359407
0 commit comments