Skip to content

Commit

Permalink
Replace usage of ContainerKeyInfoWrapper with ContainerKeyInfoResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
mladjan-gadzic committed Jan 11, 2024
1 parent de279f8 commit 0a1fbfc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public ContainerKeyInfoResponse(
this.containerKeys = containerKeys;
}

public long getKeysProcessed() {
return keysProcessed;
}

public Map<Long, List<ContainerKeyInfo>> getContainerKeys() {
return containerKeys;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.hadoop.ozone.debug;

import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
Expand Down Expand Up @@ -101,10 +100,10 @@ public class ContainerKeyScanner implements Callable<Void>,

@Override
public Void call() throws Exception {
ContainerKeyInfoWrapper containerKeyInfoWrapper =
ContainerKeyInfoResponse containerKeyInfoResponse =
scanDBForContainerKeys(parent.getDbPath());

printOutput(containerKeyInfoWrapper);
printOutput(containerKeyInfoResponse);

closeStdChannels();

Expand Down Expand Up @@ -212,9 +211,9 @@ private void addToPathMap(Pair<Long, Path> objectIDPath,
}
}

private ContainerKeyInfoWrapper scanDBForContainerKeys(String dbPath)
private ContainerKeyInfoResponse scanDBForContainerKeys(String dbPath)
throws RocksDBException, IOException {
List<ContainerKeyInfo> containerKeyInfos = new ArrayList<>();
Map<Long, List<ContainerKeyInfo>> containerKeyInfos = new HashMap<>();

List<ColumnFamilyDescriptor> columnFamilyDescriptors =
RocksDBUtils.getColumnFamilyDescriptors(dbPath);
Expand All @@ -237,13 +236,13 @@ private ContainerKeyInfoWrapper scanDBForContainerKeys(String dbPath)
processTable(dbDefinition, columnFamilyHandles, db,
containerKeyInfos, KEY_TABLE);
}
return new ContainerKeyInfoWrapper(keysProcessed, containerKeyInfos);
return new ContainerKeyInfoResponse(keysProcessed, containerKeyInfos);
}

private long processTable(DBDefinition dbDefinition,
List<ColumnFamilyHandle> columnFamilyHandles,
ManagedRocksDB db,
List<ContainerKeyInfo> containerKeyInfos,
Map<Long, List<ContainerKeyInfo>> containerKeyInfos,
String tableName)
throws IOException {
long keysProcessed = 0;
Expand Down Expand Up @@ -289,7 +288,7 @@ private long processTable(DBDefinition dbDefinition,
}
}

private void processData(List<ContainerKeyInfo> containerKeyInfos,
private void processData(Map<Long, List<ContainerKeyInfo>> containerKeyInfos,
String tableName,
List<OmKeyLocationInfoGroup> keyLocationVersions,
long volumeId, long bucketId, OmKeyInfo value)
Expand All @@ -314,11 +313,17 @@ private void processData(List<ContainerKeyInfo> containerKeyInfos,
keyName.append(getFsoKeyPrefix(volumeId, bucketId, value));
}
keyName.append(value.getKeyName());
containerKeyInfos.add(
new ContainerKeyInfo(locationInfo.getContainerID(),
value.getVolumeName(), volumeId, value.getBucketName(),
bucketId, keyName.toString(),
value.getParentObjectID()));

containerKeyInfos.merge(locationInfo.getContainerID(),
new ArrayList<>(Collections.singletonList(
new ContainerKeyInfo(locationInfo.getContainerID(),
value.getVolumeName(), volumeId, value.getBucketName(),
bucketId, keyName.toString(),
value.getParentObjectID()))),
(existingList, newList) -> {
existingList.addAll(newList);
return existingList;
});
}
}
}
Expand Down Expand Up @@ -377,35 +382,16 @@ private String removeTrailingSlashIfNeeded(String dbPath) {
return dbPath;
}

private void printOutput(ContainerKeyInfoWrapper containerKeyInfoWrapper) {
List<ContainerKeyInfo> containerKeyInfos =
containerKeyInfoWrapper.getContainerKeyInfos();
if (containerKeyInfos.isEmpty()) {
private void printOutput(ContainerKeyInfoResponse containerKeyInfoResponse) {
if (containerKeyInfoResponse.getContainerKeys().isEmpty()) {
err().println("No keys were found for container IDs: " + containerIds);
err().println(
"Keys processed: " + containerKeyInfoWrapper.getKeysProcessed());
"Keys processed: " + containerKeyInfoResponse.getKeysProcessed());
return;
}

Map<Long, List<ContainerKeyInfo>> infoMap = new HashMap<>();

for (long id : containerIds) {
List<ContainerKeyInfo> tmpList = new ArrayList<>();

for (ContainerKeyInfo info : containerKeyInfos) {
if (id == info.getContainerID()) {
tmpList.add(info);
}
}
infoMap.put(id, tmpList);
}

Gson gson = new GsonBuilder().setPrettyPrinting().create();
String prettyJson = gson.toJson(
new ContainerKeyInfoResponse(containerKeyInfoWrapper.getKeysProcessed(),
infoMap));

out().print(prettyJson);
out().print(new GsonBuilder().setPrettyPrinting().create()
.toJson(containerKeyInfoResponse));
}

}

0 comments on commit 0a1fbfc

Please sign in to comment.