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