Search in sources :

Example 46 with PartitionId

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

the class RequestResponseTest method doRequestControlAdminRequestTest.

/**
 * Does the actual test of ser/de of {@link RequestControlAdminRequest} and checks for equality of fields with
 * reference data.
 * @param requestOrResponseType the {@link RequestOrResponseType} to be used in the {@link RequestControlAdminRequest}
 * @param enable the value for the enable field in {@link RequestControlAdminRequest}.
 * @throws IOException
 */
private void doRequestControlAdminRequestTest(RequestOrResponseType requestOrResponseType, 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.RequestControl, id, correlationId, clientId);
    RequestControlAdminRequest controlRequest = new RequestControlAdminRequest(requestOrResponseType, enable, adminRequest);
    DataInputStream requestStream = serAndPrepForRead(controlRequest, -1, true);
    AdminRequest deserializedAdminRequest = deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, AdminRequestOrResponseType.RequestControl, id);
    RequestControlAdminRequest deserializedControlRequest = RequestControlAdminRequest.readFrom(requestStream, deserializedAdminRequest);
    Assert.assertEquals(requestOrResponseType, deserializedControlRequest.getRequestTypeToControl());
    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 47 with PartitionId

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

the class ReplicaThread method controlReplicationForPartitions.

/**
 * Enables/disables replication on the given {@code ids}.
 * @param ids the {@link PartitionId}s to enable/disable it on.
 * @param enable whether to enable ({@code true}) or disable.
 */
void controlReplicationForPartitions(Collection<PartitionId> ids, boolean enable) {
    lock.lock();
    try {
        for (PartitionId id : ids) {
            if (allReplicatedPartitions.contains(id)) {
                if (enable) {
                    if (replicationDisabledPartitions.remove(id)) {
                        allDisabled = false;
                        pauseCondition.signal();
                    }
                } else {
                    replicationDisabledPartitions.add(id);
                    allDisabled = allReplicatedPartitions.size() == replicationDisabledPartitions.size();
                }
                logger.info("Disable status of replication of {} from {} is {}. allDisabled for {} is {}", id, datacenterName, replicationDisabledPartitions.contains(id), getName(), allDisabled);
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : PartitionId(com.github.ambry.clustermap.PartitionId)

Example 48 with PartitionId

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

the class ReplicationManager method createRemoteReplicaInfos.

/**
 * Create {@link RemoteReplicaInfo}(s) that associates with given local replica.
 * @param peerReplicas the list peer replicas of given local replica
 * @param replicaId the local replica
 * @return list of {@link RemoteReplicaInfo} associated with local replica.
 */
private List<RemoteReplicaInfo> createRemoteReplicaInfos(List<? extends ReplicaId> peerReplicas, ReplicaId replicaId) {
    List<RemoteReplicaInfo> remoteReplicaInfos = new ArrayList<>();
    PartitionId partition = replicaId.getPartitionId();
    Store store = storeManager.getStore(partition);
    for (ReplicaId remoteReplica : peerReplicas) {
        // We need to ensure that a replica token gets persisted only after the corresponding data in the
        // store gets flushed to disk. We use the store flush interval multiplied by a constant factor
        // to determine the token flush interval
        FindToken findToken = this.tokenHelper.getFindTokenFactoryFromReplicaType(remoteReplica.getReplicaType()).getNewFindToken();
        RemoteReplicaInfo remoteReplicaInfo = new RemoteReplicaInfo(remoteReplica, replicaId, store, findToken, TimeUnit.SECONDS.toMillis(storeConfig.storeDataFlushIntervalSeconds) * Replication_Delay_Multiplier, SystemTime.getInstance(), remoteReplica.getDataNodeId().getPortToConnectTo());
        replicationMetrics.addMetricsForRemoteReplicaInfo(remoteReplicaInfo, trackPerPartitionLagInMetric);
        remoteReplicaInfos.add(remoteReplicaInfo);
    }
    replicationMetrics.addLagMetricForPartition(partition, replicationConfig.replicationTrackPerPartitionLagFromRemote);
    return remoteReplicaInfos;
}
Also used : ArrayList(java.util.ArrayList) Store(com.github.ambry.store.Store) PartitionId(com.github.ambry.clustermap.PartitionId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 49 with PartitionId

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

the class CloudToStoreReplicationManager method handleChangeInVcrNodes.

/**
 * When there is a change in vcr nodes state, update the new list of live vcr nodes.
 * Also if there are nodes that are removed as part of change, then replication from
 * those nodes should stop and the partitions should find new nodes to replicate from.
 * Note that this method is not thread safe in the wake of arriving helix notifications.
 * @param newVcrNodes Set of new vcr nodes.
 */
private void handleChangeInVcrNodes(Set<CloudDataNode> newVcrNodes) {
    Set<CloudDataNode> removedNodes = new HashSet<>(vcrNodes.get());
    removedNodes.removeAll(newVcrNodes);
    vcrNodes.set(new ArrayList<>(newVcrNodes));
    logger.info("Handling VCR nodes change. The removed vcr nodes: {}", removedNodes);
    List<PartitionId> partitionsOnRemovedNodes = getPartitionsOnNodes(removedNodes);
    for (PartitionId partitionId : partitionsOnRemovedNodes) {
        try {
            // We first remove replica to stop replication from removed node, and then add replica so that it can pick a
            // new cloud node to start replicating from.
            removeCloudReplica(partitionId.toPathString());
            addCloudReplica(partitionId.toPathString());
        } catch (ReplicationException rex) {
            replicationMetrics.addCloudPartitionErrorCount.inc();
            logger.error("Exception {} during remove/add replica for partitionId {}", rex, partitionId);
        }
    }
}
Also used : PartitionId(com.github.ambry.clustermap.PartitionId) CloudDataNode(com.github.ambry.clustermap.CloudDataNode) HashSet(java.util.HashSet)

Example 50 with PartitionId

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

the class CloudToStoreReplicationManager method removeCloudReplica.

/**
 * Remove a replica of given partition and its {@link RemoteReplicaInfo}s from the backup list.
 * @param partitionName the partition of the replica to be removed.
 */
private void removeCloudReplica(String partitionName) {
    // Removing cloud replica occurs when replica from LEADER to STANDBY (this may be triggered by "Move Replica" or
    // regular leadership hand-off due to server deployment). No matter what triggers this transition, the local replica
    // should be present in storage manager at this point of time.
    ReplicaId localReplica = storeManager.getReplica(partitionName);
    if (localReplica == null) {
        logger.warn("Attempting to remove cloud partition {} that is not present on the node", partitionName);
        return;
    }
    PartitionId partitionId = localReplica.getPartitionId();
    stopPartitionReplication(partitionId);
    replicationMetrics.removeLagMetricForPartition(partitionId);
    replicationMetrics.removeCatchupPointMetricForPartition(partitionId);
    logger.info("Cloud Partition {} removed from {}", partitionId, dataNodeId);
}
Also used : PartitionId(com.github.ambry.clustermap.PartitionId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

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