Uploaded image for project: 'Geode'
  1. Geode
  2. GEODE-6559

PdxInstance.getObject() is using class from older jar in case of Reconnect

    XMLWordPrintableJSON

Details

    Description

      Given a function as below:

      public void execute(FunctionContext context) {
      
              RegionFunctionContext rctx = (RegionFunctionContext)context;
              Region<Object, Object> dataSet = rctx.getDataSet();
              Object o = ((PdxInstance)context.getArguments()).getObject();
              LogService.getLogger().warn(o.getClass() + " loaded from " + getClassLoaderJar(o.getClass()));
              printCallerStack("Function execution called from");
              LogService.getLogger().warn("Thread context classloader is " + Thread.currentThread().getContextClassLoader());
              LogService.getLogger().error(this);
              LogService.getLogger().warn(Student.class + " loaded from " + getClassLoaderJar(Student.class));
              LogService.getLogger().warn(o.getClass() + " args class parent is " + o.getClass().getClassLoader().getParent());
              LogService.getLogger().warn(o.getClass() + " loaded from " + getClassLoaderJar(o.getClass()));
              LogService.getLogger().warn(this.getClass() + " loaded from " + getClassLoaderJar(this.getClass()));
      
              Student args = (Student) o;
      
              LogService.getLogger().warn("args = " + args);
      
              Integer first = 1;
              Integer second = 2;
      
              LogService.getLogger().info("Function returning result " + this.getClass() + " loaded from " + this.getClass().getClassLoader());
      
              rctx.getResultSender().lastResult(first * second);
          }
      

      It works fine in case of normal operations and jar --deploy , but in case of auto-reconnect, the below line

       Object o = ((PdxInstance)context.getArguments()).getObject();
      

      Loads the class from older jar

      [warning 2019/03/14 14:23:43.420 IST server2 <Function Execution Processor1> tid=0x11f] class com.pivotal.support.hot.deploy.Student loaded from [file:/Users/rajiv/kumar/gemfire/deployJarTest/server2/deploy.v1.jar]
      

      Mostly due to the caching in the InternalDeserializer.

      Whereas the below

              Student args = (Student) o;
      

      Loads the class from the latest jar, for each reconnect attempt the jar is downloaded from the locators and the version is increased

      [warning 2019/03/14 14:23:43.426 IST server2 <Function Execution Processor1> tid=0x11f] class com.pivotal.support.hot.deploy.Student loaded from [file:/Users/rajiv/kumar/gemfire/deployJarTest/server2/deploy.v3.jar]
      

      This is causing ClassCastExcetpion

      [warning 2019/03/14 14:23:43.426 IST server2 <Function Execution Processor1> tid=0x11f] Exception on server while executing function : com.pivotal.support.hot.deploy.Multiply@3e484c00
      java.lang.ClassCastException: com.pivotal.support.hot.deploy.Student cannot be cast to com.pivotal.support.hot.deploy.Student
              at com.pivotal.support.hot.deploy.Multiply.execute(Multiply.java:43)
              at org.apache.geode.internal.cache.execute.AbstractExecution.executeFunctionLocally(AbstractExecution.java:332)
              at org.apache.geode.internal.cache.execute.AbstractExecution$1.run(AbstractExecution.java:274)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
              at org.apache.geode.distributed.internal.DistributionManager.runUntilShutdown(DistributionManager.java:665)
              at org.apache.geode.distributed.internal.DistributionManager$9$1.run(DistributionManager.java:1111)
              at java.lang.Thread.run(Thread.java:745)
      

      Attachments

        Issue Links

          Activity

            People

              jens.deppe Jens Deppe
              jens.deppe Jens Deppe
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m