// in the compressed block is >= seekKey... therefore this method shouldn't go past the end of the
// compressed block... if it does, there is probably an error in the caller's logic
// this method mostly avoids object allocation and only does compares when the row changes
MutableByteSequence row, cf, cq, cv;
MutableByteSequence prow, pcf, pcq, pcv;
ByteSequence stopRow = seekKey.getRowData();
ByteSequence stopCF = seekKey.getColumnFamilyData();
ByteSequence stopCQ = seekKey.getColumnQualifierData();
long ts = -1;
long pts = -1;
boolean pdel = false;
int rowCmp = -1, cfCmp = -1, cqCmp = -1;
if (currKey != null) {
prow = new MutableByteSequence(currKey.getRowData());
pcf = new MutableByteSequence(currKey.getColumnFamilyData());
pcq = new MutableByteSequence(currKey.getColumnQualifierData());
pcv = new MutableByteSequence(currKey.getColumnVisibilityData());
pts = currKey.getTimestamp();
row = new MutableByteSequence(currKey.getRowData());
cf = new MutableByteSequence(currKey.getColumnFamilyData());
cq = new MutableByteSequence(currKey.getColumnQualifierData());
cv = new MutableByteSequence(currKey.getColumnVisibilityData());
ts = currKey.getTimestamp();
rowCmp = row.compareTo(stopRow);
cfCmp = cf.compareTo(stopCF);
cqCmp = cq.compareTo(stopCQ);
if (rowCmp >= 0) {
if (rowCmp > 0) {
RelativeKey rk = new RelativeKey();
rk.key = rk.prevKey = new Key(currKey);
return new SkippR(rk, 0, prevKey);
}
if (cfCmp >= 0) {
if (cfCmp > 0) {
RelativeKey rk = new RelativeKey();
rk.key = rk.prevKey = new Key(currKey);
return new SkippR(rk, 0, prevKey);
}
if (cqCmp >= 0) {
RelativeKey rk = new RelativeKey();
rk.key = rk.prevKey = new Key(currKey);
return new SkippR(rk, 0, prevKey);
}
}
}
} else {
row = new MutableByteSequence(new byte[64], 0, 0);
cf = new MutableByteSequence(new byte[64], 0, 0);
cq = new MutableByteSequence(new byte[64], 0, 0);
cv = new MutableByteSequence(new byte[64], 0, 0);
prow = new MutableByteSequence(new byte[64], 0, 0);
pcf = new MutableByteSequence(new byte[64], 0, 0);
pcq = new MutableByteSequence(new byte[64], 0, 0);
pcv = new MutableByteSequence(new byte[64], 0, 0);
}
byte fieldsSame = -1;
byte fieldsPrefixed = 0;
int count = 0;
Key newPrevKey = null;
while (true) {
pdel = (fieldsSame & DELETED) == DELETED;
fieldsSame = in.readByte();
if ((fieldsSame & PREFIX_COMPRESSION_ENABLED) == PREFIX_COMPRESSION_ENABLED)
fieldsPrefixed = in.readByte();
else
fieldsPrefixed = 0;
boolean changed = false;
if ((fieldsSame & ROW_SAME) != ROW_SAME) {
MutableByteSequence tmp = prow;
prow = row;
row = tmp;
if ((fieldsPrefixed & ROW_COMMON_PREFIX) == ROW_COMMON_PREFIX)
readPrefix(in, row, prow);
else
read(in, row);
// read a new row, so need to compare...
rowCmp = row.compareTo(stopRow);
changed = true;
}// else the row is the same as the last, so no need to compare
if ((fieldsSame & CF_SAME) != CF_SAME) {
MutableByteSequence tmp = pcf;
pcf = cf;
cf = tmp;
if ((fieldsPrefixed & CF_COMMON_PREFIX) == CF_COMMON_PREFIX)
readPrefix(in, cf, pcf);
else
read(in, cf);
cfCmp = cf.compareTo(stopCF);
changed = true;
}
if ((fieldsSame & CQ_SAME) != CQ_SAME) {
MutableByteSequence tmp = pcq;
pcq = cq;
cq = tmp;
if ((fieldsPrefixed & CQ_COMMON_PREFIX) == CQ_COMMON_PREFIX)
readPrefix(in, cq, pcq);
else
read(in, cq);
cqCmp = cq.compareTo(stopCQ);
changed = true;
}
if ((fieldsSame & CV_SAME) != CV_SAME) {
MutableByteSequence tmp = pcv;
pcv = cv;
cv = tmp;
if ((fieldsPrefixed & CV_COMMON_PREFIX) == CV_COMMON_PREFIX)
readPrefix(in, cv, pcv);
else
read(in, cv);
}
if ((fieldsSame & TS_SAME) != TS_SAME) {
pts = ts;
if ((fieldsPrefixed & TS_DIFF) == TS_DIFF)
ts = WritableUtils.readVLong(in) + pts;
else
ts = WritableUtils.readVLong(in);
}
readValue(in, value);
count++;
if (changed && rowCmp >= 0) {
if (rowCmp > 0)
break;
if (cfCmp >= 0) {
if (cfCmp > 0)
break;
if (cqCmp >= 0)
break;
}
}
}
if (count > 1) {
MutableByteSequence trow, tcf, tcq, tcv;
long tts;
// when the current keys field is same as the last, then
// set the prev keys field the same as the current key
trow = (fieldsSame & ROW_SAME) == ROW_SAME ? row : prow;
tcf = (fieldsSame & CF_SAME) == CF_SAME ? cf : pcf;
tcq = (fieldsSame & CQ_SAME) == CQ_SAME ? cq : pcq;
tcv = (fieldsSame & CV_SAME) == CV_SAME ? cv : pcv;
tts = (fieldsSame & TS_SAME) == TS_SAME ? ts : pts;
newPrevKey = new Key(trow.getBackingArray(), trow.offset(), trow.length(), tcf.getBackingArray(), tcf.offset(), tcf.length(), tcq.getBackingArray(),
tcq.offset(), tcq.length(), tcv.getBackingArray(), tcv.offset(), tcv.length(), tts);
newPrevKey.setDeleted(pdel);
} else if (count == 1) {
if (currKey != null)
newPrevKey = currKey;