Skip to content

HBASE-29831: Fix for NPE in region replication - #7629

Merged
guluo2016 merged 3 commits into
apache:branch-2from
HubSpot:HBASE-29831-read-replicas-npe
Jan 28, 2026
Merged

HBASE-29831: Fix for NPE in region replication#7629
guluo2016 merged 3 commits into
apache:branch-2from
HubSpot:HBASE-29831-read-replicas-npe

Conversation

@krconv

Copy link
Copy Markdown

The RegionReplicaSinkWriter.append() method checks table descriptors to determine if a table has region replication enabled (to decide whether to bypass the location cache). When a table is dropped concurrently, tableDescriptors.get(tableName) returns null, and the subsequent call to getRegionReplication() throws a NullPointerException.

This race condition can occur in the following scenario:

  1. WAL entries for a table are queued for replication to region replicas
  2. The table is dropped (via disable + drop or other means)
  3. Before the dropped table is added to the disabledAndDroppedTables cache (which happens when TableNotFoundException is caught during location lookup), the code attempts to read the table descriptor
  4. tableDescriptors.get() returns null for the now-deleted table
  5. NPE crashes the replication endpoint

Since RegionReplicaReplicationEndpoint handles replica updates for all tables on a RegionServer, a single dropped table crashes the entire endpoint. This stops replica updates for all regions (including those from unrelated tables) hosted by that RegionServer until it is restarted.

@Apache-HBase

This comment has been minimized.

@charlesconnellcharlesconnell changed the title Fix for NPE in region replicationHBASE-29831: Fix for NPE in region replicationJan 15, 2026
@charlesconnell
charlesconnell self-requested a review January 15, 2026 12:56
@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

if (useCache && locations.size() == 1) {
if (tableDescriptors.get(tableName).getRegionReplication() > 1 && retries <= 3) {
TableDescriptor td = tableDescriptors.get(tableName);
if (td != null && td.getRegionReplication() > 1 && retries <= 3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed through idea's smart suggestions that retries <= 3 seems is unnecessary.

Image

And I analyzed it and it's true

After removing it, there are 3 main cases, and none lead to an infinite loop:

  • case 1

First loop: useCache && locations.size() == 1 && RegionReplication > 1 is true.
Set useCache = false and continue.
Second loop: The logic will proceed and eventually return or break.

  • case2

First loop: useCache && locations.size() == 1 is true but RegionReplication > 1 is false.
Go to subsequent logic.
If !Bytes.equals(primaryLocation.getRegionInfo().getEncodedNameAsBytes(), encodedRegionName) is false: break (loop ends).
If !Bytes.equals(primaryLocation.getRegionInfo().getEncodedNameAsBytes(), encodedRegionName) is true and useCache is true: set useCache = false and continue. Second loop will then return or break.

  • case3

First loop: useCache && locations.size() == 1 is false.
Go to subsequent logic.
If useCache is alread false: return or break.
If useCache is true : similar to case 2, it will either break or retry once (setting useCache=false), then finish.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for walking through the logic here; I agree it is unneeded, just removed it

@guluo2016

Copy link
Copy Markdown
Member

Is it possible to add a unit test for this? Thanks

@chandrasekhar-188kchandrasekhar-188k left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@krconv
krconvforce-pushed the HBASE-29831-read-replicas-npe branch from d95de47 to 1f43067CompareJanuary 20, 2026 17:15
@krconv

krconv commented Jan 20, 2026

Copy link
Copy Markdown
Author

Thanks for the reviews! Added a new unit test that catches the original problem, and removed the unneeded retries variable. Also, we encountered this problem on 100s of hosts across all of the data centers where we use HBase last week, hopefully this fix helps others

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@Apache-HBase

Copy link
Copy Markdown

🎊 +1 overall

VoteSubsystemRuntimeLogfileComment
+0 🆗reexec1m 15sDocker mode activated.
_ Prechecks _
+1 💚dupname0m 0sNo case conflicting files found.
+0 🆗codespell0m 0scodespell was not available.
+0 🆗detsecrets0m 0sdetect-secrets was not available.
+1 💚@author0m 0sThe patch does not contain any @author tags.
+1 💚hbaseanti0m 0sPatch does not have any anti-patterns.
_ branch-2 Compile Tests _
+1 💚mvninstall4m 29sbranch-2 passed
+1 💚compile3m 45sbranch-2 passed
+1 💚checkstyle0m 46sbranch-2 passed
+1 💚spotbugs1m 53sbranch-2 passed
+1 💚spotless0m 55sbranch has no errors when running spotless:check.
_ Patch Compile Tests _
+1 💚mvninstall4m 6sthe patch passed
+1 💚compile3m 49sthe patch passed
+1 💚javac3m 49sthe patch passed
+1 💚blanks0m 0sThe patch has no blanks issues.
+1 💚checkstyle0m 47sthe patch passed
+1 💚spotbugs2m 15sthe patch passed
+1 💚hadoopcheck24m 35sPatch does not cause any errors with Hadoop 2.10.2 or 3.3.6 3.4.1.
+1 💚spotless1m 2spatch has no errors when running spotless:check.
_ Other Tests _
+1 💚asflicense0m 13sThe patch does not generate ASF License warnings.
52m 11s
SubsystemReport/Notes
DockerClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/artifact/yetus-general-check/output/Dockerfile
GITHUB PR#7629
JIRA IssueHBASE-29831
Optional Testsdupname asflicense javac spotbugs checkstyle codespell detsecrets compile hadoopcheck hbaseanti spotless
unameLinux f5e8bc2464c7 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev-support/hbase-personality.sh
git revisionbranch-2 / 1f43067
Default JavaEclipse Adoptium-11.0.23+9
Max. process+thread count79 (vs. ulimit of 30000)
modulesC: hbase-server U: hbase-server
Console outputhttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/console
versionsgit=2.34.1 maven=3.9.8 spotbugs=4.7.3
Powered byApache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@Apache-HBase

Copy link
Copy Markdown

💔 -1 overall

VoteSubsystemRuntimeLogfileComment
+0 🆗reexec0m 48sDocker mode activated.
-0 ⚠️yetus0m 5sUnprocessed flag(s): --brief-report-file --spotbugs-strict-precheck --author-ignore-list --blanks-eol-ignore-file --blanks-tabs-ignore-file --quick-hadoopcheck
_ Prechecks _
_ branch-2 Compile Tests _
+1 💚mvninstall3m 8sbranch-2 passed
+1 💚compile0m 59sbranch-2 passed
+1 💚javadoc0m 28sbranch-2 passed
+1 💚shadedjars6m 10sbranch has no errors when building our shaded downstream artifacts.
_ Patch Compile Tests _
+1 💚mvninstall3m 10sthe patch passed
+1 💚compile0m 59sthe patch passed
+1 💚javac0m 59sthe patch passed
+1 💚javadoc0m 28sthe patch passed
+1 💚shadedjars6m 9spatch has no errors when building our shaded downstream artifacts.
_ Other Tests _
-1 ❌unit226m 14s/patch-unit-hbase-server.txthbase-server in the patch failed.
253m 0s
SubsystemReport/Notes
DockerClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/artifact/yetus-jdk17-hadoop3-check/output/Dockerfile
GITHUB PR#7629
JIRA IssueHBASE-29831
Optional Testsjavac javadoc unit compile shadedjars
unameLinux 70295dbf72dd 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev-support/hbase-personality.sh
git revisionbranch-2 / 1f43067
Default JavaEclipse Adoptium-17.0.11+9
Test Resultshttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/testReport/
Max. process+thread count3430 (vs. ulimit of 30000)
modulesC: hbase-server U: hbase-server
Console outputhttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/console
versionsgit=2.34.1 maven=3.9.8
Powered byApache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@Apache-HBase

Copy link
Copy Markdown

🎊 +1 overall

VoteSubsystemRuntimeLogfileComment
+0 🆗reexec1m 19sDocker mode activated.
-0 ⚠️yetus0m 6sUnprocessed flag(s): --brief-report-file --spotbugs-strict-precheck --author-ignore-list --blanks-eol-ignore-file --blanks-tabs-ignore-file --quick-hadoopcheck
_ Prechecks _
_ branch-2 Compile Tests _
+1 💚mvninstall4m 54sbranch-2 passed
+1 💚compile1m 11sbranch-2 passed
+1 💚javadoc0m 40sbranch-2 passed
+1 💚shadedjars7m 41sbranch has no errors when building our shaded downstream artifacts.
_ Patch Compile Tests _
+1 💚mvninstall4m 8sthe patch passed
+1 💚compile0m 59sthe patch passed
+1 💚javac0m 59sthe patch passed
+1 💚javadoc0m 30sthe patch passed
+1 💚shadedjars7m 24spatch has no errors when building our shaded downstream artifacts.
_ Other Tests _
+1 💚unit240m 53shbase-server in the patch passed.
275m 14s
SubsystemReport/Notes
DockerClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/artifact/yetus-jdk11-hadoop3-check/output/Dockerfile
GITHUB PR#7629
JIRA IssueHBASE-29831
Optional Testsjavac javadoc unit compile shadedjars
unameLinux 6941778e670d 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev-support/hbase-personality.sh
git revisionbranch-2 / 1f43067
Default JavaEclipse Adoptium-11.0.23+9
Test Resultshttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/testReport/
Max. process+thread count3283 (vs. ulimit of 30000)
modulesC: hbase-server U: hbase-server
Console outputhttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/console
versionsgit=2.34.1 maven=3.9.8
Powered byApache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@Apache-HBase

Copy link
Copy Markdown

💔 -1 overall

VoteSubsystemRuntimeLogfileComment
+0 🆗reexec1m 11sDocker mode activated.
-0 ⚠️yetus0m 5sUnprocessed flag(s): --brief-report-file --spotbugs-strict-precheck --author-ignore-list --blanks-eol-ignore-file --blanks-tabs-ignore-file --quick-hadoopcheck
_ Prechecks _
_ branch-2 Compile Tests _
+1 💚mvninstall4m 20sbranch-2 passed
+1 💚compile1m 14sbranch-2 passed
+1 💚javadoc0m 49sbranch-2 passed
+1 💚shadedjars8m 36sbranch has no errors when building our shaded downstream artifacts.
_ Patch Compile Tests _
+1 💚mvninstall3m 55sthe patch passed
+1 💚compile1m 8sthe patch passed
+1 💚javac1m 8sthe patch passed
+1 💚javadoc0m 38sthe patch passed
+1 💚shadedjars7m 27spatch has no errors when building our shaded downstream artifacts.
_ Other Tests _
-1 ❌unit312m 13s/patch-unit-hbase-server.txthbase-server in the patch failed.
346m 28s
SubsystemReport/Notes
DockerClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/artifact/yetus-jdk8-hadoop2-check/output/Dockerfile
GITHUB PR#7629
JIRA IssueHBASE-29831
Optional Testsjavac javadoc unit compile shadedjars
unameLinux 46be563ba736 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build toolmaven
Personalitydev-support/hbase-personality.sh
git revisionbranch-2 / 1f43067
Default JavaTemurin-1.8.0_412-b08
Test Resultshttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/testReport/
Max. process+thread count3389 (vs. ulimit of 30000)
modulesC: hbase-server U: hbase-server
Console outputhttps://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-7629/3/console
versionsgit=2.34.1 maven=3.9.8
Powered byApache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@krconv
krconv requested a review from guluo2016January 21, 2026 17:45

@guluo2016guluo2016 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@krconv

Copy link
Copy Markdown
Author

@guluo2016 or @chandrasekhar-188k, would one of you mind merging this for me?

@Apache9

Copy link
Copy Markdown
Contributor

This does not affect master and branch-3?

@krconv

Copy link
Copy Markdown
Author

From what I can tell it only affects HBase 2. It looks like the implementation was rewritten for HBase 3, replacing the RegionReplicaReplicationEndpoint with RegionReplicationSink. The new implementation in branch-3/master doesn't seem to suffer from this same issue, because the RegionReplicationSink has an immutable TableDescriptor (instead of attempting to periodically poll for table descriptor updates like the branch-2 implementation, branch-3/master recreate the sink when the region reopens) and so it can't hit a NPE when a table is dropped.

@guluo2016

Copy link
Copy Markdown
Member

Sorry for the late reply, a bit busy recently.
I manually tested it, it is ok.

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 14.10 s -- in org.apache.hadoop.hbase.replication.regionserver.TestRegionReplicaReplicationEndpoint
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- surefire:3.5.3:test (secondPartTestsExecution) @ hbase-server ---
[INFO] Tests are skipped.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Apache HBase 2.7.0-SNAPSHOT:
[INFO]
[INFO] Apache HBase ....................................... SUCCESS [ 1.606 s]
[INFO] Apache HBase - Checkstyle .......................... SUCCESS [ 0.484 s]
[INFO] Apache HBase - Annotations ......................... SUCCESS [ 0.330 s]
[INFO] Apache HBase - Build Configuration ................. SUCCESS [ 0.158 s]
[INFO] Apache HBase - Logging ............................. SUCCESS [ 0.501 s]
[INFO] Apache HBase - Shaded Protocol ..................... SUCCESS [ 16.933 s]
[INFO] Apache HBase - Common .............................. SUCCESS [ 3.668 s]
[INFO] Apache HBase - Metrics API ......................... SUCCESS [ 1.372 s]
[INFO] Apache HBase - Hadoop Compatibility ................ SUCCESS [ 1.284 s]
[INFO] Apache HBase - Metrics Implementation .............. SUCCESS [ 0.815 s]
[INFO] Apache HBase - Hadoop Two Compatibility ............ SUCCESS [ 1.927 s]
[INFO] Apache HBase - Protocol ............................ SUCCESS [ 4.494 s]
[INFO] Apache HBase - Client .............................. SUCCESS [ 2.285 s]
[INFO] Apache HBase - Zookeeper ........................... SUCCESS [ 1.339 s]
[INFO] Apache HBase - Replication ......................... SUCCESS [ 1.242 s]
[INFO] Apache HBase - Resource Bundle ..................... SUCCESS [ 0.107 s]
[INFO] Apache HBase - HTTP ................................ SUCCESS [ 0.563 s]
[INFO] Apache HBase - Asynchronous FileSystem ............. SUCCESS [ 2.261 s]
[INFO] Apache HBase - Procedure ........................... SUCCESS [ 1.222 s]
[INFO] Apache HBase - Server .............................. SUCCESS [ 26.601 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Thanks @krconv

@guluo2016
guluo2016 merged commit 758dc33 into apache:branch-2Jan 28, 2026
0 of 2 checks passed
guluo2016 pushed a commit that referenced this pull request Jan 28, 2026
Signed-off-by: Chandra Kambham <chandra@apache.org>
Signed-off-by: Peng Lu <lupeng@apache.org>
@guluo2016

Copy link
Copy Markdown
Member

@krconv , The patch can not be applied to branch-2.5 cleanly. Please open a new PR for branch-2.5, thanks a lot!

krconv added a commit to HubSpot/hbase that referenced this pull request Jan 28, 2026
Signed-off-by: Chandra Kambham <chandra@apache.org>
Signed-off-by: Peng Lu <lupeng@apache.org>
@krconv

Copy link
Copy Markdown
Author

@guluo2016 Thank you! Just put up the PR for branch-2.5 here: #7684

@krconv
krconv deleted the HBASE-29831-read-replicas-npe branch February 2, 2026 11:56
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@krconv@Apache-HBase@guluo2016@Apache9@chandrasekhar-188k