jojochuang commented on code in PR #6094:
URL: https://github.com/apache/ozone/pull/6094#discussion_r1467061661
##########
hadoop-ozone/ozonefs-hadoop3/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java:
##########
@@ -155,15 +155,17 @@ public boolean recoverLease(Path f) throws IOException {
// finalize the final block and get block length
List<OmKeyLocationInfo> locationInfoList =
keyInfo.getLatestVersionLocations().getLocationList();
- OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() -
1);
- try {
- block.setLength(getAdapter().finalizeBlock(block));
- } catch (Throwable e) {
- if (!forceRecovery) {
- throw e;
+ if (locationInfoList.size() > 0) {
Review Comment:
```suggestion
if (!locationInfoList.isEmpty()) {
```
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java:
##########
@@ -433,6 +433,27 @@ public void testRecoverWrongFile() throws Exception {
}
}
+ @Test
+ public void testRecoveryWithoutBlocks() throws Exception {
+ RootedOzoneFileSystem fs = (RootedOzoneFileSystem)FileSystem.get(conf);
+
+ final FSDataOutputStream stream = fs.create(file, true);
+ try {
+ stream.hsync();
+ assertFalse(fs.isFileClosed(file));
+
+ int count = 0;
+ while (count++ < 15 && !fs.recoverLease(file)) {
+ Thread.sleep(1000);
+ }
+ // The lease should have been recovered.
+ assertTrue(fs.isFileClosed(file), "File should be closed");
+
+ } finally {
+ closeIgnoringKeyNotFound(stream);
Review Comment:
is it supposed to ignore if key is not found? can we just do stream.close()
instead
##########
hadoop-ozone/ozonefs-hadoop3/src/main/java/org/apache/hadoop/fs/ozone/RootedOzoneFileSystem.java:
##########
@@ -159,15 +159,17 @@ public boolean recoverLease(final Path f) throws
IOException {
// finalize the final block and get block length
List<OmKeyLocationInfo> locationInfoList =
keyInfo.getLatestVersionLocations().getLocationList();
- OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() -
1);
- try {
- block.setLength(getAdapter().finalizeBlock(block));
- } catch (Throwable e) {
- if (!forceRecovery) {
- throw e;
+ if (locationInfoList.size() > 0) {
Review Comment:
ditto
--
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]