Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-22622 - WALKey Extended Attributes#352
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,11 +19,13 @@ | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.NavigableMap; | ||
| import java.util.TreeMap; | ||
| import java.util.UUID; | ||
| import org.apache.hadoop.hbase.HBaseInterfaceAudience; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| @@ -116,14 +118,16 @@ public void setWriteEntry(MultiVersionConcurrencyControl.WriteEntry writeEntry) | ||
| */ | ||
| private MultiVersionConcurrencyControl.WriteEntry writeEntry; | ||
| private Map<String, byte[]> extendedAttributes; | ||
| public WALKeyImpl() { | ||
| init(null, null, 0L, HConstants.LATEST_TIMESTAMP, | ||
| new ArrayList<>(), HConstants.NO_NONCE, HConstants.NO_NONCE, null, null); | ||
| new ArrayList<>(), HConstants.NO_NONCE, HConstants.NO_NONCE, null, null, null); | ||
| } | ||
| public WALKeyImpl(final NavigableMap<byte[], Integer> replicationScope) { | ||
| init(null, null, 0L, HConstants.LATEST_TIMESTAMP, | ||
| new ArrayList<>(), HConstants.NO_NONCE, HConstants.NO_NONCE, null, replicationScope); | ||
| new ArrayList<>(), HConstants.NO_NONCE, HConstants.NO_NONCE, null, replicationScope, null); | ||
| } | ||
| @VisibleForTesting | ||
| @@ -132,7 +136,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon | ||
| List<UUID> clusterIds = new ArrayList<>(1); | ||
| clusterIds.add(clusterId); | ||
| init(encodedRegionName, tablename, logSeqNum, now, clusterIds, HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, null, null); | ||
| HConstants.NO_NONCE, null, null, null); | ||
| } | ||
| @VisibleForTesting | ||
| @@ -141,7 +145,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon | ||
| List<UUID> clusterIds = new ArrayList<>(1); | ||
| clusterIds.add(clusterId); | ||
| init(encodedRegionName, tablename, logSeqNum, now, clusterIds, HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, mvcc, null); | ||
| HConstants.NO_NONCE, mvcc, null, null); | ||
| } | ||
| // TODO: Fix being able to pass in sequenceid. | ||
| @@ -153,20 +157,28 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, fin | ||
| EMPTY_UUIDS, | ||
| HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, | ||
| null, null); | ||
| null, null, null); | ||
| } | ||
| // TODO: Fix being able to pass in sequenceid. | ||
| public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, final long now, | ||
| final NavigableMap<byte[], Integer> replicationScope) { | ||
| init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, EMPTY_UUIDS, HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, null, replicationScope); | ||
| HConstants.NO_NONCE, null, replicationScope, null); | ||
| } | ||
| public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, final long now, | ||
| MultiVersionConcurrencyControl mvcc, final NavigableMap<byte[], Integer> replicationScope) { | ||
| init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, EMPTY_UUIDS, HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, mvcc, replicationScope); | ||
| HConstants.NO_NONCE, mvcc, replicationScope, null); | ||
| } | ||
| public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, final long now, | ||
| MultiVersionConcurrencyControl mvcc, | ||
| final NavigableMap<byte[], Integer> replicationScope, | ||
| Map<String, byte[]> extendedAttributes) { | ||
| init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, EMPTY_UUIDS, HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, mvcc, replicationScope, extendedAttributes); | ||
| } | ||
| public WALKeyImpl(final byte[] encodedRegionName, | ||
| @@ -180,7 +192,7 @@ public WALKeyImpl(final byte[] encodedRegionName, | ||
| EMPTY_UUIDS, | ||
| HConstants.NO_NONCE, | ||
| HConstants.NO_NONCE, | ||
| mvcc, null); | ||
| mvcc, null, null); | ||
| } | ||
| /** | ||
| @@ -206,7 +218,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon | ||
| final long now, List<UUID> clusterIds, long nonceGroup, long nonce, | ||
| MultiVersionConcurrencyControl mvcc, final NavigableMap<byte[], Integer> replicationScope) { | ||
| init(encodedRegionName, tablename, logSeqNum, now, clusterIds, nonceGroup, nonce, mvcc, | ||
| replicationScope); | ||
| replicationScope, null); | ||
| } | ||
| /** | ||
| @@ -231,7 +243,8 @@ public WALKeyImpl(final byte[] encodedRegionName, | ||
| long nonceGroup, | ||
| long nonce, | ||
| MultiVersionConcurrencyControl mvcc) { | ||
| init(encodedRegionName, tablename, logSeqNum, now, clusterIds, nonceGroup, nonce, mvcc, null); | ||
| init(encodedRegionName, tablename, logSeqNum, now, clusterIds, nonceGroup, | ||
| nonce, mvcc, null, null); | ||
| } | ||
| /** | ||
| @@ -252,7 +265,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, | ||
| final long now, List<UUID> clusterIds, long nonceGroup, | ||
| final long nonce, final MultiVersionConcurrencyControl mvcc) { | ||
| init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, clusterIds, nonceGroup, nonce, mvcc, | ||
| null); | ||
| null, null); | ||
| } | ||
| /** | ||
| @@ -275,7 +288,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, | ||
| final long nonce, final MultiVersionConcurrencyControl mvcc, | ||
| NavigableMap<byte[], Integer> replicationScope) { | ||
| init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, clusterIds, nonceGroup, nonce, mvcc, | ||
| replicationScope); | ||
| replicationScope, null); | ||
| } | ||
| /** | ||
| @@ -304,7 +317,22 @@ public WALKeyImpl(final byte[] encodedRegionName, | ||
| EMPTY_UUIDS, | ||
| nonceGroup, | ||
| nonce, | ||
| mvcc, null); | ||
| mvcc, null, null); | ||
| } | ||
| public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, | ||
| final long now, List<UUID> clusterIds, long nonceGroup, | ||
| final long nonce, final MultiVersionConcurrencyControl mvcc, | ||
| NavigableMap<byte[], Integer> replicationScope, | ||
| Map<String, byte[]> extendedAttributes){ | ||
| init(encodedRegionName, | ||
| tablename, | ||
| NO_SEQUENCE_ID, | ||
| now, | ||
| clusterIds, | ||
| nonceGroup, | ||
| nonce, | ||
| mvcc, replicationScope, extendedAttributes); | ||
| } | ||
| @InterfaceAudience.Private | ||
| @@ -316,7 +344,8 @@ protected void init(final byte[] encodedRegionName, | ||
| long nonceGroup, | ||
| long nonce, | ||
| MultiVersionConcurrencyControl mvcc, | ||
| NavigableMap<byte[], Integer> replicationScope) { | ||
| NavigableMap<byte[], Integer> replicationScope, | ||
| Map<String, byte[]> extendedAttributes) { | ||
| this.sequenceId = logSeqNum; | ||
| this.writeTime = now; | ||
| this.clusterIds = clusterIds; | ||
| @@ -329,6 +358,7 @@ protected void init(final byte[] encodedRegionName, | ||
| setSequenceId(logSeqNum); | ||
| } | ||
| this.replicationScope = replicationScope; | ||
| this.extendedAttributes = extendedAttributes; | ||
| } | ||
| // For deserialization. DO NOT USE. See setWriteEntry below. | ||
| @@ -434,6 +464,17 @@ public UUID getOriginatingClusterId(){ | ||
| return clusterIds.isEmpty()? HConstants.DEFAULT_CLUSTER_ID: clusterIds.get(0); | ||
| } | ||
| @Override | ||
| public byte[] getExtendedAttribute(String attributeKey){ | ||
| return extendedAttributes.get(attributeKey); | ||
| } | ||
| @Override | ||
| public Map<String, byte[]> getExtendedAttributes(){ | ||
| return extendedAttributes != null ? new HashMap<String, byte[]>(extendedAttributes) : | ||
| new HashMap<String, byte[]>(); | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| return tablename + "/" + Bytes.toString(encodedRegionName) + "/" + sequenceId; | ||
| @@ -539,6 +580,14 @@ public WALProtos.WALKey.Builder getBuilder(WALCellCodec.ByteStringCompressor com | ||
| .setScopeType(ScopeType.forNumber(e.getValue()))); | ||
| } | ||
| } | ||
| if (extendedAttributes != null){ | ||
| for (Map.Entry<String, byte[]> e : extendedAttributes.entrySet()){ | ||
| WALProtos.Attribute attr = WALProtos.Attribute.newBuilder(). | ||
| setKey(e.getKey()).setValue(compressor.compress(e.getValue(), | ||
| CompressionContext.DictionaryIndex.TABLE)).build(); | ||
| builder.addExtendedAttributes(attr); | ||
| } | ||
| } | ||
| return builder; | ||
| } | ||
| @@ -573,6 +622,12 @@ public void readFieldsFromPb(WALProtos.WALKey walKey, | ||
| if (walKey.hasOrigSequenceNumber()) { | ||
| this.origLogSeqNum = walKey.getOrigSequenceNumber(); | ||
| } | ||
| if (walKey.getExtendedAttributesCount() > 0){ | ||
| this.extendedAttributes = new HashMap<>(walKey.getExtendedAttributesCount()); | ||
| for (WALProtos.Attribute attr : walKey.getExtendedAttributesList()){ | ||
| extendedAttributes.put(attr.getKey(), attr.getValue().toByteArray()); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed while backporting. Attribute values may have been compressed and need to be decompressed. Will fix up for commit. | ||
| } | ||
| } | ||
| } | ||
| @Override | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Missing setters?
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.
@apurtell - WALKey's interface comments specifically say that setters aren't permitted. They're meant to be immutable, so the extended attributes will be set during construction of the WALKeyImpl