Changed database cleaning constants to suit smaller devices.

This commit is contained in:
akwizgran
2013-03-01 22:13:08 +00:00
parent 1ce1cf6f63
commit 71e1dd9acb
5 changed files with 18 additions and 18 deletions

View File

@@ -44,4 +44,10 @@ public interface MessagingConstants {
/** The length of a message's random salt in bytes. */
int SALT_LENGTH = 8;
/**
* The timestamp of the oldest message in the database is rounded using
* this modulus to avoid revealing the presence of any particular message.
*/
long RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour
}

View File

@@ -39,6 +39,7 @@ class DatabaseCleanerImpl extends TimerTask implements DatabaseCleaner {
if(callback == null) throw new IllegalStateException();
try {
if(callback.shouldCheckFreeSpace()) {
if(LOG.isLoggable(INFO)) LOG.info("Checking free space");
callback.checkFreeSpaceAndClean();
}
} catch(DbClosedException e) {

View File

@@ -1,5 +1,6 @@
package net.sf.briar.db;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.Rating.GOOD;
import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP;
@@ -84,6 +85,7 @@ DatabaseCleaner.Callback {
private static final Logger LOG =
Logger.getLogger(DatabaseComponentImpl.class.getName());
private static final int MS_BETWEEN_SWEEPS = 10 * 1000; // 10 seconds
/*
* Locks must always be acquired in alphabetical order. See the Database
@@ -135,7 +137,7 @@ DatabaseCleaner.Callback {
if(open) throw new IllegalStateException();
open = true;
db.open(resume);
cleaner.startCleaning(this, MAX_MS_BETWEEN_SPACE_CHECKS);
cleaner.startCleaning(this, MS_BETWEEN_SWEEPS);
shutdownHandle = shutdown.addShutdownHook(new Runnable() {
public void run() {
try {
@@ -1802,6 +1804,7 @@ DatabaseCleaner.Callback {
public void checkFreeSpaceAndClean() throws DbException {
long freeSpace = db.getFreeSpace();
if(LOG.isLoggable(INFO)) LOG.info(freeSpace + " bytes free space");
while(freeSpace < MIN_FREE_SPACE) {
boolean expired = expireMessages(BYTES_PER_SWEEP);
if(freeSpace < CRITICAL_FREE_SPACE && !expired) {
@@ -1832,6 +1835,8 @@ DatabaseCleaner.Callback {
for(MessageId m : old) removeMessage(txn, m);
db.incrementRetentionVersions(txn);
removed = true;
if(LOG.isLoggable(INFO))
LOG.info("Expired " + old.size() + " messages");
}
db.commitTransaction(txn);
} catch(DbException e) {

View File

@@ -9,20 +9,20 @@ interface DatabaseConstants {
* device where the database is stored. Whenever less than this much space
* is free, old messages will be expired from the database.
*/
long MIN_FREE_SPACE = 300 * 1024 * 1024; // 300 MiB
long MIN_FREE_SPACE = 50 * 1024 * 1024; // 50 MiB
/**
* The minimum amount of space in bytes that must be kept free on the device
* where the database is stored. If less than this much space is free and
* there are no more messages to expire, an Error will be thrown.
*/
long CRITICAL_FREE_SPACE = 100 * 1024 * 1024; // 100 MiB
long CRITICAL_FREE_SPACE = 10 * 1024 * 1024; // 10 MiB
/**
* The amount of free space will be checked whenever this many bytes of
* messages have been added to the database since the last check.
*/
int MAX_BYTES_BETWEEN_SPACE_CHECKS = 5 * 1024 * 1024; // 5 MiB
int MAX_BYTES_BETWEEN_SPACE_CHECKS = 1024 * 1024; // 1 MiB
/**
* The amount of free space will be checked whenever this many milliseconds
@@ -34,17 +34,5 @@ interface DatabaseConstants {
* Up to this many bytes of messages will be expired from the database each
* time it is necessary to expire messages.
*/
int BYTES_PER_SWEEP = 5 * 1024 * 1024; // 5 MiB
/**
* The timestamp of the oldest message in the database is rounded using
* this modulus to avoid revealing the presence of any particular message.
*/
long RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour
/**
* The time in milliseconds after which a subscription or transport update
* should be sent to a contact even if no changes have occurred.
*/
long MAX_UPDATE_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
int BYTES_PER_SWEEP = 10 * 1024 * 1024; // 10 MiB
}

View File

@@ -6,7 +6,7 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.Rating.UNRATED;
import static net.sf.briar.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS;
import static net.sf.briar.db.DatabaseConstants.RETENTION_MODULUS;
import static net.sf.briar.api.messaging.MessagingConstants.RETENTION_MODULUS;
import static net.sf.briar.db.ExponentialBackoff.calculateExpiry;
import java.io.File;