jojochuang commented on code in PR #6603:
URL: https://github.com/apache/ozone/pull/6603#discussion_r1583937646


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSync.java:
##########
@@ -962,4 +966,300 @@ public void writeWithBigBuffer(boolean 
incrementalChunkList, int bufferSize)
     }
     bucket.deleteKey(keyName);
   }
+
+  @Test
+  public void testNormalKeyOverwriteHSyncKey() throws Exception {
+    // Set the fs.defaultFS
+    final String rootPath = String.format("%s://%s/",
+        OZONE_OFS_URI_SCHEME, CONF.get(OZONE_OM_ADDRESS_KEY));
+    CONF.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
+
+    final String dir = OZONE_ROOT + bucket.getVolumeName()
+        + OZONE_URI_DELIMITER + bucket.getName();
+
+    // Expect empty OpenKeyTable before key creation
+    OzoneManager ozoneManager = cluster.getOzoneManager();
+    cleanupDeletedTable(ozoneManager);
+    cleanupOpenKeyTable(ozoneManager, BUCKET_LAYOUT);
+    OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+    Table<String, OmKeyInfo> openKeyTable = 
metadataManager.getOpenKeyTable(BUCKET_LAYOUT);
+    Table<String, RepeatedOmKeyInfo> deletedTable = 
metadataManager.getDeletedTable();
+    assertTrue(openKeyTable.isEmpty());
+    assertTrue(deletedTable.isEmpty());
+    ozoneManager.getKeyManager().getDeletingService().suspend();
+    OMMetrics metrics = ozoneManager.getMetrics();
+    metrics.incDataCommittedBytes(-metrics.getDataCommittedBytes());
+    assertEquals(0, metrics.getDataCommittedBytes());
+    OzoneVolume volume = 
client.getObjectStore().getVolume(bucket.getVolumeName());
+    OzoneBucket ozoneBucket = volume.getBucket(bucket.getName());
+    long usedBytes = ozoneBucket.getUsedBytes();
+
+    String data1 = "data for normal file";
+    String data2 = "data for hsynced file";
+    final Path file = new Path(dir, "file-normal-overwrite-hsync");
+    try (FileSystem fs = FileSystem.get(CONF)) {
+      FSDataOutputStream outputStream1 = null;
+      FSDataOutputStream outputStream2 = null;
+
+      // create hsync key
+      outputStream1 = fs.create(file, true);
+      outputStream1.write(data2.getBytes(UTF_8), 0, data2.length());
+      outputStream1.hsync();
+
+      // create normal key and commit
+      outputStream2 = fs.create(file, true);
+      outputStream2.write(data1.getBytes(UTF_8), 0, data1.length());
+      outputStream2.close();
+      assertEquals(data1.length(), metrics.getDataCommittedBytes());
+
+      // allocate new block for overwritten hsync key, should fail
+      String s = RandomStringUtils.randomAlphabetic(BLOCK_SIZE);
+      byte[] newData = s.getBytes(StandardCharsets.UTF_8);
+      try {
+        outputStream1.write(newData);
+      } catch (IOException e) {
+        assertTrue(e.getCause() instanceof OMException);
+        assertTrue(((OMException)e.getCause()).getResult() == 
OMException.ResultCodes.KEY_NOT_FOUND);
+        assertTrue(e.getMessage().contains("already deleted/overwritten"));
+      }

Review Comment:
   If exception is expected here, use assertThrows()
   ```suggestion
         IOException e = assertThrows(IOException.class,
            () -> outputStream1.write(newData));
         assertTrue(e.getCause() instanceof OMException);
         assertTrue(((OMException)e.getCause()).getResult() == 
OMException.ResultCodes.KEY_NOT_FOUND);
         assertTrue(e.getMessage().contains("already deleted/overwritten"));
   ```



##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneKeyLocation.java:
##########
@@ -90,4 +90,15 @@ public long getKeyOffset() {
     return keyOffset;
   }
 
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+    sb.append("conID ").append(containerID);
+    sb.append(" ");
+    sb.append("locID ").append(localID);
+    sb.append(" ");
+    sb.append("length ").append(length);
+    sb.append(" ");
+    sb.append("keyOffset ").append(keyOffset);

Review Comment:
   should it print offset as well?



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSync.java:
##########
@@ -962,4 +966,300 @@ public void writeWithBigBuffer(boolean 
incrementalChunkList, int bufferSize)
     }
     bucket.deleteKey(keyName);
   }
+
+  @Test
+  public void testNormalKeyOverwriteHSyncKey() throws Exception {
+    // Set the fs.defaultFS
+    final String rootPath = String.format("%s://%s/",
+        OZONE_OFS_URI_SCHEME, CONF.get(OZONE_OM_ADDRESS_KEY));
+    CONF.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
+
+    final String dir = OZONE_ROOT + bucket.getVolumeName()
+        + OZONE_URI_DELIMITER + bucket.getName();
+
+    // Expect empty OpenKeyTable before key creation
+    OzoneManager ozoneManager = cluster.getOzoneManager();
+    cleanupDeletedTable(ozoneManager);
+    cleanupOpenKeyTable(ozoneManager, BUCKET_LAYOUT);
+    OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+    Table<String, OmKeyInfo> openKeyTable = 
metadataManager.getOpenKeyTable(BUCKET_LAYOUT);
+    Table<String, RepeatedOmKeyInfo> deletedTable = 
metadataManager.getDeletedTable();
+    assertTrue(openKeyTable.isEmpty());
+    assertTrue(deletedTable.isEmpty());
+    ozoneManager.getKeyManager().getDeletingService().suspend();
+    OMMetrics metrics = ozoneManager.getMetrics();
+    metrics.incDataCommittedBytes(-metrics.getDataCommittedBytes());
+    assertEquals(0, metrics.getDataCommittedBytes());
+    OzoneVolume volume = 
client.getObjectStore().getVolume(bucket.getVolumeName());
+    OzoneBucket ozoneBucket = volume.getBucket(bucket.getName());
+    long usedBytes = ozoneBucket.getUsedBytes();
+
+    String data1 = "data for normal file";
+    String data2 = "data for hsynced file";
+    final Path file = new Path(dir, "file-normal-overwrite-hsync");
+    try (FileSystem fs = FileSystem.get(CONF)) {
+      FSDataOutputStream outputStream1 = null;
+      FSDataOutputStream outputStream2 = null;
+
+      // create hsync key
+      outputStream1 = fs.create(file, true);
+      outputStream1.write(data2.getBytes(UTF_8), 0, data2.length());
+      outputStream1.hsync();
+
+      // create normal key and commit
+      outputStream2 = fs.create(file, true);
+      outputStream2.write(data1.getBytes(UTF_8), 0, data1.length());
+      outputStream2.close();
+      assertEquals(data1.length(), metrics.getDataCommittedBytes());
+
+      // allocate new block for overwritten hsync key, should fail
+      String s = RandomStringUtils.randomAlphabetic(BLOCK_SIZE);
+      byte[] newData = s.getBytes(StandardCharsets.UTF_8);
+      try {
+        outputStream1.write(newData);
+      } catch (IOException e) {
+        assertTrue(e.getCause() instanceof OMException);
+        assertTrue(((OMException)e.getCause()).getResult() == 
OMException.ResultCodes.KEY_NOT_FOUND);
+        assertTrue(e.getMessage().contains("already deleted/overwritten"));
+      }
+      // commit overwritten hsync key, should fail
+      try {
+        outputStream1.close();

Review Comment:
   here, too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to