You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mi...@apache.org on 2021/06/22 15:33:17 UTC
svn commit: r1890974 - in /jackrabbit/oak/trunk/oak-segment-azure/src:
main/java/org/apache/jackrabbit/oak/segment/azure/
test/java/org/apache/jackrabbit/oak/segment/azure/ test/resources/
test/resources/mockito-extensions/
Author: miroslav
Date: Tue Jun 22 15:33:17 2021
New Revision: 1890974
URL: http://svn.apache.org/viewvc?rev=1890974&view=rev
Log:
OAK-9469 in case of the timeout in AzureRepositoryLock, retry renewing the lease
Added:
jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/
jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/mockito-extensions/
jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
Modified:
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLock.java
jackrabbit/oak/trunk/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java
Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLock.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLock.java?rev=1890974&r1=1890973&r2=1890974&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLock.java (original)
+++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLock.java Tue Jun 22 15:33:17 2021
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.oak.segment.azure;
import com.microsoft.azure.storage.AccessCondition;
+import com.microsoft.azure.storage.StorageErrorCodeStrings;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlockBlob;
import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock;
@@ -103,10 +104,14 @@ public class AzureRepositoryLock impleme
lastUpdate = System.currentTimeMillis();
}
} catch (StorageException e) {
- log.error("Can't renew the lease", e);
- shutdownHook.run();
- doUpdate = false;
- return;
+ if (e.getErrorCode().equals(StorageErrorCodeStrings.OPERATION_TIMED_OUT)) {
+ log.warn("Could not renew the lease due to the operation timeout. Retry in progress ...", e);
+ } else {
+ log.error("Can't renew the lease", e);
+ shutdownHook.run();
+ doUpdate = false;
+ return;
+ }
}
try {
Thread.sleep(100);
Modified: jackrabbit/oak/trunk/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java?rev=1890974&r1=1890973&r2=1890974&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java (original)
+++ jackrabbit/oak/trunk/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java Tue Jun 22 15:33:17 2021
@@ -18,13 +18,16 @@
*/
package org.apache.jackrabbit.oak.segment.azure;
+import com.microsoft.azure.storage.StorageErrorCodeStrings;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
import com.microsoft.azure.storage.blob.CloudBlockBlob;
import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock;
import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Ignore;
import org.junit.Test;
+import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,6 +36,7 @@ import java.net.URISyntaxException;
import java.rmi.server.ExportException;
import java.security.InvalidKeyException;
import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeoutException;
import static org.junit.Assert.fail;
@@ -81,4 +85,33 @@ public class AzureRepositoryLockTest {
new AzureRepositoryLock(blob, () -> {}, 10).lock();
}
+ @Test
+ public void testLeaseRefreshUnsuccessful() throws URISyntaxException, StorageException, IOException, InterruptedException {
+ CloudBlockBlob blob = container.getBlockBlobReference("oak/repo.lock");
+
+ CloudBlockBlob blobMocked = Mockito.spy(blob);
+
+ // instrument the mock to throw the exception twice when renewing the lease
+ StorageException storageException =
+ new StorageException(StorageErrorCodeStrings.OPERATION_TIMED_OUT, "operation timeout", new TimeoutException());
+ Mockito.doThrow(storageException)
+ .doThrow(storageException)
+ .doCallRealMethod()
+ .when(blobMocked).renewLease(Mockito.any());
+
+ new AzureRepositoryLock(blobMocked, () -> {}, 0).lock();
+
+ // wait till lease expires
+ Thread.sleep(70000);
+
+ // reset the mock to default behaviour
+ Mockito.doCallRealMethod().when(blobMocked).renewLease(Mockito.any());
+
+ try {
+ new AzureRepositoryLock(blobMocked, () -> {}, 0).lock();
+ fail("The second lock should fail.");
+ } catch (IOException e) {
+ // it's fine
+ }
+ }
}
Added: jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker?rev=1890974&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker (added)
+++ jackrabbit/oak/trunk/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker Tue Jun 22 15:33:17 2021
@@ -0,0 +1 @@
+mock-maker-inline
\ No newline at end of file