diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java index d2463c80..b5779c65 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java @@ -415,13 +415,17 @@ public class HSQLDBATRepository implements ATRepository { @Override public void setAtTrimHeight(int trimHeight) throws DataException { - String updateSql = "UPDATE DatabaseInfo SET AT_trim_height = ?"; + // trimHeightsLock is to prevent concurrent update on DatabaseInfo + // that could result in "transaction rollback: serialization failure" + synchronized (this.repository.trimHeightsLock) { + String updateSql = "UPDATE DatabaseInfo SET AT_trim_height = ?"; - try { - this.repository.executeCheckedUpdate(updateSql, trimHeight); - } catch (SQLException e) { - repository.examineException(e); - throw new DataException("Unable to set AT state trim height in repository", e); + try { + this.repository.executeCheckedUpdate(updateSql, trimHeight); + } catch (SQLException e) { + repository.examineException(e); + throw new DataException("Unable to set AT state trim height in repository", e); + } } } diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java index 8d544e0b..de76d17b 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java @@ -477,13 +477,17 @@ public class HSQLDBBlockRepository implements BlockRepository { @Override public void setOnlineAccountsSignaturesTrimHeight(int trimHeight) throws DataException { - String updateSql = "UPDATE DatabaseInfo SET online_signatures_trim_height = ?"; + // trimHeightsLock is to prevent concurrent update on DatabaseInfo + // that could result in "transaction rollback: serialization failure" + synchronized (this.repository.trimHeightsLock) { + String updateSql = "UPDATE DatabaseInfo SET online_signatures_trim_height = ?"; - try { - this.repository.executeCheckedUpdate(updateSql, trimHeight); - } catch (SQLException e) { - repository.examineException(e); - throw new DataException("Unable to set online accounts signatures trim height in repository", e); + try { + this.repository.executeCheckedUpdate(updateSql, trimHeight); + } catch (SQLException e) { + repository.examineException(e); + throw new DataException("Unable to set online accounts signatures trim height in repository", e); + } } } diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java index 8391d7ae..dd53e742 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java @@ -60,6 +60,7 @@ public class HSQLDBRepository implements Repository { protected List sqlStatements; protected long sessionId; protected final Map preparedStatementCache = new HashMap<>(); + protected final Object trimHeightsLock = new Object(); private final ATRepository atRepository = new HSQLDBATRepository(this); private final AccountRepository accountRepository = new HSQLDBAccountRepository(this);