asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amo...@apache.org
Subject [1/2] asterixdb git commit: [NO ISSUE][STO] Recover from failure in memory allocation callback
Date Wed, 31 Jan 2018 05:24:25 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 248e18aad -> caf43069b


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/caf43069/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
index e9f410d..749b3ba 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
@@ -438,9 +438,29 @@ public abstract class AbstractLSMIndex implements ILSMIndex {
         if (memoryComponentsAllocated || memoryComponents == null) {
             return;
         }
-        for (ILSMMemoryComponent c : memoryComponents) {
-            c.allocate();
-            ioOpCallback.allocated(c);
+        int i = 0;
+        boolean allocated = false;
+        try {
+            for (; i < memoryComponents.size(); i++) {
+                allocated = false;
+                ILSMMemoryComponent c = memoryComponents.get(i);
+                c.allocate();
+                allocated = true;
+                ioOpCallback.allocated(c);
+            }
+        } finally {
+            if (i < memoryComponents.size()) {
+                // something went wrong
+                if (allocated) {
+                    ILSMMemoryComponent c = memoryComponents.get(i);
+                    c.deallocate();
+                }
+                // deallocate all previous components
+                for (int j = i - 1; j >= 0; j--) {
+                    ILSMMemoryComponent c = memoryComponents.get(j);
+                    c.deallocate();
+                }
+            }
         }
         memoryComponentsAllocated = true;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/caf43069/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
index c0bef7d..3fbef18 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
@@ -237,19 +237,40 @@ public abstract class AbstractLSMMemoryComponent extends AbstractLSMComponent
im
 
     @Override
     public final void allocate() throws HyracksDataException {
+        boolean allocated = false;
         ((IVirtualBufferCache) getIndex().getBufferCache()).open();
-        doAllocate();
+        try {
+            doAllocate();
+            allocated = true;
+        } finally {
+            if (!allocated) {
+                ((IVirtualBufferCache) getIndex().getBufferCache()).close();
+            }
+        }
     }
 
     protected void doAllocate() throws HyracksDataException {
-        getIndex().create();
-        getIndex().activate();
+        boolean created = false;
+        boolean activated = false;
+        try {
+            getIndex().create();
+            created = true;
+            getIndex().activate();
+            activated = true;
+        } finally {
+            if (created && !activated) {
+                getIndex().destroy();
+            }
+        }
     }
 
     @Override
     public final void deallocate() throws HyracksDataException {
-        doDeallocate();
-        getIndex().getBufferCache().close();
+        try {
+            doDeallocate();
+        } finally {
+            getIndex().getBufferCache().close();
+        }
     }
 
     protected void doDeallocate() throws HyracksDataException {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/caf43069/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/MultitenantVirtualBufferCache.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/MultitenantVirtualBufferCache.java
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/MultitenantVirtualBufferCache.java
index 7a3d58b..9b25471 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/MultitenantVirtualBufferCache.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/MultitenantVirtualBufferCache.java
@@ -108,7 +108,15 @@ public class MultitenantVirtualBufferCache implements IVirtualBufferCache
{
     public synchronized void open() throws HyracksDataException {
         ++openCount;
         if (openCount == 1) {
-            vbc.open();
+            boolean failed = true;
+            try {
+                vbc.open();
+                failed = false;
+            } finally {
+                if (failed) {
+                    openCount--;
+                }
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/caf43069/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/IIndex.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/IIndex.java
b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/IIndex.java
index 816550b..19b4856 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/IIndex.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/IIndex.java
@@ -34,6 +34,7 @@ public interface IIndex {
      * Initializes the persistent state of an index.
      * An index cannot be created if it is in the activated state.
      * Calling create on an index that is deactivated has the effect of clearing the index.
+     * This method is atomic. If an exception is thrown, then the call had no effect.
      *
      * @throws HyracksDataException
      *             if there is an error in the BufferCache while (un)pinning pages, (un)latching
pages,

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/caf43069/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/ITestOpCallback.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/ITestOpCallback.java
b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/ITestOpCallback.java
index acc3347..e888238 100644
--- a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/ITestOpCallback.java
+++ b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/ITestOpCallback.java
@@ -18,8 +18,10 @@
  */
 package org.apache.hyracks.storage.am.lsm.btree.impl;
 
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
 public interface ITestOpCallback<T> {
-    void before(T t);
+    void before(T t) throws HyracksDataException;
 
-    void after();
+    void after() throws HyracksDataException;
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/caf43069/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/TestLsmBtree.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/TestLsmBtree.java
b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/TestLsmBtree.java
index bf3bb31..3c781a6 100644
--- a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/TestLsmBtree.java
+++ b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/org/apache/hyracks/storage/am/lsm/btree/impl/TestLsmBtree.java
@@ -109,7 +109,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public static <T> void callback(ITestOpCallback<T> callback, T t) {
+    public static <T> void callback(ITestOpCallback<T> callback, T t) throws
HyracksDataException {
         if (callback != null) {
             callback.before(t);
         }
@@ -344,7 +344,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void beforeIoOperationCalled() {
+    public void beforeIoOperationCalled() throws HyracksDataException {
         synchronized (ioBeforeCallbacks) {
             for (ITestOpCallback<Void> callback : ioBeforeCallbacks) {
                 callback.before(null);
@@ -352,7 +352,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void beforeIoOperationReturned() {
+    public void beforeIoOperationReturned() throws HyracksDataException {
         synchronized (ioBeforeCallbacks) {
             for (ITestOpCallback<Void> callback : ioBeforeCallbacks) {
                 callback.after();
@@ -360,7 +360,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void afterIoOperationCalled() {
+    public void afterIoOperationCalled() throws HyracksDataException {
         synchronized (ioAfterOpCallbacks) {
             for (ITestOpCallback<Void> callback : ioAfterOpCallbacks) {
                 callback.before(null);
@@ -368,7 +368,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void afterIoOperationReturned() {
+    public void afterIoOperationReturned() throws HyracksDataException {
         synchronized (ioAfterOpCallbacks) {
             for (ITestOpCallback<Void> callback : ioAfterOpCallbacks) {
                 callback.after();
@@ -376,7 +376,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void afterIoFinalizeCalled() {
+    public void afterIoFinalizeCalled() throws HyracksDataException {
         synchronized (ioAfterFinalizeCallbacks) {
             for (ITestOpCallback<Void> callback : ioAfterFinalizeCallbacks) {
                 callback.before(null);
@@ -384,7 +384,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void afterIoFinalizeReturned() {
+    public void afterIoFinalizeReturned() throws HyracksDataException {
         synchronized (ioAfterFinalizeCallbacks) {
             for (ITestOpCallback<Void> callback : ioAfterFinalizeCallbacks) {
                 callback.after();
@@ -392,7 +392,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void recycledCalled(ILSMMemoryComponent component) {
+    public void recycledCalled(ILSMMemoryComponent component) throws HyracksDataException
{
         synchronized (ioRecycleCallbacks) {
             for (ITestOpCallback<ILSMMemoryComponent> callback : ioRecycleCallbacks)
{
                 callback.before(component);
@@ -400,7 +400,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void recycledReturned(ILSMMemoryComponent component) {
+    public void recycledReturned(ILSMMemoryComponent component) throws HyracksDataException
{
         synchronized (ioRecycleCallbacks) {
             for (ITestOpCallback<ILSMMemoryComponent> callback : ioRecycleCallbacks)
{
                 callback.after();
@@ -408,7 +408,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void allocatedCalled(ILSMMemoryComponent component) {
+    public void allocatedCalled(ILSMMemoryComponent component) throws HyracksDataException
{
         synchronized (ioAllocateCallbacks) {
             for (ITestOpCallback<ILSMMemoryComponent> callback : ioAllocateCallbacks)
{
                 callback.before(component);
@@ -416,7 +416,7 @@ public class TestLsmBtree extends LSMBTree {
         }
     }
 
-    public void allocatedReturned(ILSMMemoryComponent component) {
+    public void allocatedReturned(ILSMMemoryComponent component) throws HyracksDataException
{
         synchronized (ioAllocateCallbacks) {
             for (ITestOpCallback<ILSMMemoryComponent> callback : ioAllocateCallbacks)
{
                 callback.after();


Mime
View raw message