-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-4315. Use Epoch to generate unique ObjectIDs #1480
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| package org.apache.hadoop.ozone; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.protobuf.ServiceException; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
@@ -76,6 +78,18 @@ public final class OmUtils { | |
| private static final SecureRandom SRAND = new SecureRandom(); | ||
| private static byte[] randomBytes = new byte[32]; | ||
|
|
||
| private static final long TRANSACTION_ID_SHIFT = 8; | ||
| // from the 64 bits of ObjectID (long variable), 2 bits are reserved for | ||
| // epoch and 8 bits for recursive directory creation, if required. This | ||
| // leaves 54 bits for the transaction ID. Also, the last transaction ID is | ||
| // reserved for creating S3G volume on OM start {@link | ||
| // OzoneManager#addS3GVolumeToDB()}. | ||
| public static final long EPOCH_ID_SHIFT = 62; // 64 - 2 | ||
| public static final long REVERSE_EPOCH_ID_SHIFT = 2; // 64 - EPOCH_ID_SHIFT | ||
| public static final long MAX_TRXN_ID = (long) ((1 << 54) - 2); | ||
| public static final int EPOCH_WHEN_RATIS_NOT_ENABLED = 1; | ||
| public static final int EPOCH_WHEN_RATIS_ENABLED = 2; | ||
|
|
||
| private OmUtils() { | ||
| } | ||
|
|
||
|
|
@@ -360,8 +374,6 @@ public static Collection<String> emptyAsSingletonNull(Collection<String> | |
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * If a OM conf is only set with key suffixed with OM Node ID, return the | ||
| * set value. | ||
|
|
@@ -524,6 +536,49 @@ public static OmKeyInfo prepareKeyForRecover(OmKeyInfo keyInfo, | |
| } | ||
| } | ||
|
|
||
| public static int getOMEpoch(boolean isRatisEnabled) { | ||
| return isRatisEnabled ? EPOCH_WHEN_RATIS_ENABLED : | ||
| EPOCH_WHEN_RATIS_NOT_ENABLED; | ||
| } | ||
|
|
||
| /** | ||
| * Get the valid base object id given the transaction id. | ||
| * @param epoch a 2 bit epoch number. The 2 most significant bits of the | ||
| * object will be set to this epoch. | ||
| * @param txId of the transaction. This value cannot exceed 2^54 - 1 as | ||
| * out of the 64 bits for a long, 2 are reserved for the epoch | ||
| * and 8 for recursive directory creation. | ||
| * @return base object id allocated against the transaction | ||
| */ | ||
| public static long getObjectIdFromTxId(long epoch, long txId) { | ||
| Preconditions.checkArgument(txId <= MAX_TRXN_ID, "TransactionID " + | ||
| "exceeds max limit of " + MAX_TRXN_ID); | ||
|
||
| return addEpochToTxId(epoch, txId); | ||
| } | ||
|
|
||
| /** | ||
| * Note - This function should not be called directly. It is directly called | ||
| * only from OzoneManager#addS3GVolumeToDB() which is a one time operation | ||
| * when OM is started first time to add S3G volume. In call other cases, | ||
| * getObjectIdFromTxId() should be called to append epoch to objectID. | ||
| */ | ||
| public static long addEpochToTxId(long epoch, long txId) { | ||
| long lsb54 = txId << TRANSACTION_ID_SHIFT; | ||
| long msb2 = epoch << EPOCH_ID_SHIFT; | ||
|
|
||
| return msb2 | lsb54; | ||
| } | ||
|
|
||
| /** | ||
| * Given an objectId, unset the 2 most significant bits to get the | ||
| * corresponding transaction index. | ||
| */ | ||
| @VisibleForTesting | ||
| public static long getTxIdFromObjectId(long objectId) { | ||
| return ((Long.MAX_VALUE >> REVERSE_EPOCH_ID_SHIFT) & objectId) | ||
| >> TRANSACTION_ID_SHIFT; | ||
| } | ||
|
|
||
| /** | ||
| * Verify key name is a valid name. | ||
| */ | ||
|
|
||
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
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
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.
Don't we want these values to be 0 and 1 instead of 1 & 2 ?
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.
Wanted to avoid 0 as we can assume that currently it is 0. This would give us a way to separate out objectIds created before this fix. If ever, these non-unique objectIds need to be fixed, it would be easy to identify them.