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

feature(db): optimize properties query frequency #5378

Conversation

CarlChaoCarl
Copy link
Contributor

@CarlChaoCarl CarlChaoCarl commented Jul 28, 2023

close #5375

isOptimized = snapshot.isOptimized();
if (isOptimized) {
if (root == previous) {
Streams.stream(root.iterator()).forEach( e -> put(e.getKey(),e.getValue()));
Copy link
Contributor

Choose a reason for hiding this comment

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

reformat the code style, put the white space to the right place

Copy link
Contributor

Choose a reason for hiding this comment

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

These two if statements can be combined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌🏻

}
}
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Why reserve these if they are useless?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this part of the commented code

SnapshotImpl fromImpl = (SnapshotImpl) from;
Streams.stream(fromImpl.db).forEach(e ->
{
if (db.get(e.getKey()) == null && e.getValue() != null ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

code format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌🏻

@@ -83,6 +99,20 @@ public void merge(Snapshot from) {
Streams.stream(fromImpl.db).forEach(e -> db.put(e.getKey(), e.getValue()));
}

public void mergeFullData(Snapshot from) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As I see, the merge method is used for merging the snapshotImpl which is behind itself, this method mergeFullData is used for merging the snapshotImpl which is ahead, and only one snapshot. it only can merge all data by another outside iteration.

So renaming the method name to mergeAhead or mergeBefore or mergeFront may be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I renamed the mergeFullData function to mergeAhead

@@ -233,6 +233,12 @@ public synchronized void commit() {
}

--activeSession;

dbs.forEach(db -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why set the reload logic in commit(), commit() only invoked by the end of pushing a block, not a transaction.

Are there other reasons for doing this, can you explain?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because if the transaction ends without a commit,
Revoke is needed at this time,
session.close is called,
Then call snapshotManager.revoke,
Then there is no need to perform reload logic.
So the reload logic is only executed when the transaction commits.

@tomatoishealthy @halibobo1205

@tomatoishealthy
Copy link
Contributor

Any issue associated with this PR? So we can have a comprehensive background

@halibobo1205 halibobo1205 changed the title feature(mechanism): optimize properties query frequency feature(db): optimize properties query frequency Aug 3, 2023
@CarlChaoCarl
Copy link
Contributor Author

Any issue associated with this PR? So we can have a comprehensive background

This Issue is associated with the current pr
#5375

@halibobo1205
Copy link
Contributor

@CarlChaoCarl Please fix CI.

@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.7.3 milestone Aug 9, 2023
@CarlChaoCarl
Copy link
Contributor Author

@CarlChaoCarl Please fix CI.

OK, I have solved the CI problem

@CarlChaoCarl CarlChaoCarl reopened this Aug 9, 2023
}
SnapshotImpl fromImpl = (SnapshotImpl) from;
Streams.stream(fromImpl.db).forEach(e -> {
if (db.get(e.getKey()) == null && e.getValue() != null) {
Copy link
Contributor

@halibobo1205 halibobo1205 Aug 10, 2023

Choose a reason for hiding this comment

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

How would happen for e.getValue() == null?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is necessary to count which keys are null and whether the access frequency is high

Copy link
Contributor Author

Choose a reason for hiding this comment

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

db.get(e.getKey()) == null && e.getValue() != null
Passing these two judgments means:

  1. The current db does not have this key, that is, db.get(e.getKey()) is null,
  2. At the same time, the snapshotimpl from has this key and the value is not empty, that is, e.getValue() != null.

@wubin01 @halibobo1205

Copy link
Contributor

Choose a reason for hiding this comment

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

How would happen for e.getValue() == null?

@halibobo1205 is it possible that key exists but value is null in the property database?

Copy link
Contributor

Choose a reason for hiding this comment

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

@yuekun0707 , It shouldn't be null.
image

@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2023

Codecov Report

Merging #5378 (0f86735) into develop (ad728fa) will increase coverage by 0.00%.
The diff coverage is 95.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             develop    #5378   +/-   ##
==========================================
  Coverage      61.35%   61.35%           
- Complexity      9348     9352    +4     
==========================================
  Files            846      846           
  Lines          50211    50231   +20     
  Branches        5583     5584    +1     
==========================================
+ Hits           30805    30818   +13     
+ Misses         17002    17001    -1     
- Partials        2404     2412    +8     
Files Changed Coverage Δ
...src/main/java/org/tron/core/db2/core/Snapshot.java 0.00% <ø> (ø)
...main/java/org/tron/core/db2/core/SnapshotRoot.java 73.87% <50.00%> (-0.44%) ⬇️
.../java/org/tron/core/db2/core/AbstractSnapshot.java 90.00% <100.00%> (+1.11%) ⬆️
...main/java/org/tron/core/db2/core/SnapshotImpl.java 91.56% <100.00%> (+1.56%) ⬆️
...n/java/org/tron/core/db2/core/SnapshotManager.java 74.58% <100.00%> (+0.85%) ⬆️

... and 11 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

SnapshotImpl fromImpl = (SnapshotImpl) from;
Streams.stream(fromImpl.db).forEach(e ->
{
if (db.get(e.getKey()) == null && e.getValue() != null ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will there be a frequently accessed key with a value of null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

db.get(e.getKey()) == null && e.getValue() != null
Passing these two judgments means:

  1. The current db does not have this key, that is, db.get(e.getKey()) is null,
  2. At the same time, the snapshotimpl from has this key and the value is not empty, that is, e.getValue() != null.

@wubin01

isOptimized = snapshot.isOptimized();
if (isOptimized) {
if (root == previous) {
Streams.stream(root.iterator()).forEach( e -> put(e.getKey(),e.getValue()));
Copy link
Contributor

Choose a reason for hiding this comment

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

These two if statements can be combined


dbs.forEach(db -> {
if (db.getHead().isOptimized()) {
db.getHead().reloadToMem();
Copy link
Contributor

Choose a reason for hiding this comment

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

isOptimized judged twice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK,I get 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.

I have fixed this

}
SnapshotImpl fromImpl = (SnapshotImpl) from;
Streams.stream(fromImpl.db).forEach(e -> {
if (db.get(e.getKey()) == null && e.getValue() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is necessary to count which keys are null and whether the access frequency is high

@tomatoishealthy
Copy link
Contributor

Better to add the unit test for these changes

@CarlChaoCarl
Copy link
Contributor Author

Better to add the unit test for these changes

@tomatoishealthy Yeah, I have added unit tests.

@halibobo1205 halibobo1205 merged commit 068764b into tronprotocol:develop Sep 4, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Query Performance of Property Store
6 participants