You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "hiwuya (via GitHub)" <gi...@apache.org> on 2026/07/24 16:33:02 UTC
[PR] HDDS-15963. Fix EC degraded read NPE caused by CodecRegistry depending on TCCL in isolated ClassLoader [ozone]
hiwuya opened a new pull request, #10861:
URL: https://github.com/apache/ozone/pull/10861
## What changes were proposed in this pull request?
This PR fixes a `NullPointerException` during EC degraded reads when the Ozone client runs inside an isolated plugin class loader (e.g. Trino Hive connector).
Normal reads succeed, but when a DataNode is unavailable, the EC degraded read path fails with:
```
java.lang.NullPointerException:
Cannot read the array length because "<local3>" is null
at org.apache.ozone.erasurecode.rawcoder.util.CodecUtil
.createRawDecoderWithFallback(CodecUtil.java:90)
```
Root cause: `CodecRegistry` loads coder factories via `ServiceLoader.load(RawErasureCoderFactory.class)`, which uses the **thread context class loader (TCCL)**. In Trino's isolated plugin class loader, the TCCL cannot see the Ozone `META-INF/services` providers, so `getCoderNames("rs")` returns `null`, causing the NPE in `CodecUtil`. Spark works because its TCCL can see the Ozone providers.
**Fix:** Use `CodecRegistry`'s own class loader instead of the TCCL:
```java
ServiceLoader.load(RawErasureCoderFactory.class,
CodecRegistry.class.getClassLoader());
```
No changes to the singleton pattern, registration logic, native coder priority, fallback order, or public API.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-15963
## How was this patch tested?
- Added `testRegistryLoadsWithoutTccl`: sets TCCL to an empty `ClassLoader(null)` before first `CodecRegistry` initialization, then verifies `getCoderNames("rs")` is non-null, non-empty, and contains `rs_java`. Restores TCCL in `finally`.
- Confirmed the test fails when the fix is reverted.
- Full `hdds-erasurecode` module test suite: 80 tests pass, 39 native tests skipped (environment), no regressions.
- Note: This test must run in its own JVM (`reuseForks=false`) due to the eagerly-initialized singleton.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-15963. Fix EC degraded read NPE caused by CodecRegistry depending on TCCL in isolated ClassLoader [ozone]
Posted by "chihsuan (via GitHub)" <gi...@apache.org>.
chihsuan commented on code in PR #10861:
URL: https://github.com/apache/ozone/pull/10861#discussion_r3649824346
##########
hadoop-hdds/erasurecode/src/test/java/org/apache/ozone/erasurecode/TestCodecRegistryTcclIsolation.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.ozone.erasurecode;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.ozone.erasurecode.rawcoder.RSRawErasureCoderFactory;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests that CodecRegistry does not depend on the thread context class loader
+ * (TCCL) for discovering RawErasureCoderFactory providers.
+ *
+ * <p>CodecRegistry is an eagerly-initialized singleton, so this test must run
+ * in its own JVM (e.g. reuseForks=false) as the first test to touch
+ * CodecRegistry, otherwise initialization already happened under the normal
+ * TCCL and the test passes vacuously.
+ */
+public class TestCodecRegistryTcclIsolation {
+
+ @Test
+ public void testRegistryLoadsWithoutTccl() {
+ ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(new ClassLoader(null) {
+ });
+ String[] rsCoderNames = CodecRegistry.getInstance()
+ .getCoderNames(ECReplicationConfig.EcCodec.RS.name().toLowerCase());
+ assertThat(rsCoderNames).isNotNull();
+ assertThat(rsCoderNames).isNotEmpty();
+ assertThat(rsCoderNames).contains(RSRawErasureCoderFactory.CODER_NAME);
Review Comment:
nit: `assertThat(rsCoderNames).contains(...)` alone already implies non-null and non-empty.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-15963. Fix EC degraded read NPE caused by CodecRegistry depending on TCCL in isolated ClassLoader [ozone]
Posted by "chihsuan (via GitHub)" <gi...@apache.org>.
chihsuan commented on code in PR #10861:
URL: https://github.com/apache/ozone/pull/10861#discussion_r3649093598
##########
hadoop-hdds/erasurecode/src/test/java/org/apache/ozone/erasurecode/TestCodecRegistry.java:
##########
@@ -158,4 +158,20 @@ public void testGetCoderByName() {
NativeXORRawErasureCoderFactory.CODER_NAME);
assertInstanceOf(NativeXORRawErasureCoderFactory.class, coder);
}
+
+ @Test
+ public void testRegistryLoadsWithoutTccl() {
Review Comment:
`CodecRegistry.instance` is a static singleton, so if any other test in this class runs first, the registry is already initialized, and this test passes even with the fix reverted.
https://github.com/apache/ozone/blob/d38e83979ff857dcf6a68c47403613151b0d5a26/hadoop-hdds/erasurecode/src/main/java/org/apache/ozone/erasurecode/CodecRegistry.java#L46
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-15963. Fix EC degraded read NPE caused by CodecRegistry depending on TCCL in isolated ClassLoader [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #10861:
URL: https://github.com/apache/ozone/pull/10861
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-15963. Fix EC degraded read NPE caused by CodecRegistry depending on TCCL in isolated ClassLoader [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #10861:
URL: https://github.com/apache/ozone/pull/10861#issuecomment-5141266730
Thanks @hiwuya for the patch, @chihsuan, @smengcl for the review.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-15963. Fix EC degraded read NPE caused by CodecRegistry depending on TCCL in isolated ClassLoader [ozone]
Posted by "hiwuya (via GitHub)" <gi...@apache.org>.
hiwuya commented on PR #10861:
URL: https://github.com/apache/ozone/pull/10861#issuecomment-5076500608
@chihsuan Good catch. I've moved the test to a separate class TestCodecRegistryTcclIsolation so it runs in its own JVM and is guaranteed to be the first test touching CodecRegistry.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org