use of io.opencensus.trace.Tracing in project ignite by apache.
the class OpenCensusSqlNativeTracingTest method testDistributedJoin.
/**
* Tests tracing of distributed join query which includes all communications between reducer and mapped nodes and
* index range requests.
*
* @throws Exception If failed.
*/
@Test
public void testDistributedJoin() throws Exception {
String prsnTable = createTableAndPopulate(Person.class, PARTITIONED, 1);
String orgTable = createTableAndPopulate(Organization.class, PARTITIONED, 1);
SpanId rootSpan = executeAndCheckRootSpan("SELECT * FROM " + prsnTable + " AS p JOIN " + orgTable + " AS o ON o.orgId = p.prsnId", TEST_SCHEMA, false, true, true);
String qryId = getAttribute(rootSpan, SQL_QRY_ID);
assertTrue(Long.parseLong(qryId.substring(qryId.indexOf('_') + 1)) > 0);
UUID.fromString(qryId.substring(0, qryId.indexOf('_')));
checkChildSpan(SQL_QRY_PARSE, rootSpan);
checkChildSpan(SQL_CURSOR_OPEN, rootSpan);
SpanId iterSpan = checkChildSpan(SQL_ITER_OPEN, rootSpan);
List<SpanId> execReqSpans = checkSpan(SQL_QRY_EXEC_REQ, iterSpan, GRID_CNT, null);
int idxRangeReqRows = 0;
int preparedRows = 0;
int fetchedRows = 0;
for (int i = 0; i < GRID_CNT; i++) {
SpanId execReqSpan = execReqSpans.get(i);
Ignite ignite = Ignition.ignite(UUID.fromString(getAttribute(execReqSpan, NODE_ID)));
SpanId partsReserveSpan = checkChildSpan(SQL_PARTITIONS_RESERVE, execReqSpan);
List<String> partsReserveLogs = handler().spanById(partsReserveSpan).getAnnotations().getEvents().stream().map(e -> e.getEvent().getDescription()).collect(Collectors.toList());
assertEquals(2, partsReserveLogs.size());
Pattern ptrn = compile("Cache partitions were reserved \\[cache=(.+), partitions=\\[(.+)], topology=(.+)]");
partsReserveLogs.forEach(l -> {
Matcher matcher = ptrn.matcher(l);
assertTrue(matcher.matches());
Set<Integer> expParts = Arrays.stream(ignite.affinity(matcher.group(1)).primaryPartitions(ignite.cluster().localNode())).boxed().collect(Collectors.toSet());
Set<Integer> parts = Arrays.stream(matcher.group(2).split(",")).map(s -> parseInt(s.trim())).collect(Collectors.toSet());
assertEquals(expParts, parts);
});
SpanId execSpan = checkChildSpan(SQL_QRY_EXECUTE, execReqSpan);
List<SpanId> distrLookupReqSpans = findChildSpans(SQL_IDX_RANGE_REQ, execSpan);
for (SpanId span : distrLookupReqSpans) {
idxRangeReqRows += parseInt(getAttribute(span, SQL_IDX_RANGE_ROWS));
checkChildSpan(SQL_IDX_RANGE_RESP, span);
}
preparedRows += parseInt(getAttribute(checkChildSpan(SQL_PAGE_PREPARE, execReqSpan), SQL_PAGE_ROWS));
checkChildSpan(SQL_PAGE_RESP, execReqSpan);
}
SpanId pageFetchSpan = checkChildSpan(SQL_PAGE_FETCH, iterSpan);
fetchedRows += parseInt(getAttribute(pageFetchSpan, SQL_PAGE_ROWS));
checkChildSpan(SQL_PAGE_WAIT, pageFetchSpan);
SpanId nexPageSpan = checkChildSpan(SQL_NEXT_PAGE_REQ, pageFetchSpan);
preparedRows += parseInt(getAttribute(checkChildSpan(SQL_PAGE_PREPARE, nexPageSpan), SQL_PAGE_ROWS));
checkChildSpan(SQL_PAGE_RESP, nexPageSpan);
List<SpanId> pageFetchSpans = findChildSpans(SQL_PAGE_FETCH, rootSpan);
for (SpanId span : pageFetchSpans) {
fetchedRows += parseInt(getAttribute(span, SQL_PAGE_ROWS));
checkChildSpan(SQL_PAGE_WAIT, span);
List<SpanId> nextPageSpans = findChildSpans(SQL_NEXT_PAGE_REQ, span);
if (!nextPageSpans.isEmpty()) {
assertEquals(1, nextPageSpans.size());
SpanId nextPageSpan = nextPageSpans.get(0);
preparedRows += parseInt(getAttribute(checkChildSpan(SQL_PAGE_PREPARE, nextPageSpan), SQL_PAGE_ROWS));
checkChildSpan(SQL_PAGE_RESP, nextPageSpan);
}
}
assertEquals(TEST_TABLE_POPULATION, fetchedRows);
assertEquals(TEST_TABLE_POPULATION, preparedRows);
assertEquals(TEST_TABLE_POPULATION, idxRangeReqRows);
checkSpan(SQL_QRY_CANCEL_REQ, rootSpan, mapNodesCount(), null);
assertFalse(findChildSpans(SQL_CURSOR_CLOSE, rootSpan).isEmpty());
}
Aggregations