[NO ISSUE][STO] Ensure IFrameTupleProcessor Finish is Called

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
Currently when an exception is encountered while processing the frame
in LSMHarness, IFrameTupleProcessor finish is not called which results
in "Operation already has access to components of index" exception.

Change-Id: I5f4188fa3de3c91f5f6aae95716db016a315ddd6
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2083
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
index c8be9b9..ac38cba 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
@@ -643,9 +643,9 @@
         exitComponents(ctx, LSMOperationType.REPLICATE, null, false);
     }
 
-    protected void validateOperationEnterComponentsState(ILSMIndexOperationContext ctx) throws HyracksDataException {
+    protected void validateOperationEnterComponentsState(ILSMIndexOperationContext ctx) {
         if (ctx.isAccessingComponents()) {
-            throw new HyracksDataException("Opeartion already has access to components of index " + lsmIndex);
+            throw new IllegalStateException("Operation already has access to components of index " + lsmIndex);
         }
     }
 
@@ -684,17 +684,17 @@
         processor.start();
         enter(ctx);
         try {
-            int tupleCount = accessor.getTupleCount();
-            int i = 0;
-            while (i < tupleCount) {
-                tuple.reset(accessor, i);
-                processor.process(tuple, i);
-                i++;
+            try {
+                processFrame(accessor, tuple, processor);
+                frameOpCallback.frameCompleted();
+            } finally {
+                processor.finish();
             }
-            frameOpCallback.frameCompleted();
-            processor.finish();
-        } catch (Exception e) {
-            throw HyracksDataException.create(e);
+        } catch (HyracksDataException e) {
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.log(Level.SEVERE, "Failed to process frame", e);
+            }
+            throw e;
         } finally {
             exit(ctx);
         }
@@ -853,6 +853,17 @@
         return false;
     }
 
+    private static void processFrame(FrameTupleAccessor accessor, FrameTupleReference tuple,
+            IFrameTupleProcessor processor) throws HyracksDataException {
+        int tupleCount = accessor.getTupleCount();
+        int i = 0;
+        while (i < tupleCount) {
+            tuple.reset(accessor, i);
+            processor.process(tuple, i);
+            i++;
+        }
+    }
+
     @Override
     public String toString() {
         return getClass().getSimpleName() + ":" + lsmIndex;