6666import org .apache .hadoop .ozone .client .SecretKeyTestClient ;
6767import org .apache .hadoop .ozone .client .io .OzoneInputStream ;
6868import org .apache .hadoop .ozone .client .io .OzoneOutputStream ;
69- import org .apache .hadoop .ozone .om .OMConfigKeys ;
7069import org .apache .hadoop .ozone .om .OMMetadataManager ;
7170import org .apache .hadoop .ozone .om .OMMetrics ;
7271import org .apache .hadoop .ozone .om .OzoneManager ;
@@ -100,7 +99,7 @@ class TestSecureOzoneRpcClient extends OzoneRpcClientTests {
10099
101100 @ TempDir
102101 private static File testDir ;
103- private static String keyProviderUri = "kms://http@kms :9600/kms" ;
102+ private static String keyProviderUri = "kms://http@localhost :9600/kms" ;
104103
105104 @ BeforeAll
106105 public static void init () throws Exception {
@@ -115,11 +114,6 @@ public static void init() throws Exception {
115114 OzoneConfigKeys .OZONE_ACL_AUTHORIZER_CLASS_NATIVE );
116115 CertificateClientTestImpl certificateClientTest =
117116 new CertificateClientTestImpl (conf );
118- // These tests manually insert keys into RocksDB. This is easier to do
119- // with object store layout so keys with path IDs do not need to be
120- // constructed.
121- conf .set (OMConfigKeys .OZONE_DEFAULT_BUCKET_LAYOUT ,
122- OMConfigKeys .OZONE_BUCKET_LAYOUT_OBJECT_STORE );
123117 conf .setBoolean (OzoneConfigKeys .OZONE_HBASE_ENHANCEMENTS_ALLOWED , true );
124118 conf .setBoolean ("ozone.client.hbase.enhancements.allowed" , true );
125119 conf .setBoolean (OzoneConfigKeys .OZONE_FS_HSYNC_ENABLED , true );
@@ -236,26 +230,27 @@ public void testFileRecovery(boolean forceRecovery) throws Exception {
236230 // force recovery file
237231 System .setProperty (FORCE_LEASE_RECOVERY_ENV , String .valueOf (forceRecovery ));
238232 conf .setBoolean (String .format ("fs.%s.impl.disable.cache" , OZONE_OFS_URI_SCHEME ), true );
239- RootedOzoneFileSystem fs = (RootedOzoneFileSystem ) FileSystem .get (conf );
240- OzoneOutputStream out = null ;
241- try {
242- out = bucket .createKey (keyName , value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
243- ReplicationFactor .THREE , new HashMap <>());
244- out .write (value .getBytes (UTF_8 ));
245- out .hsync ();
246-
247- if (forceRecovery ) {
248- fs .recoverLease (file );
249- } else {
250- assertThrows (OMException .class , () -> fs .recoverLease (file ));
251- }
252- } finally {
253- if (out != null ) {
233+ try (RootedOzoneFileSystem fs = (RootedOzoneFileSystem ) FileSystem .get (conf )) {
234+ OzoneOutputStream out = null ;
235+ try {
236+ out = bucket .createKey (keyName , value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
237+ ReplicationFactor .THREE , new HashMap <>());
238+ out .write (value .getBytes (UTF_8 ));
239+ out .hsync ();
240+
254241 if (forceRecovery ) {
255- // close failure because the key is already committed
256- assertThrows (OMException .class , out ::close );
242+ fs .recoverLease (file );
257243 } else {
258- out .close ();
244+ assertThrows (OMException .class , () -> fs .recoverLease (file ));
245+ }
246+ } finally {
247+ if (out != null ) {
248+ if (forceRecovery ) {
249+ // close failure because the key is already committed
250+ assertThrows (OMException .class , out ::close );
251+ } else {
252+ out .close ();
253+ }
259254 }
260255 }
261256 }
@@ -288,51 +283,52 @@ public void testPreallocateFileRecovery(long dataSize) throws Exception {
288283 final String rootPath = String .format ("%s://%s/" ,
289284 OZONE_OFS_URI_SCHEME , conf .get (OZONE_OM_ADDRESS_KEY ));
290285 conf .set (CommonConfigurationKeysPublic .FS_DEFAULT_NAME_KEY , rootPath );
291- RootedOzoneFileSystem fs = (RootedOzoneFileSystem ) FileSystem .get (conf );
292- OzoneOutputStream out = null ;
293- long totalBlock = 10 ;
294- long usedBlock = (dataSize - 1 ) / fs .getDefaultBlockSize () + 1 ;
295- long fileSize = fs .getDefaultBlockSize () * totalBlock ;
296- OMMetrics metrics = getCluster ().getOzoneManager ().getMetrics ();
297- long committedBytes = metrics .getDataCommittedBytes ();
298- try {
299- out = bucket .createKey (keyName , fileSize , ReplicationType .RATIS ,
300- ReplicationFactor .THREE , new HashMap <>());
301- // init used quota check
302- bucket = volume .getBucket (bucketName );
303- assertEquals (0 , bucket .getUsedNamespace ());
304- assertEquals (0 , bucket .getUsedBytes ());
305-
306- out .write (data );
307- out .hsync ();
308- fs .recoverLease (file );
309-
310- // check file length
311- FileStatus fileStatus = fs .getFileStatus (file );
312- assertEquals (dataSize , fileStatus .getLen ());
313- // check committed bytes
314- assertEquals (committedBytes + dataSize ,
315- getCluster ().getOzoneManager ().getMetrics ().getDataCommittedBytes ());
316- // check used quota
317- bucket = volume .getBucket (bucketName );
318- assertEquals (1 , bucket .getUsedNamespace ());
319- assertEquals (dataSize * ReplicationFactor .THREE .getValue (), bucket .getUsedBytes ());
320-
321- // check unused pre-allocated blocks are reclaimed
322- Table <String , RepeatedOmKeyInfo > deletedTable =
323- getCluster ().getOzoneManager ().getMetadataManager ().getDeletedTable ();
324- try (TableIterator <String , ? extends Table .KeyValue <String , RepeatedOmKeyInfo >>
325- keyIter = deletedTable .iterator ()) {
326- while (keyIter .hasNext ()) {
327- Table .KeyValue <String , RepeatedOmKeyInfo > kv = keyIter .next ();
328- OmKeyInfo key = kv .getValue ().getOmKeyInfoList ().get (0 );
329- assertEquals (totalBlock - usedBlock , key .getKeyLocationVersions ().get (0 ).getLocationListCount ());
286+ try (RootedOzoneFileSystem fs = (RootedOzoneFileSystem ) FileSystem .get (conf )) {
287+ OzoneOutputStream out = null ;
288+ long totalBlock = 10 ;
289+ long usedBlock = (dataSize - 1 ) / fs .getDefaultBlockSize () + 1 ;
290+ long fileSize = fs .getDefaultBlockSize () * totalBlock ;
291+ OMMetrics metrics = getCluster ().getOzoneManager ().getMetrics ();
292+ long committedBytes = metrics .getDataCommittedBytes ();
293+ try {
294+ out = bucket .createKey (keyName , fileSize , ReplicationType .RATIS ,
295+ ReplicationFactor .THREE , new HashMap <>());
296+ // init used quota check
297+ bucket = volume .getBucket (bucketName );
298+ assertEquals (0 , bucket .getUsedNamespace ());
299+ assertEquals (0 , bucket .getUsedBytes ());
300+
301+ out .write (data );
302+ out .hsync ();
303+ fs .recoverLease (file );
304+
305+ // check file length
306+ FileStatus fileStatus = fs .getFileStatus (file );
307+ assertEquals (dataSize , fileStatus .getLen ());
308+ // check committed bytes
309+ assertEquals (committedBytes + dataSize ,
310+ getCluster ().getOzoneManager ().getMetrics ().getDataCommittedBytes ());
311+ // check used quota
312+ bucket = volume .getBucket (bucketName );
313+ assertEquals (1 , bucket .getUsedNamespace ());
314+ assertEquals (dataSize * ReplicationFactor .THREE .getValue (), bucket .getUsedBytes ());
315+
316+ // check unused pre-allocated blocks are reclaimed
317+ Table <String , RepeatedOmKeyInfo > deletedTable =
318+ getCluster ().getOzoneManager ().getMetadataManager ().getDeletedTable ();
319+ try (TableIterator <String , ? extends Table .KeyValue <String , RepeatedOmKeyInfo >>
320+ keyIter = deletedTable .iterator ()) {
321+ while (keyIter .hasNext ()) {
322+ Table .KeyValue <String , RepeatedOmKeyInfo > kv = keyIter .next ();
323+ OmKeyInfo key = kv .getValue ().getOmKeyInfoList ().get (0 );
324+ assertEquals (totalBlock - usedBlock , key .getKeyLocationVersions ().get (0 ).getLocationListCount ());
325+ }
326+ }
327+ } finally {
328+ if (out != null ) {
329+ // close failure because the key is already committed
330+ assertThrows (OMException .class , out ::close );
330331 }
331- }
332- } finally {
333- if (out != null ) {
334- // close failure because the key is already committed
335- assertThrows (OMException .class , out ::close );
336332 }
337333 }
338334 }
0 commit comments