19
19
20
20
import java .io .IOException ;
21
21
import java .util .ArrayList ;
22
+ import java .util .HashMap ;
22
23
import java .util .List ;
23
24
import java .util .Map ;
24
25
import java .util .NavigableMap ;
25
26
import java .util .TreeMap ;
26
27
import java .util .UUID ;
28
+
27
29
import org .apache .hadoop .hbase .HBaseInterfaceAudience ;
28
30
import org .apache .hadoop .hbase .HConstants ;
29
31
import org .apache .hadoop .hbase .TableName ;
@@ -116,14 +118,16 @@ public void setWriteEntry(MultiVersionConcurrencyControl.WriteEntry writeEntry)
116
118
*/
117
119
private MultiVersionConcurrencyControl .WriteEntry writeEntry ;
118
120
121
+ private Map <String , byte []> extendedAttributes ;
122
+
119
123
public WALKeyImpl () {
120
124
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 );
122
126
}
123
127
124
128
public WALKeyImpl (final NavigableMap <byte [], Integer > replicationScope ) {
125
129
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 );
127
131
}
128
132
129
133
@ VisibleForTesting
@@ -132,7 +136,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon
132
136
List <UUID > clusterIds = new ArrayList <>(1 );
133
137
clusterIds .add (clusterId );
134
138
init (encodedRegionName , tablename , logSeqNum , now , clusterIds , HConstants .NO_NONCE ,
135
- HConstants .NO_NONCE , null , null );
139
+ HConstants .NO_NONCE , null , null , null );
136
140
}
137
141
138
142
@ VisibleForTesting
@@ -141,7 +145,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon
141
145
List <UUID > clusterIds = new ArrayList <>(1 );
142
146
clusterIds .add (clusterId );
143
147
init (encodedRegionName , tablename , logSeqNum , now , clusterIds , HConstants .NO_NONCE ,
144
- HConstants .NO_NONCE , mvcc , null );
148
+ HConstants .NO_NONCE , mvcc , null , null );
145
149
}
146
150
147
151
// TODO: Fix being able to pass in sequenceid.
@@ -153,20 +157,28 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, fin
153
157
EMPTY_UUIDS ,
154
158
HConstants .NO_NONCE ,
155
159
HConstants .NO_NONCE ,
156
- null , null );
160
+ null , null , null );
157
161
}
158
162
159
163
// TODO: Fix being able to pass in sequenceid.
160
164
public WALKeyImpl (final byte [] encodedRegionName , final TableName tablename , final long now ,
161
165
final NavigableMap <byte [], Integer > replicationScope ) {
162
166
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 );
164
168
}
165
169
166
170
public WALKeyImpl (final byte [] encodedRegionName , final TableName tablename , final long now ,
167
171
MultiVersionConcurrencyControl mvcc , final NavigableMap <byte [], Integer > replicationScope ) {
168
172
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 );
170
182
}
171
183
172
184
public WALKeyImpl (final byte [] encodedRegionName ,
@@ -180,7 +192,7 @@ public WALKeyImpl(final byte[] encodedRegionName,
180
192
EMPTY_UUIDS ,
181
193
HConstants .NO_NONCE ,
182
194
HConstants .NO_NONCE ,
183
- mvcc , null );
195
+ mvcc , null , null );
184
196
}
185
197
186
198
/**
@@ -206,7 +218,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename, lon
206
218
final long now , List <UUID > clusterIds , long nonceGroup , long nonce ,
207
219
MultiVersionConcurrencyControl mvcc , final NavigableMap <byte [], Integer > replicationScope ) {
208
220
init (encodedRegionName , tablename , logSeqNum , now , clusterIds , nonceGroup , nonce , mvcc ,
209
- replicationScope );
221
+ replicationScope , null );
210
222
}
211
223
212
224
/**
@@ -231,7 +243,8 @@ public WALKeyImpl(final byte[] encodedRegionName,
231
243
long nonceGroup ,
232
244
long nonce ,
233
245
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 );
235
248
}
236
249
237
250
/**
@@ -252,7 +265,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename,
252
265
final long now , List <UUID > clusterIds , long nonceGroup ,
253
266
final long nonce , final MultiVersionConcurrencyControl mvcc ) {
254
267
init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , clusterIds , nonceGroup , nonce , mvcc ,
255
- null );
268
+ null , null );
256
269
}
257
270
258
271
/**
@@ -275,7 +288,7 @@ public WALKeyImpl(final byte[] encodedRegionName, final TableName tablename,
275
288
final long nonce , final MultiVersionConcurrencyControl mvcc ,
276
289
NavigableMap <byte [], Integer > replicationScope ) {
277
290
init (encodedRegionName , tablename , NO_SEQUENCE_ID , now , clusterIds , nonceGroup , nonce , mvcc ,
278
- replicationScope );
291
+ replicationScope , null );
279
292
}
280
293
281
294
/**
@@ -304,7 +317,22 @@ public WALKeyImpl(final byte[] encodedRegionName,
304
317
EMPTY_UUIDS ,
305
318
nonceGroup ,
306
319
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 );
308
336
}
309
337
310
338
@ InterfaceAudience .Private
@@ -316,7 +344,8 @@ protected void init(final byte[] encodedRegionName,
316
344
long nonceGroup ,
317
345
long nonce ,
318
346
MultiVersionConcurrencyControl mvcc ,
319
- NavigableMap <byte [], Integer > replicationScope ) {
347
+ NavigableMap <byte [], Integer > replicationScope ,
348
+ Map <String , byte []> extendedAttributes ) {
320
349
this .sequenceId = logSeqNum ;
321
350
this .writeTime = now ;
322
351
this .clusterIds = clusterIds ;
@@ -329,6 +358,7 @@ protected void init(final byte[] encodedRegionName,
329
358
setSequenceId (logSeqNum );
330
359
}
331
360
this .replicationScope = replicationScope ;
361
+ this .extendedAttributes = extendedAttributes ;
332
362
}
333
363
334
364
// For deserialization. DO NOT USE. See setWriteEntry below.
@@ -434,6 +464,17 @@ public UUID getOriginatingClusterId(){
434
464
return clusterIds .isEmpty ()? HConstants .DEFAULT_CLUSTER_ID : clusterIds .get (0 );
435
465
}
436
466
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
+
437
478
@ Override
438
479
public String toString () {
439
480
return tablename + "/" + Bytes .toString (encodedRegionName ) + "/" + sequenceId ;
@@ -539,6 +580,14 @@ public WALProtos.WALKey.Builder getBuilder(WALCellCodec.ByteStringCompressor com
539
580
.setScopeType (ScopeType .forNumber (e .getValue ())));
540
581
}
541
582
}
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
+ }
542
591
return builder ;
543
592
}
544
593
@@ -573,6 +622,12 @@ public void readFieldsFromPb(WALProtos.WALKey walKey,
573
622
if (walKey .hasOrigSequenceNumber ()) {
574
623
this .origLogSeqNum = walKey .getOrigSequenceNumber ();
575
624
}
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
+ }
576
631
}
577
632
578
633
@ Override
0 commit comments