Search in sources :

Example 61 with ReplicaId

use of com.github.ambry.clustermap.ReplicaId 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 62 with ReplicaId

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

the class UndeleteOperationTrackerTest method sendRequests.

/**
 * Send requests to all replicas provided by the {@link UndeleteOperationTracker#getReplicaIterator()}
 * @param tracker the {@link UndeleteOperationTracker} that provides replicas.
 * @param numRequestsExpected the number of requests expected to be sent out.
 */
private void sendRequests(UndeleteOperationTracker tracker, int numRequestsExpected) {
    int sent = 0;
    Iterator<ReplicaId> replicaIdIterator = tracker.getReplicaIterator();
    while (replicaIdIterator.hasNext()) {
        ReplicaId nextReplica = replicaIdIterator.next();
        assertNotNull("There should be a replica to send a request to", nextReplica);
        assertFalse("Replica that was used for a request returned by iterator again: " + nextReplica, repetitionTracker.contains(nextReplica));
        inflightReplicas.offer(nextReplica);
        replicaIdIterator.remove();
        repetitionTracker.add(nextReplica);
        sent++;
    }
    assertEquals("Did not send expected number of requests: " + inflightReplicas, numRequestsExpected, sent);
}
Also used : MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 63 with ReplicaId

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

the class ServerAdminTool method sendRequestGetResponse.

/**
 * Sends {@code request} to {@code dataNodeId} and returns the response as a {@link ByteBuffer}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param partitionId the {@link PartitionId} associated with request.
 * @param request the request to send.
 * @return the response as a {@link ResponseInfo} if the response was successfully received. {@code null} otherwise.
 * @throws TimeoutException
 */
private ResponseInfo sendRequestGetResponse(DataNodeId dataNodeId, PartitionId partitionId, SendWithCorrelationId request) throws TimeoutException {
    ReplicaId replicaId = getReplicaFromNode(dataNodeId, partitionId);
    String hostname = dataNodeId.getHostname();
    Port port = dataNodeId.getPortToConnectTo();
    String identifier = hostname + ":" + port.getPort();
    RequestInfo requestInfo = new RequestInfo(hostname, port, request, replicaId, null);
    List<RequestInfo> requestInfos = Collections.singletonList(requestInfo);
    ResponseInfo responseInfo = null;
    long startTimeMs = time.milliseconds();
    do {
        if (time.milliseconds() - startTimeMs > OPERATION_TIMEOUT_MS) {
            throw new TimeoutException(identifier + ": Operation did not complete within " + OPERATION_TIMEOUT_MS + " ms");
        }
        List<ResponseInfo> responseInfos = networkClient.sendAndPoll(requestInfos, Collections.emptySet(), POLL_TIMEOUT_MS);
        if (responseInfos.size() > 1) {
            // May need to relax this check because response list may contain more than 1 response
            throw new IllegalStateException("Received more than one response even though a single request was sent");
        } else if (!responseInfos.isEmpty()) {
            responseInfo = responseInfos.get(0);
        }
        requestInfos = Collections.emptyList();
    } while (responseInfo == null);
    if (responseInfo.getError() != null) {
        throw new IllegalStateException(identifier + ": Encountered error while trying to send request - " + responseInfo.getError());
    }
    return responseInfo;
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) Port(com.github.ambry.network.Port) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) ReplicaId(com.github.ambry.clustermap.ReplicaId) TimeoutException(java.util.concurrent.TimeoutException)

Example 64 with ReplicaId

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

the class BlobValidator method validateBlobOnAllReplicas.

/**
 * Validates {@code blobId} on all of its replicas.
 * @param blobId the {@link BlobId} to operate on.
 * @param getOption the {@link GetOption} to use with the {@link com.github.ambry.protocol.GetRequest}.
 * @param clusterMap the {@link ClusterMap} instance to use.
 * @param storeKeyFactory the {@link StoreKeyFactory} to use.
 * @return a list of details if there are mismatches. Zero sized list if there aren't any mismatches.
 * @throws InterruptedException
 */
private List<String> validateBlobOnAllReplicas(BlobId blobId, GetOption getOption, ClusterMap clusterMap, StoreKeyFactory storeKeyFactory) throws InterruptedException {
    Map<DataNodeId, ServerResponse> dataNodeIdBlobContentMap = new HashMap<>();
    for (ReplicaId replicaId : blobId.getPartition().getReplicaIds()) {
        ServerResponse response = getRecordFromNode(replicaId.getDataNodeId(), blobId, getOption, clusterMap, storeKeyFactory);
        dataNodeIdBlobContentMap.put(replicaId.getDataNodeId(), response);
    }
    return getMismatchDetails(blobId.getID(), dataNodeIdBlobContentMap);
}
Also used : HashMap(java.util.HashMap) DataNodeId(com.github.ambry.clustermap.DataNodeId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 65 with ReplicaId

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

the class StorageManagerTest method setBlobStoreStoppedStateWithMultiDelegatesTest.

/**
 * Test setting blob stop state in two clusters (if server participates into two Helix clusters)
 * @throws Exception
 */
@Test
public void setBlobStoreStoppedStateWithMultiDelegatesTest() throws Exception {
    MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
    List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
    MockClusterParticipant mockClusterParticipant1 = new MockClusterParticipant();
    MockClusterParticipant mockClusterParticipant2 = new MockClusterParticipant(null, false);
    List<ClusterParticipant> participants = Arrays.asList(mockClusterParticipant1, mockClusterParticipant2);
    StorageManager storageManager = createStorageManager(dataNode, metricRegistry, participants);
    storageManager.start();
    PartitionId id = replicas.get(0).getPartitionId();
    // test that any delegate fails to update stop state, then the whole operation fails
    List<PartitionId> failToUpdateList = storageManager.setBlobStoreStoppedState(Collections.singletonList(id), true);
    assertEquals("Set store stopped state should fail because one of delegates returns false", id, failToUpdateList.get(0));
    // test the success case, both delegates succeed in updating stop state of replica
    mockClusterParticipant2.setStopStateReturnVal = null;
    failToUpdateList = storageManager.setBlobStoreStoppedState(Collections.singletonList(id), true);
    assertTrue("Set store stopped state should succeed", failToUpdateList.isEmpty());
    // verify both delegates have the correct stopped replica list.
    List<String> expectedStoppedReplicas = Collections.singletonList(id.toPathString());
    assertEquals("Stopped replica list from participant 1 is not expected", expectedStoppedReplicas, mockClusterParticipant1.getStoppedReplicas());
    assertEquals("Stopped replica list from participant 2 is not expected", expectedStoppedReplicas, mockClusterParticipant2.getStoppedReplicas());
    shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
Also used : MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) ReplicaId(com.github.ambry.clustermap.ReplicaId) ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) BlobStoreTest(com.github.ambry.store.BlobStoreTest) Test(org.junit.Test)

Aggregations

ReplicaId (com.github.ambry.clustermap.ReplicaId)147 Test (org.junit.Test)83 PartitionId (com.github.ambry.clustermap.PartitionId)68 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)60 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)57 ArrayList (java.util.ArrayList)55 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)43 DataNodeId (com.github.ambry.clustermap.DataNodeId)32 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)31 MetricRegistry (com.codahale.metrics.MetricRegistry)29 HashMap (java.util.HashMap)28 HashSet (java.util.HashSet)25 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)24 VerifiableProperties (com.github.ambry.config.VerifiableProperties)24 BlobStoreTest (com.github.ambry.store.BlobStoreTest)24 File (java.io.File)24 List (java.util.List)21 Map (java.util.Map)21 Port (com.github.ambry.network.Port)20 Properties (java.util.Properties)20