use of org.h2.engine.Session in project jackrabbit-oak by apache.
the class ManyChildrenTest method manyChildrenWithoutIndex.
@Test
public void manyChildrenWithoutIndex() throws Exception {
if (session == null) {
return;
}
Node index = session.getRootNode().getNode("oak:index");
if (index.hasNode("nodetype")) {
index.getNode("nodetype").remove();
session.save();
}
long start = System.currentTimeMillis(), last = start;
// to test with more nodes, use:
// int count = 1000000;
int count = 10;
Profiler prof = null;
String nodeType = NodeTypeConstants.NT_OAK_UNSTRUCTURED;
if (session.getRootNode().hasNode("many")) {
session.getRootNode().getNode("many").remove();
session.save();
}
Node many = session.getRootNode().addNode("many", nodeType);
for (int i = 0; i < count; i++) {
Node n = many.addNode("test" + i, nodeType);
n.setProperty("prop", i);
if (i % 100 == 0) {
session.save();
}
long now = System.currentTimeMillis();
if (now - last > 5000) {
int opsPerSecond = (int) (i * 1000 / (now - start));
System.out.println(i + " ops; " + opsPerSecond + " op/s");
last = now;
if (prof != null) {
System.out.println(prof.getTop(5));
}
if (opsPerSecond < 1000 && i % 100 == 0) {
prof = new Profiler();
prof.startCollecting();
}
}
}
start = System.currentTimeMillis();
last = start;
for (int i = 0; i < count; i++) {
Node n = many.getNode("test" + i);
long x = n.getProperty("prop").getValue().getLong();
assertEquals(i, x);
long now = System.currentTimeMillis();
if (now - last > 5000) {
int opsPerSecond = (int) (i * 1000 / (now - start));
System.out.println(i + " read ops; " + opsPerSecond + " op/s");
last = now;
if (prof != null) {
System.out.println(prof.getTop(5));
}
if (opsPerSecond < 1000 && i % 100 == 0) {
prof = new Profiler();
prof.startCollecting();
}
}
}
}
use of org.h2.engine.Session in project jackrabbit-oak by apache.
the class SlowObservationIT method observation.
@Test
public void observation() throws Exception {
if (!isDocumentNodeStore()) {
return;
}
AtomicBoolean saveInObservation = new AtomicBoolean();
saveInObservation.set(true);
ArrayList<MyListener> listeners = new ArrayList<MyListener>();
for (int i = 0; i < OBSERVER_COUNT; i++) {
Session observingSession = createAdminSession();
MyListener listener = new MyListener(i, observingSession, saveInObservation);
listener.open();
listeners.add(listener);
}
log("Starting...");
Profiler prof = null;
long start = System.currentTimeMillis();
for (int i = 1; ; i++) {
if (prof == null && PROFILE) {
// prof = new Profiler().startCollecting();
}
long time = System.currentTimeMillis() - start;
if (time > 20 * 1000) {
if (saveInObservation.get()) {
log("Disable saves in observation now");
saveInObservation.set(false);
}
}
if (time > 30 * 1000) {
break;
}
Node testNode;
if (i % 100 < 52) {
// in 52% of the cases, use testNode
testNode = getNode(TEST_PATH);
} else {
// in 48% of the cases, use testNode2
testNode = getNode(TEST2_PATH);
}
String a = "c-" + (i / 40);
String b = "c-" + (i % 40);
Node x;
if (testNode.hasNode(a)) {
x = testNode.getNode(a);
} else {
x = testNode.addNode(a, "oak:Unstructured");
}
Node t = x.addNode(b, "oak:Unstructured");
for (int j = 0; j < 10; j++) {
t.addNode("c-" + j, "oak:Unstructured");
}
long saveTime = System.currentTimeMillis();
getAdminSession().save();
saveTime = System.currentTimeMillis() - saveTime;
if (saveTime > 100 || i % 200 == 0) {
if (prof != null) {
log(prof.getTop(1));
prof = null;
}
log("Save #" + i + " took " + saveTime + " ms");
}
}
log("Stopping...");
for (MyListener listener : listeners) {
listener.stop();
listener.waitUntilDone();
listener.close();
}
log("Done");
if (PROFILE) {
printFullThreadDump();
}
}
use of org.h2.engine.Session in project ignite by apache.
the class H2TreeIndex method find.
/**
* {@inheritDoc}
*/
@Override
public Cursor find(Session ses, SearchRow lower, SearchRow upper) {
try {
IndexingQueryCacheFilter filter = partitionFilter(threadLocalFilter());
int seg = threadLocalSegment();
H2Tree tree = treeForRead(seg);
if (indexType.isPrimaryKey() && lower != null && upper != null && tree.compareRows(lower, upper) == 0) {
GridH2Row row = tree.findOne(lower, filter);
return (row == null) ? EMPTY_CURSOR : new SingleRowCursor(row);
} else {
GridCursor<GridH2Row> cursor = tree.find(lower, upper, filter);
return new H2Cursor(cursor);
}
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
}
use of org.h2.engine.Session in project ignite by apache.
the class GridH2SpatialIndex method findFirstOrLast.
/**
* {@inheritDoc}
*/
@Override
public Cursor findFirstOrLast(Session ses, boolean first) {
Lock l = lock.readLock();
l.lock();
try {
checkClosed();
if (!first)
throw DbException.throwInternalError("Spatial Index can only be fetch by ascending order");
final int seg = threadLocalSegment();
final MVRTreeMap<Long> segment = segments[seg];
GridCursor<GridH2Row> iter = rowIterator(segment.keySet().iterator(), null);
return new SingleRowCursor(iter.next() ? iter.get() : null);
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
} finally {
l.unlock();
}
}
use of org.h2.engine.Session in project ignite by apache.
the class GridReduceQueryExecutor method createMergeTable.
/**
* @param conn Connection.
* @param qry Query.
* @param explain Explain.
* @return Table.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private GridMergeTable createMergeTable(JdbcConnection conn, GridCacheSqlQuery qry, boolean explain) throws IgniteCheckedException {
try {
Session ses = (Session) conn.getSession();
CreateTableData data = new CreateTableData();
data.tableName = "T___";
data.schema = ses.getDatabase().getSchema(ses.getCurrentSchemaName());
data.create = true;
if (!explain) {
LinkedHashMap<String, ?> colsMap = qry.columns();
assert colsMap != null;
ArrayList<Column> cols = new ArrayList<>(colsMap.size());
for (Map.Entry<String, ?> e : colsMap.entrySet()) {
String alias = e.getKey();
GridSqlType t = (GridSqlType) e.getValue();
assert !F.isEmpty(alias);
Column c = new Column(alias, t.type(), t.precision(), t.scale(), t.displaySize());
cols.add(c);
}
data.columns = cols;
} else
data.columns = planColumns();
boolean sortedIndex = !F.isEmpty(qry.sortColumns());
GridMergeTable tbl = new GridMergeTable(data);
ArrayList<Index> idxs = new ArrayList<>(2);
if (explain) {
idxs.add(new GridMergeIndexUnsorted(ctx, tbl, sortedIndex ? MERGE_INDEX_SORTED : MERGE_INDEX_UNSORTED));
} else if (sortedIndex) {
List<GridSqlSortColumn> sortCols = (List<GridSqlSortColumn>) qry.sortColumns();
GridMergeIndexSorted sortedMergeIdx = new GridMergeIndexSorted(ctx, tbl, MERGE_INDEX_SORTED, GridSqlSortColumn.toIndexColumns(tbl, sortCols));
idxs.add(GridMergeTable.createScanIndex(sortedMergeIdx));
idxs.add(sortedMergeIdx);
} else
idxs.add(new GridMergeIndexUnsorted(ctx, tbl, MERGE_INDEX_UNSORTED));
tbl.indexes(idxs);
return tbl;
} catch (Exception e) {
U.closeQuiet(conn);
throw new IgniteCheckedException(e);
}
}
Aggregations