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

Cherry Pick Migration Fix #10308

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.hedera.mirror.common.domain.transaction.Transaction;
import com.hedera.mirror.common.domain.transaction.TransactionType;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.config.Owner;
import com.hedera.mirror.importer.parser.record.entity.EntityProperties;
import com.hedera.mirror.importer.parser.record.transactionhandler.AbstractNodeTransactionHandler;
import com.hederahashgraph.api.proto.java.TransactionRecord;
Expand All @@ -39,8 +40,8 @@
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.jdbc.core.DataClassRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

@Named
public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
Expand All @@ -56,7 +57,7 @@ public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
"""
select consensus_timestamp, transaction_bytes, transaction_record_bytes
from transaction
where consensus_timestamp >= :startTimestamp and type in (54, 55, 56)
where consensus_timestamp >= ? and type in (54, 55, 56)
order by consensus_timestamp asc;
""";

Expand All @@ -66,7 +67,7 @@ public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
values (?, ?, ?, ?, ?::int8range);
""";

private final NamedParameterJdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
private final ObjectProvider<AbstractNodeTransactionHandler> nodeTransactionHandlers;
private final EntityProperties entityProperties;
private final Map<TransactionType, AbstractNodeTransactionHandler> nodeTransactionHandlerMap =
Expand All @@ -79,7 +80,7 @@ public class FixNodeTransactionsMigration extends ConfigurableJavaMigration {
ObjectProvider<AbstractNodeTransactionHandler> nodeTransactionHandlers,
ImporterProperties importerProperties,
EntityProperties entityProperties,
NamedParameterJdbcTemplate jdbcTemplate) {
@Owner JdbcTemplate jdbcTemplate) {
super(importerProperties.getMigration());
this.v2 = environment.acceptsProfiles(Profiles.of("v2"));
this.nodeTransactionHandlers = nodeTransactionHandlers;
Expand Down Expand Up @@ -122,14 +123,16 @@ protected void doMigrate() throws IOException {
ps.setString(5, PostgreSQLGuavaRangeType.INSTANCE.asString(node.getTimestampRange()));
};

jdbcTemplate.getJdbcTemplate().execute(DROP_DATA_SQL);
jdbcTemplate
.getJdbcTemplate()
.batchUpdate(INSERT_SQL.formatted("node"), nodeState.values(), nodeState.size(), statementSetter);
jdbcTemplate
.getJdbcTemplate()
.batchUpdate(
INSERT_SQL.formatted("node_history"), historicalNodes, historicalNodes.size(), statementSetter);
jdbcTemplate.execute(DROP_DATA_SQL);
jdbcTemplate.batchUpdate(INSERT_SQL.formatted("node"), nodeState.values(), nodeState.size(), statementSetter);
jdbcTemplate.batchUpdate(
INSERT_SQL.formatted("node_history"), historicalNodes, historicalNodes.size(), statementSetter);

log.info(
"Successfully processed {} node transactions producing {} rows and {} history rows",
nodeRecordItems.size(),
nodeState.size(),
historicalNodes.size());
}

private Node recordItemToNode(RecordItem recordItem) {
Expand Down Expand Up @@ -165,10 +168,7 @@ public String getDescription() {

private List<RecordItem> getRecordItems() {
return jdbcTemplate
.query(
NODE_TRANSACTIONS_SQL,
Map.of("startTimestamp", LOWER_TIMESTAMP),
new DataClassRowMapper<>(Transaction.class))
.query(NODE_TRANSACTIONS_SQL, new DataClassRowMapper<>(Transaction.class), LOWER_TIMESTAMP)
.stream()
.map(this::toRecordItem)
.toList();
Expand Down
Loading