Skip to content

Commit 476d8d1

Browse files
committed
add initial purging of legacy history
1 parent 3164fab commit 476d8d1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/main/java/app/attestation/server/Maintenance.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Maintenance implements Runnable {
1414
private static final long DELETE_EXPIRY_MS = 7L * 24 * 60 * 60 * 1000;
1515
private static final long INACTIVE_DEVICE_EXPIRY_MS = 90L * 24 * 60 * 60 * 1000;
1616
private static final boolean PURGE_INACTIVE_DEVICES = true;
17+
private static final long HISTORY_EXPIRY_MS = 180L * 24 * 60 * 60 * 1000;
18+
private static final boolean PURGE_LEGACY_HISTORY = true;
1719

1820
private static final Logger logger = Logger.getLogger(Maintenance.class.getName());
1921

@@ -23,12 +25,14 @@ public void run() {
2325
final SQLiteConnection attestationConn = new SQLiteConnection(AttestationProtocol.ATTESTATION_DATABASE);
2426
final SQLiteStatement deleteDeletedDevices;
2527
final SQLiteStatement purgeInactiveDevices;
28+
final SQLiteStatement purgeLegacyHistory;
2629
try {
2730
AttestationServer.open(samplesConn, false);
2831
AttestationServer.open(attestationConn, false);
2932
deleteDeletedDevices = attestationConn.prepare("DELETE FROM Devices WHERE deletionTime < ?");
3033
purgeInactiveDevices = attestationConn.prepare("UPDATE Devices SET deletionTime = ? " +
3134
"WHERE verifiedTimeLast < ? AND deletionTime IS NULL");
35+
purgeLegacyHistory = attestationConn.prepare("DELETE FROM Attestations WHERE time < ?");
3236
} catch (final SQLiteException e) {
3337
attestationConn.dispose();
3438
throw new RuntimeException(e);
@@ -52,6 +56,12 @@ public void run() {
5256
logger.info("cleared " + attestationConn.getChanges() + " inactive devices");
5357
}
5458

59+
if (PURGE_LEGACY_HISTORY) {
60+
purgeLegacyHistory.bind(1, now - HISTORY_EXPIRY_MS);
61+
purgeLegacyHistory.step();
62+
logger.info("cleared " + attestationConn.getChanges() + " legacy history entries");
63+
}
64+
5565
attestationConn.exec("ANALYZE");
5666
attestationConn.exec("VACUUM");
5767
} catch (final SQLiteException e) {
@@ -60,6 +70,7 @@ public void run() {
6070
try {
6171
deleteDeletedDevices.reset();
6272
purgeInactiveDevices.reset();
73+
purgeLegacyHistory.reset();
6374
} catch (final SQLiteException e) {
6475
logger.log(Level.WARNING, "database error", e);
6576
}

0 commit comments

Comments
 (0)