16
16
*/
17
17
package org .apache .hadoop .ozone .om ;
18
18
19
- import org .apache .commons .lang3 .RandomStringUtils ;
20
19
import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
21
20
import org .apache .hadoop .hdds .conf .StorageUnit ;
22
21
import org .apache .hadoop .hdds .utils .IOUtils ;
65
64
import java .util .UUID ;
66
65
import java .util .concurrent .TimeUnit ;
67
66
import java .util .concurrent .TimeoutException ;
67
+ import java .util .concurrent .atomic .AtomicInteger ;
68
68
import java .util .concurrent .atomic .AtomicLong ;
69
69
import java .util .concurrent .atomic .AtomicReference ;
70
70
88
88
*/
89
89
@ Timeout (5000 )
90
90
public class TestSnapshotBackgroundServices {
91
-
92
- private MiniOzoneHAClusterImpl cluster = null ;
91
+ private MiniOzoneHAClusterImpl cluster ;
93
92
private ObjectStore objectStore ;
94
93
private OzoneBucket ozoneBucket ;
95
94
private String volumeName ;
96
95
private String bucketName ;
97
96
98
97
private static final long SNAPSHOT_THRESHOLD = 50 ;
99
98
private static final int LOG_PURGE_GAP = 50 ;
100
- // This test depends on direct RocksDB checks that are easier done with OBS
101
- // buckets.
102
- private static final BucketLayout TEST_BUCKET_LAYOUT =
103
- BucketLayout .OBJECT_STORE ;
104
- private static final String SNAPSHOT_NAME_PREFIX = "snapshot" ;
99
+ // This test depends on direct RocksDB checks that are easier done with OBS buckets.
100
+ private static final BucketLayout TEST_BUCKET_LAYOUT = BucketLayout .OBJECT_STORE ;
101
+ private static final String SNAPSHOT_NAME_PREFIX = "snapshot-" ;
102
+ private static final String KEY_NAME_PREFIX = "key-" ;
105
103
private OzoneClient client ;
104
+ private final AtomicInteger counter = new AtomicInteger ();
106
105
107
106
/**
108
107
* Create a MiniOzoneCluster for testing. The cluster initially has one
@@ -174,12 +173,12 @@ public void init(TestInfo testInfo) throws Exception {
174
173
client = OzoneClientFactory .getRpcClient (omServiceId , conf );
175
174
objectStore = client .getObjectStore ();
176
175
177
- volumeName = "volume" + RandomStringUtils . randomNumeric ( 5 );
178
- bucketName = "bucket" + RandomStringUtils . randomNumeric ( 5 );
176
+ volumeName = "volume" + counter . incrementAndGet ( );
177
+ bucketName = "bucket" + counter . incrementAndGet ( );
179
178
180
179
VolumeArgs createVolumeArgs = VolumeArgs .newBuilder ()
181
- .setOwner ("user" + RandomStringUtils . randomNumeric ( 5 ))
182
- .setAdmin ("admin" + RandomStringUtils . randomNumeric ( 5 ))
180
+ .setOwner ("user" + counter . incrementAndGet ( ))
181
+ .setAdmin ("admin" + counter . incrementAndGet ( ))
183
182
.build ();
184
183
185
184
objectStore .createVolume (volumeName , createVolumeArgs );
@@ -224,8 +223,7 @@ public void testSnapshotAndKeyDeletionBackgroundServices()
224
223
cluster .getOzoneManager (leaderOM .getOMNodeId ());
225
224
assertEquals (leaderOM , newFollowerOM );
226
225
227
- SnapshotInfo newSnapshot = createOzoneSnapshot (newLeaderOM ,
228
- SNAPSHOT_NAME_PREFIX + RandomStringUtils .randomNumeric (5 ));
226
+ SnapshotInfo newSnapshot = createOzoneSnapshot (newLeaderOM , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ());
229
227
230
228
/*
231
229
Check whether newly created key data is reclaimed
@@ -250,8 +248,7 @@ public void testSnapshotAndKeyDeletionBackgroundServices()
250
248
assertNotNull (keyInfoA );
251
249
252
250
// create snapshot b
253
- SnapshotInfo snapshotInfoB = createOzoneSnapshot (newLeaderOM ,
254
- SNAPSHOT_NAME_PREFIX + RandomStringUtils .randomNumeric (5 ));
251
+ SnapshotInfo snapshotInfoB = createOzoneSnapshot (newLeaderOM , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ());
255
252
assertNotNull (snapshotInfoB );
256
253
257
254
// delete key a
@@ -261,8 +258,7 @@ public void testSnapshotAndKeyDeletionBackgroundServices()
261
258
() -> !isKeyInTable (keyA , omKeyInfoTable ));
262
259
263
260
// create snapshot c
264
- SnapshotInfo snapshotInfoC = createOzoneSnapshot (newLeaderOM ,
265
- SNAPSHOT_NAME_PREFIX + RandomStringUtils .randomNumeric (5 ));
261
+ SnapshotInfo snapshotInfoC = createOzoneSnapshot (newLeaderOM , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ());
266
262
267
263
// get snapshot c
268
264
OmSnapshot snapC ;
@@ -279,8 +275,7 @@ public void testSnapshotAndKeyDeletionBackgroundServices()
279
275
() -> isKeyInTable (keyA , snapC .getMetadataManager ().getDeletedTable ()));
280
276
281
277
// create snapshot d
282
- SnapshotInfo snapshotInfoD = createOzoneSnapshot (newLeaderOM ,
283
- SNAPSHOT_NAME_PREFIX + RandomStringUtils .randomNumeric (5 ));
278
+ SnapshotInfo snapshotInfoD = createOzoneSnapshot (newLeaderOM , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ());
284
279
285
280
// delete snapshot c
286
281
client .getObjectStore ()
@@ -533,18 +528,14 @@ public void testSSTFilteringBackgroundService()
533
528
private void confirmSnapDiffForTwoSnapshotsDifferingBySingleKey (
534
529
OzoneManager ozoneManager )
535
530
throws IOException , InterruptedException , TimeoutException {
536
- String firstSnapshot = createOzoneSnapshot (ozoneManager ,
537
- TestSnapshotBackgroundServices .SNAPSHOT_NAME_PREFIX +
538
- RandomStringUtils .randomNumeric (10 )).getName ();
531
+ String firstSnapshot = createOzoneSnapshot (ozoneManager , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ())
532
+ .getName ();
539
533
String diffKey = writeKeys (1 ).get (0 );
540
- String secondSnapshot = createOzoneSnapshot (ozoneManager ,
541
- TestSnapshotBackgroundServices .SNAPSHOT_NAME_PREFIX +
542
- RandomStringUtils .randomNumeric (10 )).getName ();
543
- SnapshotDiffReportOzone diff = getSnapDiffReport (volumeName , bucketName ,
544
- firstSnapshot , secondSnapshot );
534
+ String secondSnapshot = createOzoneSnapshot (ozoneManager , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ())
535
+ .getName ();
536
+ SnapshotDiffReportOzone diff = getSnapDiffReport (volumeName , bucketName , firstSnapshot , secondSnapshot );
545
537
assertEquals (Collections .singletonList (
546
- SnapshotDiffReportOzone .getDiffReportEntry (
547
- SnapshotDiffReport .DiffType .CREATE , diffKey , null )),
538
+ SnapshotDiffReportOzone .getDiffReportEntry (SnapshotDiffReport .DiffType .CREATE , diffKey , null )),
548
539
diff .getDiffList ());
549
540
}
550
541
@@ -574,9 +565,7 @@ private static File getSstBackupDir(OzoneManager ozoneManager) {
574
565
private void checkIfSnapshotGetsProcessedBySFS (OzoneManager ozoneManager )
575
566
throws IOException , TimeoutException , InterruptedException {
576
567
writeKeys (1 );
577
- SnapshotInfo newSnapshot = createOzoneSnapshot (ozoneManager ,
578
- TestSnapshotBackgroundServices .SNAPSHOT_NAME_PREFIX +
579
- RandomStringUtils .randomNumeric (5 ));
568
+ SnapshotInfo newSnapshot = createOzoneSnapshot (ozoneManager , SNAPSHOT_NAME_PREFIX + counter .incrementAndGet ());
580
569
assertNotNull (newSnapshot );
581
570
Table <String , SnapshotInfo > snapshotInfoTable =
582
571
ozoneManager .getMetadataManager ().getSnapshotInfoTable ();
@@ -640,22 +629,17 @@ private SnapshotDiffReportOzone getSnapDiffReport(String volume,
640
629
return response .get ().getSnapshotDiffReport ();
641
630
}
642
631
643
- private SnapshotInfo createOzoneSnapshot (OzoneManager leaderOM , String name )
644
- throws IOException {
632
+ private SnapshotInfo createOzoneSnapshot (OzoneManager leaderOM , String name ) throws IOException {
645
633
objectStore .createSnapshot (volumeName , bucketName , name );
646
634
647
- String tableKey = SnapshotInfo .getTableKey (volumeName ,
648
- bucketName ,
649
- name );
635
+ String tableKey = SnapshotInfo .getTableKey (volumeName , bucketName , name );
650
636
SnapshotInfo snapshotInfo = leaderOM .getMetadataManager ()
651
637
.getSnapshotInfoTable ()
652
638
.get (tableKey );
653
639
// Allow the snapshot to be written to disk
654
- String fileName =
655
- getSnapshotPath (leaderOM .getConfiguration (), snapshotInfo );
640
+ String fileName = getSnapshotPath (leaderOM .getConfiguration (), snapshotInfo );
656
641
File snapshotDir = new File (fileName );
657
- if (!RDBCheckpointUtils
658
- .waitForCheckpointDirectoryExist (snapshotDir )) {
642
+ if (!RDBCheckpointUtils .waitForCheckpointDirectoryExist (snapshotDir )) {
659
643
throw new IOException ("snapshot directory doesn't exist" );
660
644
}
661
645
return snapshotInfo ;
@@ -665,7 +649,9 @@ private List<String> writeKeys(long keyCount) throws IOException {
665
649
List <String > keys = new ArrayList <>();
666
650
long index = 0 ;
667
651
while (index < keyCount ) {
668
- keys .add (createKey (ozoneBucket ));
652
+ String key = KEY_NAME_PREFIX + counter .incrementAndGet ();
653
+ createKey (ozoneBucket , key );
654
+ keys .add (key );
669
655
index ++;
670
656
}
671
657
return keys ;
@@ -679,5 +665,4 @@ private void readKeys(List<String> keys) throws IOException {
679
665
inputStream .close ();
680
666
}
681
667
}
682
-
683
668
}
0 commit comments