use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method setBlobStoreStoppedStateFailureTest.
/**
* Test set stopped state of blobstore with given list of {@link PartitionId} in failure cases.
*/
@Test
public void setBlobStoreStoppedStateFailureTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
List<MockDataNodeId> dataNodes = new ArrayList<>();
dataNodes.add(dataNode);
MockPartitionId invalidPartition = new MockPartitionId(Long.MAX_VALUE, MockClusterMap.DEFAULT_PARTITION_CLASS, dataNodes, 0);
List<? extends ReplicaId> invalidPartitionReplicas = invalidPartition.getReplicaIds();
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
storageManager.start();
assertEquals("There should be 1 unexpected partition reported", 1, getNumUnrecognizedPartitionsReported());
// test set the state of store whose replicaStatusDelegate is null
ReplicaId replica = replicas.get(0);
PartitionId id = replica.getPartitionId();
storageManager.getDiskManager(id).shutdown();
List<PartitionId> failToUpdateList = storageManager.setBlobStoreStoppedState(Arrays.asList(id), true);
assertEquals("Set store stopped state should fail on given store whose replicaStatusDelegate is null", id, failToUpdateList.get(0));
// test invalid partition case (where diskManager == null)
replica = invalidPartitionReplicas.get(0);
id = replica.getPartitionId();
failToUpdateList = storageManager.setBlobStoreStoppedState(Arrays.asList(id), true);
assertEquals("Set store stopped state should fail on given invalid replica", id, failToUpdateList.get(0));
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method removeBlobStoreTest.
/**
* Test remove blob store with given {@link PartitionId}
* @throws Exception
*/
@Test
public void removeBlobStoreTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
List<MockDataNodeId> dataNodes = new ArrayList<>();
dataNodes.add(dataNode);
MockPartitionId invalidPartition = new MockPartitionId(Long.MAX_VALUE, MockClusterMap.DEFAULT_PARTITION_CLASS, dataNodes, 0);
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
storageManager.start();
// Replica[1] will be used to test removing a started store. Replica[2] will be used to test a store with compaction enabled
for (int i = 3; i < replicas.size(); i++) {
ReplicaId replica = replicas.get(i);
PartitionId id = replica.getPartitionId();
assertTrue("Disable compaction should succeed", storageManager.controlCompactionForBlobStore(id, false));
assertTrue("Shutdown should succeed on given store", storageManager.shutdownBlobStore(id));
assertTrue("Removing store should succeed", storageManager.removeBlobStore(id));
assertNull("The store should not exist", storageManager.getStore(id, false));
}
// test remove store that compaction is still enabled on it, even though it is shutdown
PartitionId id = replicas.get(2).getPartitionId();
assertTrue("Shutdown should succeed on given store", storageManager.shutdownBlobStore(id));
assertFalse("Removing store should fail because compaction is enabled on this store", storageManager.removeBlobStore(id));
// test remove store that is still started
id = replicas.get(1).getPartitionId();
assertFalse("Removing store should fail because store is still started", storageManager.removeBlobStore(id));
// test remove store that the disk manager is not running
id = replicas.get(0).getPartitionId();
storageManager.getDiskManager(id).shutdown();
assertFalse("Removing store should fail because disk manager is not running", storageManager.removeBlobStore(id));
// test a store that doesn't exist
assertFalse("Removing not-found store should return false", storageManager.removeBlobStore(invalidPartition));
shutdownAndAssertStoresInaccessible(storageManager, replicas);
// test that remove store when compaction executor is not instantiated
// by default, storeCompactionTriggers = "" which makes compaction executor = null during initialization
VerifiableProperties vProps = new VerifiableProperties(new Properties());
storageManager = new StorageManager(new StoreConfig(vProps), diskManagerConfig, Utils.newScheduler(1, false), metricRegistry, new MockIdFactory(), clusterMap, dataNode, new DummyMessageStoreHardDelete(), null, SystemTime.getInstance(), new DummyMessageStoreRecovery(), new InMemAccountService(false, false));
storageManager.start();
for (ReplicaId replica : replicas) {
id = replica.getPartitionId();
assertTrue("Disable compaction should succeed", storageManager.controlCompactionForBlobStore(id, false));
assertTrue("Shutdown should succeed on given store", storageManager.shutdownBlobStore(id));
assertTrue("Removing store should succeed", storageManager.removeBlobStore(id));
assertNull("The store should not exist", storageManager.getStore(id, false));
}
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method replicaFromInactiveToOfflineTest.
/**
* Test shutting down blob store failure during Inactive-To-Offline transition.
* @throws Exception
*/
@Test
public void replicaFromInactiveToOfflineTest() throws Exception {
generateConfigs(true, false);
MockDataNodeId localNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> localReplicas = clusterMap.getReplicaIds(localNode);
ReplicaId testReplica = localReplicas.get(0);
MockClusterParticipant mockHelixParticipant = new MockClusterParticipant();
StorageManager storageManager = createStorageManager(localNode, metricRegistry, Collections.singletonList(mockHelixParticipant));
storageManager.start();
// test shutdown store failure (this is induced by shutting down disk manager)
storageManager.getDiskManager(testReplica.getPartitionId()).shutdown();
mockHelixParticipant.getReplicaSyncUpManager().initiateDisconnection(testReplica);
CountDownLatch participantLatch = new CountDownLatch(1);
Utils.newThread(() -> {
try {
mockHelixParticipant.onPartitionBecomeOfflineFromInactive(testReplica.getPartitionId().toPathString());
fail("should fail because of shutting down store failure");
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", ReplicaOperationFailure, e.getErrorCode());
participantLatch.countDown();
}
}, false).start();
// make sync-up complete to let code proceed and encounter exception in storage manager.
mockHelixParticipant.getReplicaSyncUpManager().onDisconnectionComplete(testReplica);
assertTrue("Helix participant transition didn't get invoked within 1 sec", participantLatch.await(1, TimeUnit.SECONDS));
shutdownAndAssertStoresInaccessible(storageManager, localReplicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method multiParticipantsMarkStoreInErrorStateTest.
/**
* Test that, if store is not started, all participants on this node are able to mark it in ERROR state during
* OFFLINE -> BOOTSTRAP transition.
* @throws Exception
*/
@Test
public void multiParticipantsMarkStoreInErrorStateTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
List<ClusterParticipant> participants = Arrays.asList(new MockClusterParticipant(), new MockClusterParticipant());
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, participants);
storageManager.start();
// stop one of the stores to induce transition failure
PartitionId id = replicas.get(0).getPartitionId();
storageManager.shutdownBlobStore(id);
// verify that both participants throw exception during OFFLINE -> BOOTSTRAP transition
for (ClusterParticipant participant : participants) {
try {
((MockClusterParticipant) participant).onPartitionBecomeBootstrapFromOffline(id.toPathString());
fail("should fail because store is not started");
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", StoreNotStarted, e.getErrorCode());
}
}
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method replicaFromStandbyToInactiveTest.
/**
* test both success and failure cases during STANDBY -> INACTIVE transition
*/
@Test
public void replicaFromStandbyToInactiveTest() throws Exception {
generateConfigs(true, false);
MockDataNodeId localNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> localReplicas = clusterMap.getReplicaIds(localNode);
MockClusterParticipant mockHelixParticipant = new MockClusterParticipant();
StorageManager storageManager = createStorageManager(localNode, metricRegistry, Collections.singletonList(mockHelixParticipant));
storageManager.start();
// 1. get listeners from Helix participant and verify there is a storageManager listener.
Map<StateModelListenerType, PartitionStateChangeListener> listeners = mockHelixParticipant.getPartitionStateChangeListeners();
assertTrue("Should contain storage manager listener", listeners.containsKey(StateModelListenerType.StorageManagerListener));
// 2. not found replica should encounter exception
try {
mockHelixParticipant.onPartitionBecomeInactiveFromStandby("-1");
fail("should fail because replica is not found");
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", ReplicaNotFound, e.getErrorCode());
}
// 3. not found store should throw exception (induced by removing the store)
ReplicaId replicaToRemove = localReplicas.get(localReplicas.size() - 1);
storageManager.controlCompactionForBlobStore(replicaToRemove.getPartitionId(), false);
storageManager.shutdownBlobStore(replicaToRemove.getPartitionId());
storageManager.getDiskManager(replicaToRemove.getPartitionId()).removeBlobStore(replicaToRemove.getPartitionId());
try {
mockHelixParticipant.onPartitionBecomeInactiveFromStandby(replicaToRemove.getPartitionId().toPathString());
fail("should fail because store is not found");
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", ReplicaNotFound, e.getErrorCode());
}
// 4. store not started exception
ReplicaId localReplica = localReplicas.get(0);
storageManager.shutdownBlobStore(localReplica.getPartitionId());
try {
mockHelixParticipant.onPartitionBecomeInactiveFromStandby(localReplica.getPartitionId().toPathString());
fail("should fail because store is not started");
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", StoreNotStarted, e.getErrorCode());
}
storageManager.startBlobStore(localReplica.getPartitionId());
// 5. store is disabled due to disk I/O error
BlobStore localStore = (BlobStore) storageManager.getStore(localReplica.getPartitionId());
localStore.setDisableState(true);
try {
mockHelixParticipant.onPartitionBecomeInactiveFromStandby(localReplica.getPartitionId().toPathString());
fail("should fail because store is disabled");
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", ReplicaOperationFailure, e.getErrorCode());
}
localStore.setDisableState(false);
// 6. success case (verify both replica's state and decommission file)
mockHelixParticipant.onPartitionBecomeInactiveFromStandby(localReplica.getPartitionId().toPathString());
assertEquals("local store state should be set to INACTIVE", ReplicaState.INACTIVE, storageManager.getStore(localReplica.getPartitionId()).getCurrentState());
File decommissionFile = new File(localReplica.getReplicaPath(), BlobStore.DECOMMISSION_FILE_NAME);
assertTrue("Decommission file is not found in local replica's dir", decommissionFile.exists());
shutdownAndAssertStoresInaccessible(storageManager, localReplicas);
// 7. mock disable compaction failure
mockHelixParticipant = new MockClusterParticipant();
MockStorageManager mockStorageManager = new MockStorageManager(localNode, Collections.singletonList(mockHelixParticipant));
mockStorageManager.start();
try {
mockHelixParticipant.onPartitionBecomeInactiveFromStandby(localReplica.getPartitionId().toPathString());
} catch (StateTransitionException e) {
assertEquals("Error code doesn't match", ReplicaNotFound, e.getErrorCode());
} finally {
shutdownAndAssertStoresInaccessible(mockStorageManager, localReplicas);
}
}
Aggregations