You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2019/02/07 14:47:11 UTC

[asterixdb] branch master updated: [NO ISSUE] Compatibility improvements

This is an automated email from the ASF dual-hosted git repository.

mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 65ef90c  [NO ISSUE] Compatibility improvements
65ef90c is described below

commit 65ef90c7c39c7b11711b16ba4fbef92720c7b87a
Author: Michael Blow <mb...@apache.org>
AuthorDate: Wed Feb 6 13:39:37 2019 -0500

    [NO ISSUE] Compatibility improvements
    
    Change-Id: Idde612dace51121f1e5bc91519e9236b7e4f96a4
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3149
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Till Westmann <ti...@apache.org>
---
 .../api/comm/IJavaSerializationProvider.java       |  4 ++
 .../hyracks/api/util/JavaSerializationUtils.java   |  4 ++
 .../common/controllers/NodeRegistration.java       | 13 -----
 .../org/apache/hyracks/util/CompatibilityUtil.java | 56 ++++++++++++++++++----
 4 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java
index deaa966..46d68a0 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java
@@ -36,4 +36,8 @@ public interface IJavaSerializationProvider {
     default void readObject(ObjectInputStream in, Object object) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
     }
+
+    default void writeObject(ObjectOutputStream out, Object object) throws IOException {
+        out.defaultWriteObject();
+    }
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java
index 56e15a4..8e24204 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java
@@ -101,6 +101,10 @@ public class JavaSerializationUtils {
         serProvider.readObject(in, object);
     }
 
+    public static void writeObject(ObjectOutputStream out, Object object) throws IOException {
+        serProvider.writeObject(out, object);
+    }
+
     private static class ClassLoaderObjectInputStream extends ObjectInputStream {
         private ClassLoader classLoader;
 
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java
index f76d9b8..6e38473 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java
@@ -21,8 +21,6 @@ package org.apache.hyracks.control.common.controllers;
 import static org.apache.hyracks.util.MXHelper.osMXBean;
 import static org.apache.hyracks.util.MXHelper.runtimeMXBean;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.net.InetSocketAddress;
 import java.util.HashMap;
@@ -34,7 +32,6 @@ import org.apache.hyracks.api.config.IApplicationConfig;
 import org.apache.hyracks.api.config.IOption;
 import org.apache.hyracks.api.config.SerializedOption;
 import org.apache.hyracks.api.job.resource.NodeCapacity;
-import org.apache.hyracks.api.util.JavaSerializationUtils;
 import org.apache.hyracks.control.common.heartbeat.HeartbeatSchema;
 import org.apache.hyracks.util.MXHelper;
 import org.apache.hyracks.util.PidHelper;
@@ -46,10 +43,6 @@ public final class NodeRegistration implements Serializable {
 
     private final String nodeId;
 
-    @Deprecated // required for binary backward-compatibility when registering with a 0.9.4 CC
-    @SuppressWarnings("unused")
-    private final NCConfig ncConfig;
-
     private final NetworkAddress dataPort;
 
     private final NetworkAddress resultPort;
@@ -115,7 +108,6 @@ public final class NodeRegistration implements Serializable {
         for (IOption option : cfg.getOptions()) {
             config.put(option.toSerializable(), cfg.get(option));
         }
-        this.ncConfig = null;
     }
 
     public InetSocketAddress getNodeControllerAddress() {
@@ -201,9 +193,4 @@ public final class NodeRegistration implements Serializable {
     public int getPid() {
         return pid;
     }
-
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-        JavaSerializationUtils.readObject(in, this);
-    }
-
 }
\ No newline at end of file
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java
index 65da9fe..8e77ef5 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java
@@ -41,28 +41,64 @@ public class CompatibilityUtil {
         return prevLevel;
     }
 
+    public static Field getAccessibleField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
+        Field f = clazz.getDeclaredField(fieldName);
+        f.setAccessible(true);
+        return f;
+    }
+
+    public static Field getAccessibleField(Object obj, String fieldName) throws NoSuchFieldException {
+        Class<?> cl = obj.getClass();
+        while (true) {
+            Field f = null;
+            try {
+                f = getAccessibleField(cl, fieldName);
+                return f;
+            } catch (NoSuchFieldException e) {
+                cl = cl.getSuperclass();
+                if (cl == null) {
+                    throw new NoSuchFieldException(
+                            "field: '" + fieldName + "' not found in (hierarchy of) " + obj.getClass());
+                }
+            }
+        }
+    }
+
     public static Object readField(Object obj, String fieldName) throws IOException {
+        try {
+            return readField(obj, getAccessibleField(obj, fieldName));
+        } catch (NoSuchFieldException e) {
+            throw new IOException(e);
+        }
+    }
+
+    public static Object readField(Object obj, Field f) throws IOException {
         Class<?> objClass = obj.getClass();
-        LOGGER.debug("reading field '{}' on object of type {}", fieldName, objClass);
+        LOGGER.debug("reading field '{}' on object of type {}", f::getName, objClass::toString);
         try {
-            Field f = objClass.getDeclaredField(fieldName);
-            f.setAccessible(true);
             return f.get(obj);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            LOGGER.warn("exception reading field '{}' on object of type {}", fieldName, objClass, e);
+        } catch (IllegalAccessException e) {
+            LOGGER.warn("exception reading field '{}' on object of type {}", f.getName(), objClass, e);
             throw new IOException(e);
         }
     }
 
     public static void writeField(Object obj, String fieldName, Object newValue) throws IOException {
+        try {
+            writeField(obj, getAccessibleField(obj, fieldName), newValue);
+        } catch (NoSuchFieldException e) {
+            throw new IOException(e);
+        }
+    }
+
+    public static void writeField(Object obj, Field f, Object newValue) throws IOException {
         Class<?> objClass = obj.getClass();
-        LOGGER.debug("updating field '{}' on object of type {} to {}", fieldName, objClass, newValue);
+        LOGGER.debug("updating field '{}' on object of type {} to {}", f::getName, objClass::toString,
+                newValue::toString);
         try {
-            Field f = objClass.getDeclaredField(fieldName);
-            f.setAccessible(true);
             f.set(obj, newValue);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            LOGGER.warn("exception updating field '{}' object of type {} to {}", fieldName, objClass, newValue, e);
+        } catch (IllegalAccessException e) {
+            LOGGER.warn("exception updating field '{}' object of type {} to {}", f.getName(), objClass, newValue, e);
             throw new IOException(e);
         }
     }