mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Try printing db table sizes on startup
This commit is contained in:
@@ -746,4 +746,6 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
*/
|
*/
|
||||||
void updateTransportKeys(Transaction txn, Collection<TransportKeySet> keys)
|
void updateTransportKeys(Transaction txn, Collection<TransportKeySet> keys)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
void printStats(Transaction txn) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -862,4 +862,6 @@ interface Database<T> {
|
|||||||
* Stores the given transport keys, deleting any keys they have replaced.
|
* Stores the given transport keys, deleting any keys they have replaced.
|
||||||
*/
|
*/
|
||||||
void updateTransportKeys(T txn, TransportKeySet ks) throws DbException;
|
void updateTransportKeys(T txn, TransportKeySet ks) throws DbException;
|
||||||
|
|
||||||
|
void printStats(T txn) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1256,6 +1256,12 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printStats(Transaction transaction) throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
db.printStats(txn);
|
||||||
|
}
|
||||||
|
|
||||||
private class CommitActionVisitor implements Visitor {
|
private class CommitActionVisitor implements Visitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,8 +13,12 @@ import org.briarproject.bramble.util.StringUtils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -26,6 +30,7 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
||||||
import static org.briarproject.bramble.util.IoUtils.isNonEmptyDirectory;
|
import static org.briarproject.bramble.util.IoUtils.isNonEmptyDirectory;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logFileOrDir;
|
import static org.briarproject.bramble.util.LogUtils.logFileOrDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,6 +106,73 @@ class H2Database extends JdbcDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printStats(Connection txn) throws DbException {
|
||||||
|
List<String> names = printNames(txn);
|
||||||
|
for (String table : names) {
|
||||||
|
tryPrintStats(txn, table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> printNames(Connection txn) throws DbException {
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql =
|
||||||
|
"SELECT table_catalog, table_schema, table_name FROM INFORMATION_SCHEMA.TABLES";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
String catalog = rs.getString(1);
|
||||||
|
String schema = rs.getString(2);
|
||||||
|
String name = rs.getString(3);
|
||||||
|
LOG.info(
|
||||||
|
String.format("Table %s %s %s", catalog, schema, name));
|
||||||
|
names.add(schema + "." + name);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryPrintStats(Connection txn, String table) {
|
||||||
|
try {
|
||||||
|
printStats(txn, table);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printStats(Connection txn, String table) throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "CALL DISK_SPACE_USED(?)";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setString(1, table);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
if (!rs.next()) {
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
}
|
||||||
|
long size = rs.getLong(1);
|
||||||
|
if (rs.next()) throw new DbStateException();
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
LOG.info(String.format("Size of table %s: %d", table, size));
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Connection createConnection() throws DbException, SQLException {
|
protected Connection createConnection() throws DbException, SQLException {
|
||||||
SecretKey key = this.key;
|
SecretKey key = this.key;
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ class HyperSqlDatabase extends JdbcDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printStats(Connection txn) throws DbException {
|
||||||
|
// Not implemented
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Connection createConnection() throws DbException, SQLException {
|
protected Connection createConnection() throws DbException, SQLException {
|
||||||
SecretKey key = this.key;
|
SecretKey key = this.key;
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
if (IS_DEBUG_BUILD || shouldWarnOldAndroidExpiry()) {
|
if (IS_DEBUG_BUILD || shouldWarnOldAndroidExpiry()) {
|
||||||
navDrawerViewModel.checkExpiryWarning();
|
navDrawerViewModel.checkExpiryWarning();
|
||||||
}
|
}
|
||||||
|
navDrawerViewModel.printStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package org.briarproject.briar.android.navdrawer;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
@@ -41,6 +41,7 @@ public class NavDrawerViewModel extends DbViewModel {
|
|||||||
private static final String SHOW_TRANSPORTS_ONBOARDING =
|
private static final String SHOW_TRANSPORTS_ONBOARDING =
|
||||||
"showTransportsOnboarding";
|
"showTransportsOnboarding";
|
||||||
|
|
||||||
|
private final DatabaseComponent db;
|
||||||
private final SettingsManager settingsManager;
|
private final SettingsManager settingsManager;
|
||||||
|
|
||||||
private final MutableLiveData<Boolean> showExpiryWarning =
|
private final MutableLiveData<Boolean> showExpiryWarning =
|
||||||
@@ -54,10 +55,11 @@ public class NavDrawerViewModel extends DbViewModel {
|
|||||||
NavDrawerViewModel(Application app,
|
NavDrawerViewModel(Application app,
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager,
|
LifecycleManager lifecycleManager,
|
||||||
TransactionManager db,
|
DatabaseComponent db,
|
||||||
AndroidExecutor androidExecutor,
|
AndroidExecutor androidExecutor,
|
||||||
SettingsManager settingsManager) {
|
SettingsManager settingsManager) {
|
||||||
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
this.db = db;
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,4 +176,16 @@ public class NavDrawerViewModel extends DbViewModel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void printStats() {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
db.transaction(false, txn -> {
|
||||||
|
db.printStats(txn);
|
||||||
|
});
|
||||||
|
} catch (DbException e) {
|
||||||
|
handleException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user