>From Hussain Towaileb <[email protected]>:

Hussain Towaileb has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20485?usp=email )


Change subject: [NO ISSUE]: try  message only throwable on 
NotSerializableException
......................................................................

[NO ISSUE]: try  message only throwable on NotSerializableException

Change-Id: I55e69623068a6c1759803cc699417021910237fd
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/messaging/CCMessageBroker.java
1 file changed, 33 insertions(+), 2 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/85/20485/1

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/messaging/CCMessageBroker.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/messaging/CCMessageBroker.java
index 0683207..8e4ad7c 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/messaging/CCMessageBroker.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/messaging/CCMessageBroker.java
@@ -18,11 +18,15 @@
  */
 package org.apache.asterix.messaging;

+import static org.apache.hyracks.api.util.ExceptionUtils.getMessageOrToString;
+
+import java.io.NotSerializableException;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;

+import org.apache.asterix.app.message.ExecuteStatementResponseMessage;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.common.exceptions.RuntimeDataException;
@@ -31,6 +35,7 @@
 import org.apache.asterix.common.messaging.api.ICcIdentifiedMessage;
 import org.apache.asterix.common.messaging.api.INcAddressedMessage;
 import org.apache.asterix.common.messaging.api.INcResponse;
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.commons.lang3.mutable.MutableInt;
 import org.apache.commons.lang3.tuple.MutablePair;
 import org.apache.commons.lang3.tuple.Pair;
@@ -81,7 +86,7 @@
             ((ICcIdentifiedMessage) msg).setCcId(ccs.getCcId());
         }
         if (state != null) {
-            byte[] payload = JavaSerializationUtils.serialize(msg);
+            byte[] payload = serializeMessage(msg);
             if (realTime) {
                 
state.getNodeController().sendRealTimeApplicationMessageToNC(payload, null, 
nodeId);
             } else {
@@ -90,12 +95,38 @@
             return true;
         } else {
             if (LOGGER.isWarnEnabled()) {
-                LOGGER.warn("Couldn't send message to unregistered node (" + 
nodeId + ")");
+                LOGGER.warn("Couldn't send message to unregistered node ({})", 
nodeId);
             }
             return false;
         }
     }

+    private byte[] serializeMessage(INcAddressedMessage msg) throws Exception {
+        try {
+            return JavaSerializationUtils.serialize(msg);
+        } catch (NotSerializableException ex) {
+            if (!(msg instanceof ExecuteStatementResponseMessage responseMsg)) 
{
+                throw ex;
+            }
+
+            if (responseMsg.getError() == null) {
+                throw ex;
+            }
+
+            LOGGER.info(ExceptionUtils.getStackTrace(ex));
+            LOGGER.info("Attempting to send response with only the message and 
stacktrace of the original throwable");
+            setMessageAndStacktraceOnlyThrowable(responseMsg);
+            return JavaSerializationUtils.serialize(msg);
+        }
+    }
+
+    private void 
setMessageAndStacktraceOnlyThrowable(ExecuteStatementResponseMessage 
responseMsg) {
+        Throwable oldThrowable = responseMsg.getError();
+        Throwable newThrowable = new 
Throwable(getMessageOrToString(oldThrowable));
+        newThrowable.setStackTrace(oldThrowable.getStackTrace());
+        responseMsg.setError(newThrowable);
+    }
+
     @Override
     public long newRequestId() {
         return REQUEST_ID_GENERATOR.incrementAndGet();

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20485?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: phoenix
Gerrit-Change-Id: I55e69623068a6c1759803cc699417021910237fd
Gerrit-Change-Number: 20485
Gerrit-PatchSet: 1
Gerrit-Owner: Hussain Towaileb <[email protected]>

Reply via email to