You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "BewareMyPower (via GitHub)" <gi...@apache.org> on 2023/07/25 04:41:57 UTC

[GitHub] [pulsar] BewareMyPower opened a new issue, #20869: [Bug] Connector cannot access methods from pulsar-client-original

BewareMyPower opened a new issue, #20869:
URL: https://github.com/apache/pulsar/issues/20869

   ### Search before asking
   
   - [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
   
   
   ### Version
   
   - OS: macOS 13.4.1 m1
   - Pulsar: 3.0.0
   
   ### Minimal reproduce step
   
   See https://github.com/BewareMyPower/pulsar-sink-demo
   
   ### What did you expect to see?
   
   It should succeed.
   
   ### What did you see instead?
   
   ClassCastException
   
   ### Anything else?
   
   From https://github.com/apache/pulsar/pull/17835, it seems that we need to use reflection to access methods and classes in the module. But it harms the user experience.
   
   > The root problem is that connectors should not bundle the Pulsar client impl because it's provided at runtime by the Java Functions framework.
   
   From the PR description, it seems to be related to how the Java Functions framework loads the connector. Ideally, it should use the default classpath of Pulsar broker.
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on issue #20869: [Bug] Connector cannot access methods from pulsar-client-original

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-1649994660

   Logging how `NarClassLoader` load classes. It loads -
   
   ```
   - loading org.example.DemoSink
   - loading org.apache.pulsar.client.impl.MessageIdImpl
   - loading org.apache.pulsar.client.api.MessageIdAdv
   ```
   
   But not `MessageId`. So the instance is of `MessageId` loaded by the URLClassLoader while we try to cast it to `MessageIdImpl` loaded by NarClassLoader.
   
   We set the NarClassLoader as context class loader before handling result -
   
   ```
                   Thread.currentThread().setContextClassLoader(instanceClassLoader);
   
                   // register end time
                   stats.processTimeEnd();
   
                   if (result != null) {
                       // process the synchronous results
                       handleResult(currentRecord, result);
                   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on issue #20869: [Bug] Connector cannot access methods from pulsar-client-original

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-1650195372

   cc @jiangpengcheng @nlu90 @lhotari @nicoloboschi Although the root cause located, it's not quite easy to solve this issue. My workaround can work, but I'm not sure if extra affect coupled.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on issue #20869: [Bug] Connector cannot access methods from pulsar-client-original

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-1649943172

   Can reproduce on my local env. This is a X is not X class loading issue -
   
   ```
   java.lang.ClassCastException: class org.apache.pulsar.client.impl.MessageIdImpl cannot be cast to class org.apache.pulsar.client.impl.MessageIdImpl (org.apache.pulsar.client.impl.MessageIdImpl is in unnamed module of loader java.net.URLClassLoader @148080bb; org.apache.pulsar.client.impl.MessageIdImpl is in unnamed module of loader org.apache.pulsar.common.nar.NarClassLoader @2416a51)
   	at org.example.DemoSink.lambda$write$0(DemoSink.java:25) ~[OjpVVcIuC05Ba5ELqz3aLA/:?]
   	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
   	at org.example.DemoSink.write(DemoSink.java:22) ~[OjpVVcIuC05Ba5ELqz3aLA/:?]
   	at org.apache.pulsar.functions.instance.JavaInstanceRunnable.sendOutputMessage(JavaInstanceRunnable.java:439) ~[?:?]
   	at org.apache.pulsar.functions.instance.JavaInstanceRunnable.handleResult(JavaInstanceRunnable.java:401) ~[?:?]
   	at org.apache.pulsar.functions.instance.JavaInstanceRunnable.run(JavaInstanceRunnable.java:341) ~[?:?]
   	at java.lang.Thread.run(Thread.java:833) ~[?:?]
   ```
   
   I'll try to investigate it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Connector cannot access methods from pulsar-client-original [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-6385929001

   Still present on master. `pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceStarter.java` line 216 still creates the connector's class loader with `rootClassLoader` as its parent. The records passed to `Sink.write` carry client implementation objects (for example `MessageIdImpl`) loaded by `functionInstanceClassLoader`. A sink that bundles `pulsar-client-original` and casts to those classes therefore gets `ClassCastException: MessageIdImpl cannot be cast to MessageIdImpl`, as traced above. Whether connectors should see the runtime's client implementation classes is a class-loader isolation decision for maintainers. https://github.com/apache/pulsar/pull/17835 recommended that connectors not bundle the client implementation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on issue #20869: [Bug] Connector cannot access methods from pulsar-client-original

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-1650193823

   Workaround with a hack internal -
   
   ```patch
   diff --git a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
   index c3f36f754d..cc4bd4d7d2 100644
   --- a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
   +++ b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
   @@ -211,6 +211,8 @@ public class JavaInstanceRunnable implements AutoCloseable, Runnable {
            this.collectorRegistry = collectorRegistry;
    
            this.instanceClassLoader = Thread.currentThread().getContextClassLoader();
   +        log.info("componentClassLoader: {}", this.componentClassLoader);
   +        log.info("instanceClassLoader: {}", this.instanceClassLoader);
        }
    
        /**
   diff --git a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceStarter.java b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceStarter.java
   index 89281a2f55..c47c2bf9fa 100644
   --- a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceStarter.java
   +++ b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceStarter.java
   @@ -195,7 +195,7 @@ public class JavaInstanceStarter implements AutoCloseable {
                functionDetailsJsonString = functionDetailsJsonString.substring(0, functionDetailsJsonString.length() - 1);
            }
            JsonFormat.parser().merge(functionDetailsJsonString, functionDetailsBuilder);
   -        FunctionCacheManager fnCache = new FunctionCacheManagerImpl(rootClassLoader);
   +        FunctionCacheManager fnCache = new FunctionCacheManagerImpl(functionInstanceClassLoader);
            ClassLoader functionClassLoader = ThreadRuntime.loadJars(jarFile, instanceConfig, functionId,
                    functionDetailsBuilder.getName(), narExtractionDirectory, fnCache);
            inferringMissingTypeClassName(functionDetailsBuilder, functionClassLoader);
   ```
   
   The root cause is that the `Record` passed to `sink.write` is loaded by `functionInstanceClassLoader` and thus its internal `MessageIdImpl`. The class loader is URLClassLoader loading `pulsar.functions.instance.classpath`.
   
   ... while the sink class is loaded by `NarClassLoader` whose parent is "root classloader" a.k.a. the default AppClassLoader.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on issue #20869: [Bug] Connector cannot access methods from pulsar-client-original

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-1692637121

   The issue had no activity for 30 days, mark with Stale label.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Connector cannot access methods from pulsar-client-original [pulsar]

Posted by "rokadepiyush49-rgb (via GitHub) via commits" <co...@pulsar.apache.org>.
rokadepiyush49-rgb commented on issue #20869:
URL: https://github.com/apache/pulsar/issues/20869#issuecomment-7084889982

   `JavaInstanceStarter` still parents the connector loader on `rootClassLoader`, so this is what happens:
   
   ```mermaid
   flowchart TD
     R[rootClassLoader: API classes only] --> C[connector class loader]
     I[client impl classes] -. not visible .-> C
     C --> S[Sink.write gets an impl record]
     S --> X[ClassCastException]
   ```
   
   I'd like to reproduce this with a tiny sink, then write up two options: expose what connectors need through API types, or add a connector-only path to the impl classes. tisonkun, is your 2023 workaround still the direction you'd go?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org