sadanand48 commented on code in PR #3942:
URL: https://github.com/apache/ozone/pull/3942#discussion_r1018250043


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -0,0 +1,235 @@
+/*
+ * 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.snapshot;
+
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OmSnapshot;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.snapshot.SnapshotDiffReport.DiffType;
+import org.apache.hadoop.ozone.om.snapshot.SnapshotDiffReport.DiffReportEntry;
+
+import org.apache.ozone.rocksdb.util.ManagedSstFileReader;
+import org.apache.ozone.rocksdb.util.RdbUtil;
+import org.rocksdb.RocksDBException;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+
+/**
+ * Class to generate snapshot diff.
+ */
+public class SnapshotDiffManager {
+
+  public SnapshotDiffReport getSnapshotDiffReport(final String volume,
+                                                  final String bucket,
+                                                  final OmSnapshot 
fromSnapshot,
+                                                  final OmSnapshot toSnapshot)
+      throws IOException, RocksDBException {
+
+    // TODO: Once RocksDBCheckpointDiffer exposes method to get list
+    //  of delta SST files, plug it in here.
+
+    Set<String> fromSnapshotFiles = RdbUtil.getKeyTableSSTFiles(fromSnapshot
+        .getMetadataManager().getStore().getDbLocation().getPath());
+    Set<String> toSnapshotFiles = RdbUtil.getKeyTableSSTFiles(toSnapshot
+        .getMetadataManager().getStore().getDbLocation().getPath());
+
+    final Set<String> deltaFiles = new HashSet<>();

Review Comment:
   The sst files to be checked here need to be obtained from 
RocksDBCheckpointDiffer#getSSTDiffList . although we could keep this code path 
as fallback for cases where there is no DAG /compaction log optimisation



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java:
##########
@@ -217,4 +224,40 @@ public static boolean isSnapshotKey(String[] keyParts) {
     return (keyParts.length > 1) &&
         (keyParts[0].compareTo(OM_SNAPSHOT_INDICATOR) == 0);
   }
+
+  public SnapshotDiffReport getSnapshotDiffReport(final String volume,
+                                                  final String bucket,
+                                                  final String fromSnapshot,
+                                                  final String toSnapshot)
+      throws IOException {
+    // Validate fromSnapshot and toSnapshot
+    final SnapshotInfo fsInfo = getSnapshotInfo(volume, bucket, fromSnapshot);
+    final SnapshotInfo tsInfo = getSnapshotInfo(volume, bucket, toSnapshot);
+    verifySnapshotInfoForSnapDiff(fsInfo, tsInfo);

Review Comment:
   We need to assert that the from and to snapshots are from same volume/bucket.



##########
hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdb/util/RdbUtil.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.ozone.rocksdb.util;
+
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.DBOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Temporary class to test snapshot diff functionality.
+ * This should be removed later.
+ */
+public final class RdbUtil {
+
+  private RdbUtil() { }
+
+  public static Set<String> getKeyTableSSTFiles(final String dbLocation)
+      throws RocksDBException {
+    final List<ColumnFamilyHandle> columnFamilyHandles  = new ArrayList<>();
+    final List<ColumnFamilyDescriptor> cfd = new ArrayList<>();
+    cfd.add(
+        new ColumnFamilyDescriptor(
+            "keyTable".getBytes(StandardCharsets.UTF_8)));

Review Comment:
   also need to consider file and directory tables.



-- 
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]

Reply via email to