[ 
https://issues.apache.org/jira/browse/HADOOP-16948?focusedWorklogId=537773&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-537773
 ]

ASF GitHub Bot logged work on HADOOP-16948:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Jan/21 12:24
            Start Date: 19/Jan/21 12:24
    Worklog Time Spent: 10m 
      Work Description: steveloughran commented on a change in pull request 
#1925:
URL: https://github.com/apache/hadoop/pull/1925#discussion_r560135489



##########
File path: 
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java
##########
@@ -120,7 +120,7 @@ private AbfsClient(final URL baseUrl, final 
SharedKeyCredentials sharedKeyCreden
     this.abfsCounters = abfsClientContext.getAbfsCounters();
 
     this.executorService = MoreExecutors.listeningDecorator(
-        
Executors.newScheduledThreadPool(this.abfsConfiguration.getNumLeaseThreads()));
+        
HadoopExecutors.newScheduledThreadPool(this.abfsConfiguration.getNumLeaseThreads()));

Review comment:
       can you make sure this executor marks its threads as daemons. Otherwise 
processes can hang during shutdown. @bgaborg has encountered this elsewhere

##########
File path: 
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/SelfRenewingLease.java
##########
@@ -71,7 +72,7 @@
 
   public static class LeaseException extends AzureBlobFileSystemException {
     public LeaseException(Throwable t) {
-      super(ERR_ACQUIRING_LEASE + ": " + t.getMessage());
+      super(ERR_ACQUIRING_LEASE, t);

Review comment:
       I think I'd keep that t text in the superclass text, in case a deep tree 
causes the nested cause not to be listed.
   
   but: use toString() (implicitly) rather than getMessage, because some 
exceptions (NPW) have a null message.

##########
File path: 
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemLease.java
##########
@@ -146,8 +150,7 @@ private void twoWriters(AzureBlobFileSystem fs, Path 
testFilePath, boolean expec
         out2.hsync();
       } catch (IOException e) {
         if (expectException) {
-          Assert.assertTrue("Unexpected error message: " + e.getMessage(),
-              e.getMessage().contains(ERR_ACQUIRING_LEASE));
+          GenericTestUtils.assertExceptionContains(ERR_ACQUIRING_LEASE, e);
         } else {
           Assert.fail("Unexpected exception " + e.getMessage());

Review comment:
       just rethrow it or wrap in an assertion error. we need that full stack 
trace

##########
File path: 
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java
##########
@@ -476,6 +476,20 @@ public FileStatus getFileStatus(final Path f) throws 
IOException {
     }
   }
 
+  /**
+   * Acquire a lease on an ABFS file for a specified duration. This requires 
the file to exist.

Review comment:
       little architecture question. Would this be better in the Store than the 
FS? I don't know, and it is higher level than the Rest API, isn't it? Which 
implies this is the right place.

##########
File path: 
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemLease.java
##########
@@ -0,0 +1,295 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.azurebfs.services.AbfsOutputStream;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.concurrent.RejectedExecutionException;
+
+import static 
org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_LEASE_THREADS;
+import static 
org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_SINGLE_WRITER_KEY;
+import static 
org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT;
+import static 
org.apache.hadoop.fs.azurebfs.services.AbfsErrors.ERR_ACQUIRING_LEASE;
+import static 
org.apache.hadoop.fs.azurebfs.services.AbfsErrors.ERR_LEASE_EXPIRED;
+import static 
org.apache.hadoop.fs.azurebfs.services.AbfsErrors.ERR_LEASE_NOT_PRESENT;
+import static 
org.apache.hadoop.fs.azurebfs.services.AbfsErrors.ERR_NO_LEASE_ID_SPECIFIED;
+import static 
org.apache.hadoop.fs.azurebfs.services.AbfsErrors.ERR_NO_LEASE_THREADS;
+import static 
org.apache.hadoop.fs.azurebfs.services.AbfsErrors.ERR_PARALLEL_ACCESS_DETECTED;
+
+/**
+ * Test lease operations.
+ */
+public class ITestAzureBlobFileSystemLease extends AbstractAbfsIntegrationTest 
{
+  private static final int TEST_EXECUTION_TIMEOUT = 30 * 1000;
+  private static final int LONG_TEST_EXECUTION_TIMEOUT = 90 * 1000;
+  private static final String TEST_FILE = "testfile";
+  private final boolean isHNSEnabled;
+
+  public ITestAzureBlobFileSystemLease() throws Exception {
+    super();
+
+    this.isHNSEnabled = getConfiguration()
+        .getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false);
+  }
+
+  private AzureBlobFileSystem getCustomFileSystem(String singleWriterDirs, int 
numLeaseThreads)
+      throws Exception {
+    Configuration conf = getRawConfiguration();
+    conf.setBoolean(String.format("fs.%s.impl.disable.cache", 
getAbfsScheme()), true);
+    conf.set(FS_AZURE_SINGLE_WRITER_KEY, singleWriterDirs);
+    conf.setInt(FS_AZURE_LEASE_THREADS, numLeaseThreads);
+    return getFileSystem(conf);
+  }
+
+  @Test
+  public void testNoSingleWriter() throws IOException {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = getFileSystem();
+    fs.mkdirs(testFilePath.getParent());
+    try (FSDataOutputStream out = fs.create(testFilePath)) {
+      Assert.assertFalse("Output stream should not have lease",
+          ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    }
+    Assert.assertTrue(fs.getAbfsStore().areLeasesFreed());
+  }
+
+  @Test
+  public void testNoLeaseThreads() throws Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = 
getCustomFileSystem(testFilePath.getParent().toString(), 0);
+    fs.mkdirs(testFilePath.getParent());
+    try (FSDataOutputStream out = fs.create(testFilePath)) {
+      Assert.fail("No failure when lease requested with 0 lease threads");
+    } catch (Exception e) {
+      GenericTestUtils.assertExceptionContains(ERR_NO_LEASE_THREADS, e);
+    }
+  }
+
+  @Test
+  public void testOneWriter() throws Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = 
getCustomFileSystem(testFilePath.getParent().toString(), 1);
+    fs.mkdirs(testFilePath.getParent());
+
+    FSDataOutputStream out = fs.create(testFilePath);
+    Assert.assertTrue("Output stream should have lease",
+        ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    out.close();
+    Assert.assertFalse("Output stream should not have lease",
+        ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    Assert.assertTrue(fs.getAbfsStore().areLeasesFreed());
+  }
+
+  @Test
+  public void testSubDir() throws Exception {
+    final Path testFilePath = new Path(new 
Path(path(methodName.getMethodName()), "subdir"),
+        TEST_FILE);
+    final AzureBlobFileSystem fs =
+        getCustomFileSystem(testFilePath.getParent().getParent().toString(), 
1);
+    fs.mkdirs(testFilePath.getParent().getParent());
+
+    FSDataOutputStream out = fs.create(testFilePath);
+    Assert.assertTrue("Output stream should have lease",
+        ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    out.close();
+    Assert.assertFalse("Output stream should not have lease",
+        ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    Assert.assertTrue(fs.getAbfsStore().areLeasesFreed());
+  }
+
+  @Test
+  public void testTwoCreate() throws Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = 
getCustomFileSystem(testFilePath.getParent().toString(), 1);
+    fs.mkdirs(testFilePath.getParent());
+
+    try (FSDataOutputStream out = fs.create(testFilePath)) {
+      try (FSDataOutputStream out2 = fs.create(testFilePath)) {
+        Assert.fail("Second create succeeded");
+      } catch (IOException e) {
+        if (isHNSEnabled) {
+          
GenericTestUtils.assertExceptionContains(ERR_PARALLEL_ACCESS_DETECTED, e);
+        } else {
+          GenericTestUtils.assertExceptionContains(ERR_NO_LEASE_ID_SPECIFIED, 
e);
+        }
+      }
+    }
+    Assert.assertTrue(fs.getAbfsStore().areLeasesFreed());
+  }
+
+  private void twoWriters(AzureBlobFileSystem fs, Path testFilePath, boolean 
expectException) throws Exception {
+    try (FSDataOutputStream out = fs.create(testFilePath)) {
+      try (FSDataOutputStream out2 = fs.append(testFilePath)) {
+        out2.writeInt(2);
+        out2.hsync();
+      } catch (IOException e) {
+        if (expectException) {
+          Assert.assertTrue("Unexpected error message: " + e.getMessage(),
+              e.getMessage().contains(ERR_ACQUIRING_LEASE));
+        } else {
+          Assert.fail("Unexpected exception " + e.getMessage());
+        }
+      }
+      out.writeInt(1);
+      out.hsync();
+    }
+
+    Assert.assertTrue(fs.getAbfsStore().areLeasesFreed());
+  }
+
+  @Test(timeout = TEST_EXECUTION_TIMEOUT)
+  public void testTwoWritersCreateAppendNoSingleWriter() throws Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = getFileSystem();
+    fs.mkdirs(testFilePath.getParent());
+
+    twoWriters(fs, testFilePath, false);
+  }
+
+  @Test(timeout = LONG_TEST_EXECUTION_TIMEOUT)
+  public void testTwoWritersCreateAppendWithSingleWriterEnabled() throws 
Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = 
getCustomFileSystem(testFilePath.getParent().toString(), 1);
+    fs.mkdirs(testFilePath.getParent());
+
+    twoWriters(fs, testFilePath, true);
+  }
+
+  @Test(timeout = TEST_EXECUTION_TIMEOUT)
+  public void testLeaseFreedOnClose() throws Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = 
getCustomFileSystem(testFilePath.getParent().toString(), 1);
+    fs.mkdirs(testFilePath.getParent());
+
+    FSDataOutputStream out;
+    out = fs.create(testFilePath);
+    out.write(0);
+    Assert.assertTrue("Output stream should have lease",
+        ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    out.close();
+    Assert.assertFalse("Output stream should not have lease after close",
+        ((AbfsOutputStream) out.getWrappedStream()).hasLease());
+    Assert.assertTrue(fs.getAbfsStore().areLeasesFreed());
+  }
+
+  @Test(timeout = TEST_EXECUTION_TIMEOUT)
+  public void testWriteAfterBreakLease() throws Exception {
+    final Path testFilePath = new Path(path(methodName.getMethodName()), 
TEST_FILE);
+    final AzureBlobFileSystem fs = 
getCustomFileSystem(testFilePath.getParent().toString(), 1);
+    fs.mkdirs(testFilePath.getParent());
+
+    FSDataOutputStream out;
+    out = fs.create(testFilePath);
+    out.write(0);
+    out.hsync();
+
+    fs.breakLease(testFilePath);
+    try {
+      out.write(1);
+      out.hsync();
+      Assert.fail("Expected exception on write after lease break");
+    } catch (IOException e) {
+      GenericTestUtils.assertExceptionContains(ERR_LEASE_EXPIRED, e);
+    }
+    try {
+      out.close();

Review comment:
       should it be doing that flush?




----------------------------------------------------------------
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.

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 537773)
    Time Spent: 2h 50m  (was: 2h 40m)

> ABFS: Support single writer dirs
> --------------------------------
>
>                 Key: HADOOP-16948
>                 URL: https://issues.apache.org/jira/browse/HADOOP-16948
>             Project: Hadoop Common
>          Issue Type: Sub-task
>            Reporter: Billie Rinaldi
>            Assignee: Billie Rinaldi
>            Priority: Minor
>              Labels: abfsactive, pull-request-available
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> This would allow some directories to be configured as single writer 
> directories. The ABFS driver would obtain a lease when creating or opening a 
> file for writing and would automatically renew the lease and release the 
> lease when closing the file.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to