@@ -381,129 +381,7 @@ protected void copyFromNext(SeekerState that) {
381381
382382 @ Override
383383 public EncodedSeeker createSeeker (HFileBlockDecodingContext decodingCtx ) {
384- return new BufferedEncodedSeeker <DiffSeekerState >(decodingCtx ) {
385- private byte [] familyNameWithSize ;
386- private static final int TIMESTAMP_WITH_TYPE_LENGTH =
387- Bytes .SIZEOF_LONG + Bytes .SIZEOF_BYTE ;
388-
389- private void decode (boolean isFirst ) {
390- byte flag = currentBuffer .get ();
391- byte type = 0 ;
392- if ((flag & FLAG_SAME_KEY_LENGTH ) == 0 ) {
393- if (!isFirst ) {
394- type = current .keyBuffer [current .keyLength - Bytes .SIZEOF_BYTE ];
395- }
396- current .keyLength = ByteBuff .readCompressedInt (currentBuffer );
397- }
398- if ((flag & FLAG_SAME_VALUE_LENGTH ) == 0 ) {
399- current .valueLength = ByteBuff .readCompressedInt (currentBuffer );
400- }
401- current .lastCommonPrefix = ByteBuff .readCompressedInt (currentBuffer );
402-
403- current .ensureSpaceForKey ();
404-
405- if (current .lastCommonPrefix < Bytes .SIZEOF_SHORT ) {
406- // length of row is different, copy everything except family
407-
408- // copy the row size
409- currentBuffer .get (current .keyBuffer , current .lastCommonPrefix ,
410- Bytes .SIZEOF_SHORT - current .lastCommonPrefix );
411- current .rowLengthWithSize = Bytes .toShort (current .keyBuffer , 0 ) +
412- Bytes .SIZEOF_SHORT ;
413-
414- // copy the rest of row
415- currentBuffer .get (current .keyBuffer , Bytes .SIZEOF_SHORT ,
416- current .rowLengthWithSize - Bytes .SIZEOF_SHORT );
417-
418- // copy the column family
419- System .arraycopy (familyNameWithSize , 0 , current .keyBuffer ,
420- current .rowLengthWithSize , familyNameWithSize .length );
421-
422- // copy the qualifier
423- currentBuffer .get (current .keyBuffer ,
424- current .rowLengthWithSize + familyNameWithSize .length ,
425- current .keyLength - current .rowLengthWithSize -
426- familyNameWithSize .length - TIMESTAMP_WITH_TYPE_LENGTH );
427- } else if (current .lastCommonPrefix < current .rowLengthWithSize ) {
428- // we have to copy part of row and qualifier,
429- // but column family is in right place
430-
431- // before column family (rest of row)
432- currentBuffer .get (current .keyBuffer , current .lastCommonPrefix ,
433- current .rowLengthWithSize - current .lastCommonPrefix );
434-
435- // after column family (qualifier)
436- currentBuffer .get (current .keyBuffer ,
437- current .rowLengthWithSize + familyNameWithSize .length ,
438- current .keyLength - current .rowLengthWithSize -
439- familyNameWithSize .length - TIMESTAMP_WITH_TYPE_LENGTH );
440- } else {
441- // copy just the ending
442- currentBuffer .get (current .keyBuffer , current .lastCommonPrefix ,
443- current .keyLength - TIMESTAMP_WITH_TYPE_LENGTH -
444- current .lastCommonPrefix );
445- }
446-
447- // timestamp
448- int pos = current .keyLength - TIMESTAMP_WITH_TYPE_LENGTH ;
449- int timestampFitInBytes = 1 +
450- ((flag & MASK_TIMESTAMP_LENGTH ) >>> SHIFT_TIMESTAMP_LENGTH );
451- long timestampOrDiff = ByteBuff .readLong (currentBuffer , timestampFitInBytes );
452- if ((flag & FLAG_TIMESTAMP_SIGN ) != 0 ) {
453- timestampOrDiff = -timestampOrDiff ;
454- }
455- if ((flag & FLAG_TIMESTAMP_IS_DIFF ) == 0 ) { // it is timestamp
456- current .timestamp = timestampOrDiff ;
457- } else { // it is diff
458- current .timestamp = current .timestamp - timestampOrDiff ;
459- }
460- Bytes .putLong (current .keyBuffer , pos , current .timestamp );
461- pos += Bytes .SIZEOF_LONG ;
462-
463- // type
464- if ((flag & FLAG_SAME_TYPE ) == 0 ) {
465- currentBuffer .get (current .keyBuffer , pos , Bytes .SIZEOF_BYTE );
466- } else if ((flag & FLAG_SAME_KEY_LENGTH ) == 0 ) {
467- current .keyBuffer [pos ] = type ;
468- }
469-
470- current .valueOffset = currentBuffer .position ();
471- currentBuffer .skip (current .valueLength );
472-
473- if (includesTags ()) {
474- decodeTags ();
475- }
476- if (includesMvcc ()) {
477- current .memstoreTS = ByteBufferUtils .readVLong (currentBuffer );
478- } else {
479- current .memstoreTS = 0 ;
480- }
481- current .nextKvOffset = currentBuffer .position ();
482- }
483-
484- @ Override
485- protected void decodeFirst () {
486- currentBuffer .skip (Bytes .SIZEOF_INT );
487-
488- // read column family
489- byte familyNameLength = currentBuffer .get ();
490- familyNameWithSize = new byte [familyNameLength + Bytes .SIZEOF_BYTE ];
491- familyNameWithSize [0 ] = familyNameLength ;
492- currentBuffer .get (familyNameWithSize , Bytes .SIZEOF_BYTE ,
493- familyNameLength );
494- decode (true );
495- }
496-
497- @ Override
498- protected void decodeNext () {
499- decode (false );
500- }
501-
502- @ Override
503- protected DiffSeekerState createSeekerState () {
504- return new DiffSeekerState (this .tmpPair , this .includesTags ());
505- }
506- };
384+ return new DiffSeekerStateBufferedEncodedSeeker (decodingCtx );
507385 }
508386
509387 @ Override
@@ -525,4 +403,133 @@ protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocat
525403
526404 return buffer ;
527405 }
406+
407+ private static class DiffSeekerStateBufferedEncodedSeeker
408+ extends BufferedEncodedSeeker <DiffSeekerState > {
409+ private byte [] familyNameWithSize ;
410+ private static final int TIMESTAMP_WITH_TYPE_LENGTH =
411+ Bytes .SIZEOF_LONG + Bytes .SIZEOF_BYTE ;
412+
413+ private DiffSeekerStateBufferedEncodedSeeker (HFileBlockDecodingContext decodingCtx ) {
414+ super (decodingCtx );
415+ }
416+
417+ private void decode (boolean isFirst ) {
418+ byte flag = currentBuffer .get ();
419+ byte type = 0 ;
420+ if ((flag & FLAG_SAME_KEY_LENGTH ) == 0 ) {
421+ if (!isFirst ) {
422+ type = current .keyBuffer [current .keyLength - Bytes .SIZEOF_BYTE ];
423+ }
424+ current .keyLength = ByteBuff .readCompressedInt (currentBuffer );
425+ }
426+ if ((flag & FLAG_SAME_VALUE_LENGTH ) == 0 ) {
427+ current .valueLength = ByteBuff .readCompressedInt (currentBuffer );
428+ }
429+ current .lastCommonPrefix = ByteBuff .readCompressedInt (currentBuffer );
430+
431+ current .ensureSpaceForKey ();
432+
433+ if (current .lastCommonPrefix < Bytes .SIZEOF_SHORT ) {
434+ // length of row is different, copy everything except family
435+
436+ // copy the row size
437+ currentBuffer .get (current .keyBuffer , current .lastCommonPrefix ,
438+ Bytes .SIZEOF_SHORT - current .lastCommonPrefix );
439+ current .rowLengthWithSize = Bytes .toShort (current .keyBuffer , 0 ) +
440+ Bytes .SIZEOF_SHORT ;
441+
442+ // copy the rest of row
443+ currentBuffer .get (current .keyBuffer , Bytes .SIZEOF_SHORT ,
444+ current .rowLengthWithSize - Bytes .SIZEOF_SHORT );
445+
446+ // copy the column family
447+ System .arraycopy (familyNameWithSize , 0 , current .keyBuffer ,
448+ current .rowLengthWithSize , familyNameWithSize .length );
449+
450+ // copy the qualifier
451+ currentBuffer .get (current .keyBuffer ,
452+ current .rowLengthWithSize + familyNameWithSize .length ,
453+ current .keyLength - current .rowLengthWithSize -
454+ familyNameWithSize .length - TIMESTAMP_WITH_TYPE_LENGTH );
455+ } else if (current .lastCommonPrefix < current .rowLengthWithSize ) {
456+ // we have to copy part of row and qualifier,
457+ // but column family is in right place
458+
459+ // before column family (rest of row)
460+ currentBuffer .get (current .keyBuffer , current .lastCommonPrefix ,
461+ current .rowLengthWithSize - current .lastCommonPrefix );
462+
463+ // after column family (qualifier)
464+ currentBuffer .get (current .keyBuffer ,
465+ current .rowLengthWithSize + familyNameWithSize .length ,
466+ current .keyLength - current .rowLengthWithSize -
467+ familyNameWithSize .length - TIMESTAMP_WITH_TYPE_LENGTH );
468+ } else {
469+ // copy just the ending
470+ currentBuffer .get (current .keyBuffer , current .lastCommonPrefix ,
471+ current .keyLength - TIMESTAMP_WITH_TYPE_LENGTH -
472+ current .lastCommonPrefix );
473+ }
474+
475+ // timestamp
476+ int pos = current .keyLength - TIMESTAMP_WITH_TYPE_LENGTH ;
477+ int timestampFitInBytes = 1 +
478+ ((flag & MASK_TIMESTAMP_LENGTH ) >>> SHIFT_TIMESTAMP_LENGTH );
479+ long timestampOrDiff = ByteBuff .readLong (currentBuffer , timestampFitInBytes );
480+ if ((flag & FLAG_TIMESTAMP_SIGN ) != 0 ) {
481+ timestampOrDiff = -timestampOrDiff ;
482+ }
483+ if ((flag & FLAG_TIMESTAMP_IS_DIFF ) == 0 ) { // it is timestamp
484+ current .timestamp = timestampOrDiff ;
485+ } else { // it is diff
486+ current .timestamp = current .timestamp - timestampOrDiff ;
487+ }
488+ Bytes .putLong (current .keyBuffer , pos , current .timestamp );
489+ pos += Bytes .SIZEOF_LONG ;
490+
491+ // type
492+ if ((flag & FLAG_SAME_TYPE ) == 0 ) {
493+ currentBuffer .get (current .keyBuffer , pos , Bytes .SIZEOF_BYTE );
494+ } else if ((flag & FLAG_SAME_KEY_LENGTH ) == 0 ) {
495+ current .keyBuffer [pos ] = type ;
496+ }
497+
498+ current .valueOffset = currentBuffer .position ();
499+ currentBuffer .skip (current .valueLength );
500+
501+ if (includesTags ()) {
502+ decodeTags ();
503+ }
504+ if (includesMvcc ()) {
505+ current .memstoreTS = ByteBufferUtils .readVLong (currentBuffer );
506+ } else {
507+ current .memstoreTS = 0 ;
508+ }
509+ current .nextKvOffset = currentBuffer .position ();
510+ }
511+
512+ @ Override
513+ protected void decodeFirst () {
514+ currentBuffer .skip (Bytes .SIZEOF_INT );
515+
516+ // read column family
517+ byte familyNameLength = currentBuffer .get ();
518+ familyNameWithSize = new byte [familyNameLength + Bytes .SIZEOF_BYTE ];
519+ familyNameWithSize [0 ] = familyNameLength ;
520+ currentBuffer .get (familyNameWithSize , Bytes .SIZEOF_BYTE ,
521+ familyNameLength );
522+ decode (true );
523+ }
524+
525+ @ Override
526+ protected void decodeNext () {
527+ decode (false );
528+ }
529+
530+ @ Override
531+ protected DiffSeekerState createSeekerState () {
532+ return new DiffSeekerState (this .tmpPair , this .includesTags ());
533+ }
534+ }
528535}
0 commit comments