use of org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow in project ignite by apache.
the class CacheDataTree method compareKeys.
/**
* @param key Key.
* @param link Link.
* @return Compare result.
* @throws IgniteCheckedException If failed.
*/
private int compareKeys(KeyCacheObject key, final long link) throws IgniteCheckedException {
byte[] bytes = key.valueBytes(grp.cacheObjectContext());
final long pageId = pageId(link);
final long page = acquirePage(pageId);
try {
// Non-empty data page must not be recycled.
long pageAddr = readLock(pageId, page);
assert pageAddr != 0L : link;
try {
DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
DataPagePayload data = io.readPayload(pageAddr, itemId(link), pageSize());
if (data.nextLink() == 0) {
long addr = pageAddr + data.offset();
if (grp.mvccEnabled())
// Skip MVCC info.
addr += MVCC_INFO_SIZE;
if (grp.storeCacheIdInDataPage())
// Skip cache id.
addr += 4;
final int len = PageUtils.getInt(addr, 0);
int lenCmp = Integer.compare(len, bytes.length);
if (lenCmp != 0)
return lenCmp;
// Skip length and type byte.
addr += 5;
final int words = len / 8;
for (int i = 0; i < words; i++) {
int off = i * 8;
long b1 = PageUtils.getLong(addr, off);
long b2 = GridUnsafe.getLong(bytes, GridUnsafe.BYTE_ARR_OFF + off);
int cmp = Long.compare(b1, b2);
if (cmp != 0)
return cmp;
}
for (int i = words * 8; i < len; i++) {
byte b1 = PageUtils.getByte(addr, i);
byte b2 = bytes[i];
if (b1 != b2)
return b1 > b2 ? 1 : -1;
}
return 0;
}
} finally {
readUnlock(pageId, page, pageAddr);
}
} finally {
releasePage(pageId, page);
}
// TODO GG-11768.
CacheDataRowAdapter other = grp.mvccEnabled() ? new MvccDataRow(link) : new CacheDataRowAdapter(link);
other.initFromLink(grp, CacheDataRowAdapter.RowData.KEY_ONLY);
byte[] bytes1 = other.key().valueBytes(grp.cacheObjectContext());
byte[] bytes2 = key.valueBytes(grp.cacheObjectContext());
int lenCmp = Integer.compare(bytes1.length, bytes2.length);
if (lenCmp != 0)
return lenCmp;
final int len = bytes1.length;
final int words = len / 8;
for (int i = 0; i < words; i++) {
int off = GridUnsafe.BYTE_ARR_INT_OFF + i * 8;
long b1 = GridUnsafe.getLong(bytes1, off);
long b2 = GridUnsafe.getLong(bytes2, off);
int cmp = Long.compare(b1, b2);
if (cmp != 0)
return cmp;
}
for (int i = words * 8; i < len; i++) {
byte b1 = bytes1[i];
byte b2 = bytes2[i];
if (b1 != b2)
return b1 > b2 ? 1 : -1;
}
return 0;
}
use of org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow in project ignite by apache.
the class InlineIndexTree method createMvccIndexRow.
/**
* Creates an mvcc index row for this tree.
*/
public IndexRowImpl createMvccIndexRow(long link, long mvccCrdVer, long mvccCntr, int mvccOpCntr) throws IgniteCheckedException {
IndexRowImpl cachedRow = idxRowCache == null ? null : idxRowCache.get(link);
if (cachedRow != null)
return cachedRow;
int partId = PageIdUtils.partId(PageIdUtils.pageId(link));
MvccDataRow row = new MvccDataRow(cacheGroupContext(), 0, link, partId, null, mvccCrdVer, mvccCntr, mvccOpCntr, true);
IndexRowImpl r = new IndexRowImpl(rowHandler(), row);
if (idxRowCache != null)
idxRowCache.put(r);
return r;
}
Aggregations