Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-28956 RSMobFileCleanerChore may close the StoreFileReader object which is being used by Compaction thread #6439

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

guluo2016
Copy link
Contributor

Details see: HBASE-28956

Comment on lines 129 to 142
if (sf.getReader() == null) {
synchronized (sf) {
if (sf.getReader() == null) {
needCreateReader = true;
sf.initReader();
mobRefData = sf.getMetadataValue(HStoreFile.MOB_FILE_REFS);
bulkloadMarkerData = sf.getMetadataValue(HStoreFile.BULKLOAD_TASK_KEY);
// close store file to avoid memory leaks
sf.closeStoreFile(true);
}
}
}
// If the StoreFileReader object was created by another thread, even if the reader
// has been closed now, we can still obtain the data by HStoreFile.metataMap,
// because the map will not be cleared when the reader is closed.
if (!needCreateReader) {
mobRefData = sf.getMetadataValue(HStoreFile.MOB_FILE_REFS);
bulkloadMarkerData = sf.getMetadataValue(HStoreFile.BULKLOAD_TASK_KEY);
}
Copy link
Contributor

@wchevreuil wchevreuil Nov 4, 2024

Choose a reason for hiding this comment

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

Could we save some lines here? Seems we only need to avoid the sf.closeStoreFile(true); if the reader was not yet null, so maybe just the below would do:

            boolean needCreateReader = sf.getReader() == null;
            sf.initReader();
            byte[] mobRefData = sf.getMetadataValue(HStoreFile.MOB_FILE_REFS);
            byte[] bulkloadMarkerData = sf.getMetadataValue(HStoreFile.BULKLOAD_TASK_KEY);
            // close store file to avoid memory leaks
            if(needCreateReader) {
                sf.closeStoreFile(true);
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review.
I think this way may still have the same problem.

Assume that there are two threads holding the same StoreFile object.
Let's take a look at this situation:

// Time1 RSMobFileCleanerChore (Thread A) executing this code, and reader is null
// now needCreateReader is true
boolean needCreateReader = sf.getReader() == null; 

// Time2 another thread (Thread B) create the reader object

// Time3 Thread A continue to execute the code
// now reader has been created by Thread B, 
// so RSMobFileCleanerChore will not create the reader object
sf.initReader();
byte[] mobRefData = sf.getMetadataValue(HStoreFile.MOB_FILE_REFS);
byte[] bulkloadMarkerData = sf.getMetadataValue(HStoreFile.BULKLOAD_TASK_KEY);

// Time4 RSMobFileCleanerChore continue to execute the code
// because needCreateReader is true, so it will close the reader which isn't created by itself
if(needCreateReader) {
  sf.closeStoreFile(true);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Put it under synchronized ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, writing code this way will be much more concise.
But at the same time, I think performance also needs to be considered.
When the reader does not need to be created by itself, We do not need to perform read operations in the synchronization code block because locking may cause other threads to wait. In this case, exiting the synchronization code block early may reduce the waiting time for other threads. (If there are other threads waiting to obtain this lock)
Therefore, when executing the following code, I think it needs to be divided into two cases:

if (sf.getReader() == null) {
      synchronized (sf) {
        boolean needCreateReader = sf.getReader() == null; 
        // Case 1: needCreateReader = true, create reader, and do something
        // Case 2: needCreateReader = false, exit the synchronization code block to reduce performance overhead
      }
}

What do you think?
I look forward to your response. Thanks a lot!

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the operations within the synchronized block are all O(1), apart from close when we have to evict blocks from the cache, but we would only call close here if the reader was null, which means, this file has probably been compacted already and have no references to it. Now, in such cases when reader was null, would we ever open a reader again outside this cleaner chore? I suppose not.

Nevertheless, this is a minor style suggestion, am ok to go without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agree with you, Let me make some changes later.

Thank you very much for your patient and detailed review!

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

Copy link
Contributor

@wchevreuil wchevreuil left a comment

Choose a reason for hiding this comment

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

UT failure seems unrelated. The pending comment is just a minor (style) suggestion.

@guluo2016
Copy link
Contributor Author

The change has been made. thanks.

@Apache-HBase
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 49s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 hbaseanti 0m 0s Patch does not have any anti-patterns.
_ master Compile Tests _
+1 💚 mvninstall 3m 44s master passed
+1 💚 compile 3m 51s master passed
+1 💚 checkstyle 0m 42s master passed
+1 💚 spotbugs 1m 42s master passed
+1 💚 spotless 0m 52s branch has no errors when running spotless:check.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 37s the patch passed
+1 💚 compile 3m 34s the patch passed
+1 💚 javac 3m 34s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 46s the patch passed
+1 💚 spotbugs 1m 55s the patch passed
+1 💚 hadoopcheck 10m 56s Patch does not cause any errors with Hadoop 3.3.6 3.4.0.
+1 💚 spotless 0m 43s patch has no errors when running spotless:check.
_ Other Tests _
+1 💚 asflicense 0m 11s The patch does not generate ASF License warnings.
40m 19s
Subsystem Report/Notes
Docker ClientAPI=1.47 ServerAPI=1.47 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6439/2/artifact/yetus-general-check/output/Dockerfile
GITHUB PR #6439
Optional Tests dupname asflicense javac spotbugs checkstyle codespell detsecrets compile hadoopcheck hbaseanti spotless
uname Linux b76b8b4b0acf 5.4.0-195-generic #215-Ubuntu SMP Fri Aug 2 18:28:05 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/hbase-personality.sh
git revision master / 3cd6d64
Default Java Eclipse Adoptium-17.0.11+9
Max. process+thread count 84 (vs. ulimit of 30000)
modules C: hbase-server U: hbase-server
Console output https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6439/2/console
versions git=2.34.1 maven=3.9.8 spotbugs=4.7.3
Powered by Apache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@Apache-HBase
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 54s Docker mode activated.
-0 ⚠️ yetus 0m 3s Unprocessed flag(s): --brief-report-file --spotbugs-strict-precheck --author-ignore-list --blanks-eol-ignore-file --blanks-tabs-ignore-file --quick-hadoopcheck
_ Prechecks _
_ master Compile Tests _
+1 💚 mvninstall 3m 7s master passed
+1 💚 compile 0m 57s master passed
+1 💚 javadoc 0m 32s master passed
+1 💚 shadedjars 5m 23s branch has no errors when building our shaded downstream artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 22s the patch passed
+1 💚 compile 1m 3s the patch passed
+1 💚 javac 1m 3s the patch passed
+1 💚 javadoc 0m 29s the patch passed
+1 💚 shadedjars 5m 34s patch has no errors when building our shaded downstream artifacts.
_ Other Tests _
-1 ❌ unit 266m 23s /patch-unit-hbase-server.txt hbase-server in the patch failed.
293m 14s
Subsystem Report/Notes
Docker ClientAPI=1.47 ServerAPI=1.47 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6439/2/artifact/yetus-jdk17-hadoop3-check/output/Dockerfile
GITHUB PR #6439
Optional Tests javac javadoc unit compile shadedjars
uname Linux 53729de22581 5.4.0-195-generic #215-Ubuntu SMP Fri Aug 2 18:28:05 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/hbase-personality.sh
git revision master / 3cd6d64
Default Java Eclipse Adoptium-17.0.11+9
Test Results https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6439/2/testReport/
Max. process+thread count 4721 (vs. ulimit of 30000)
modules C: hbase-server U: hbase-server
Console output https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6439/2/console
versions git=2.34.1 maven=3.9.8
Powered by Apache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

Sign up for free to 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.

3 participants