Browse Source

Extend CHECKPOINT_LOCK to HSQLDBSaver.execute()

This is used when saving new data to the db, so also needs to be blocked if we are checkpointing or deciding whether to checkpoint.
pull/52/head^2
CalDescent 3 years ago
parent
commit
52b0c244a8
  1. 2
      src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java
  2. 16
      src/main/java/org/qortal/repository/hsqldb/HSQLDBSaver.java

2
src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java

@ -55,7 +55,7 @@ public class HSQLDBRepository implements Repository {
private static final Logger LOGGER = LogManager.getLogger(HSQLDBRepository.class);
private static final Object CHECKPOINT_LOCK = new Object();
public static final Object CHECKPOINT_LOCK = new Object();
// "serialization failure"
private static final Integer DEADLOCK_ERROR_CODE = Integer.valueOf(-4861);

16
src/main/java/org/qortal/repository/hsqldb/HSQLDBSaver.java

@ -61,13 +61,15 @@ public class HSQLDBSaver {
public boolean execute(HSQLDBRepository repository) throws SQLException {
String sql = this.formatInsertWithPlaceholders();
try {
PreparedStatement preparedStatement = repository.prepareStatement(sql);
this.bindValues(preparedStatement);
return preparedStatement.execute();
} catch (SQLException e) {
throw repository.examineException(e);
synchronized (HSQLDBRepository.CHECKPOINT_LOCK) {
try {
PreparedStatement preparedStatement = repository.prepareStatement(sql);
this.bindValues(preparedStatement);
return preparedStatement.execute();
} catch (SQLException e) {
throw repository.examineException(e);
}
}
}

Loading…
Cancel
Save