Search in sources :

Example 11 with MockReplicaId

use of com.github.ambry.clustermap.MockReplicaId in project ambry by linkedin.

the class AmbryServerRequestsTest method changePartitionState.

/**
 * Changes the write state of the partition
 * @param id the {@link MockPartitionId} whose status needs to change
 * @param seal if {@code true}, partition will become
 * {@link com.github.ambry.clustermap.PartitionState#READ_ONLY}. Otherwise
 * {@link com.github.ambry.clustermap.PartitionState#READ_WRITE}
 */
private void changePartitionState(PartitionId id, boolean seal) {
    MockReplicaId replicaId = (MockReplicaId) findReplica(id);
    replicaId.setSealedState(seal);
    ((MockPartitionId) id).resolvePartitionStatus();
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId)

Example 12 with MockReplicaId

use of com.github.ambry.clustermap.MockReplicaId in project ambry by linkedin.

the class UndeleteOperationTrackerTest method populateReplicaList.

/**
 * Populate replicas for a partition.
 * @param replicaCount The number of replicas to populate.
 * @param replicaState The {@link ReplicaState} associated with these replicas.
 */
private void populateReplicaList(int replicaCount, ReplicaState replicaState) {
    for (int i = 0; i < replicaCount; i++) {
        ReplicaId replicaId = new MockReplicaId(PORT, mockPartition, datanodes.get(i % datanodes.size()), 0);
        mockPartition.replicaIds.add(replicaId);
        mockPartition.replicaAndState.put(replicaId, replicaState);
    }
}
Also used : MockReplicaId(com.github.ambry.clustermap.MockReplicaId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 13 with MockReplicaId

use of com.github.ambry.clustermap.MockReplicaId in project ambry by linkedin.

the class BlobStoreCompactorTest method generateLocalAndPeerReplicas.

// helpers
// general
/**
 * Generate local replica and two peer replicas.
 * @return a list of replicas (first one is local replica, others are remote peer replicas)
 */
private List<MockReplicaId> generateLocalAndPeerReplicas() {
    Port port = new Port(6667, PortType.PLAINTEXT);
    List<String> mountPaths = Arrays.asList("/mnt/u001", "/mnt/u002", "/mnt/u003");
    // generate two peer replicas
    MockDataNodeId peerNode1 = new MockDataNodeId("node1_host", Collections.singletonList(port), mountPaths, null);
    MockDataNodeId peerNode2 = new MockDataNodeId("node2_host", Collections.singletonList(port), mountPaths, null);
    MockDataNodeId localNode = new MockDataNodeId("local_host", Collections.singletonList(port), mountPaths, null);
    MockPartitionId mockPartitionId = new MockPartitionId(101L, MockClusterMap.DEFAULT_PARTITION_CLASS);
    MockReplicaId peerReplica1 = new MockReplicaId(port.getPort(), mockPartitionId, peerNode1, 0);
    MockReplicaId peerReplica2 = new MockReplicaId(port.getPort(), mockPartitionId, peerNode2, 1);
    MockReplicaId localReplica = new MockReplicaId(port.getPort(), mockPartitionId, localNode, 2);
    localReplica.setPeerReplicas(Arrays.asList(peerReplica1, peerReplica2));
    return Arrays.asList(localReplica, peerReplica1, peerReplica2);
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) Port(com.github.ambry.network.Port) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId)

Example 14 with MockReplicaId

use of com.github.ambry.clustermap.MockReplicaId in project ambry by linkedin.

the class CloudStorageManagerTest method shutdownBlobStoreTest.

/**
 * Test {@code CloudStorageManager#shutdownBlobStore}
 * @throws IOException
 */
@Test
public void shutdownBlobStoreTest() throws IOException {
    CloudStorageManager cloudStorageManager = createNewCloudStorageManager();
    ReplicaId mockReplicaId = clusterMap.getReplicaIds(clusterMap.getDataNodeIds().get(0)).get(0);
    PartitionId partitionId = mockReplicaId.getPartitionId();
    // try shutdown for a store of partition that was never added
    Assert.assertFalse(cloudStorageManager.shutdownBlobStore(partitionId));
    // add and start a replica to the store
    Assert.assertTrue(cloudStorageManager.addBlobStore(mockReplicaId));
    // try shutdown for a store of partition that was added
    Assert.assertTrue(cloudStorageManager.shutdownBlobStore(partitionId));
    // try shutdown for a removed partition
    Assert.assertTrue(cloudStorageManager.removeBlobStore(partitionId));
    Assert.assertFalse(cloudStorageManager.shutdownBlobStore(partitionId));
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Example 15 with MockReplicaId

use of com.github.ambry.clustermap.MockReplicaId in project ambry by linkedin.

the class CloudStorageManagerTest method checkLocalPartitionStatusTest.

/**
 * Test {@code CloudStorageManager#checkLocalPartitionStatus}
 * @throws IOException
 */
@Test
public void checkLocalPartitionStatusTest() throws IOException {
    CloudStorageManager cloudStorageManager = createNewCloudStorageManager();
    ReplicaId mockReplicaId = clusterMap.getReplicaIds(clusterMap.getDataNodeIds().get(0)).get(0);
    PartitionId partitionId = mockReplicaId.getPartitionId();
    // try checkLocalPartitionStatus for a partition that doesn't exist
    Assert.assertEquals(cloudStorageManager.checkLocalPartitionStatus(partitionId, new MockReplicaId(ReplicaType.DISK_BACKED)), ServerErrorCode.No_Error);
    // add and start a replica to the store
    Assert.assertTrue(cloudStorageManager.addBlobStore(mockReplicaId));
    // try checkLocalPartitionStatus for an added replica
    Assert.assertEquals(cloudStorageManager.checkLocalPartitionStatus(partitionId, new MockReplicaId(ReplicaType.DISK_BACKED)), ServerErrorCode.No_Error);
    // stop a replica on the store
    Assert.assertTrue("Failed in stopping replica", cloudStorageManager.shutdownBlobStore(partitionId));
    // try checkLocalPartitionStatus for a stopped replica (stopped blob store)
    Assert.assertEquals(cloudStorageManager.checkLocalPartitionStatus(partitionId, mockReplicaId), ServerErrorCode.No_Error);
    // try checkLocalPartitionStatus for a removed replica
    Assert.assertTrue(cloudStorageManager.removeBlobStore(partitionId));
    Assert.assertEquals(cloudStorageManager.checkLocalPartitionStatus(partitionId, new MockReplicaId(ReplicaType.DISK_BACKED)), ServerErrorCode.No_Error);
}
Also used : MockReplicaId(com.github.ambry.clustermap.MockReplicaId) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Aggregations

MockReplicaId (com.github.ambry.clustermap.MockReplicaId)27 ReplicaId (com.github.ambry.clustermap.ReplicaId)20 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)19 Test (org.junit.Test)19 PartitionId (com.github.ambry.clustermap.PartitionId)13 ArrayList (java.util.ArrayList)10 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)8 StorageManager (com.github.ambry.store.StorageManager)8 HashSet (java.util.HashSet)7 Port (com.github.ambry.network.Port)6 Store (com.github.ambry.store.Store)6 HashMap (java.util.HashMap)6 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)5 VerifiableProperties (com.github.ambry.config.VerifiableProperties)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)4 StoreKey (com.github.ambry.store.StoreKey)4 IOException (java.io.IOException)4 List (java.util.List)4 Counter (com.codahale.metrics.Counter)3