Search in sources :

Example 96 with PartitionId

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

the class StorageManager method setBlobStoreStoppedState.

@Override
public List<PartitionId> setBlobStoreStoppedState(List<PartitionId> partitionIds, boolean markStop) {
    Map<DiskManager, List<PartitionId>> diskManagerToPartitionMap = new HashMap<>();
    List<PartitionId> failToUpdateStores = new ArrayList<>();
    for (PartitionId id : partitionIds) {
        DiskManager diskManager = partitionToDiskManager.get(id);
        if (diskManager != null) {
            diskManagerToPartitionMap.computeIfAbsent(diskManager, disk -> new ArrayList<>()).add(id);
        } else {
            failToUpdateStores.add(id);
        }
    }
    for (Map.Entry<DiskManager, List<PartitionId>> diskToPartitions : diskManagerToPartitionMap.entrySet()) {
        List<PartitionId> failList = diskToPartitions.getKey().setBlobStoreStoppedState(diskToPartitions.getValue(), markStop);
        failToUpdateStores.addAll(failList);
    }
    return failToUpdateStores;
}
Also used : DiskId(com.github.ambry.clustermap.DiskId) StoreManager(com.github.ambry.server.StoreManager) ServerErrorCode(com.github.ambry.server.ServerErrorCode) DataNodeId(com.github.ambry.clustermap.DataNodeId) LoggerFactory(org.slf4j.LoggerFactory) AccountService(com.github.ambry.account.AccountService) HashMap(java.util.HashMap) LogSegment(com.github.ambry.store.LogSegment) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Time(com.github.ambry.utils.Time) ReplicaState(com.github.ambry.clustermap.ReplicaState) StateModelListenerType(com.github.ambry.clustermap.StateModelListenerType) StoreConfig(com.github.ambry.config.StoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) ReplicaSyncUpManager(com.github.ambry.clustermap.ReplicaSyncUpManager) DiskManagerConfig(com.github.ambry.config.DiskManagerConfig) Logger(org.slf4j.Logger) ReplicaStatusDelegate(com.github.ambry.clustermap.ReplicaStatusDelegate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ClusterMap(com.github.ambry.clustermap.ClusterMap) Utils(com.github.ambry.utils.Utils) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) PartitionStateChangeListener(com.github.ambry.clustermap.PartitionStateChangeListener) StateTransitionException(com.github.ambry.clustermap.StateTransitionException) ReplicaId(com.github.ambry.clustermap.ReplicaId) TransitionErrorCode(com.github.ambry.clustermap.StateTransitionException.TransitionErrorCode) Collections(java.util.Collections) PartitionId(com.github.ambry.clustermap.PartitionId) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PartitionId(com.github.ambry.clustermap.PartitionId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterMap(com.github.ambry.clustermap.ClusterMap)

Example 97 with PartitionId

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

the class StatsManagerTest method testStatsManagerDeleteTombstoneStats.

/**
 * Test to verify that the {@link StatsManager} is collecting delete tombstone stats.
 */
@Test
public void testStatsManagerDeleteTombstoneStats() {
    List<PartitionId> unreachablePartitions = Collections.emptyList();
    Map<Long, Map<Short, Map<Short, ContainerStorageStats>>> hostAccountStorageStatsMap = new HashMap<>();
    for (PartitionId partitionId : storeMap.keySet()) {
        statsManager.collectAndAggregateAccountStorageStats(hostAccountStorageStatsMap, partitionId, unreachablePartitions);
    }
    statsManager.updateAggregatedDeleteTombstoneStats();
    // verify aggregated delete tombstone stats
    StatsManager.AggregatedDeleteTombstoneStats deleteTombstoneStats = statsManager.getAggregatedDeleteTombstoneStats();
    Pair<Long, Long> expectedExpiredDeleteStats = storeDeleteTombstoneStats.get(EXPIRED_DELETE_TOMBSTONE);
    Pair<Long, Long> expectedPermanentDeleteStats = storeDeleteTombstoneStats.get(PERMANENT_DELETE_TOMBSTONE);
    assertEquals("Mismatch in expired delete count", storeMap.size() * expectedExpiredDeleteStats.getFirst(), deleteTombstoneStats.getExpiredDeleteTombstoneCount());
    assertEquals("Mismatch in expired delete size", storeMap.size() * expectedExpiredDeleteStats.getSecond(), deleteTombstoneStats.getExpiredDeleteTombstoneSize());
    assertEquals("Mismatch in permanent delete count", storeMap.size() * expectedPermanentDeleteStats.getFirst(), deleteTombstoneStats.getPermanentDeleteTombstoneCount());
    assertEquals("Mismatch in permanent delete size", storeMap.size() * expectedPermanentDeleteStats.getSecond(), deleteTombstoneStats.getPermanentDeleteTombstoneSize());
}
Also used : ContainerStorageStats(com.github.ambry.server.storagestats.ContainerStorageStats) HashMap(java.util.HashMap) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) Map(java.util.Map) HashMap(java.util.HashMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 98 with PartitionId

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

the class DiskManager method shutdown.

/**
 * Shuts down all the stores on this disk.
 * @throws InterruptedException
 */
void shutdown() throws InterruptedException {
    long startTimeMs = time.milliseconds();
    rwLock.readLock().lock();
    try {
        running = false;
        compactionManager.disable();
        diskIOScheduler.disable();
        final AtomicInteger numFailures = new AtomicInteger(0);
        List<Thread> shutdownThreads = new ArrayList<>();
        for (final Map.Entry<PartitionId, BlobStore> partitionAndStore : stores.entrySet()) {
            if (!partitionAndStore.getValue().isStarted()) {
                continue;
            }
            Thread thread = Utils.newThread("store-shutdown-" + partitionAndStore.getKey(), () -> {
                try {
                    partitionAndStore.getValue().shutdown();
                } catch (Exception e) {
                    numFailures.incrementAndGet();
                    metrics.totalStoreShutdownFailures.inc();
                    logger.error("Exception while shutting down store {} on disk {}", partitionAndStore.getKey(), disk, e);
                }
            }, false);
            thread.start();
            shutdownThreads.add(thread);
        }
        for (Thread shutdownThread : shutdownThreads) {
            shutdownThread.join();
        }
        if (numFailures.get() > 0) {
            logger.error("Could not shutdown {} out of {} stores on the disk {}", numFailures.get(), stores.size(), disk);
        }
        compactionManager.awaitTermination();
        longLivedTaskScheduler.shutdown();
        if (!longLivedTaskScheduler.awaitTermination(30, TimeUnit.SECONDS)) {
            logger.error("Could not terminate long live tasks after DiskManager shutdown");
        }
    } finally {
        rwLock.readLock().unlock();
        metrics.diskShutdownTimeMs.update(time.milliseconds() - startTimeMs);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) PartitionId(com.github.ambry.clustermap.PartitionId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException)

Example 99 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, FindTokenFactory factory) throws IOException {
    String hostName = Utils.readIntString(stream);
    String replicaPath = Utils.readIntString(stream);
    PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream);
    FindToken token = factory.getFindToken(stream);
    return new ReplicaMetadataRequestInfo(partitionId, token, hostName, replicaPath);
}
Also used : FindToken(com.github.ambry.store.FindToken) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 100 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, FindTokenFactory factory, ClusterMap clusterMap, short replicaMetadataResponseVersion) throws IOException {
    PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream);
    ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
    if (error != ServerErrorCode.No_Error) {
        return new ReplicaMetadataResponseInfo(partitionId, error);
    } else {
        FindToken token = factory.getFindToken(stream);
        Pair<List<MessageInfo>, List<MessageMetadata>> messageInfoAndMetadataList = MessageInfoAndMetadataListSerde.deserializeMessageInfoAndMetadataList(stream, clusterMap, getMessageInfoAndMetadataListSerDeVersion(replicaMetadataResponseVersion));
        long remoteReplicaLag = stream.readLong();
        return new ReplicaMetadataResponseInfo(partitionId, token, messageInfoAndMetadataList.getFirst(), remoteReplicaLag, replicaMetadataResponseVersion);
    }
}
Also used : FindToken(com.github.ambry.store.FindToken) List(java.util.List) PartitionId(com.github.ambry.clustermap.PartitionId) ServerErrorCode(com.github.ambry.commons.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