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. 29
      src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java
  2. 8
      src/main/java/org/qortal/repository/hsqldb/HSQLDBDatabaseUpdates.java

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

@ -428,32 +428,27 @@ public class HSQLDBATRepository implements ATRepository {
@Override @Override
public void prepareForAtStateTrimming() throws DataException { public void prepareForAtStateTrimming() throws DataException {
// Rebuild cache of latest, non-finished AT states that we can't trim // 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 { try {
this.repository.executeCheckedUpdate(dropSql); this.repository.executeCheckedUpdate(deleteSql);
} catch (SQLException e) { } catch (SQLException e) {
repository.examineException(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 " String insertSql = "INSERT INTO LatestATStates ("
+ "AS (" + "SELECT AT_address, height FROM ATs "
+ "SELECT AT_address, height FROM ATs " + "CROSS JOIN LATERAL("
+ "CROSS JOIN LATERAL(" + "SELECT height FROM ATStates "
+ "SELECT height FROM ATStates " + "WHERE ATStates.AT_address = ATs.AT_address "
+ "WHERE ATStates.AT_address = ATs.AT_address " + "ORDER BY AT_address DESC, height DESC LIMIT 1"
+ "ORDER BY AT_address DESC, height DESC LIMIT 1"
+ ") "
+ ") " + ") "
+ "WITH DATA " + ")";
+ "ON COMMIT PRESERVE ROWS";
try { try {
this.repository.executeCheckedUpdate(createSql); this.repository.executeCheckedUpdate(insertSql);
} catch (SQLException e) { } catch (SQLException e) {
repository.examineException(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)"); stmt.execute("CREATE INDEX IF NOT EXISTS ATTransactionsRecipientIndex ON ATTransactions (recipient)");
break; 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: default:
// nothing to do // nothing to do
return false; return false;

Loading…
Cancel
Save