use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class CompactionManagerTest method testConstructorBadArgs.
/**
* Tests construction failure on bad input.
*/
@Test
public void testConstructorBadArgs() {
properties.setProperty("store.compaction.triggers", "@@BAD_TRIGGER@@");
config = new StoreConfig(new VerifiableProperties(properties));
StorageManagerMetrics metrics = new StorageManagerMetrics(new MetricRegistry());
try {
new CompactionManager(MOUNT_PATH, config, Collections.singleton(blobStore), metrics, time);
fail("Construction should have failed because one of the trigger values is invalid");
} catch (IllegalArgumentException e) {
// expected. Nothing to do.
}
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class CompactionManagerTest method doTestTrigger.
// testDifferentTriggers() helpers
/**
* Does the compaction triggers test by running each trigger in {@code triggerRunners} after resetting state.
* @param triggerRunners the code that triggers compaction.
* @throws Exception
*/
private void doTestTrigger(List<Runnable> triggerRunners) throws Exception {
blobStore.resumeCompactionCalled = false;
StorageManagerMetrics metrics = new StorageManagerMetrics(new MetricRegistry());
config = new StoreConfig(new VerifiableProperties(properties));
compactionManager = new CompactionManager(MOUNT_PATH, config, Collections.singleton(blobStore), metrics, time);
compactionManager.enable();
if (config.storeCompactionTriggers[0].isEmpty()) {
assertNull("Compaction thread should not be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
} else {
assertNotNull("Compaction thread should be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
}
for (Runnable triggerRunner : triggerRunners) {
blobStore.compactCallsCountdown = new CountDownLatch(1);
blobStore.compactCalled = false;
triggerRunner.run();
}
compactionManager.disable();
compactionManager.awaitTermination();
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class CompactionManagerTest method testEnableDisable.
/**
* Tests the enabling and disabling of the {@link CompactionManager} with and without compaction enabled.
*/
@Test
public void testEnableDisable() {
// without compaction enabled.
compactionManager.enable();
// functions should work ok
assertNull("Compaction thread should not be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
assertFalse("Compaction Executor should not be running", compactionManager.isCompactionExecutorRunning());
assertFalse("Compactions should not be scheduled after termination", compactionManager.scheduleNextForCompaction(blobStore));
compactionManager.disable();
compactionManager.awaitTermination();
// with compaction enabled.
properties.setProperty("store.compaction.triggers", ALL_COMPACTION_TRIGGERS);
config = new StoreConfig(new VerifiableProperties(properties));
StorageManagerMetrics metrics = new StorageManagerMetrics(new MetricRegistry());
compactionManager = new CompactionManager(MOUNT_PATH, config, Collections.singleton(blobStore), metrics, time);
compactionManager.enable();
assertNotNull("Compaction thread should be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
compactionManager.disable();
compactionManager.awaitTermination();
assertFalse("Compaction thread should not be running", compactionManager.isCompactionExecutorRunning());
assertFalse("Compactions should not be scheduled after termination", compactionManager.scheduleNextForCompaction(blobStore));
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class CompactionManagerTest method testCompactionExecutorHappyPath.
/**
* Tests that compaction is triggered on all stores provided they do not misbehave. Also includes a store that is
* not ready for compaction. Ensures that {@link BlobStore#maybeResumeCompaction()} is called before
* {@link BlobStore#compact(CompactionDetails)} is called.
* @throws Exception
*/
@Test
public void testCompactionExecutorHappyPath() throws Exception {
int numStores = 5;
List<BlobStore> stores = new ArrayList<>();
// one store with nothing to compact isn't going to get compact calls.
// since we are using mock time, wait for compact calls to arrive twice to ensure the time based scheduling works
CountDownLatch compactCallsCountdown = new CountDownLatch(2 * (numStores - 1));
properties.setProperty("store.compaction.triggers", ALL_COMPACTION_TRIGGERS);
config = new StoreConfig(new VerifiableProperties(properties));
MetricRegistry metricRegistry = new MetricRegistry();
StoreMetrics metrics = new StoreMetrics(metricRegistry);
MockBlobStore lastStore = null;
for (int i = 0; i < numStores; i++) {
MockBlobStore store = new MockBlobStore(config, metrics, time, compactCallsCountdown, null);
// one store should not have any segments to compact
store.details = i == 0 ? null : generateRandomCompactionDetails(i);
stores.add(store);
lastStore = store;
}
compactionManager = new CompactionManager(MOUNT_PATH, config, stores, new StorageManagerMetrics(metricRegistry), time);
compactionManager.enable();
assertNotNull("Compaction thread should be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
assertTrue("Compaction calls did not come within the expected time", compactCallsCountdown.await(1, TimeUnit.SECONDS));
assertTrue("Compaction Executor should be running", compactionManager.isCompactionExecutorRunning());
for (int i = 0; i < numStores; i++) {
MockBlobStore store = (MockBlobStore) stores.get(i);
if (store.callOrderException != null) {
throw store.callOrderException;
}
if (i > 0) {
assertTrue("Compact was not called", store.compactCalled);
} else {
// should not call for i == 0 because there are no compaction details.
assertFalse("Compact should not have been called", store.compactCalled);
}
}
// test scheduleNextForCompaction()
lastStore.compactCallsCountdown = new CountDownLatch(1);
lastStore.compactCalled = false;
assertTrue("Should schedule compaction", compactionManager.scheduleNextForCompaction(lastStore));
assertTrue("Compaction call did not come within the expected time", lastStore.compactCallsCountdown.await(1, TimeUnit.HOURS));
if (lastStore.callOrderException != null) {
throw lastStore.callOrderException;
}
assertTrue("compact() should have been called", lastStore.compactCalled);
compactionManager.disable();
compactionManager.awaitTermination();
assertFalse("Compaction thread should not be running", compactionManager.isCompactionExecutorRunning());
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class MockBlobStoreStats method initializeBlobStore.
// helper methods
/**
* Initializes {@link BlobStore}
* @param minLogSizeToTriggerCompactionInPercentage Property value to be set for
* {@link StoreConfig#storeMinUsedCapacityToTriggerCompactionInPercentage}
* @param messageRetentionInDays Property value to be set for {@link StoreConfig#storeDeletedMessageRetentionDays
* @throws InterruptedException
*/
static Pair<MockBlobStore, StoreConfig> initializeBlobStore(Properties properties, Time time, int minLogSizeToTriggerCompactionInPercentage, int messageRetentionInDays, long maxBlobSize) throws InterruptedException {
if (minLogSizeToTriggerCompactionInPercentage != -1) {
properties.setProperty("store.min.log.size.to.trigger.compaction.in.percent", String.valueOf(minLogSizeToTriggerCompactionInPercentage));
}
if (messageRetentionInDays != -1) {
properties.setProperty("store.deleted.message.retention.days", String.valueOf(messageRetentionInDays));
}
StoreConfig config = new StoreConfig(new VerifiableProperties(properties));
time.sleep(2 * TimeUnit.DAYS.toMillis(config.storeDeletedMessageRetentionDays));
MetricRegistry metricRegistry = new MetricRegistry();
StoreMetrics metrics = new StoreMetrics(metricRegistry);
MockBlobStoreStats mockBlobStoreStats = new MockBlobStoreStats(maxBlobSize);
MockBlobStore blobStore = new MockBlobStore(config, metrics, time, CAPACITY_IN_BYTES, SEGMENT_CAPACITY_IN_BYTES, SEGMENT_HEADER_SIZE, DEFAULT_USED_CAPACITY_IN_BYTES, mockBlobStoreStats);
return new Pair<>(blobStore, config);
}
Aggregations