1919
2020import java .io .IOException ;
2121import java .util .ArrayList ;
22+ import java .util .HashMap ;
2223import java .util .List ;
2324import java .util .Map ;
2425import java .util .NavigableMap ;
2526import java .util .TreeMap ;
2627import java .util .UUID ;
28+
2729import org .apache .hadoop .hbase .HBaseInterfaceAudience ;
2830import org .apache .hadoop .hbase .HConstants ;
2931import org .apache .hadoop .hbase .TableName ;
@@ -116,14 +118,16 @@ public void setWriteEntry(MultiVersionConcurrencyControl.WriteEntry writeEntry)
116118 */
117119 private MultiVersionConcurrencyControl .WriteEntry writeEntry ;
118120
121+ private Map <String , byte []> extendedAttributes ;
122+
119123 public WALKeyImpl () {
120124 init (null , null , 0L , HConstants .LATEST_TIMESTAMP ,
121- new ArrayList <>(), HConstants .NO_NONCE , HConstants .NO_NONCE , null , null );
125+ new ArrayList <>(), HConstants .NO_NONCE , HConstants .NO_NONCE , null , null , null );
122126 }
123127
124128 public WALKeyImpl (final NavigableMap <byte [], Integer > replicationScope ) {
125129 init (null , null , 0L , HConstants .LATEST_TIMESTAMP ,
126- new ArrayList <>(), HConstants .NO_NONCE , HConstants .NO_NONCE , null , replicationScope );
130+ new ArrayList <>(), HConstants .NO_NONCE , HConstants .NO_NONCE , null , replicationScope , null );
127131 }
128132
129133 @ VisibleForTesting
@@ -132,7 +136,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon
132136 List <UUID > clusterIds = new ArrayList <>(1 );
133137 clusterIds .add (clusterId );
134138 init (encodedRegionName , tablename , logSeqNum , now , clusterIds , HConstants .NO_NONCE ,
135- HConstants .NO_NONCE , null , null );
139+ HConstants .NO_NONCE , null , null , null );
136140 }
137141
138142 @ VisibleForTesting
@@ -141,7 +145,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon
141145 List <UUID > clusterIds = new ArrayList <>(1 );
142146 clusterIds .add (clusterId );
143147 init (encodedRegionName , tablename , logSeqNum , now , clusterIds , HConstants .NO_NONCE ,
144- HConstants .NO_NONCE , mvcc , null );
148+ HConstants .NO_NONCE , mvcc , null , null );
145149 }
146150
147151 // TODO: Fix being able to pass in sequenceid.
@@ -153,20 +157,28 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, fin
153157 EMPTY_UUIDS ,
154158 HConstants .NO_NONCE ,
155159 HConstants .NO_NONCE ,
156- null , null );
160+ null , null , null );
157161 }
158162
159163 // TODO: Fix being able to pass in sequenceid.
160164 public WALKeyImpl (final byte [] encodedRegionName , final TableName tablename , final long now ,
161165 final NavigableMap <byte [], Integer > replicationScope ) {
162166 init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , EMPTY_UUIDS , HConstants .NO_NONCE ,
163- HConstants .NO_NONCE , null , replicationScope );
167+ HConstants .NO_NONCE , null , replicationScope , null );
164168 }
165169
166170 public WALKeyImpl (final byte [] encodedRegionName , final TableName tablename , final long now ,
167171 MultiVersionConcurrencyControl mvcc , final NavigableMap <byte [], Integer > replicationScope ) {
168172 init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , EMPTY_UUIDS , HConstants .NO_NONCE ,
169- HConstants .NO_NONCE , mvcc , replicationScope );
173+ HConstants .NO_NONCE , mvcc , replicationScope , null );
174+ }
175+
176+ public WALKeyImpl (final byte [] encodedRegionName , final TableName tablename , final long now ,
177+ MultiVersionConcurrencyControl mvcc ,
178+ final NavigableMap <byte [], Integer > replicationScope ,
179+ Map <String , byte []> extendedAttributes ) {
180+ init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , EMPTY_UUIDS , HConstants .NO_NONCE ,
181+ HConstants .NO_NONCE , mvcc , replicationScope , extendedAttributes );
170182 }
171183
172184 public WALKeyImpl (final byte [] encodedRegionName ,
@@ -180,7 +192,7 @@ public WALKeyImpl(final byte[] encodedRegionName,
180192 EMPTY_UUIDS ,
181193 HConstants .NO_NONCE ,
182194 HConstants .NO_NONCE ,
183- mvcc , null );
195+ mvcc , null , null );
184196 }
185197
186198 /**
@@ -206,7 +218,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon
206218 final long now , List <UUID > clusterIds , long nonceGroup , long nonce ,
207219 MultiVersionConcurrencyControl mvcc , final NavigableMap <byte [], Integer > replicationScope ) {
208220 init (encodedRegionName , tablename , logSeqNum , now , clusterIds , nonceGroup , nonce , mvcc ,
209- replicationScope );
221+ replicationScope , null );
210222 }
211223
212224 /**
@@ -231,7 +243,8 @@ public WALKeyImpl(final byte[] encodedRegionName,
231243 long nonceGroup ,
232244 long nonce ,
233245 MultiVersionConcurrencyControl mvcc ) {
234- init (encodedRegionName , tablename , logSeqNum , now , clusterIds , nonceGroup , nonce , mvcc , null );
246+ init (encodedRegionName , tablename , logSeqNum , now , clusterIds , nonceGroup ,
247+ nonce , mvcc , null , null );
235248 }
236249
237250 /**
@@ -252,7 +265,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename,
252265 final long now , List <UUID > clusterIds , long nonceGroup ,
253266 final long nonce , final MultiVersionConcurrencyControl mvcc ) {
254267 init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , clusterIds , nonceGroup , nonce , mvcc ,
255- null );
268+ null , null );
256269 }
257270
258271 /**
@@ -275,7 +288,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename,
275288 final long nonce , final MultiVersionConcurrencyControl mvcc ,
276289 NavigableMap <byte [], Integer > replicationScope ) {
277290 init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , clusterIds , nonceGroup , nonce , mvcc ,
278- replicationScope );
291+ replicationScope , null );
279292 }
280293
281294 /**
@@ -304,7 +317,22 @@ public WALKeyImpl(final byte[] encodedRegionName,
304317 EMPTY_UUIDS ,
305318 nonceGroup ,
306319 nonce ,
307- mvcc , null );
320+ mvcc , null , null );
321+ }
322+
323+ public WALKeyImpl (final byte [] encodedRegionName , final TableName tablename ,
324+ final long now , List <UUID > clusterIds , long nonceGroup ,
325+ final long nonce , final MultiVersionConcurrencyControl mvcc ,
326+ NavigableMap <byte [], Integer > replicationScope ,
327+ Map <String , byte []> extendedAttributes ){
328+ init (encodedRegionName ,
329+ tablename ,
330+ NO_SEQUENCE_ID ,
331+ now ,
332+ clusterIds ,
333+ nonceGroup ,
334+ nonce ,
335+ mvcc , replicationScope , extendedAttributes );
308336 }
309337
310338 @ InterfaceAudience .Private
@@ -316,7 +344,8 @@ protected void init(final byte[] encodedRegionName,
316344 long nonceGroup ,
317345 long nonce ,
318346 MultiVersionConcurrencyControl mvcc ,
319- NavigableMap <byte [], Integer > replicationScope ) {
347+ NavigableMap <byte [], Integer > replicationScope ,
348+ Map <String , byte []> extendedAttributes ) {
320349 this .sequenceId = logSeqNum ;
321350 this .writeTime = now ;
322351 this .clusterIds = clusterIds ;
@@ -329,6 +358,7 @@ protected void init(final byte[] encodedRegionName,
329358 setSequenceId (logSeqNum );
330359 }
331360 this .replicationScope = replicationScope ;
361+ this .extendedAttributes = extendedAttributes ;
332362 }
333363
334364 // For deserialization. DO NOT USE. See setWriteEntry below.
@@ -434,6 +464,17 @@ public UUID getOriginatingClusterId(){
434464 return clusterIds .isEmpty ()? HConstants .DEFAULT_CLUSTER_ID : clusterIds .get (0 );
435465 }
436466
467+ @ Override
468+ public byte [] getExtendedAttribute (String attributeKey ){
469+ return extendedAttributes .get (attributeKey );
470+ }
471+
472+ @ Override
473+ public Map <String , byte []> getExtendedAttributes (){
474+ return extendedAttributes != null ? new HashMap <String , byte []>(extendedAttributes ) :
475+ new HashMap <String , byte []>();
476+ }
477+
437478 @ Override
438479 public String toString () {
439480 return tablename + "/" + Bytes .toString (encodedRegionName ) + "/" + sequenceId ;
@@ -539,6 +580,14 @@ public WALProtos.WALKey.Builder getBuilder(WALCellCodec.ByteStringCompressor com
539580 .setScopeType (ScopeType .forNumber (e .getValue ())));
540581 }
541582 }
583+ if (extendedAttributes != null ){
584+ for (Map .Entry <String , byte []> e : extendedAttributes .entrySet ()){
585+ WALProtos .Attribute attr = WALProtos .Attribute .newBuilder ().
586+ setKey (e .getKey ()).setValue (compressor .compress (e .getValue (),
587+ CompressionContext .DictionaryIndex .TABLE )).build ();
588+ builder .addExtendedAttributes (attr );
589+ }
590+ }
542591 return builder ;
543592 }
544593
@@ -573,6 +622,12 @@ public void readFieldsFromPb(WALProtos.WALKey walKey,
573622 if (walKey .hasOrigSequenceNumber ()) {
574623 this .origLogSeqNum = walKey .getOrigSequenceNumber ();
575624 }
625+ if (walKey .getExtendedAttributesCount () > 0 ){
626+ this .extendedAttributes = new HashMap <>(walKey .getExtendedAttributesCount ());
627+ for (WALProtos .Attribute attr : walKey .getExtendedAttributesList ()){
628+ extendedAttributes .put (attr .getKey (), attr .getValue ().toByteArray ());
629+ }
630+ }
576631 }
577632
578633 @ Override
0 commit comments