-
Notifications
You must be signed in to change notification settings - Fork 112
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
Conversation
Codecov ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
@@ -44,6 +47,9 @@ protected AbstractStreamFileParser( | |||
MeterRegistry meterRegistry, | |||
ParserProperties parserProperties, | |||
StreamFileRepository<T, Long> streamFileRepository) { | |||
|
|||
this.last = new AtomicReference<>(); | |||
this.lastFromDb = new AtomicReference<>(); |
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 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)); |
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 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() { |
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.
Moved this into another function to reduce cognitive complexity.
return; | ||
} | ||
|
||
/*if(shouldRerun(streamFile,HAPI_VERSION_0_38_10,recordFileRepository)) { |
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.
These comments will be removed once we Merge Xin's changes to have async migration extend repeatable migration.
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
@@ -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) { |
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 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 { |
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 migration took 10158 ms on mainnet.So not converting it to Async.
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.
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.
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.
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.
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.
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?
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.
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.
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.
Ok. Lets discuss further offline.
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.
I verified that even when migrate is called from with the onEnd it uses the mirror_node user.
...main/java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalMigration.java
Show resolved
Hide resolved
...main/java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalMigration.java
Outdated
Show resolved
Hide resolved
...main/java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalMigration.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/hedera/mirror/importer/migration/SyntheticNftAllowanceOwnerMigration.java
Outdated
Show resolved
Hide resolved
...rc/main/java/com/hedera/mirror/importer/parser/record/MigrationRecordStreamFileListener.java
Outdated
Show resolved
Hide resolved
...ter/src/main/java/com/hedera/mirror/importer/migration/InitializeEntityBalanceMigration.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/parser/balance/AccountBalanceFileParser.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/parser/balance/AccountBalanceFileParser.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/parser/balance/AccountBalanceFileParser.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/parser/balance/AccountBalanceFileParser.java
Outdated
Show resolved
Hide resolved
…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.
...porter/src/main/java/com/hedera/mirror/importer/migration/TimeSensitiveBalanceMigration.java
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/migration/TimeSensitiveBalanceMigration.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/migration/TimeSensitiveBalanceMigration.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/migration/TimeSensitiveBalanceMigration.java
Outdated
Show resolved
Hide resolved
...ter/src/test/java/com/hedera/mirror/importer/migration/TokenAccountBalanceMigrationTest.java
Outdated
Show resolved
Hide resolved
...java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalsMigrationTest.java
Outdated
Show resolved
Hide resolved
...java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalsMigrationTest.java
Outdated
Show resolved
Hide resolved
...java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalsMigrationTest.java
Outdated
Show resolved
Hide resolved
...java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalsMigrationTest.java
Outdated
Show resolved
Hide resolved
...est/java/com/hedera/mirror/importer/migration/SyntheticTokenAllowanceOwnerMigrationTest.java
Outdated
Show resolved
Hide resolved
.../test/java/com/hedera/mirror/importer/migration/SyntheticNftAllowanceOwnerMigrationTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
...src/test/java/com/hedera/mirror/importer/migration/InitializeEntityBalanceMigrationTest.java
Show resolved
Hide resolved
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
...src/test/java/com/hedera/mirror/importer/migration/InitializeEntityBalanceMigrationTest.java
Outdated
Show resolved
Hide resolved
...java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalsMigrationTest.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/migration/TimeSensitiveBalanceMigration.java
Outdated
Show resolved
Hide resolved
...porter/src/main/java/com/hedera/mirror/importer/migration/TimeSensitiveBalanceMigration.java
Outdated
Show resolved
Hide resolved
...java/com/hedera/mirror/importer/migration/SyntheticCryptoTransferApprovalsMigrationTest.java
Show resolved
Hide resolved
.../test/java/com/hedera/mirror/importer/migration/SyntheticNftAllowanceOwnerMigrationTest.java
Outdated
Show resolved
Hide resolved
…yBalanceMigrationTest and TokenAccountBalanceMigrationTest Arranging fields. Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
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
...src/test/java/com/hedera/mirror/importer/migration/InitializeEntityBalanceMigrationTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: mgoelswirlds <mugdha.goel@swirldslabs.com>
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
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
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
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
Description:
This PR is created to address re-running certain time sensitive migrations, for newer mirror nodes.
This PR modifies:
Related issue(s):
Fixes #6397
Notes for reviewer:
Checklist