Search in sources :

Example 26 with ContainerStorageStats

use of com.github.ambry.server.storagestats.ContainerStorageStats in project ambry by linkedin.

the class MySqlClusterAggregator method mergeAccountStorageStatsMap.

/**
 * Merge two maps from account id to container id to storage stats. If the storage stats exists in both map, this method
 * will add the storage stats up and replace the existing storage stats in first map with the new one. If it only exists
 * in the second map, this method would add it to the first map.
 * @param result The resulting map
 * @param current The map to merge to the resulting map.
 */
void mergeAccountStorageStatsMap(Map<Short, Map<Short, ContainerStorageStats>> result, Map<Short, Map<Short, ContainerStorageStats>> current) {
    for (Map.Entry<Short, Map<Short, ContainerStorageStats>> currentEntry : current.entrySet()) {
        short accountId = currentEntry.getKey();
        if (!result.containsKey(accountId)) {
            result.put(accountId, currentEntry.getValue());
        } else {
            for (Map.Entry<Short, ContainerStorageStats> containerStorageStatsEntry : currentEntry.getValue().entrySet()) {
                short containerId = containerStorageStatsEntry.getKey();
                if (!result.get(accountId).containsKey(containerId)) {
                    result.get(accountId).put(containerId, containerStorageStatsEntry.getValue());
                } else {
                    ContainerStorageStats existingStats = result.get(accountId).get(containerId);
                    ContainerStorageStats currentStats = containerStorageStatsEntry.getValue();
                    ContainerStorageStats newStats = currentStats.add(existingStats);
                    result.get(accountId).put(containerId, newStats);
                }
            }
        }
    }
}
Also used : ContainerStorageStats(com.github.ambry.server.storagestats.ContainerStorageStats) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with ContainerStorageStats

use of com.github.ambry.server.storagestats.ContainerStorageStats in project ambry by linkedin.

the class StorageStatsUtil method convertStatsSnapshotToHostPartitionClassStorageStats.

/**
 * Convert a {@link StatsSnapshot} to a {@link HostPartitionClassStorageStats}. We assume the given {@link StatsSnapshot}
 * follows the proper format so we can construct an {@link HostPartitionClassStorageStats} from it.
 * @param snapshot The {@link StatsSnapshot}.
 * @return The {@link HostPartitionClassStorageStats}.
 */
public static HostPartitionClassStorageStats convertStatsSnapshotToHostPartitionClassStorageStats(StatsSnapshot snapshot) {
    if (snapshot == null) {
        return null;
    }
    HostPartitionClassStorageStats hostPartitionClassStorageStats = new HostPartitionClassStorageStats();
    Map<String, StatsSnapshot> partitionClassSubMap = Optional.ofNullable(snapshot.getSubMap()).orElseGet(HashMap::new);
    for (Map.Entry<String, StatsSnapshot> partitionClassSubMapEntry : partitionClassSubMap.entrySet()) {
        String partitionClassName = partitionClassSubMapEntry.getKey();
        Map<String, StatsSnapshot> partitionSubMap = Optional.ofNullable(partitionClassSubMapEntry.getValue().getSubMap()).orElseGet(HashMap::new);
        for (Map.Entry<String, StatsSnapshot> partitionSubMapEntry : partitionSubMap.entrySet()) {
            long partitionId = Utils.partitionIdFromStatsPartitionKey(partitionSubMapEntry.getKey());
            Map<String, StatsSnapshot> accountContainerSubMap = Optional.ofNullable(partitionSubMapEntry.getValue().getSubMap()).orElseGet(HashMap::new);
            for (Map.Entry<String, StatsSnapshot> accountContainerSubMapEntry : accountContainerSubMap.entrySet()) {
                short[] accountContainerIds = Utils.accountContainerIdFromPartitionClassStatsKey(accountContainerSubMapEntry.getKey());
                short accountId = accountContainerIds[0];
                short containerId = accountContainerIds[1];
                long logicalStorageUsage = accountContainerSubMapEntry.getValue().getValue();
                hostPartitionClassStorageStats.addContainerStorageStats(partitionClassName, partitionId, accountId, new ContainerStorageStats(containerId, logicalStorageUsage, logicalStorageUsage, 0));
            }
        }
    }
    return hostPartitionClassStorageStats;
}
Also used : ContainerStorageStats(com.github.ambry.server.storagestats.ContainerStorageStats) HashMap(java.util.HashMap) HostPartitionClassStorageStats(com.github.ambry.server.storagestats.HostPartitionClassStorageStats) Map(java.util.Map) HashMap(java.util.HashMap)

Example 28 with ContainerStorageStats

use of com.github.ambry.server.storagestats.ContainerStorageStats in project ambry by linkedin.

the class StorageStatsUtil method convertStatsSnapshotToAggregatedAccountStorageStats.

/**
 * Convert a {@link StatsSnapshot} to {@link AggregatedAccountStorageStats}. We assume the given {@link StatsSnapshot}
 * follows the proper format so we can construct an {@link AggregatedAccountStorageStats} from it.
 * @param snapshot The {@link StatsSnapshot}.
 * @return The {@link AggregatedAccountStorageStats}.
 */
public static AggregatedAccountStorageStats convertStatsSnapshotToAggregatedAccountStorageStats(StatsSnapshot snapshot) {
    if (snapshot == null) {
        return null;
    }
    AggregatedAccountStorageStats aggregatedAccountStorageStats = new AggregatedAccountStorageStats(null);
    Map<String, StatsSnapshot> accountMap = Optional.ofNullable(snapshot.getSubMap()).orElseGet(HashMap::new);
    for (Map.Entry<String, StatsSnapshot> accountMapEntry : accountMap.entrySet()) {
        short accountId = Utils.accountIdFromStatsAccountKey(accountMapEntry.getKey());
        Map<String, StatsSnapshot> containerMap = Optional.ofNullable(accountMapEntry.getValue().getSubMap()).orElseGet(HashMap::new);
        for (Map.Entry<String, StatsSnapshot> containerMapEntry : containerMap.entrySet()) {
            short containerId = Utils.containerIdFromStatsContainerKey(containerMapEntry.getKey());
            long logicalStorageUsage = containerMapEntry.getValue().getValue();
            aggregatedAccountStorageStats.addContainerStorageStats(accountId, new ContainerStorageStats(containerId, logicalStorageUsage, logicalStorageUsage, 0));
        }
    }
    return aggregatedAccountStorageStats;
}
Also used : ContainerStorageStats(com.github.ambry.server.storagestats.ContainerStorageStats) HashMap(java.util.HashMap) AggregatedAccountStorageStats(com.github.ambry.server.storagestats.AggregatedAccountStorageStats) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with ContainerStorageStats

use of com.github.ambry.server.storagestats.ContainerStorageStats in project ambry by linkedin.

the class StorageStatsUtilTest method testAggregatedPartitionClassStorageStatsConverter.

/**
 * Test case for {@link StorageStatsUtil#convertAggregatedPartitionClassStorageStatsToStatsSnapshot}.
 */
@Test
public void testAggregatedPartitionClassStorageStatsConverter() {
    AggregatedPartitionClassStorageStats aggregatedPartitionClassStorageStats = new AggregatedPartitionClassStorageStats(generateRandomAggregatedPartitionClassStorageStats(new String[] { "default", "newClass" }, (short) 100, 10, 10, 10000L, 2, 10));
    Map<String, Map<Short, Map<Short, ContainerStorageStats>>> storageStats = aggregatedPartitionClassStorageStats.getStorageStats();
    StatsSnapshot expected = TestUtils.makePartitionClassSnasphotFromContainerStorageMap(convertAggregatedPartitionClassStorageStatsMapToContainerStorageMap(storageStats, false));
    StatsSnapshot snapshot = StorageStatsUtil.convertAggregatedPartitionClassStorageStatsToStatsSnapshot(aggregatedPartitionClassStorageStats, false);
    Assert.assertEquals(expected, snapshot);
    expected = TestUtils.makePartitionClassSnasphotFromContainerStorageMap(convertAggregatedPartitionClassStorageStatsMapToContainerStorageMap(storageStats, true));
    snapshot = StorageStatsUtil.convertAggregatedPartitionClassStorageStatsToStatsSnapshot(aggregatedPartitionClassStorageStats, true);
    Assert.assertEquals(expected, snapshot);
}
Also used : ContainerStorageStats(com.github.ambry.server.storagestats.ContainerStorageStats) AggregatedPartitionClassStorageStats(com.github.ambry.server.storagestats.AggregatedPartitionClassStorageStats) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 30 with ContainerStorageStats

use of com.github.ambry.server.storagestats.ContainerStorageStats in project ambry by linkedin.

the class StorageStatsTest method testAggregatedPartitionClassStorageStats.

@Test
public void testAggregatedPartitionClassStorageStats() throws Exception {
    Map<String, Map<Short, Map<Short, ContainerStorageStats>>> storageStatsMap = StorageStatsUtilTest.generateRandomAggregatedPartitionClassStorageStats(new String[] { "default", "newClass" }, (short) 10, 10, 5, 10000L, 2, 100);
    String serialized = objectMapper.writeValueAsString(storageStatsMap);
    AggregatedPartitionClassStorageStats deserialized = objectMapper.readValue(serialized, AggregatedPartitionClassStorageStats.class);
    Assert.assertEquals(storageStatsMap, deserialized.getStorageStats());
    serialized = objectMapper.writeValueAsString(deserialized);
    deserialized = objectMapper.readValue(serialized, AggregatedPartitionClassStorageStats.class);
    Assert.assertEquals(storageStatsMap, deserialized.getStorageStats());
}
Also used : ContainerStorageStats(com.github.ambry.server.storagestats.ContainerStorageStats) AggregatedPartitionClassStorageStats(com.github.ambry.server.storagestats.AggregatedPartitionClassStorageStats) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ContainerStorageStats (com.github.ambry.server.storagestats.ContainerStorageStats)39 HashMap (java.util.HashMap)36 Map (java.util.Map)36 Test (org.junit.Test)20 HostAccountStorageStats (com.github.ambry.server.storagestats.HostAccountStorageStats)16 HostAccountStorageStatsWrapper (com.github.ambry.server.HostAccountStorageStatsWrapper)12 StorageStatsUtilTest (com.github.ambry.server.StorageStatsUtilTest)12 StatsHeader (com.github.ambry.server.StatsHeader)10 AggregatedAccountStorageStats (com.github.ambry.server.storagestats.AggregatedAccountStorageStats)10 Pair (com.github.ambry.utils.Pair)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 HostPartitionClassStorageStats (com.github.ambry.server.storagestats.HostPartitionClassStorageStats)6 Utils (com.github.ambry.utils.Utils)6 MetricRegistry (com.codahale.metrics.MetricRegistry)5 AggregatedPartitionClassStorageStats (com.github.ambry.server.storagestats.AggregatedPartitionClassStorageStats)5 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5 NavigableMap (java.util.NavigableMap)5 Set (java.util.Set)5