You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/12/31 06:57:47 UTC
[GitHub] [pulsar] mattisonchao opened a new pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
mattisonchao opened a new pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589
### Motivation
It's ``BrokerInterceptor`` side change, like #11270
### Modifications
Change context class loader through Thread.currentThread().setContextClassLoader(classLoader) before every interceptor handler callback, and change it back to original class loader afterwards.
### Verifying this change
- [x] Make sure that the change passes the CI checks.
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): ( no)
- The public API: ( no)
- The schema: ( no)
- The default values of configurations: ( no)
- The wire protocol: (no)
- The rest endpoints: (no)
- The admin cli options: (no)
- Anything that affects deployment: (no)
### Documentation
Check the box below and label this PR (if you have committer privilege).
Need to update docs?
- [x] `no-need-doc`
--
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] mattisonchao commented on a change in pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on a change in pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#discussion_r780028816
##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorWithClassLoaderTest.java
##########
@@ -18,14 +18,26 @@
*/
package org.apache.pulsar.broker.intercept;
-import org.apache.pulsar.broker.PulsarService;
-import org.apache.pulsar.common.nar.NarClassLoader;
-import org.testng.annotations.Test;
-
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.testng.Assert.assertEquals;
+import com.google.common.collect.Maps;
+import io.netty.buffer.ByteBuf;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.service.*;
Review comment:
fixed
--
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] mattisonchao commented on pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#issuecomment-1008223510
@codelipenghui @BewareMyPower
PTAL :)
--
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] mattisonchao commented on pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#issuecomment-1005428418
/pulsarbot rerun-failure-checks
--
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] codelipenghui commented on a change in pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#discussion_r780027408
##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorWithClassLoaderTest.java
##########
@@ -18,14 +18,26 @@
*/
package org.apache.pulsar.broker.intercept;
-import org.apache.pulsar.broker.PulsarService;
-import org.apache.pulsar.common.nar.NarClassLoader;
-import org.testng.annotations.Test;
-
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.testng.Assert.assertEquals;
+import com.google.common.collect.Maps;
+import io.netty.buffer.ByteBuf;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.service.*;
Review comment:
Avoid using star import.
--
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] mattisonchao commented on pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#issuecomment-1005654381
@BewareMyPower PTAL :)
--
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] mattisonchao commented on pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#issuecomment-1004537831
@codelipenghui @BewareMyPower @eolivelli
PTAL :)
--
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] mattisonchao commented on a change in pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on a change in pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#discussion_r778560235
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/ClassLoaderSwitcher.java
##########
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker;
+
+/**
+ * Help to switch the class loader of current thread to the NarClassLoader, and change it back when it's done.
+ * With the help of try-with-resources statement, the code would be cleaner than using try finally every time.
+ */
+public class ClassLoaderSwitcher implements AutoCloseable {
Review comment:
done.
--
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] codelipenghui merged pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
codelipenghui merged pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589
--
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] BewareMyPower commented on a change in pull request #13589: Change ``ContextClassLoader`` to ``NarClassLoader`` in BrokerInterceptor
Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #13589:
URL: https://github.com/apache/pulsar/pull/13589#discussion_r778130381
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/ClassLoaderSwitcher.java
##########
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker;
+
+/**
+ * Help to switch the class loader of current thread to the NarClassLoader, and change it back when it's done.
+ * With the help of try-with-resources statement, the code would be cleaner than using try finally every time.
+ */
+public class ClassLoaderSwitcher implements AutoCloseable {
Review comment:
Could you use the existing `ClassLoaderSwitcher` class introduced from https://github.com/apache/pulsar/pull/13501 instead of adding the same code?
--
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