asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amo...@apache.org
Subject [1/3] incubator-asterixdb-hyracks git commit: Changed the IFrameWriter Contract
Date Wed, 16 Dec 2015 06:35:22 GMT
Repository: incubator-asterixdb-hyracks
Updated Branches:
  refs/heads/master 3a88250d9 -> 0ad2cceb0


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/0ad2cceb/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
index 4434871..a2913f4 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
@@ -55,6 +55,7 @@ public class IndexInsertUpdateDeleteOperatorNodePushable extends AbstractUnaryIn
     protected IIndexAccessor indexAccessor;
     protected ITupleFilter tupleFilter;
     protected IModificationOperationCallback modCallback;
+    protected IIndex index;
 
     public IndexInsertUpdateDeleteOperatorNodePushable(IIndexOperatorDescriptor opDesc, IHyracksTaskContext
ctx,
             int partition, int[] fieldPermutation, IRecordDescriptorProvider recordDescProvider,
IndexOperation op) {
@@ -71,12 +72,12 @@ public class IndexInsertUpdateDeleteOperatorNodePushable extends AbstractUnaryIn
         RecordDescriptor inputRecDesc = recordDescProvider.getInputRecordDescriptor(opDesc.getActivityId(),
0);
         accessor = new FrameTupleAccessor(inputRecDesc);
         writeBuffer = new VSizeFrame(ctx);
-        writer.open();
         indexHelper.open();
-        IIndex index = indexHelper.getIndexInstance();
+        index = indexHelper.getIndexInstance();
         try {
-            modCallback = opDesc.getModificationOpCallbackFactory().createModificationOperationCallback(indexHelper.getResourceName(),
-                    indexHelper.getResourceID(), index, ctx);
+            writer.open();
+            modCallback = opDesc.getModificationOpCallbackFactory().createModificationOperationCallback(
+                    indexHelper.getResourceName(), indexHelper.getResourceID(), index, ctx);
             indexAccessor = index.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
             ITupleFilterFactory tupleFilterFactory = opDesc.getTupleFilterFactory();
             if (tupleFilterFactory != null) {
@@ -84,7 +85,6 @@ public class IndexInsertUpdateDeleteOperatorNodePushable extends AbstractUnaryIn
                 frameTuple = new FrameTupleReference();
             }
         } catch (Exception e) {
-            indexHelper.close();
             throw new HyracksDataException(e);
         }
     }
@@ -129,8 +129,8 @@ public class IndexInsertUpdateDeleteOperatorNodePushable extends AbstractUnaryIn
                         break;
                     }
                     default: {
-                        throw new HyracksDataException("Unsupported operation " + op
-                                + " in tree index InsertUpdateDelete operator");
+                        throw new HyracksDataException(
+                                "Unsupported operation " + op + " in tree index InsertUpdateDelete
operator");
                     }
                 }
             } catch (HyracksDataException e) {
@@ -147,15 +147,19 @@ public class IndexInsertUpdateDeleteOperatorNodePushable extends AbstractUnaryIn
 
     @Override
     public void close() throws HyracksDataException {
-        try {
-            writer.close();
-        } finally {
-            indexHelper.close();
+        if (index != null) {
+            try {
+                writer.close();
+            } finally {
+                indexHelper.close();
+            }
         }
     }
 
     @Override
     public void fail() throws HyracksDataException {
-        writer.fail();
+        if (index != null) {
+            writer.fail();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/0ad2cceb/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexSearchOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexSearchOperatorNodePushable.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexSearchOperatorNodePushable.java
index 3db94e8..568bde8 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexSearchOperatorNodePushable.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexSearchOperatorNodePushable.java
@@ -107,11 +107,10 @@ public abstract class IndexSearchOperatorNodePushable extends AbstractUnaryInput
 
     @Override
     public void open() throws HyracksDataException {
-        accessor = new FrameTupleAccessor(inputRecDesc);
         writer.open();
         indexHelper.open();
         index = indexHelper.getIndexInstance();
-
+        accessor = new FrameTupleAccessor(inputRecDesc);
         if (retainNull) {
             int fieldCount = getFieldCount();
             nullTupleBuild = new ArrayTupleBuilder(fieldCount);
@@ -141,7 +140,6 @@ public abstract class IndexSearchOperatorNodePushable extends AbstractUnaryInput
                 frameTuple = new FrameTupleReference();
             }
         } catch (Exception e) {
-            indexHelper.close();
             throw new HyracksDataException(e);
         }
     }
@@ -164,13 +162,12 @@ public abstract class IndexSearchOperatorNodePushable extends AbstractUnaryInput
                 dos.write(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
                 tb.addFieldEndOffset();
             }
-            FrameUtils.appendToWriter(writer, appender, tb.getFieldEndOffsets(), tb.getByteArray(),
0,
-                    tb.getSize());
+            FrameUtils.appendToWriter(writer, appender, tb.getFieldEndOffsets(), tb.getByteArray(),
0, tb.getSize());
         }
 
         if (!matched && retainInput && retainNull) {
-            FrameUtils.appendConcatToWriter(writer, appender, accessor, tupleIndex,
-                    nullTupleBuild.getFieldEndOffsets(), nullTupleBuild.getByteArray(), 0,
nullTupleBuild.getSize());
+            FrameUtils.appendConcatToWriter(writer, appender, accessor, tupleIndex, nullTupleBuild.getFieldEndOffsets(),
+                    nullTupleBuild.getByteArray(), 0, nullTupleBuild.getSize());
         }
     }
 
@@ -192,16 +189,46 @@ public abstract class IndexSearchOperatorNodePushable extends AbstractUnaryInput
 
     @Override
     public void close() throws HyracksDataException {
-        try {
-            appender.flush(writer, true);
+        HyracksDataException closeException = null;
+        if (index != null) {
+            // if index == null, then the index open was not successful
+            try {
+                appender.flush(writer, true);
+            } catch (Throwable th) {
+                closeException = new HyracksDataException(th);
+            }
+
             try {
                 cursor.close();
-            } catch (Exception e) {
-                throw new HyracksDataException(e);
+            } catch (Throwable th) {
+                if (closeException == null) {
+                    closeException = new HyracksDataException(th);
+                } else {
+                    closeException.addSuppressed(th);
+                }
             }
+            try {
+                indexHelper.close();
+            } catch (Throwable th) {
+                if (closeException == null) {
+                    closeException = new HyracksDataException(th);
+                } else {
+                    closeException.addSuppressed(th);
+                }
+            }
+        }
+        try {
+            // will definitely be called regardless of exceptions
             writer.close();
-        } finally {
-            indexHelper.close();
+        } catch (Throwable th) {
+            if (closeException == null) {
+                closeException = new HyracksDataException(th);
+            } else {
+                closeException.addSuppressed(th);
+            }
+        }
+        if (closeException != null) {
+            throw closeException;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/0ad2cceb/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/TreeIndexDiskOrderScanOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/TreeIndexDiskOrderScanOperatorNodePushable.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/TreeIndexDiskOrderScanOperatorNodePushable.java
index 8c73272..08775bb 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/TreeIndexDiskOrderScanOperatorNodePushable.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/TreeIndexDiskOrderScanOperatorNodePushable.java
@@ -56,12 +56,12 @@ public class TreeIndexDiskOrderScanOperatorNodePushable extends AbstractUnaryOut
         try {
             ITreeIndexFrame cursorFrame = treeIndex.getLeafFrameFactory().createFrame();
             ITreeIndexCursor cursor = treeIndexHelper.createDiskOrderScanCursor(cursorFrame);
-            ISearchOperationCallback searchCallback = opDesc.getSearchOpCallbackFactory().createSearchOperationCallback(
-                    treeIndexHelper.getResourceID(), ctx);
-            ITreeIndexAccessor indexAccessor = (ITreeIndexAccessor) treeIndex.createAccessor(
-                    NoOpOperationCallback.INSTANCE, searchCallback);
-            writer.open();
+            ISearchOperationCallback searchCallback = opDesc.getSearchOpCallbackFactory()
+                    .createSearchOperationCallback(treeIndexHelper.getResourceID(), ctx);
+            ITreeIndexAccessor indexAccessor = (ITreeIndexAccessor) treeIndex
+                    .createAccessor(NoOpOperationCallback.INSTANCE, searchCallback);
             try {
+                writer.open();
                 indexAccessor.diskOrderScan(cursor);
                 int fieldCount = treeIndex.getFieldCount();
                 FrameTupleAppender appender = new FrameTupleAppender(new VSizeFrame(ctx));
@@ -83,16 +83,21 @@ public class TreeIndexDiskOrderScanOperatorNodePushable extends AbstractUnaryOut
                             tb.getSize());
                 }
                 appender.flush(writer, true);
-            } catch (Exception e) {
+            } catch (Throwable th) {
                 writer.fail();
-                throw new HyracksDataException(e);
+                throw new HyracksDataException(th);
             } finally {
-                cursor.close();
-                writer.close();
+                try {
+                    cursor.close();
+                } catch (Exception cursorCloseException) {
+                    throw new IllegalStateException(cursorCloseException);
+                } finally {
+                    writer.close();
+                }
             }
-        } catch (Exception e) {
+        } catch (Throwable th) {
             treeIndexHelper.close();
-            throw new HyracksDataException(e);
+            throw new HyracksDataException(th);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/0ad2cceb/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/dataflow/BinaryTokenizerOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/dataflow/BinaryTokenizerOperatorNodePushable.java
b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/dataflow/BinaryTokenizerOperatorNodePushable.java
index 4a9ea27..c91aff7 100644
--- a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/dataflow/BinaryTokenizerOperatorNodePushable.java
+++ b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/dataflow/BinaryTokenizerOperatorNodePushable.java
@@ -66,11 +66,11 @@ public class BinaryTokenizerOperatorNodePushable extends AbstractUnaryInputUnary
 
     @Override
     public void open() throws HyracksDataException {
+        writer.open();
         accessor = new FrameTupleAccessor(inputRecDesc);
         builder = new ArrayTupleBuilder(outputRecDesc.getFieldCount());
         builderData = builder.getFieldData();
         appender = new FrameTupleAppender(new VSizeFrame(ctx), true);
-        writer.open();
     }
 
     @Override
@@ -81,10 +81,9 @@ public class BinaryTokenizerOperatorNodePushable extends AbstractUnaryInputUnary
         for (int i = 0; i < tupleCount; i++) {
             short numTokens = 0;
 
-            tokenizer.reset(
-                    accessor.getBuffer().array(),
-                    accessor.getTupleStartOffset(i) + accessor.getFieldSlotsLength()
-                            + accessor.getFieldStartOffset(i, docField), accessor.getFieldLength(i,
docField));
+            tokenizer.reset(accessor.getBuffer().array(), accessor.getTupleStartOffset(i)
+                    + accessor.getFieldSlotsLength() + accessor.getFieldStartOffset(i, docField),
+                    accessor.getFieldLength(i, docField));
 
             if (addNumTokensKey) {
                 // Get the total number of tokens.
@@ -154,8 +153,11 @@ public class BinaryTokenizerOperatorNodePushable extends AbstractUnaryInputUnary
 
     @Override
     public void close() throws HyracksDataException {
-        appender.flush(writer, true);
-        writer.close();
+        try {
+            appender.flush(writer, true);
+        } finally {
+            writer.close();
+        }
     }
 
     @Override


Mime
View raw message