Skip to content

HDDS-14037. Create DBDefinition and corresponding MetadataManager for SnapshotDiff DB#9398

Merged
swamirishi merged 3 commits intoapache:masterfrom
swamirishi:HDDS-14037
Dec 12, 2025
Merged

HDDS-14037. Create DBDefinition and corresponding MetadataManager for SnapshotDiff DB#9398
swamirishi merged 3 commits intoapache:masterfrom
swamirishi:HDDS-14037

Conversation

@swamirishi
Copy link
Contributor

What changes were proposed in this pull request?

Create DBDefinition and corresponding MetadataManager for SnapshotDiff DB

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-14037

How was this patch tested?

Just refactoring no additional unit tests required

… SnapshotDiff DB

Change-Id: I30eb4fe01cd73fcf8113b2896e6eaff4b77eeb26
@swamirishi swamirishi added the snapshot https://issues.apache.org/jira/browse/HDDS-6517 label Nov 30, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should be in hadoop-ozone/interface-storage (or -client, if it's needed for client/server communication), not in hadoop-hdds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need this for client server communication

Copy link
Contributor

Choose a reason for hiding this comment

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

Then move to hadoop-ozone/interface-storage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the snapshot diff database management by creating dedicated DBDefinition and MetadataManager classes for the SnapshotDiff DB. The refactoring extracts table definitions and constants previously scattered across OmSnapshotManager and consolidates them into a new SnapshotDiffDBDefinition class, along with a corresponding SnapshotDiffMetadataManager interface and implementation for better separation of concerns.

  • Introduces SnapshotDiffDBDefinition with all table definitions and column family definitions for snapshot diff operations
  • Creates SnapshotDiffMetadataManager interface and SnapshotDiffMetadataManagerImpl for managing snapshot diff metadata with version control
  • Adds SnapshotDiffObjectInfo helper class with protobuf serialization support
  • Updates existing classes to reference the new centralized definitions

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
hadoop-hdds/interface-server/src/main/proto/OmServerProtocol.proto New protobuf definition for SnapDiffObjectInfo message used in snapshot diff serialization
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/db/package-info.java Package documentation for snapshot diff DB management classes
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/db/SnapshotDiffDBDefinition.java Defines schema and table definitions for snapshot diff database with 6 tables (jobs, reports, purged jobs, from/to snapshot objects, unique IDs)
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/db/SnapshotDiffMetadataManager.java Interface providing access methods for all snapshot diff metadata tables
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/db/SnapshotDiffMetadataManagerImpl.java Implementation of metadata manager with DB initialization, version management, and table access
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/helper/package-info.java Package documentation for snapshot diff helper classes
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/helper/SnapshotDiffObjectInfo.java Helper class representing object information in snapshot diffs with protobuf codec support
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java Updated to use centralized table name constants from SnapshotDiffDBDefinition instead of local definitions
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java Updated to reference table name constants from SnapshotDiffDBDefinition for column family creation
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java Updated test imports to use new SnapshotDiffDBDefinition constants

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1081 to +1082
Arrays.asList(DEFAULT_COLUMN_FAMILY_NAME, SnapshotDiffDBDefinition.SNAP_DIFF_JOB_TABLE_NAME,
SnapshotDiffDBDefinition.SNAP_DIFF_REPORT_TABLE_NAME, SNAP_DIFF_PURGED_JOB_TABLE_NAME));
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.
option java_outer_classname = "OmServerProtocolProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
package hadoop.hdds.block;
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 proto package hadoop.hdds.block seems inconsistent with the file name OmServerProtocol.proto and the comment "// OM Server protocol". Since this is related to OM (Ozone Manager) server protocol, consider using a more appropriate package name like hadoop.hdds.om or hadoop.hdds.ozone.om instead of hadoop.hdds.block.

Suggested change
package hadoop.hdds.block;
package hadoop.hdds.om;

Copilot uses AI. Check for mistakes.
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.
this.objectId = objectId;
this.key = key;
}

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 SnapshotDiffObjectInfo class is missing getter methods for its fields (objectId and key). While the class currently only needs to support serialization/deserialization, adding getters would make it more useful when the stored data needs to be read and used by other code.

Suggested change
/**
* Returns the object ID.
*/
public long getObjectId() {
return objectId;
}
/**
* Returns the key name.
*/
public String getKey() {
return key;
}

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +83
if (!versionContentMatches) {
writeVersionFileContent(versionFilePath);
}
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 version file is written after the database is created. If writeVersionFileContent() fails (line 82), the database will exist without a proper version file. On the next startup, this will cause the database to be deleted (line 102). Consider writing the version file before creating the database or immediately after in a try-catch block with rollback logic to ensure consistency.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

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

snapDiffJobTable looks backward compatible.
snapDiffReportTable however, the serialization mapping was updated from byte[], byte[] to string, DiffReportEntry.

@swamirishi
Copy link
Contributor Author

snapDiffJobTable looks backward compatible. snapDiffReportTable however, the serialization mapping was updated from byte[], byte[] to string, DiffReportEntry.

We don't need the db to be ever backward compatible. This is an ephemeral db we would delete it if the version in the version file and code doesn't match and recreate it

Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

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

Ok this looks more like a refactoring, not really adding new changes.
SnapshotDiffMetadataManagerImpl: I assume you'll be adding test code around it later?

Apart from Attila's suggest it looks good to me.

@swamirishi
Copy link
Contributor Author

SnapshotDiffMetadataManagerImpl: I assume you'll be adding test code around it later?

I don't think we need test as it is just wrapper interface on DBStore but I can add something later

Change-Id: I385d44a6390218b8ff67b9cbdc5908222118ad78
Change-Id: I0db942ce8c1fad1ad621221ecf1ad8b2cf2224a5
@swamirishi swamirishi marked this pull request as ready for review December 12, 2025 07:59
@swamirishi swamirishi merged commit 89df7ed into apache:master Dec 12, 2025
55 checks passed
@swamirishi
Copy link
Contributor Author

thanks for the review @jojochuang and @adoroszlai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot https://issues.apache.org/jira/browse/HDDS-6517

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants