hemantk-12 commented on code in PR #5301:
URL: https://github.com/apache/ozone/pull/5301#discussion_r1338977264
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -88,6 +94,9 @@ public class KeyDeletingService extends
AbstractKeyDeletingService {
private final int keyLimitPerTask;
private final AtomicLong deletedKeyCount;
private final AtomicBoolean suspended;
+ private final Map<String, Long> exclusiveSizeMap;
+ private final Map<String, Long> exclusiveReplicatedSizeMap;
+ private final Set<String> completedExclusiveSizeMap;
Review Comment:
nit: keep it as a set or a list.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -309,6 +348,47 @@ private void processSnapshotDeepClean(int delCount)
RepeatedOmKeyInfo newRepeatedOmKeyInfo =
new RepeatedOmKeyInfo();
for (OmKeyInfo keyInfo : repeatedOmKeyInfo.getOmKeyInfoList())
{
+ // To calculate Exclusive Size for current snapshot, Check
+ // the next snapshot deletedTable if the deleted key is
+ // referenced in current snapshot and not referenced in the
+ // previous snapshot then that key is exclusive to the
current
+ // snapshot. Here since we are only iterating through
+ // deletedTable we can check the previous and previous to
Review Comment:
May be:
```suggestion
// deletedTable we can check the previous and previous to
// previous snapshot to achieve the same.
// previousSnapshot - Snapshot for which exclusive size is
// getting calculating.
// currSnapshot - Snapshot's deletedTable is used to
calculate
// previousSnapshot snapshot's exclusive
size.
// previousToPrevSnapshot - Snapshot which is used to check
// if key is exclusive to previousSnapshot.
```
optional: you can also attach the design doc link for reference.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -348,14 +436,85 @@ private void processSnapshotDeepClean(int delCount)
if (previousSnapshot != null) {
rcPrevOmSnapshot.close();
}
+ if (previousToPrevSnapshot != null) {
+ rcPrevToPrevOmSnapshot.close();
+ }
}
}
}
}
+
+ updateSnapshotExclusiveSize();
updateDeepCleanedSnapshots(deepCleanedSnapshots);
}
+ private OmKeyInfo getPreviousSnapshotKeyName(
+ OmKeyInfo keyInfo, OmBucketInfo bucketInfo, long volumeId,
+ Table<String, String> snapRenamedTable,
+ Table<String, OmKeyInfo> previousKeyTable) throws IOException {
+
+ if (keyInfo == null) {
+ return null;
+ }
+
+ String dbKeyPrevSnap;
+ if (bucketInfo.getBucketLayout().isFileSystemOptimized()) {
+ dbKeyPrevSnap = getOzoneManager().getMetadataManager().getOzonePathKey(
+ volumeId,
+ bucketInfo.getObjectID(),
+ keyInfo.getParentObjectID(),
+ keyInfo.getFileName());
+ } else {
+ dbKeyPrevSnap = getOzoneManager().getMetadataManager().getOzoneKey(
+ keyInfo.getVolumeName(),
+ keyInfo.getBucketName(),
+ keyInfo.getKeyName());
+ }
+
+ String dbRenameKey = getOzoneManager().getMetadataManager().getRenameKey(
+ keyInfo.getVolumeName(),
+ keyInfo.getBucketName(),
+ keyInfo.getObjectID());
+
+ String renamedKey = snapRenamedTable.getIfExist(dbRenameKey);
+ dbKeyPrevSnap = renamedKey != null ? renamedKey : dbKeyPrevSnap;
+
+ return previousKeyTable.get(dbKeyPrevSnap);
+ }
+
+ private void updateSnapshotExclusiveSize() {
+
+ List<SnapshotProperty> snapshotPropertyList = new ArrayList<>();
+ for (String dbKey: completedExclusiveSizeList) {
+ SnapshotProperty snapshotProperty = SnapshotProperty.newBuilder()
+ .setSnapshotKey(dbKey)
+ .setExclusiveSize(exclusiveSizeList.get(dbKey))
+ .setExclusiveReplicatedSize(
+ exclusiveReplicatedSizeList.get(dbKey))
+ .build();
+ snapshotPropertyList.add(snapshotProperty);
+ exclusiveSizeList.remove(dbKey);
+ exclusiveReplicatedSizeList.remove(dbKey);
+ }
+
+ if (!snapshotPropertyList.isEmpty()) {
Review Comment:
This check is not needed any more.
Could be simply this:
```
private void updateSnapshotExclusiveSize() {
if (completedExclusiveSizeMap.isEmpty()) {
return;
}
List<SnapshotProperty> snapshotPropertyList = new ArrayList<>();
for (String dbKey: completedExclusiveSizeMap) {
SnapshotProperty snapshotProperty = SnapshotProperty.newBuilder()
.setSnapshotKey(dbKey)
.setExclusiveSize(exclusiveSizeMap.get(dbKey))
.setExclusiveReplicatedSize(
exclusiveReplicatedSizeMap.get(dbKey))
.build();
snapshotPropertyList.add(snapshotProperty);
exclusiveSizeMap.remove(dbKey);
exclusiveReplicatedSizeMap.remove(dbKey);
}
SetSnapshotPropertyRequest setSnapshotPropertyRequest =
SetSnapshotPropertyRequest.newBuilder()
.addAllSnapshotProperty(snapshotPropertyList)
.build();
OMRequest omRequest = OMRequest.newBuilder()
.setCmdType(Type.SetSnapshotProperty)
.setSetSnapshotPropertyRequest(setSnapshotPropertyRequest)
.setClientId(clientId.toString())
.build();
submitRequest(omRequest);
completedExclusiveSizeMap.clear();
}
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotSetPropertyRequest.java:
##########
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.om.request.snapshot;
+
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import
org.apache.hadoop.ozone.om.response.snapshot.OMSnapshotSetPropertyResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Updates the exclusive size of the snapshot.
+ */
+public class OMSnapshotSetPropertyRequest extends OMClientRequest {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(OMSnapshotSetPropertyRequest.class);
+
+ public OMSnapshotSetPropertyRequest(OMRequest omRequest) {
+ super(omRequest);
+ }
+
+ @Override
+ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+ long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+ OMClientResponse omClientResponse = null;
+ OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+ OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+ OmResponseUtil.getOMResponseBuilder(getOmRequest());
+ OzoneManagerProtocolProtos.SetSnapshotPropertyRequest
+ setSnapshotPropertyRequest = getOmRequest()
+ .getSetSnapshotPropertyRequest();
+
+ List<SnapshotProperty> snapshotPropertyList = setSnapshotPropertyRequest
+ .getSnapshotPropertyList();
+ Map<String, SnapshotInfo> updatedSnapInfos = new HashMap<>();
+
+ try {
+ for (SnapshotProperty snapshotProperty: snapshotPropertyList) {
+ String snapshotKey = snapshotProperty.getSnapshotKey();
+ long exclusiveSize = snapshotProperty.getExclusiveSize();
+ long exclusiveReplicatedSize = snapshotProperty
+ .getExclusiveReplicatedSize();
+ SnapshotInfo snapshotInfo = metadataManager
+ .getSnapshotInfoTable().get(snapshotKey);
+
+ if (snapshotInfo == null) {
+ LOG.error("SnapshotInfo for Snapshot: {} is not found", snapshotKey);
+ continue;
Review Comment:
Since it is an "internal" API, I don't have strong argument against it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]