mukund-thakur commented on code in PR #4331:
URL: https://github.com/apache/hadoop/pull/4331#discussion_r900367104
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java:
##########
@@ -531,13 +538,37 @@ public Pair<AbfsRestOperation, Boolean> renamePath(
url,
requestHeaders);
try {
+ incrementAbfsRenamePath();
op.execute(tracingContext);
- return Pair.of(op, false);
+ // AbfsClientResult contains the AbfsOperation, If recovery happened or
+ // not, and the incompleteMetaDataState is true or false.
+ return new AbfsClientResult(op, isMetadataIncompleteState ? true :
false, isMetadataIncompleteState);
Review Comment:
isMetadataIncompleteState ? true : false
How do this makes sure if recovery happened or not?
##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemRename.java:
##########
@@ -167,4 +173,29 @@ public void testPosixRenameDirectory() throws Exception {
new Path(testDir2 + "/test1/test2/test3"));
}
+ @Test
+ public void testRenameWithNoDestinationParentDir() throws Exception {
+ describe("Verifying the expected behaviour of ABFS rename when "
+ + "destination parent Dir doesn't exist.");
+
+ final AzureBlobFileSystem fs = getFileSystem();
+ Path sourcePath = path(getMethodName());
+ Path destPath = new Path("falseParent", "someChildFile");
+
+ byte[] data = dataset(1024, 'a', 'z');
+ writeDataset(fs, sourcePath, data, data.length, 1024, true);
+
+ // Verify that Renaming on a destination with no parent dir wasn't
Review Comment:
nit : smallcase renaming
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java:
##########
@@ -531,13 +538,37 @@ public Pair<AbfsRestOperation, Boolean> renamePath(
url,
requestHeaders);
try {
+ incrementAbfsRenamePath();
op.execute(tracingContext);
- return Pair.of(op, false);
+ // AbfsClientResult contains the AbfsOperation, If recovery happened or
+ // not, and the incompleteMetaDataState is true or false.
+ return new AbfsClientResult(op, isMetadataIncompleteState ? true :
false, isMetadataIncompleteState);
Review Comment:
Okay so this is updated recursively. But still it is just a boolean variable
why to use a ternary operator.
it is like returning (op, true, true) or (op, false, false)
##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRenameRetryRecovery.java:
##########
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.azurebfs.services;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.fs.azurebfs.AbstractAbfsIntegrationTest;
+import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem;
+import
org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
+import
org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
+
+import static
org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.HTTP_METHOD_PUT;
+import static
org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode.RENAME_DESTINATION_PARENT_PATH_NOT_FOUND;
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testing Abfs Rename recovery using Mockito.
+ */
+public class TestAbfsRenameRetryRecovery extends AbstractAbfsIntegrationTest {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(TestAbfsRenameRetryRecovery.class);
+
+ public TestAbfsRenameRetryRecovery() throws Exception {
+ }
+
+ /**
+ * Mock the AbfsClient to run a metadata incomplete scenario with recovery
+ * rename.
+ */
+ @Test
+ public void testRenameFailuresDueToIncompleteMetadata() throws Exception {
+ String sourcePath = getMethodName() + "Source";
+ String destNoParentPath = "/NoParent/Dest";
+ AzureBlobFileSystem fs = getFileSystem();
+
+ AbfsClient mockClient = TestAbfsClient.getMockAbfsClient(
+ fs.getAbfsStore().getClient(),
+ fs.getAbfsStore().getAbfsConfiguration());
+
+ AbfsCounters abfsCounters = mock(AbfsCounters.class);
+ when(mockClient.getAbfsCounters()).thenReturn(abfsCounters);
+ // SuccessFul Result.
+ AbfsRestOperation successOp =
+ new AbfsRestOperation(AbfsRestOperationType.RenamePath, mockClient,
+ HTTP_METHOD_PUT, null, null);
+ AbfsClientResult successResult = mock(AbfsClientResult.class);
+ doReturn(successOp).when(successResult).getOp();
+ when(successResult.isIncompleteMetadataState()).thenReturn(false);
+
+ // Failed Result.
+ AbfsRestOperation failedOp = new
AbfsRestOperation(AbfsRestOperationType.RenamePath, mockClient,
+ HTTP_METHOD_PUT, null, null);
+ AbfsClientResult recoveredMetaDataIncompleteResult =
+ mock(AbfsClientResult.class);
+
+ doReturn(failedOp).when(recoveredMetaDataIncompleteResult).getOp();
+
when(recoveredMetaDataIncompleteResult.isIncompleteMetadataState()).thenReturn(true);
+
+ // No destination Parent dir exception.
+ AzureBlobFileSystemException destParentNotFound
+ = getMockAbfsRestOperationException(
+ RENAME_DESTINATION_PARENT_PATH_NOT_FOUND.getStatusCode(),
+ RENAME_DESTINATION_PARENT_PATH_NOT_FOUND.getErrorCode());
+
+ // We need to throw an exception once a rename is triggered with
+ // destination having no parent, but after a retry it needs to succeed.
+ when(mockClient.renamePath(sourcePath, destNoParentPath, null, null,
+ null, false))
+ .thenThrow(destParentNotFound)
+ .thenReturn(recoveredMetaDataIncompleteResult);
+
+ // Dest parent not found exc. to be raised.
+ intercept(AzureBlobFileSystemException.class,
+ () -> mockClient.renamePath(sourcePath,
+ destNoParentPath, null, null,
+ null, false));
+
+ AbfsClientResult resultOfSecondRenameCall =
+ mockClient.renamePath(sourcePath,
+ destNoParentPath, null, null,
+ null, false);
+
+ // the second rename call should be the recoveredResult due to
+ // metaDataIncomplete
+ Assertions.assertThat(resultOfSecondRenameCall)
+ .describedAs("This result should be recovered result due to MetaData "
+ + "being in incomplete state")
+ .isSameAs(recoveredMetaDataIncompleteResult);
+ // Verify Incomplete metadata state happened for our second rename call.
+ assertTrue(resultOfSecondRenameCall.isIncompleteMetadataState());
Review Comment:
nit: message
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java:
##########
@@ -531,13 +538,37 @@ public Pair<AbfsRestOperation, Boolean> renamePath(
url,
requestHeaders);
try {
+ incrementAbfsRenamePath();
op.execute(tracingContext);
- return Pair.of(op, false);
+ // AbfsClientResult contains the AbfsOperation, If recovery happened or
+ // not, and the incompleteMetaDataState is true or false.
+ return new AbfsClientResult(op, isMetadataIncompleteState ? true :
false, isMetadataIncompleteState);
Review Comment:
Logic looks correct to me. Took some time to understand line by line. So I
think just use
return new AbfsClientResult(op, isMetadataIncompleteState,
isMetadataIncompleteState);
and write a comment saying something like
default of isMetadataIncompleteState is false, if this has changed to true
and the above call succeeded it means the rename recovery has happened because
of fixing the incomplete metatdata via getPathStatus call in catch clause
below.
See if this sounds correct.
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsStatistic.java:
##########
@@ -100,7 +100,16 @@ public enum AbfsStatistic {
AbfsHttpConstants.HTTP_METHOD_PATCH),
HTTP_POST_REQUEST(StoreStatisticNames.ACTION_HTTP_POST_REQUEST,
"Time taken to complete a POST request",
- AbfsHttpConstants.HTTP_METHOD_POST);
+ AbfsHttpConstants.HTTP_METHOD_POST),
+
+ // Rename recovery
+ RENAME_RECOVERY("rename_recovery",
+ "Number of times Rename recoveries happened"),
+ METADATA_INCOMPLETE_FAILURES("metadata_incomplete_failures",
Review Comment:
nit: change to METADATA_INCOMPLETE_RENAME_FAILURES bcoz as per the
explanation it is related to rename
--
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]