forked from Qortal/qortal
Add synchronization around updating trim heights to prevent deadlock/rollback
This commit is contained in:
parent
c125a53655
commit
16397852ae
@ -415,13 +415,17 @@ public class HSQLDBATRepository implements ATRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAtTrimHeight(int trimHeight) throws DataException {
|
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 {
|
try {
|
||||||
this.repository.executeCheckedUpdate(updateSql, trimHeight);
|
this.repository.executeCheckedUpdate(updateSql, trimHeight);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
repository.examineException(e);
|
repository.examineException(e);
|
||||||
throw new DataException("Unable to set AT state trim height in repository", e);
|
throw new DataException("Unable to set AT state trim height in repository", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,13 +477,17 @@ public class HSQLDBBlockRepository implements BlockRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOnlineAccountsSignaturesTrimHeight(int trimHeight) throws DataException {
|
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 {
|
try {
|
||||||
this.repository.executeCheckedUpdate(updateSql, trimHeight);
|
this.repository.executeCheckedUpdate(updateSql, trimHeight);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
repository.examineException(e);
|
repository.examineException(e);
|
||||||
throw new DataException("Unable to set online accounts signatures trim height in repository", e);
|
throw new DataException("Unable to set online accounts signatures trim height in repository", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ public class HSQLDBRepository implements Repository {
|
|||||||
protected List<String> sqlStatements;
|
protected List<String> sqlStatements;
|
||||||
protected long sessionId;
|
protected long sessionId;
|
||||||
protected final Map<String, PreparedStatement> preparedStatementCache = new HashMap<>();
|
protected final Map<String, PreparedStatement> preparedStatementCache = new HashMap<>();
|
||||||
|
protected final Object trimHeightsLock = new Object();
|
||||||
|
|
||||||
private final ATRepository atRepository = new HSQLDBATRepository(this);
|
private final ATRepository atRepository = new HSQLDBATRepository(this);
|
||||||
private final AccountRepository accountRepository = new HSQLDBAccountRepository(this);
|
private final AccountRepository accountRepository = new HSQLDBAccountRepository(this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user