use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2KeyValueRowOffheap method updateWeakValue.
/** {@inheritDoc} */
@SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod")
@Override
protected synchronized Value updateWeakValue(Object valObj) throws IgniteCheckedException {
Value val = peekValue(VAL_COL);
if (val != null)
return val;
Value upd = desc.wrap(valObj, desc.valueType());
setValue(VAL_COL, upd);
notifyAll();
return upd;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2KeyValueRowOffheap method incrementRefCount.
/** {@inheritDoc} */
@SuppressWarnings({ "NonPrivateFieldAccessedInSynchronizedContext" })
@Override
public void incrementRefCount() {
long p = ptr;
GridUnsafeMemory mem = desc.memory();
if (p == 0) {
// Serialize data to offheap memory.
Value key = peekValue(KEY_COL);
Value val = peekValue(VAL_COL);
assert key != null;
assert val != null;
Data data = Data.create(null, new byte[SIZE_CALCULATOR.getValueLen(key)]);
data.writeValue(key);
int keySize = data.length();
p = mem.allocate(keySize + OFFSET_KEY);
// We don't need any synchronization or volatility here because we publish via
// volatile write to tree node.
mem.writeInt(p, 1);
mem.writeLong(p + OFFSET_EXPIRATION, expirationTime);
mem.writeInt(p + OFFSET_KEY_SIZE, keySize);
mem.writeBytes(p + OFFSET_KEY, data.getBytes(), 0, keySize);
data = Data.create(null, new byte[SIZE_CALCULATOR.getValueLen(val)]);
data.writeValue(val);
int valSize = data.length();
long valPtr = mem.allocate(valSize + OFFSET_VALUE);
mem.writeInt(valPtr, valSize);
mem.writeBytes(valPtr + OFFSET_VALUE, data.getBytes(), 0, valSize);
mem.writeLongVolatile(p + OFFSET_VALUE_REF, valPtr);
ptr = p;
desc.cache(this);
} else {
for (; ; ) {
int cnt = mem.readIntVolatile(p);
assert cnt > 0 : cnt;
if (mem.casInt(p, cnt, cnt + 1))
break;
}
}
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class MapQueryResult method fetchNextPage.
/**
* @param rows Collection to fetch into.
* @param pageSize Page size.
* @return {@code true} If there are no more rows available.
*/
synchronized boolean fetchNextPage(List<Value[]> rows, int pageSize) {
assert lazyWorker == null || lazyWorker == MapQueryLazyWorker.currentWorker();
if (closed)
return true;
boolean readEvt = cctx != null && cctx.name() != null && cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
page++;
for (int i = 0; i < pageSize; i++) {
if (!res.next())
return true;
Value[] row = res.currentRow();
if (cpNeeded) {
boolean copied = false;
for (int j = 0; j < row.length; j++) {
Value val = row[j];
if (val instanceof GridH2ValueCacheObject) {
GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject) val;
row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheObject(), h2.objectContext()) {
@Override
public Object getObject() {
return getObject(true);
}
};
copied = true;
}
}
if (i == 0 && !copied)
// No copy on read caches, skip next checks.
cpNeeded = false;
}
assert row != null;
if (readEvt) {
GridKernalContext ctx = h2.kernalContext();
ctx.event().record(new CacheQueryReadEvent<>(ctx.discovery().localNode(), "SQL fields query result set row read.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.SQL.name(), cctx.name(), null, qry.query(), null, null, params, qrySrcNodeId, null, null, null, null, row(row)));
}
rows.add(res.currentRow());
}
return false;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class H2Tree method compareRows.
/**
* Compares two H2 rows.
*
* @param r1 Row 1.
* @param r2 Row 2.
* @return Compare result: see {@link Comparator#compare(Object, Object)} for values.
*/
public int compareRows(SearchRow r1, SearchRow r2) {
if (r1 == r2)
return 0;
for (int i = 0, len = cols.length; i < len; i++) {
int idx = columnIds[i];
Value v1 = r1.getValue(idx);
Value v2 = r2.getValue(idx);
if (v1 == null || v2 == null) {
// Can't compare further.
return 0;
}
int c = compareValues(v1, v2);
if (c != 0)
return InlineIndexHelper.fixSort(c, cols[i].sortType);
}
return 0;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class H2Tree method compare.
/**
* {@inheritDoc}
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
protected int compare(BPlusIO<SearchRow> io, long pageAddr, int idx, SearchRow row) throws IgniteCheckedException {
if (inlineSize() == 0)
return compareRows(getRow(io, pageAddr, idx), row);
else {
int off = io.offset(idx);
int fieldOff = 0;
int lastIdxUsed = 0;
for (int i = 0; i < inlineIdxs.size(); i++) {
InlineIndexHelper inlineIdx = inlineIdxs.get(i);
Value v2 = row.getValue(inlineIdx.columnIndex());
if (v2 == null)
return 0;
int c = inlineIdx.compare(pageAddr, off + fieldOff, inlineSize() - fieldOff, v2, comp);
if (c == -2)
break;
lastIdxUsed++;
if (c != 0)
return c;
fieldOff += inlineIdx.fullSize(pageAddr, off + fieldOff);
if (fieldOff > inlineSize())
break;
}
if (lastIdxUsed == cols.length)
return 0;
SearchRow rowData = getRow(io, pageAddr, idx);
for (int i = lastIdxUsed, len = cols.length; i < len; i++) {
IndexColumn col = cols[i];
int idx0 = col.column.getColumnId();
Value v2 = row.getValue(idx0);
if (v2 == null) {
// Can't compare further.
return 0;
}
Value v1 = rowData.getValue(idx0);
int c = compareValues(v1, v2);
if (c != 0)
return InlineIndexHelper.fixSort(c, col.sortType);
}
return 0;
}
}
Aggregations