Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ message FileSizeCountKeyProto {
required string volume = 1;
required string bucket = 2;
required int64 fileSizeUpperBound = 3;
}

message SnapDiffObjectInfo {
optional uint64 objectID = 1;
optional string keyName = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import static org.apache.hadoop.ozone.om.snapshot.SnapshotDiffManager.getSnapshotRootPath;
import static org.apache.hadoop.ozone.om.snapshot.SnapshotUtils.checkSnapshotActive;
import static org.apache.hadoop.ozone.om.snapshot.SnapshotUtils.dropColumnFamilyHandle;
import static org.apache.hadoop.ozone.om.snapshot.db.SnapshotDiffDBDefinition.SNAP_DIFF_PURGED_JOB_TABLE_NAME;
import static org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus.DONE;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -103,6 +104,7 @@
import org.apache.hadoop.ozone.om.snapshot.SnapshotCache;
import org.apache.hadoop.ozone.om.snapshot.SnapshotDiffManager;
import org.apache.hadoop.ozone.om.snapshot.SnapshotUtils;
import org.apache.hadoop.ozone.om.snapshot.db.SnapshotDiffDBDefinition;
import org.apache.hadoop.ozone.snapshot.CancelSnapshotDiffResponse;
import org.apache.hadoop.ozone.snapshot.ListSnapshotDiffJobResponse;
import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
Expand Down Expand Up @@ -132,43 +134,6 @@ public final class OmSnapshotManager implements AutoCloseable {

public static final String DELIMITER = "-";

/**
* Contains all the snap diff job which are either queued, in_progress or
* done. This table is used to make sure that there is only single job for
* requests with the same snapshot pair at any point of time.
* |------------------------------------------------|
* | KEY | VALUE |
* |------------------------------------------------|
* | fromSnapshotId-toSnapshotId | SnapshotDiffJob |
* |------------------------------------------------|
*/
public static final String SNAP_DIFF_JOB_TABLE_NAME =
"snap-diff-job-table";

/**
* Global table to keep the diff report. Each key is prefixed by the jobId
* to improve look up and clean up. JobId comes from snap-diff-job-table.
* |--------------------------------|
* | KEY | VALUE |
* |--------------------------------|
* | jobId-index | DiffReportEntry |
* |--------------------------------|
*/
public static final String SNAP_DIFF_REPORT_TABLE_NAME =
"snap-diff-report-table";

/**
* Contains all the snap diff job which can be purged either due to max
* allowed time is over, FAILED or REJECTED.
* |-------------------------------------------|
* | KEY | VALUE |
* |-------------------------------------------|
* | jobId | numOfTotalEntriesInReportTable |
* |-------------------------------------------|
*/
private static final String SNAP_DIFF_PURGED_JOB_TABLE_NAME =
"snap-diff-purged-job-table";

/**
* For snapshot compaction we need to capture SST files following column
* families before compaction.
Expand Down Expand Up @@ -248,9 +213,9 @@ public OmSnapshotManager(OzoneManager ozoneManager) throws IOException {
this.snapshotDiffDb = createRocksDbForSnapshotDiff(options,
dbPath, columnFamilyDescriptors, columnFamilyHandles);

snapDiffJobCf = getOrCreateColumnFamily(SNAP_DIFF_JOB_TABLE_NAME,
snapDiffJobCf = getOrCreateColumnFamily(SnapshotDiffDBDefinition.SNAP_DIFF_JOB_TABLE_NAME,
columnFamilyDescriptors, columnFamilyHandles);
snapDiffReportCf = getOrCreateColumnFamily(SNAP_DIFF_REPORT_TABLE_NAME,
snapDiffReportCf = getOrCreateColumnFamily(SnapshotDiffDBDefinition.SNAP_DIFF_REPORT_TABLE_NAME,
columnFamilyDescriptors, columnFamilyHandles);
snapDiffPurgedJobCf = getOrCreateColumnFamily(
SNAP_DIFF_PURGED_JOB_TABLE_NAME, columnFamilyDescriptors,
Expand Down Expand Up @@ -1090,8 +1055,8 @@ private void dropUnknownColumnFamilies(
List<ColumnFamilyHandle> familyHandles
) {
Set<String> allowedColumnFamilyOnStartUp = new HashSet<>(
Arrays.asList(DEFAULT_COLUMN_FAMILY_NAME, SNAP_DIFF_JOB_TABLE_NAME,
SNAP_DIFF_REPORT_TABLE_NAME, SNAP_DIFF_PURGED_JOB_TABLE_NAME));
Arrays.asList(DEFAULT_COLUMN_FAMILY_NAME, SnapshotDiffDBDefinition.SNAP_DIFF_JOB_TABLE_NAME,
SnapshotDiffDBDefinition.SNAP_DIFF_REPORT_TABLE_NAME, SNAP_DIFF_PURGED_JOB_TABLE_NAME));
Comment on lines +1058 to +1059
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent constant usage: SNAP_DIFF_PURGED_JOB_TABLE_NAME is statically imported (line 56), while SNAP_DIFF_JOB_TABLE_NAME and SNAP_DIFF_REPORT_TABLE_NAME are referenced with the class prefix SnapshotDiffDBDefinition. For consistency, either statically import all three table name constants or use the class prefix for all of them.

Copilot uses AI. Check for mistakes.

try {
for (ColumnFamilyHandle columnFamilyHandle : familyHandles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.helpers.WithObjectID;
import org.apache.hadoop.ozone.om.helpers.WithParentObjectId;
import org.apache.hadoop.ozone.om.snapshot.db.SnapshotDiffDBDefinition;
import org.apache.hadoop.ozone.om.snapshot.diff.delta.CompositeDeltaDiffComputer;
import org.apache.hadoop.ozone.om.snapshot.diff.delta.DeltaFileComputer;
import org.apache.hadoop.ozone.om.snapshot.util.TableMergeIterator;
Expand All @@ -141,11 +142,7 @@
* Class to generate snapshot diff.
*/
public class SnapshotDiffManager implements AutoCloseable {
private static final Logger LOG =
LoggerFactory.getLogger(SnapshotDiffManager.class);
private static final String FROM_SNAP_TABLE_SUFFIX = "-from-snap";
private static final String TO_SNAP_TABLE_SUFFIX = "-to-snap";
private static final String UNIQUE_IDS_TABLE_SUFFIX = "-unique-ids";
private static final Logger LOG = LoggerFactory.getLogger(SnapshotDiffManager.class);
private static final String DELETE_DIFF_TABLE_SUFFIX = "-delete-diff";
private static final String RENAME_DIFF_TABLE_SUFFIX = "-rename-diff";
private static final String CREATE_DIFF_TABLE_SUFFIX = "-create-diff";
Expand Down Expand Up @@ -816,11 +813,11 @@ void generateSnapshotDiffReport(final String jobKey,
// JobId is prepended to column families name to make them unique
// for request.
fromSnapshotColumnFamily =
createColumnFamily(jobId + FROM_SNAP_TABLE_SUFFIX);
createColumnFamily(jobId + SnapshotDiffDBDefinition.SNAP_DIFF_FROM_SNAP_OBJECT_TABLE_NAME);
toSnapshotColumnFamily =
createColumnFamily(jobId + TO_SNAP_TABLE_SUFFIX);
createColumnFamily(jobId + SnapshotDiffDBDefinition.SNAP_DIFF_TO_SNAP_OBJECT_TABLE_NAME);
objectIDsColumnFamily =
createColumnFamily(jobId + UNIQUE_IDS_TABLE_SUFFIX);
createColumnFamily(jobId + SnapshotDiffDBDefinition.SNAP_DIFF_UNIQUE_IDS_TABLE_NAME);

// ObjectId to keyName map to keep key info for fromSnapshot.
// objectIdToKeyNameMap is used to identify what keys were touched
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.db;

import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_DIFF_DB_NAME;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DIFF_DB_DIR;
import static org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone.getDiffReportEntryCodec;

import java.util.Map;
import org.apache.hadoop.hdds.utils.db.BooleanCodec;
import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition;
import org.apache.hadoop.hdds.utils.db.DBDefinition;
import org.apache.hadoop.hdds.utils.db.LongCodec;
import org.apache.hadoop.hdds.utils.db.StringCodec;
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry;
import org.apache.hadoop.ozone.om.helpers.SnapshotDiffJob;
import org.apache.hadoop.ozone.om.snapshot.diff.helper.SnapshotDiffObjectInfo;

/**
* The SnapshotDiffDBDefinition class defines the schema for the snapshot
* difference database tables used in snapshot diff operations. Each table
* corresponds to a specific aspect of snapshot diff job processing and data
* storage, ensuring proper organization and efficient access.
*/
public final class SnapshotDiffDBDefinition extends DBDefinition.WithMap {
/**
* Contains all the snap diff job which are either queued, in_progress or
* done. This table is used to make sure that there is only single job for
* requests with the same snapshot pair at any point of time.
* |------------------------------------------------|
* | KEY | VALUE |
* |------------------------------------------------|
* | fromSnapshotId-toSnapshotId | SnapshotDiffJob |
* |------------------------------------------------|
*/
public static final String SNAP_DIFF_JOB_TABLE_NAME = "snap-diff-job-table";

public static final DBColumnFamilyDefinition<String, SnapshotDiffJob> SNAP_DIFF_JOB_TABLE_DEF
= new DBColumnFamilyDefinition<>(SNAP_DIFF_JOB_TABLE_NAME, StringCodec.get(), SnapshotDiffJob.getCodec());
/**
* Global table to keep the diff report. Each key is prefixed by the jobId
* to improve look up and clean up. JobId comes from snap-diff-job-table.
* |--------------------------------|
* | KEY | VALUE |
* |--------------------------------|
* | jobId-index | DiffReportEntry |
* |--------------------------------|
*/
public static final String SNAP_DIFF_REPORT_TABLE_NAME = "snap-diff-report-table";
public static final DBColumnFamilyDefinition<String, DiffReportEntry> SNAP_DIFF_REPORT_TABLE_NAME_DEF
= new DBColumnFamilyDefinition<>(SNAP_DIFF_REPORT_TABLE_NAME, StringCodec.get(), getDiffReportEntryCodec());
/**
* Contains all the snap diff job which can be purged either due to max
* allowed time is over, FAILED or REJECTED.
* |-------------------------------------------|
* | KEY | VALUE |
* |-------------------------------------------|
* | jobId | numOfTotalEntriesInReportTable |
* |-------------------------------------------|
*/
public static final String SNAP_DIFF_PURGED_JOB_TABLE_NAME = "snap-diff-purged-job-table";
public static final DBColumnFamilyDefinition<String, Long> SNAP_DIFF_PURGED_JOB_TABLE_DEF
= new DBColumnFamilyDefinition<>(SNAP_DIFF_PURGED_JOB_TABLE_NAME, StringCodec.get(), LongCodec.get());
/**
* Contains all the snap diff job intermediate object output for from snapshot.
* |----------------------------------------------------|
* | KEY | VALUE |
* |----------------------------------------------------|
* | jobId-objectId | SnapshotDiffObjectInfo |
* |----------------------------------------------------|
*/
public static final String SNAP_DIFF_FROM_SNAP_OBJECT_TABLE_NAME = "-from-snap";
public static final DBColumnFamilyDefinition<String, SnapshotDiffObjectInfo> SNAP_DIFF_FROM_SNAP_OBJECT_TABLE_DEF
= new DBColumnFamilyDefinition<>(SNAP_DIFF_FROM_SNAP_OBJECT_TABLE_NAME, StringCodec.get(),
SnapshotDiffObjectInfo.getCodec());

/**
* Contains all the snap diff job intermediate object output for to snapshot.
* |----------------------------------------------------|
* | KEY | VALUE |
* |----------------------------------------------------|
* | jobId-objectId | SnapshotDiffObjectInfo |
* |----------------------------------------------------|
*/
public static final String SNAP_DIFF_TO_SNAP_OBJECT_TABLE_NAME = "-to-snap";
public static final DBColumnFamilyDefinition<String, SnapshotDiffObjectInfo> SNAP_DIFF_TO_SNAP_OBJECT_TABLE_DEF
= new DBColumnFamilyDefinition<>(SNAP_DIFF_TO_SNAP_OBJECT_TABLE_NAME, StringCodec.get(),
SnapshotDiffObjectInfo.getCodec());

/**
* Contains all the snap diff job intermediate object output for to snapshot.
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comment incorrectly states "Contains all the snap diff job intermediate object output for to snapshot." This should describe what the unique IDs table actually stores (e.g., "Contains unique object IDs encountered during snapshot diff job processing.").

Suggested change
* Contains all the snap diff job intermediate object output for to snapshot.
* Contains unique object IDs encountered during snapshot diff job processing.
* Each entry maps a jobId-objectId pair to a boolean indicating whether the
* object ID is unique for the given job.

Copilot uses AI. Check for mistakes.
* |----------------------------------------------------|
* | KEY | VALUE |
* |----------------------------------------------------|
* | jobId-objectId | boolean |
* |----------------------------------------------------|
*/
public static final String SNAP_DIFF_UNIQUE_IDS_TABLE_NAME = "-unique-ids";
public static final DBColumnFamilyDefinition<String, Boolean> SNAP_DIFF_UNIQUE_IDS_TABLE_DEF
= new DBColumnFamilyDefinition<>(SNAP_DIFF_UNIQUE_IDS_TABLE_NAME, StringCodec.get(), BooleanCodec.get());

//---------------------------------------------------------------------------//
private static final Map<String, DBColumnFamilyDefinition<?, ?>> COLUMN_FAMILIES =
DBColumnFamilyDefinition.newUnmodifiableMap(SNAP_DIFF_JOB_TABLE_DEF,
SNAP_DIFF_REPORT_TABLE_NAME_DEF,
SNAP_DIFF_PURGED_JOB_TABLE_DEF,
SNAP_DIFF_FROM_SNAP_OBJECT_TABLE_DEF,
SNAP_DIFF_TO_SNAP_OBJECT_TABLE_DEF,
SNAP_DIFF_UNIQUE_IDS_TABLE_DEF);

private static final SnapshotDiffDBDefinition INSTANCE = new SnapshotDiffDBDefinition();

public static SnapshotDiffDBDefinition get() {
return INSTANCE;
}

private SnapshotDiffDBDefinition() {
super(COLUMN_FAMILIES);
}

@Override
public String getName() {
return OM_SNAPSHOT_DIFF_DB_NAME;
}

@Override
public String getLocationConfigKey() {
return OZONE_OM_SNAPSHOT_DIFF_DB_DIR;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.db;

import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry;
import org.apache.hadoop.ozone.om.helpers.SnapshotDiffJob;
import org.apache.hadoop.ozone.om.snapshot.diff.helper.SnapshotDiffObjectInfo;

/**
* Interface representing the metadata manager for snapshot difference operations.
* This interface provides methods to access various tables storing metadata
* related to snapshot diff jobs, diff reports, purged jobs, and object information
* for snapshots.
*
* Implementations of this interface should handle the setup, maintenance, and
* querying of the relevant metadata tables.
*
* The interface extends {@link AutoCloseable}, requiring implementations to
* handle proper resource cleanup.
*/
public interface SnapshotDiffMetadataManager extends AutoCloseable {

Table<String, SnapshotDiffJob> getSnapshotDiffJobTable();

Table<String, DiffReportEntry> getSnapshotDiffReportTable();

Table<String, Long> getSnapshotDiffPurgedJobTable();

Table<String, SnapshotDiffObjectInfo> getSnapshotDiffFromSnapshotObjectInfoTable();

Table<String, SnapshotDiffObjectInfo> getSnapshotDiffToSnapshotObjectInfoTable();

Table<String, Boolean> getSnapshotDiffUniqueObjectIdsTable();

}
Loading