-
Notifications
You must be signed in to change notification settings - Fork 634
HDDS-15394. Sequential Reader of from and to snapshots for full snapshot diff. #11083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
SaketaChalamchala
wants to merge
2
commits into
apache:master
Choose a base branch
from
SaketaChalamchala:HDDS-15394
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,153
−5
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...zone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/EntryValue.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /* | ||
| * 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.diff; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Compact intermediate value stored in the {@code newList}/{@code oldList} | ||
| * column families of the optimized snapshot diff. It keeps only the fields | ||
| * required to classify a diff entry in the later merge-join stage, avoiding the | ||
| * cost of holding a full {@code OmKeyInfo}/{@code OmDirectoryInfo}. | ||
| * | ||
| * <p>The fields are: | ||
| * <ul> | ||
| * <li>{@code parentId} - parent object id (parent directory for FSO).</li> | ||
| * <li>{@code name} - leaf name for FSO buckets, full key path for OBS.</li> | ||
| * <li>{@code isDir} - whether the entry is a directory.</li> | ||
| * <li>{@code signature} - SHA-256 compare signature computed by | ||
| * {@code SnapshotDiffValueParser} over the meaningful fields.</li> | ||
| * </ul> | ||
| * | ||
| * <p>The wire layout is fixed so both the full diff and the DAG diff Stage 1 | ||
| * readers produce identical bytes: | ||
| * <pre> | ||
| * | parentId (8, big-endian) | isDir (1) | sigLen (4, big-endian) | signature | name (UTF-8, remaining) | | ||
| * </pre> | ||
| */ | ||
| public final class EntryValue { | ||
|
|
||
| private static final int PARENT_ID_BYTES = Long.BYTES; | ||
| private static final int IS_DIR_BYTES = 1; | ||
| private static final int SIG_LEN_BYTES = Integer.BYTES; | ||
| private static final int HEADER_BYTES = PARENT_ID_BYTES + IS_DIR_BYTES + SIG_LEN_BYTES; | ||
|
|
||
| private final long parentId; | ||
| private final String name; | ||
| private final boolean isDir; | ||
| private final byte[] signature; | ||
|
|
||
| public EntryValue(long parentId, String name, boolean isDir, byte[] signature) { | ||
| this.parentId = parentId; | ||
| this.name = name == null ? "" : name; | ||
| this.isDir = isDir; | ||
| this.signature = signature == null ? new byte[0] : signature; | ||
| } | ||
|
|
||
| public long getParentId() { | ||
| return parentId; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public boolean isDir() { | ||
| return isDir; | ||
| } | ||
|
|
||
| public byte[] getSignature() { | ||
| return Arrays.copyOf(signature, signature.length); | ||
| } | ||
|
|
||
| /** | ||
| * Serializes this value to its fixed byte layout. | ||
| */ | ||
| public byte[] toBytes() { | ||
| byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); | ||
| ByteBuffer buffer = ByteBuffer.allocate(HEADER_BYTES + signature.length + nameBytes.length); | ||
| buffer.putLong(parentId); | ||
| buffer.put((byte) (isDir ? 1 : 0)); | ||
| buffer.putInt(signature.length); | ||
| buffer.put(signature); | ||
| buffer.put(nameBytes); | ||
| return buffer.array(); | ||
| } | ||
|
|
||
| /** | ||
| * Deserializes a value previously produced by {@link #toBytes()}. | ||
| */ | ||
| public static EntryValue fromBytes(byte[] bytes) { | ||
| Objects.requireNonNull(bytes, "bytes must not be null"); | ||
| if (bytes.length < HEADER_BYTES) { | ||
| throw new IllegalArgumentException("EntryValue byte array too short: " + bytes.length); | ||
| } | ||
| ByteBuffer buffer = ByteBuffer.wrap(bytes); | ||
| long parentId = buffer.getLong(); | ||
| boolean isDir = buffer.get() != 0; | ||
| int sigLen = buffer.getInt(); | ||
| if (sigLen < 0 || sigLen > buffer.remaining()) { | ||
| throw new IllegalArgumentException("EntryValue has invalid signature length: " + sigLen); | ||
| } | ||
| byte[] signature = new byte[sigLen]; | ||
| buffer.get(signature); | ||
| byte[] nameBytes = new byte[buffer.remaining()]; | ||
| buffer.get(nameBytes); | ||
| String name = new String(nameBytes, StandardCharsets.UTF_8); | ||
| return new EntryValue(parentId, name, isDir, signature); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| EntryValue that = (EntryValue) o; | ||
| return parentId == that.parentId | ||
| && isDir == that.isDir | ||
| && name.equals(that.name) | ||
| && Arrays.equals(signature, that.signature); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| int result = Objects.hash(parentId, name, isDir); | ||
| result = 31 * result + Arrays.hashCode(signature); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "EntryValue{parentId=" + parentId | ||
| + ", name='" + name + '\'' | ||
| + ", isDir=" + isDir | ||
| + ", signatureLen=" + signature.length + '}'; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nore sure how this is going to be used, but a getter method should not be a O(n) operation. Either return signature object as is, or rename the method to copySignature().