@Override public void run() throws Exception { QueryRunner queryRunner = mapServiceContext.getMapQueryRunner(getName()); result = queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query); }
@Override public void run() throws Exception { QueryRunner queryRunner = mapServiceContext.getMapQueryRunner(getName()); result = queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query); }
@Override public void run() throws Exception { final QueryRunner runner = mapServiceContext.getMapQueryRunner(query.getMapName()); response = runner.runPartitionScanQueryOnPartitionChunk(query, getPartitionId(), lastTableIndex, fetchSize); }
@Override public void run() throws Exception { final QueryRunner runner = mapServiceContext.getMapQueryRunner(query.getMapName()); response = runner.runPartitionScanQueryOnPartitionChunk(query, getPartitionId(), lastTableIndex, fetchSize); }
public Collection<DocumentKey> getLastKeysForQuery(Predicate<DocumentKey, Document> query) { MapService svc = nodeEngine.getService(MapService.SERVICE_NAME); MapServiceContext mapCtx = svc.getMapServiceContext(); Query q = new Query(CN_XDM_DOCUMENT, query, IterationType.KEY, null, null); QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(q); if (rs == null) { logger.info("getLastKeysForQuery; got null QueryResult for query: {}", query); return Collections.emptyList(); } else { List<DocumentKey> results = new ArrayList<>(rs.size()); // TODO: we must take latest keys only.. for (QueryResultRow row: rs.getRows()) { DocumentKey key = nodeEngine.toObject(row.getKey()); results.add(key); } logger.trace("getLastKeysForQuery; query: {}; returning: {}", query, results.size()); return results; } }
public Collection<DataKey> getElementKeys(long docId) { MapService svc = nodeEngine.getService(MapService.SERVICE_NAME); MapServiceContext mapCtx = svc.getMapServiceContext(); Query query = new Query(CN_XDM_ELEMENT, Predicates.equal("__key#documentKey", docId), IterationType.KEY, null, null); QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_ELEMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query); if (rs == null) { logger.info("getElementKeys; got null QueryResult for docId: {}", docId); return Collections.emptyList(); } Collection<DataKey> result = new ArrayList<>(rs.size()); for (QueryResultRow row: rs.getRows()) { result.add((DataKey) nodeEngine.toObject(row.getKey())); } return result; }
public Collection<Document> getLastDocumentsForQuery(Predicate<DocumentKey, Document> query) { MapService svc = nodeEngine.getService(MapService.SERVICE_NAME); MapServiceContext mapCtx = svc.getMapServiceContext(); Query q = new Query(CN_XDM_DOCUMENT, query, IterationType.VALUE, null, null); QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(q); if (rs == null) { logger.info("getLastDocumentsForQuery; got null QueryResult for query: {}", query); return Collections.emptyList(); } else { Map<String, Document> results = new HashMap<>(rs.size()); for (QueryResultRow row: rs.getRows()) { Document doc = nodeEngine.toObject(row.getValue()); Document last = results.get(doc.getUri()); if (last == null || doc.getVersion() > last.getVersion()) { results.put(doc.getUri(), doc); } } logger.trace("getLastDocumentsForQuery; returning: {}", results.size()); return results.values(); } }
public Map<DataKey, Elements> getElements(long docId) { MapService svc = nodeEngine.getService(MapService.SERVICE_NAME); MapServiceContext mapCtx = svc.getMapServiceContext(); Query query = new Query(CN_XDM_ELEMENT, Predicates.equal("__key#documentKey", docId), IterationType.ENTRY, null, null); QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_ELEMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query); if (rs == null) { logger.info("getElements; got null QueryResult for docId: {}", docId); return Collections.emptyMap(); } Map<DataKey, Elements> result = new HashMap<>(rs.size()); for (QueryResultRow row: rs.getRows()) { result.put((DataKey) nodeEngine.toObject(row.getKey()), (Elements) nodeEngine.toObject(row.getValue())); } return result; }
public Document getLastDocumentForUri(String uri) { MapService svc = nodeEngine.getService(MapService.SERVICE_NAME); MapServiceContext mapCtx = svc.getMapServiceContext(); Query query = new Query(CN_XDM_DOCUMENT, Predicates.equal("uri", uri), IterationType.VALUE, null, null); Document last = null; QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query); // rs can be null in case of cluster rebalancing! if (rs == null) { logger.info("getLastDocumentForUri; got null QueryResult for uri: {}", uri); } else { for (QueryResultRow row: rs.getRows()) { Document doc = nodeEngine.toObject(row.getValue()); if (last == null || doc.getVersion() > last.getVersion()) { last = doc; } } logger.trace("getLastDocumentForUri; returning: {} for uri: {}", last, uri); } return last; }
int shift = 0; do { ResultSegment rs = mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runPartitionScanQueryOnPartitionChunk(q, partId, shift, fetchSize); QueryResult qr = (QueryResult) rs.getResult(); for (QueryResultRow row: qr.getRows()) {
public DocumentKey getLastKeyForUri(String uri) { MapService svc = nodeEngine.getService(MapService.SERVICE_NAME); MapServiceContext mapCtx = svc.getMapServiceContext(); Query query = new Query(CN_XDM_DOCUMENT, Predicates.equal("uri", uri), IterationType.KEY, null, null); DocumentKey last = null; QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query); if (rs == null) { logger.info("getLastKeyForUri; got null QueryResult for uri: {}", uri); } else { for (QueryResultRow row: rs.getRows()) { DocumentKey key = nodeEngine.toObject(row.getKey()); if (last == null || key.getVersion() > last.getVersion()) { last = key; } } logger.trace("getLastKeyForUri; uri: {}; returning: {}", uri, last); } return last; //List<DocumentKey> keys = getCachedObject(CN_XDM_KEY, new UrlHashKey(uri), true); //if (keys != null) { // return keys.get(keys.size() - 1); //} //return null; }
@Override public void run() throws Exception { QueryRunner queryRunner = mapServiceContext.getMapQueryRunner(getName()); // partition scan only, since we can't run partition queries on global indexes result = queryRunner.runPartitionScanQueryOnGivenOwnedPartition(query, getPartitionId()); // we have to increment query count here manually since we are not even // trying to use indexes Indexes indexes = mapServiceContext.getMapContainer(getName()).getIndexes(); indexes.getIndexesStats().incrementQueryCount(); }
@Override public void run() throws Exception { QueryRunner queryRunner = mapServiceContext.getMapQueryRunner(getName()); // partition scan only, since we can't run partition queries on global indexes result = queryRunner.runPartitionScanQueryOnGivenOwnedPartition(query, getPartitionId()); // we have to increment query count here manually since we are not even // trying to use indexes Indexes indexes = mapServiceContext.getMapContainer(getName()).getIndexes(); indexes.getIndexesStats().incrementQueryCount(); }
int shift = 0; do { ResultSegment rs = mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runPartitionScanQueryOnPartitionChunk(q, partId, shift, fetchSize); QueryResult qr = (QueryResult) rs.getResult(); for (QueryResultRow row: qr.getRows()) {
QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query); if (rs == null) { logger.info("getLastRevisionKeyForUri; got null QueryResult for uri: {}", uri);
/** * Attempts to get keys by running an index query. This method may return * {@code null} if there is an ongoing migration, which means that it is not * safe to return results from a non-partition thread. The caller must then * run a partition query to obtain the results. * * @param nodeEngine nodeEngine of this cluster node * @return the set of keys or {@code null} if we failed to fetch the keys * because of ongoing migrations */ private Set<Data> tryToObtainKeysFromIndexes(NodeEngine nodeEngine) { // Do not use index in this case, because it requires full-table-scan. if (predicate == TruePredicate.INSTANCE) { return null; } MapService mapService = nodeEngine.getService(SERVICE_NAME); MapServiceContext mapServiceContext = mapService.getMapServiceContext(); QueryRunner runner = mapServiceContext.getMapQueryRunner(name); Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build(); final QueryResult result = (QueryResult) runner.runIndexQueryOnOwnedPartitions(query); if (result.getPartitionIds() == null) { // failed to run query because of ongoing migrations return null; } final Builder<Data> setBuilder = InflatableSet.newBuilder(result.size()); for (QueryResultRow row : result.getRows()) { setBuilder.add(row.getKey()); } return setBuilder.build(); }
/** * Attempts to get keys by running an index query. This method may return * {@code null} if there is an ongoing migration, which means that it is not * safe to return results from a non-partition thread. The caller must then * run a partition query to obtain the results. * * @param nodeEngine nodeEngine of this cluster node * @return the set of keys or {@code null} if we failed to fetch the keys * because of ongoing migrations */ private Set<Data> tryToObtainKeysFromIndexes(NodeEngine nodeEngine) { // Do not use index in this case, because it requires full-table-scan. if (predicate == TruePredicate.INSTANCE) { return null; } MapService mapService = nodeEngine.getService(SERVICE_NAME); MapServiceContext mapServiceContext = mapService.getMapServiceContext(); QueryRunner runner = mapServiceContext.getMapQueryRunner(name); Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build(); final QueryResult result = (QueryResult) runner.runIndexQueryOnOwnedPartitions(query); if (result.getPartitionIds() == null) { // failed to run query because of ongoing migrations return null; } final Builder<Data> setBuilder = InflatableSet.newBuilder(result.size()); for (QueryResultRow row : result.getRows()) { setBuilder.add(row.getKey()); } return setBuilder.build(); }