[NO ISSUE][STO] Log bulkloader state on failure

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

Details:

- Log BTree bulkloader state when an exception is encountered.

Change-Id: I00a69d4883ae7a69c28a201408504049dd70ffb5
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/8683
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/pom.xml b/hyracks-fullstack/hyracks/hyracks-storage-am-common/pom.xml
index 31463b7..703deb8 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/pom.xml
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/pom.xml
@@ -109,5 +109,9 @@
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-core</artifactId>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexFrame.java b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexFrame.java
index dc59612..18d5653 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexFrame.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/ITreeIndexFrame.java
@@ -28,6 +28,9 @@
 import org.apache.hyracks.storage.common.buffercache.IBufferCache;
 import org.apache.hyracks.storage.common.buffercache.ICachedPage;
 import org.apache.hyracks.storage.common.buffercache.IExtraPageBlockHelper;
+import org.apache.hyracks.util.JSONUtil;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
 
 public interface ITreeIndexFrame {
 
@@ -122,4 +125,14 @@
     public ITupleReference getLeftmostTuple() throws HyracksDataException;
 
     public ITupleReference getRightmostTuple() throws HyracksDataException;
+
+    default ObjectNode getState() {
+        ObjectNode json = JSONUtil.createObject();
+        json.put("tupleCount", getTupleCount());
+        json.put("freeSpaceOff", getFreeSpaceOff());
+        json.put("level", getLevel());
+        json.put("pageLsn", getPageLsn());
+        json.put("totalFreeSpace", getTotalFreeSpace());
+        return json;
+    }
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
index 6106358..08d4564 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
@@ -31,6 +31,10 @@
 import org.apache.hyracks.storage.am.common.api.ITreeIndexTupleWriter;
 import org.apache.hyracks.storage.am.common.ophelpers.SlotOffTupleOff;
 import org.apache.hyracks.storage.common.buffercache.ICachedPage;
+import org.apache.hyracks.util.JSONUtil;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 
 public abstract class TreeIndexNSMFrame implements ITreeIndexFrame {
 
@@ -354,4 +358,20 @@
             return frameTuple;
         }
     }
+
+    @Override
+    public ObjectNode getState() {
+        ObjectNode state = ITreeIndexFrame.super.getState();
+        state.put("largeFlag", getLargeFlag());
+        return state;
+    }
+
+    @Override
+    public String toString() {
+        try {
+            return JSONUtil.convertNode(getState());
+        } catch (JsonProcessingException e) {
+            return "failed to convert json";
+        }
+    }
 }