-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(db): optimize old rewards withdrawal #5406
feat(db): optimize old rewards withdrawal #5406
Conversation
c2a11c6
to
3fc4dbc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these removals part of the optimization reward calculation? If not, better fix it in another PR, just suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a class conflict.
Metrics.histogramObserve(requestTimer); | ||
} | ||
|
||
private Protocol.Account getAccount(byte[] address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get the account using accountStore.getFromRoot()
directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DB Cache pollution due to bulk queries, like accountStore.getFromRoot()
default UnmodifiableIterator<Entry<byte[], byte[]>> prefixQueryAfterThat | ||
(byte[] key, byte[] afterThat) { | ||
this.seek(afterThat == null ? key : afterThat); | ||
return Iterators.filter(this, entry -> Bytes.indexOf(entry.getKey(), key) == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I have doubt, whether this iterator will still access all data in the database but just return the data that matched the filter.
If so, it will do a lot of useless read-op?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not All, iterates over all data after the prefix. I can't think of a better way for now. It takes 2 minutes to iterate the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the default iterator and move the filter logic into startRewardCal
, or re-implement a prefix iterator.
Seems 2 minutes is not a big deal, depends on you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix does not work is fixed.
System.out.println((long) 128.9999999999999857891452847979962825775146484375); // will print 129
System.out.println((long) 128.9999999999999857891452847979962825775146484374999999999999999999); // will print 128 |
|
||
private long getOldReward(long beginCycle, long oldEndCycle, AccountCapsule accountCapsule) { | ||
long cacheData = rewardCalService.getReward(accountCapsule.createDbKey(), beginCycle); | ||
long reward = 0; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phase I only calculates without using, cache enabled for the next release.
return null; | ||
} | ||
|
||
long computeReward(long cycle, Protocol.Account account) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why rewrite this method instead of calling the original method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid circular dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
3fc4dbc
to
69b5391
Compare
Codecov Report
❗ 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 #5406 +/- ##
=============================================
+ Coverage 61.23% 61.32% +0.08%
- Complexity 9323 9374 +51
=============================================
Files 842 841 -1
Lines 50147 50275 +128
Branches 5580 5591 +11
=============================================
+ Hits 30710 30831 +121
+ Misses 17029 17028 -1
- Partials 2408 2416 +8
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
732d605
to
00e349b
Compare
@@ -13,23 +14,22 @@ public final class StoreIterator implements org.tron.core.db.common.iterator.DBI | |||
private final DBIterator dbIterator; | |||
private boolean first = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a simpler way by just setting first
false when invoking seek()
& seekToLast()
to solve the problem of pointer confusion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's exactly how it's handled.
00e349b
to
7c6235f
Compare
3203edf
to
320493a
Compare
@@ -2523,6 +2525,10 @@ public boolean useNewRewardAlgorithm() { | |||
return getNewRewardAlgorithmEffectiveCycle() != Long.MAX_VALUE; | |||
} | |||
|
|||
public boolean useNewRewardAlgorithmFromStart() { | |||
return getNewRewardAlgorithmEffectiveCycle() == 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this value possibly equal 1, even on a new chain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, It can be turned on anytime.
try { | ||
lock.await(); | ||
} catch (InterruptedException e) { | ||
logger.error("rewardViCalService lock error: {}", e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an InterruptedException occurs, the program will continue to execute, but with an additional error log. Is this the expected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
this.clearUp(true); | ||
logger.info("rewardViCalService is already done"); | ||
} else { | ||
if (this.getLatestBlockHeaderNumber() > lastBlockNumber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is getLatestSolidifiedBlockNum
& lastSolidifiedBlockNumber
better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This service is depend on root dbs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Review task on 2.28:
|
close #5354