HDDS-14037. Create DBDefinition and corresponding MetadataManager for SnapshotDiff DB#9398
Conversation
… SnapshotDiff DB Change-Id: I30eb4fe01cd73fcf8113b2896e6eaff4b77eeb26
00f0e79 to
a7fea98
Compare
There was a problem hiding this comment.
This file should be in hadoop-ozone/interface-storage (or -client, if it's needed for client/server communication), not in hadoop-hdds.
There was a problem hiding this comment.
We don't need this for client server communication
There was a problem hiding this comment.
Then move to hadoop-ozone/interface-storage.
There was a problem hiding this comment.
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
SnapshotDiffDBDefinitionwith all table definitions and column family definitions for snapshot diff operations - Creates
SnapshotDiffMetadataManagerinterface andSnapshotDiffMetadataManagerImplfor managing snapshot diff metadata with version control - Adds
SnapshotDiffObjectInfohelper 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.
| Arrays.asList(DEFAULT_COLUMN_FAMILY_NAME, SnapshotDiffDBDefinition.SNAP_DIFF_JOB_TABLE_NAME, | ||
| SnapshotDiffDBDefinition.SNAP_DIFF_REPORT_TABLE_NAME, SNAP_DIFF_PURGED_JOB_TABLE_NAME)); |
There was a problem hiding this comment.
[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.
| option java_outer_classname = "OmServerProtocolProtos"; | ||
| option java_generic_services = true; | ||
| option java_generate_equals_and_hash = true; | ||
| package hadoop.hdds.block; |
There was a problem hiding this comment.
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.
| package hadoop.hdds.block; | |
| package hadoop.hdds.om; |
| SnapshotDiffObjectInfo.getCodec()); | ||
|
|
||
| /** | ||
| * Contains all the snap diff job intermediate object output for to snapshot. |
There was a problem hiding this comment.
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.").
| * 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. |
| this.objectId = objectId; | ||
| this.key = key; | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
| /** | |
| * Returns the object ID. | |
| */ | |
| public long getObjectId() { | |
| return objectId; | |
| } | |
| /** | |
| * Returns the key name. | |
| */ | |
| public String getKey() { | |
| return key; | |
| } |
| if (!versionContentMatches) { | ||
| writeVersionFileContent(versionFilePath); | ||
| } |
There was a problem hiding this comment.
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.
jojochuang
left a comment
There was a problem hiding this comment.
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 |
jojochuang
left a comment
There was a problem hiding this comment.
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.
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
|
thanks for the review @jojochuang and @adoroszlai |
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