diff --git a/briar-core/src/net/sf/briar/db/H2Database.java b/briar-core/src/net/sf/briar/db/H2Database.java index 600b0375b859eca16123d18f2b9a9c6c8567bbed..4455ee89c7f8ae418f0079cbb051ff90ec07767b 100644 --- a/briar-core/src/net/sf/briar/db/H2Database.java +++ b/briar-core/src/net/sf/briar/db/H2Database.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.sql.Statement; import java.util.Properties; import net.sf.briar.api.clock.Clock; @@ -31,8 +32,8 @@ class H2Database extends JdbcDatabase { super(HASH_TYPE, BINARY_TYPE, COUNTER_TYPE, SECRET_TYPE, clock); this.config = config; String path = new File(config.getDatabaseDirectory(), "db").getPath(); - url = "jdbc:h2:split:" + path - + ";CIPHER=AES;MULTI_THREADED=1;DB_CLOSE_ON_EXIT=false"; + url = "jdbc:h2:split:" + path + ";CIPHER=AES;MULTI_THREADED=1" + + ";WRITE_DELAY=0;DB_CLOSE_ON_EXIT=false"; } public boolean open() throws DbException, IOException { @@ -73,7 +74,6 @@ class H2Database extends JdbcDatabase { } else return f.length(); } - @Override protected Connection createConnection() throws SQLException { byte[] key = config.getEncryptionKey(); if(key == null) throw new IllegalStateException(); @@ -101,4 +101,8 @@ class H2Database extends JdbcDatabase { for(int i = 0; i < hex.length; i++) hex[i] = 0; return combined; } + + protected void flushBuffersToDisk(Statement s) throws SQLException { + s.execute("CHECKPOINT SYNC"); + } } diff --git a/briar-core/src/net/sf/briar/db/JdbcDatabase.java b/briar-core/src/net/sf/briar/db/JdbcDatabase.java index 41202a4c947cd9fe415ea6c49ca58f94b8945644..bf70e237fef5de3179ffab23a3d248123977429c 100644 --- a/briar-core/src/net/sf/briar/db/JdbcDatabase.java +++ b/briar-core/src/net/sf/briar/db/JdbcDatabase.java @@ -371,6 +371,7 @@ abstract class JdbcDatabase implements Database<Connection> { private boolean closed = false; // Locking: connections protected abstract Connection createConnection() throws SQLException; + protected abstract void flushBuffersToDisk(Statement s) throws SQLException; JdbcDatabase(String hashType, String binaryType, String counterType, String secretType, Clock clock) { @@ -509,9 +510,14 @@ abstract class JdbcDatabase implements Database<Connection> { } public void commitTransaction(Connection txn) throws DbException { + Statement s = null; try { txn.commit(); + s = txn.createStatement(); + flushBuffersToDisk(s); + s.close(); } catch(SQLException e) { + tryToClose(s); throw new DbException(e); } synchronized(connections) {