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

Rerun conditional migrations #6565

Merged
merged 58 commits into from
Aug 18, 2023
Merged

Conversation

mgoelswirlds
Copy link
Member

@mgoelswirlds mgoelswirlds commented Aug 1, 2023

Description:
This PR is created to address re-running certain time sensitive migrations, for newer mirror nodes.

This PR modifies:

  • SyntheticCryptoTransferApprovalMigration to rerun when the HAPI version changes to 0.38.10 or above.
  • SyntheticNftAllowanceOwnerMigration and SyntheticTokenAllowanceOwnerMigration to rerun when the HAPI version changes to 0.37.0 or above.
  • InitializeEntityBalanceMigration and TokenAccountBalanceMigration to rerun, when the first account balance file comes in.

Related issue(s):

Fixes #6397

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Patch coverage: 81.72% and project coverage change: +7.29% 🎉

Comparison is base (edd4ce5) 85.24% compared to head (e7ddc3a) 92.53%.
Report is 6 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6565      +/-   ##
============================================
+ Coverage     85.24%   92.53%   +7.29%     
- Complexity      453     6555    +6102     
============================================
  Files            95      848     +753     
  Lines          1945    27566   +25621     
  Branches        124     3157    +3033     
============================================
+ Hits           1658    25508   +23850     
- Misses          236     1342    +1106     
- Partials         51      716     +665     
Files Changed Coverage Δ
...orter/parser/balance/AccountBalanceFileParser.java 100.00% <ø> (ø)
...er/balance/CompositeBalanceStreamFileListener.java 41.66% <41.66%> (ø)
...era/mirror/importer/parser/StreamFileListener.java 66.66% <66.66%> (ø)
...tion/SyntheticCryptoTransferApprovalMigration.java 78.16% <81.25%> (ø)
...orter/migration/TimeSensitiveBalanceMigration.java 85.71% <85.71%> (ø)
...migration/SyntheticNftAllowanceOwnerMigration.java 95.45% <92.30%> (ø)
...gration/SyntheticTokenAllowanceOwnerMigration.java 95.45% <92.30%> (ø)
...era/mirror/importer/migration/ErrataMigration.java 93.79% <100.00%> (ø)
...er/migration/InitializeEntityBalanceMigration.java 100.00% <100.00%> (ø)
...porter/migration/TokenAccountBalanceMigration.java 100.00% <100.00%> (ø)
... and 1 more

... and 767 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -44,6 +47,9 @@ protected AbstractStreamFileParser(
MeterRegistry meterRegistry,
ParserProperties parserProperties,
StreamFileRepository<T, Long> streamFileRepository) {

this.last = new AtomicReference<>();
this.lastFromDb = new AtomicReference<>();
Copy link
Member Author

Choose a reason for hiding this comment

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

This value is leveraging the last read from the repository.

var lastBalanceFile = last.get();
// If no account balance file has been processed since last startup.
if (lastBalanceFile == null && lastFromDb.get() == null) {
applicationEventPublisher.publishEvent(new InitializeBalanceEvent(this));
Copy link
Member Author

Choose a reason for hiding this comment

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

If this is the first account balance file being processed and the DB is empty then publishing InitializeBalanceEvent which will rerun balance migrations.

}

@Nullable
private AccountBalanceFile publishInitializeAccountBalanceEvent() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this into another function to reduce cognitive complexity.

return;
}

/*if(shouldRerun(streamFile,HAPI_VERSION_0_38_10,recordFileRepository)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These comments will be removed once we Merge Xin's changes to have async migration extend repeatable migration.

@@ -107,9 +115,13 @@ insert into nft_allowance (approved_for_all, owner, payer_account_id, spender, t
private final JdbcTemplate jdbcTemplate;

@Lazy
public SyntheticNftAllowanceOwnerMigration(@Owner JdbcTemplate jdbcTemplate, MirrorProperties mirrorProperties) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This migration took 779 ms on mainnet.So not converting it to Async.

import org.springframework.jdbc.core.JdbcTemplate;

@Named
public class SyntheticTokenAllowanceOwnerMigration extends RepeatableMigration {
public class SyntheticTokenAllowanceOwnerMigration extends RepeatableMigration implements RecordStreamFileListener {
Copy link
Member Author

Choose a reason for hiding this comment

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

This migration took 10158 ms on mainnet.So not converting it to Async.

Copy link
Collaborator

@xin-hedera xin-hedera Aug 4, 2023

Choose a reason for hiding this comment

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

I doubt it can work in environment where the owner and regular user are different, e.g., mirror_node and mirror_importer.

The migration uses the owner jdbcTemplate bean because it deletes rows. in some environment, mirror_importer may not be able to delete rows.

When the migration runs inside onEnd, it's in the same database transaction, and the connection in the thread local storage uses regular user mirror_importer. The migration most likely uses the same connection, and may fail to delete rows.

Copy link
Collaborator

@xin-hedera xin-hedera Aug 9, 2023

Choose a reason for hiding this comment

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

did you check if running it inside onEnd would actually pick a connection with different credentials other than owner?

this is a blocker for both SyntheticNftAllowanceOwnerMigration and SyntheticTokenAllowanceOwnerMigration

No I did not. Checking now.

Copy link
Member Author

@mgoelswirlds mgoelswirlds Aug 9, 2023

Choose a reason for hiding this comment

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

No I did not. Will need to check this. looking now.
Even if it is a different user i.e. mirror_importer, I need to verify that it can delete the rows right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can discuss. running with mirror_importer may not break ourselves but can break other mirrornode operators in case in their environment mirror_importer doesn't have permission to delete rows.

then we may have to turn these two migrations to be async.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. Lets discuss further offline.

Copy link
Member Author

Choose a reason for hiding this comment

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

I verified that even when migrate is called from with the onEnd it uses the mirror_node user.

@mgoelswirlds mgoelswirlds marked this pull request as ready for review August 4, 2023 00:27
@steven-sheehy steven-sheehy changed the title Initial commit to rerun said migrations. Rerun conditional migrations Aug 4, 2023
@steven-sheehy steven-sheehy requested a review from a team August 4, 2023 17:08
@steven-sheehy steven-sheehy added enhancement Type: New feature parser Area: File parsing labels Aug 4, 2023
@steven-sheehy steven-sheehy added this to the 0.87.0 milestone Aug 4, 2023
mgoelswirlds and others added 6 commits August 4, 2023 14:14
…r/migration/InitializeEntityBalanceMigration.java

Co-authored-by: Xin Li <59580070+xin-hedera@users.noreply.github.com>
Signed-off-by: Mugdha Goel <106084778+mgoelswirlds@users.noreply.github.com>
…r/migration/SyntheticCryptoTransferApprovalMigration.java

Co-authored-by: Xin Li <59580070+xin-hedera@users.noreply.github.com>
Signed-off-by: Mugdha Goel <106084778+mgoelswirlds@users.noreply.github.com>
…r/migration/InitializeEntityBalanceMigration.java

Co-authored-by: Xin Li <59580070+xin-hedera@users.noreply.github.com>
Signed-off-by: Mugdha Goel <106084778+mgoelswirlds@users.noreply.github.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
… for tokenAccountBalance or InitializeEntityBalance

Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: Mugdha Goel <106084778+mgoelswirlds@users.noreply.github.com>
Adding missing test cases.
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
…yBalanceMigrationTest and TokenAccountBalanceMigrationTest

Arranging fields.

Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
xin-hedera
xin-hedera previously approved these changes Aug 18, 2023
Copy link
Collaborator

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Copy link
Member

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

LGTM

@sonarcloud
Copy link

sonarcloud bot commented Aug 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.3% 0.3% Duplication

Copy link
Collaborator

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

@mgoelswirlds mgoelswirlds merged commit 74fb92b into main Aug 18, 2023
24 of 25 checks passed
@mgoelswirlds mgoelswirlds deleted the 6397-Time-sensitive-migrations branch August 18, 2023 18:01
bilyana-gospodinova pushed a commit that referenced this pull request Aug 23, 2023
Description:
This PR is created to address re-running certain time sensitive migrations, for newer and partial mirror nodes.

This PR modifies:
- SyntheticCryptoTransferApprovalMigration to rerun when the HAPI version changes to 0.38.10 or above.
- SyntheticNftAllowanceOwnerMigration and SyntheticTokenAllowanceOwnerMigration to rerun when the HAPI version changes to 0.37.0 or above.
- InitializeEntityBalanceMigration and TokenAccountBalanceMigration to rerun, after the first account balance file has been parsed.

Related issue(s):
Fixes #6397
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature parser Area: File parsing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure time sensitive migrations run again during parser
3 participants