Browse Source

Prevent HSQLDB prepared statement cache invalidation when rebuilding latest AT states cache

AT-sleep-until-message
catbref 4 years ago
parent
commit
38a64bdd9e
  1. 19
      src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java
  2. 8
      src/main/java/org/qortal/repository/hsqldb/HSQLDBDatabaseUpdates.java

19
src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java

@ -428,32 +428,27 @@ public class HSQLDBATRepository implements ATRepository {
@Override
public void prepareForAtStateTrimming() throws DataException {
// Rebuild cache of latest, non-finished AT states that we can't trim
String dropSql = "DROP TABLE IF EXISTS LatestATStates";
String deleteSql = "DELETE FROM LatestATStates";
try {
this.repository.executeCheckedUpdate(dropSql);
this.repository.executeCheckedUpdate(deleteSql);
} catch (SQLException e) {
repository.examineException(e);
throw new DataException("Unable to drop temporary latest AT states cache from repository", e);
throw new DataException("Unable to delete temporary latest AT states cache from repository", e);
}
String createSql = "CREATE TEMPORARY TABLE LatestATStates "
+ "AS ("
String insertSql = "INSERT INTO LatestATStates ("
+ "SELECT AT_address, height FROM ATs "
+ "CROSS JOIN LATERAL("
+ "SELECT height FROM ATStates "
+ "WHERE ATStates.AT_address = ATs.AT_address "
+ "ORDER BY AT_address DESC, height DESC LIMIT 1"
+ ") "
+ ") "
+ "WITH DATA "
+ "ON COMMIT PRESERVE ROWS";
+ ")";
try {
this.repository.executeCheckedUpdate(createSql);
this.repository.executeCheckedUpdate(insertSql);
} catch (SQLException e) {
repository.examineException(e);
throw new DataException("Unable to recreate temporary latest AT states cache in repository", e);
throw new DataException("Unable to populate temporary latest AT states cache in repository", e);
}
}

8
src/main/java/org/qortal/repository/hsqldb/HSQLDBDatabaseUpdates.java

@ -677,6 +677,14 @@ public class HSQLDBDatabaseUpdates {
stmt.execute("CREATE INDEX IF NOT EXISTS ATTransactionsRecipientIndex ON ATTransactions (recipient)");
break;
case 28:
// Latest AT state cache
stmt.execute("CREATE TEMPORARY TABLE IF NOT EXISTS LatestATStates ("
+ "AT_address QortalAddress NOT NULL, "
+ "height INT NOT NULL"
+ ")");
break;
default:
// nothing to do
return false;

Loading…
Cancel
Save