Skip to content

Commit 8d1a0ad

Browse files
authored
HDDS-13335. Implement and adopt lightweight proto for Recon listKeys API (#8699)
1 parent c696942 commit 8d1a0ad

9 files changed

Lines changed: 342 additions & 177 deletions

File tree

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ public T copyObject(T message) {
114114
}
115115
}
116116

117+
public static <T, DELEGATE> DelegatedCodec<T, DELEGATE> decodeOnly(
118+
Codec<DELEGATE> delegate, CheckedFunction<DELEGATE, T, CodecException> forward, Class<T> clazz) {
119+
return new DelegatedCodec<>(delegate, forward, unsupportedBackward(), clazz, CopyType.DEEP);
120+
}
121+
122+
private static <A, B> CheckedFunction<A, B, CodecException> unsupportedBackward() {
123+
return a -> {
124+
throw new UnsupportedOperationException("Unsupported backward conversion");
125+
};
126+
}
127+
117128
@Override
118129
public String toString() {
119130
return name;

hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,25 @@ message KeyInfo {
11721172
optional uint64 expectedDataGeneration = 22;
11731173
}
11741174

1175+
// KeyInfoProtoLight is a lightweight subset of KeyInfo message containing
1176+
// selected fields only, while maintaining the same field indices as KeyInfo
1177+
// for compatibility and consistency.
1178+
message KeyInfoProtoLight {
1179+
required string volumeName = 1;
1180+
required string bucketName = 2;
1181+
required string keyName = 3;
1182+
required uint64 dataSize = 4;
1183+
required hadoop.hdds.ReplicationType type = 5;
1184+
optional hadoop.hdds.ReplicationFactor factor = 6;
1185+
required uint64 creationTime = 8;
1186+
required uint64 modificationTime = 9;
1187+
optional uint64 objectID = 14;
1188+
optional uint64 updateID = 15;
1189+
optional uint64 parentID = 16;
1190+
optional hadoop.hdds.ECReplicationConfig ecReplicationConfig = 17;
1191+
optional bool isFile = 19;
1192+
}
1193+
11751194
message BasicKeyInfo {
11761195
optional string keyName = 1;
11771196
optional uint64 dataSize = 2;

hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
import org.apache.hadoop.ozone.recon.ReconUtils;
7070
import org.apache.hadoop.ozone.recon.api.handlers.BucketHandler;
7171
import org.apache.hadoop.ozone.recon.api.types.KeyEntityInfo;
72-
import org.apache.hadoop.ozone.recon.api.types.KeyEntityInfoProtoWrapper;
7372
import org.apache.hadoop.ozone.recon.api.types.KeyInsightInfoResponse;
7473
import org.apache.hadoop.ozone.recon.api.types.ListKeysResponse;
7574
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
7675
import org.apache.hadoop.ozone.recon.api.types.ParamInfo;
76+
import org.apache.hadoop.ozone.recon.api.types.ReconBasicOmKeyInfo;
7777
import org.apache.hadoop.ozone.recon.api.types.ResponseStatus;
7878
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
7979
import org.apache.hadoop.ozone.recon.spi.impl.ReconNamespaceSummaryManagerImpl;
@@ -1014,7 +1014,7 @@ public Response listKeys(@QueryParam("replicationType") String replicationType,
10141014
listKeysResponse = (ListKeysResponse) response.getEntity();
10151015
}
10161016

1017-
List<KeyEntityInfoProtoWrapper> keyInfoList = listKeysResponse.getKeys();
1017+
List<ReconBasicOmKeyInfo> keyInfoList = listKeysResponse.getKeys();
10181018
if (!keyInfoList.isEmpty()) {
10191019
listKeysResponse.setLastKey(keyInfoList.get(keyInfoList.size() - 1).getKey());
10201020
}
@@ -1029,9 +1029,9 @@ private Response getListKeysResponse(ParamInfo paramInfo) {
10291029
long replicatedTotal = 0;
10301030
long unreplicatedTotal = 0;
10311031

1032-
// Search keys from non-FSO layout.
1033-
Table<String, KeyEntityInfoProtoWrapper> keyTable =
1034-
omMetadataManager.getKeyTableLite(BucketLayout.LEGACY);
1032+
Table<String, ReconBasicOmKeyInfo> keyTable =
1033+
omMetadataManager.getKeyTableBasic(BucketLayout.LEGACY);
1034+
10351035
retrieveKeysFromTable(keyTable, paramInfo, listKeysResponse.getKeys());
10361036

10371037
// Search keys from FSO layout.
@@ -1042,7 +1042,7 @@ private Response getListKeysResponse(ParamInfo paramInfo) {
10421042
return ReconResponseUtils.noMatchedKeysResponse(paramInfo.getStartPrefix());
10431043
}
10441044

1045-
for (KeyEntityInfoProtoWrapper keyEntityInfo : listKeysResponse.getKeys()) {
1045+
for (ReconBasicOmKeyInfo keyEntityInfo : listKeysResponse.getKeys()) {
10461046
replicatedTotal += keyEntityInfo.getReplicatedSize();
10471047
unreplicatedTotal += keyEntityInfo.getSize();
10481048
}
@@ -1067,13 +1067,14 @@ private Response getListKeysResponse(ParamInfo paramInfo) {
10671067
}
10681068
}
10691069

1070-
public void searchKeysInFSO(ParamInfo paramInfo, List<KeyEntityInfoProtoWrapper> results)
1070+
public void searchKeysInFSO(ParamInfo paramInfo, List<ReconBasicOmKeyInfo> results)
10711071
throws IOException {
10721072
// Convert the search prefix to an object path for FSO buckets
10731073
String startPrefixObjectPath = convertStartPrefixPathToObjectIdPath(paramInfo.getStartPrefix());
10741074
String[] names = parseRequestPath(startPrefixObjectPath);
1075-
Table<String, KeyEntityInfoProtoWrapper> fileTable =
1076-
omMetadataManager.getKeyTableLite(BucketLayout.FILE_SYSTEM_OPTIMIZED);
1075+
1076+
Table<String, ReconBasicOmKeyInfo> fileTable =
1077+
omMetadataManager.getKeyTableBasic(BucketLayout.FILE_SYSTEM_OPTIMIZED);
10771078

10781079
// If names.length > 2, then the search prefix is at the level above bucket level hence
10791080
// no need to find parent or extract id's or find subpaths as the fileTable is
@@ -1181,16 +1182,16 @@ public String convertStartPrefixPathToObjectIdPath(String startPrefixPath)
11811182
* @throws IOException If there are problems accessing the table.
11821183
*/
11831184
private void retrieveKeysFromTable(
1184-
Table<String, KeyEntityInfoProtoWrapper> table, ParamInfo paramInfo, List<KeyEntityInfoProtoWrapper> results)
1185+
Table<String, ReconBasicOmKeyInfo> table, ParamInfo paramInfo, List<ReconBasicOmKeyInfo> results)
11851186
throws IOException {
11861187
boolean skipPrevKey = false;
11871188
String seekKey = paramInfo.getPrevKey();
11881189
try (
1189-
TableIterator<String, ? extends Table.KeyValue<String, KeyEntityInfoProtoWrapper>> keyIter = table.iterator()) {
1190+
TableIterator<String, ? extends Table.KeyValue<String, ReconBasicOmKeyInfo>> keyIter = table.iterator()) {
11901191

11911192
if (!paramInfo.isSkipPrevKeyDone() && isNotBlank(seekKey)) {
11921193
skipPrevKey = true;
1193-
Table.KeyValue<String, KeyEntityInfoProtoWrapper> seekKeyValue =
1194+
Table.KeyValue<String, ReconBasicOmKeyInfo> seekKeyValue =
11941195
keyIter.seek(seekKey);
11951196

11961197
// check if RocksDB was able to seek correctly to the given key prefix
@@ -1207,7 +1208,7 @@ private void retrieveKeysFromTable(
12071208
StringBuilder keyPrefix = null;
12081209
int keyPrefixLength = 0;
12091210
while (keyIter.hasNext()) {
1210-
Table.KeyValue<String, KeyEntityInfoProtoWrapper> entry = keyIter.next();
1211+
Table.KeyValue<String, ReconBasicOmKeyInfo> entry = keyIter.next();
12111212
String dbKey = entry.getKey();
12121213
if (!dbKey.startsWith(paramInfo.getStartPrefix())) {
12131214
break; // Exit the loop if the key no longer matches the prefix
@@ -1217,7 +1218,7 @@ private void retrieveKeysFromTable(
12171218
continue;
12181219
}
12191220
if (applyFilters(entry, paramInfo)) {
1220-
KeyEntityInfoProtoWrapper keyEntityInfo = entry.getValue();
1221+
ReconBasicOmKeyInfo keyEntityInfo = entry.getValue();
12211222
keyEntityInfo.setKey(dbKey);
12221223
if (keyEntityInfo.getParentId() == 0) {
12231224
// Legacy bucket keys have a parentID of zero. OBS bucket keys have a parentID of the bucketID.
@@ -1258,7 +1259,7 @@ private void retrieveKeysFromTable(
12581259
}
12591260
}
12601261

1261-
private boolean applyFilters(Table.KeyValue<String, KeyEntityInfoProtoWrapper> entry, ParamInfo paramInfo)
1262+
private boolean applyFilters(Table.KeyValue<String, ReconBasicOmKeyInfo> entry, ParamInfo paramInfo)
12621263
throws IOException {
12631264

12641265
LOG.debug("Applying filters on : {}", entry.getKey());

hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/KeyEntityInfoProtoWrapper.java

Lines changed: 0 additions & 144 deletions
This file was deleted.

hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/ListKeysResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ListKeysResponse {
4949

5050
/** list of keys. */
5151
@JsonProperty("keys")
52-
private List<KeyEntityInfoProtoWrapper> keys;
52+
private List<ReconBasicOmKeyInfo> keys;
5353

5454
public ListKeysResponse() {
5555
this.status = ResponseStatus.OK;
@@ -92,11 +92,11 @@ public void setPath(String path) {
9292
this.path = path;
9393
}
9494

95-
public List<KeyEntityInfoProtoWrapper> getKeys() {
95+
public List<ReconBasicOmKeyInfo> getKeys() {
9696
return keys;
9797
}
9898

99-
public void setKeys(List<KeyEntityInfoProtoWrapper> keys) {
99+
public void setKeys(List<ReconBasicOmKeyInfo> keys) {
100100
this.keys = keys;
101101
}
102102

0 commit comments

Comments
 (0)