-
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
Closed
Closed
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
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
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()); | ||
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 | ||
|
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.
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