forked from Qortal/qortal
Prevent HSQLDB prepared statement cache invalidation when rebuilding latest AT states cache
This commit is contained in:
parent
6a24f787c4
commit
38a64bdd9e
@ -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 ("
|
||||
+ "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"
|
||||
+ ") "
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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…
Reference in New Issue
Block a user