Search in sources :

Example 41 with PartitionId

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

the class RequestResponseTest method doReplicationControlAdminRequestTest.

/**
 * Does the actual test of ser/de of {@link ReplicationControlAdminRequest} and checks for equality of fields with
 * reference data.
 * @param origins the origins list to use in {@link ReplicationControlAdminRequest}.
 * @param enable the value for the enable field in {@link ReplicationControlAdminRequest}.
 * @throws IOException
 */
private void doReplicationControlAdminRequestTest(List<String> origins, boolean enable) throws IOException {
    MockClusterMap clusterMap = new MockClusterMap();
    PartitionId id = clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0);
    int correlationId = 1234;
    String clientId = "client";
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, id, correlationId, clientId);
    ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(origins, enable, adminRequest);
    DataInputStream requestStream = serAndPrepForRead(controlRequest, -1, true);
    AdminRequest deserializedAdminRequest = deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, AdminRequestOrResponseType.ReplicationControl, id);
    ReplicationControlAdminRequest deserializedControlRequest = ReplicationControlAdminRequest.readFrom(requestStream, deserializedAdminRequest);
    Assert.assertEquals(origins, deserializedControlRequest.getOrigins());
    Assert.assertEquals(enable, deserializedControlRequest.shouldEnable());
    controlRequest.release();
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) MockClusterMap(com.github.ambry.clustermap.MockClusterMap)

Example 42 with PartitionId

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

the class RequestResponseTest method adminRequestResponseTest.

/**
 * Tests the ser/de of {@link AdminRequest} and {@link AdminResponse} and checks for equality of fields with
 * reference data.
 * @throws IOException
 */
@Test
public void adminRequestResponseTest() throws IOException {
    int correlationId = 1234;
    String clientId = "client";
    for (AdminRequestOrResponseType type : AdminRequestOrResponseType.values()) {
        MockClusterMap clusterMap = new MockClusterMap();
        PartitionId id = clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0);
        // with a valid partition id
        AdminRequest adminRequest = new AdminRequest(type, id, correlationId, clientId);
        DataInputStream requestStream = serAndPrepForRead(adminRequest, -1, true);
        deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, type, id);
        adminRequest.release();
        // with a null partition id
        adminRequest = new AdminRequest(type, null, correlationId, clientId);
        requestStream = serAndPrepForRead(adminRequest, -1, true);
        deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, type, null);
        adminRequest.release();
        // response
        ServerErrorCode[] values = ServerErrorCode.values();
        int indexToPick = TestUtils.RANDOM.nextInt(values.length);
        ServerErrorCode responseErrorCode = values[indexToPick];
        AdminResponse response = new AdminResponse(correlationId, clientId, responseErrorCode);
        DataInputStream responseStream = serAndPrepForRead(response, -1, false);
        AdminResponse deserializedAdminResponse = AdminResponse.readFrom(responseStream);
        Assert.assertEquals(deserializedAdminResponse.getCorrelationId(), correlationId);
        Assert.assertEquals(deserializedAdminResponse.getClientId(), clientId);
        Assert.assertEquals(deserializedAdminResponse.getError(), responseErrorCode);
        response.release();
    }
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) ServerErrorCode(com.github.ambry.server.ServerErrorCode) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 43 with PartitionId

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

the class ReplicaMetadataRequestInfo method readFrom.

public static ReplicaMetadataRequestInfo readFrom(DataInputStream stream, ClusterMap clusterMap, FindTokenHelper findTokenHelper, short requestVersion) throws IOException {
    String hostName = Utils.readIntString(stream);
    String replicaPath = Utils.readIntString(stream);
    ReplicaType replicaType;
    if (requestVersion == ReplicaMetadataRequest.Replica_Metadata_Request_Version_V2) {
        replicaType = ReplicaType.values()[stream.readShort()];
    } else {
        // before version 2 we only have disk based replicas
        replicaType = ReplicaType.DISK_BACKED;
    }
    PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream);
    FindTokenFactory findTokenFactory = findTokenHelper.getFindTokenFactoryFromReplicaType(replicaType);
    FindToken token = findTokenFactory.getFindToken(stream);
    return new ReplicaMetadataRequestInfo(partitionId, token, hostName, replicaPath, replicaType, requestVersion);
}
Also used : ReplicaType(com.github.ambry.clustermap.ReplicaType) FindToken(com.github.ambry.replication.FindToken) PartitionId(com.github.ambry.clustermap.PartitionId) FindTokenFactory(com.github.ambry.replication.FindTokenFactory)

Example 44 with PartitionId

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

the class PartitionRequestInfo method readFrom.

public static PartitionRequestInfo readFrom(DataInputStream stream, ClusterMap clusterMap) throws IOException {
    int blobCount = stream.readInt();
    ArrayList<BlobId> ids = new ArrayList<BlobId>(blobCount);
    PartitionId partitionId = null;
    while (blobCount > 0) {
        BlobId id = new BlobId(stream, clusterMap);
        if (partitionId == null) {
            partitionId = id.getPartition();
        }
        ids.add(id);
        blobCount--;
    }
    return new PartitionRequestInfo(partitionId, ids);
}
Also used : ArrayList(java.util.ArrayList) PartitionId(com.github.ambry.clustermap.PartitionId) BlobId(com.github.ambry.commons.BlobId)

Example 45 with PartitionId

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

the class ReplicaMetadataResponseInfo method readFrom.

public static ReplicaMetadataResponseInfo readFrom(DataInputStream stream, FindTokenHelper helper, ClusterMap clusterMap, short replicaMetadataResponseVersion) throws IOException {
    PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream);
    ReplicaType replicaType;
    if (replicaMetadataResponseVersion == ReplicaMetadataResponse.REPLICA_METADATA_RESPONSE_VERSION_V_6) {
        replicaType = ReplicaType.values()[stream.readShort()];
    } else {
        // before REPLICA_METADATA_RESPONSE_VERSION_V_6 there were only disk based replicas
        replicaType = ReplicaType.DISK_BACKED;
    }
    ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
    if (error != ServerErrorCode.No_Error) {
        return new ReplicaMetadataResponseInfo(partitionId, replicaType, error, replicaMetadataResponseVersion);
    } else {
        FindTokenFactory findTokenFactory = helper.getFindTokenFactoryFromReplicaType(replicaType);
        FindToken token = findTokenFactory.getFindToken(stream);
        MessageInfoAndMetadataListSerde messageInfoAndMetadataList = MessageInfoAndMetadataListSerde.deserializeMessageInfoAndMetadataList(stream, clusterMap, getMessageInfoAndMetadataListSerDeVersion(replicaMetadataResponseVersion));
        long remoteReplicaLag = stream.readLong();
        return new ReplicaMetadataResponseInfo(partitionId, replicaType, token, messageInfoAndMetadataList.getMessageInfoList(), remoteReplicaLag, replicaMetadataResponseVersion);
    }
}
Also used : ReplicaType(com.github.ambry.clustermap.ReplicaType) FindToken(com.github.ambry.replication.FindToken) PartitionId(com.github.ambry.clustermap.PartitionId) FindTokenFactory(com.github.ambry.replication.FindTokenFactory) ServerErrorCode(com.github.ambry.server.ServerErrorCode)

Aggregations

PartitionId (com.github.ambry.clustermap.PartitionId)183 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)111 Test (org.junit.Test)95 ReplicaId (com.github.ambry.clustermap.ReplicaId)70 ArrayList (java.util.ArrayList)68 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)53 BlobId (com.github.ambry.commons.BlobId)50 HashMap (java.util.HashMap)48 Map (java.util.Map)41 List (java.util.List)40 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)39 DataNodeId (com.github.ambry.clustermap.DataNodeId)36 MetricRegistry (com.codahale.metrics.MetricRegistry)33 ClusterMap (com.github.ambry.clustermap.ClusterMap)32 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)30 VerifiableProperties (com.github.ambry.config.VerifiableProperties)30 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 StoreKey (com.github.ambry.store.StoreKey)26 StoreKeyFactory (com.github.ambry.store.StoreKeyFactory)25