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);
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations