Skip to content

Commit

Permalink
Add config for Raptor transaction cleaner interval
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Feb 23, 2016
1 parent 6f4426b commit c28d942
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import static java.util.concurrent.Executors.newFixedThreadPool;
import static java.util.concurrent.Executors.newScheduledThreadPool;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;

public class ShardCleaner
Expand All @@ -65,6 +64,7 @@ public class ShardCleaner
private final StorageService storageService;
private final Optional<BackupStore> backupStore;
private final Duration maxTransactionAge;
private final Duration transactionCleanerInterval;
private final Duration localCleanerInterval;
private final Duration localCleanTime;
private final Duration localPurgeTime;
Expand Down Expand Up @@ -92,6 +92,7 @@ public ShardCleaner(
storageService,
backupStore,
config.getMaxTransactionAge(),
config.getTransactionCleanerInterval(),
config.getLocalCleanerInterval(),
config.getLocalCleanTime(),
config.getLocalPurgeTime(),
Expand All @@ -109,6 +110,7 @@ public ShardCleaner(
StorageService storageService,
Optional<BackupStore> backupStore,
Duration maxTransactionAge,
Duration transactionCleanerInterval,
Duration localCleanerInterval,
Duration localCleanTime,
Duration localPurgeTime,
Expand All @@ -125,6 +127,7 @@ public ShardCleaner(
this.storageService = requireNonNull(storageService, "storageService is null");
this.backupStore = requireNonNull(backupStore, "backupStore is null");
this.maxTransactionAge = requireNonNull(maxTransactionAge, "maxTransactionAge");
this.transactionCleanerInterval = requireNonNull(transactionCleanerInterval, "transactionCleanerInterval is null");
this.localCleanerInterval = requireNonNull(localCleanerInterval, "localCleanerInterval is null");
this.localCleanTime = requireNonNull(localCleanTime, "localCleanTime is null");
this.localPurgeTime = requireNonNull(localPurgeTime, "localPurgeTime is null");
Expand Down Expand Up @@ -171,7 +174,7 @@ private void startTransactionCleanup()
catch (Throwable t) {
log.error(t, "Error cleaning transactions");
}
}, 0, 5, MINUTES);
}, 0, transactionCleanerInterval.toMillis(), MILLISECONDS);
}

private void startBackupCleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class ShardCleanerConfig
{
private Duration maxTransactionAge = new Duration(1, DAYS);
private Duration transactionCleanerInterval = new Duration(10, MINUTES);
private Duration localCleanerInterval = new Duration(1, HOURS);
private Duration localCleanTime = new Duration(4, HOURS);
private Duration localPurgeTime = new Duration(3, DAYS);
Expand All @@ -53,6 +54,21 @@ public ShardCleanerConfig setMaxTransactionAge(Duration maxTransactionAge)
return this;
}

@NotNull
@MinDuration("1m")
public Duration getTransactionCleanerInterval()
{
return transactionCleanerInterval;
}

@Config("raptor.transaction-cleaner-interval")
@ConfigDescription("How often to cleanup expired transactions")
public ShardCleanerConfig setTransactionCleanerInterval(Duration transactionCleanerInterval)
{
this.transactionCleanerInterval = transactionCleanerInterval;
return this;
}

@NotNull
@MinDuration("1m")
public Duration getLocalCleanerInterval()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void setup()
storageService,
Optional.of(backupStore),
config.getMaxTransactionAge(),
config.getTransactionCleanerInterval(),
config.getLocalCleanerInterval(),
config.getLocalCleanTime(),
config.getLocalPurgeTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void testDefaults()
{
assertRecordedDefaults(recordDefaults(ShardCleanerConfig.class)
.setMaxTransactionAge(new Duration(1, DAYS))
.setTransactionCleanerInterval(new Duration(10, MINUTES))
.setLocalCleanerInterval(new Duration(1, HOURS))
.setLocalCleanTime(new Duration(4, HOURS))
.setLocalPurgeTime(new Duration(3, DAYS))
Expand All @@ -47,6 +48,7 @@ public void testExplicitPropertyMappings()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("raptor.max-transaction-age", "42m")
.put("raptor.transaction-cleaner-interval", "43m")
.put("raptor.local-cleaner-interval", "31m")
.put("raptor.local-clean-time", "32m")
.put("raptor.local-purge-time", "33m")
Expand All @@ -58,6 +60,7 @@ public void testExplicitPropertyMappings()

ShardCleanerConfig expected = new ShardCleanerConfig()
.setMaxTransactionAge(new Duration(42, MINUTES))
.setTransactionCleanerInterval(new Duration(43, MINUTES))
.setLocalCleanerInterval(new Duration(31, MINUTES))
.setLocalCleanTime(new Duration(32, MINUTES))
.setLocalPurgeTime(new Duration(33, MINUTES))
Expand Down

0 comments on commit c28d942

Please sign in to comment.