@Override public byte[] next() throws IOException { if (!init) { key1 = result1.next(); key2 = result2.next(); init = true; byte[] result = key2; currentQResult = result2; key2 = result2.next(); return result; } else if (key2 == null) { byte[] result = key1; currentQResult = result1; key1 = result1.next(); return result; byte[] result = key1; currentQResult = result1; key1 = result1.next(); key2 = result2.next(); return result; } else if (cmp < 0) { byte[] result = key1; currentQResult = result1; key1 = result1.next(); return result; } else { // cmp > 0 byte[] result = key2; currentQResult = result2;
private AbsoluteRecordId getNextFromQueryResult() throws IOException { // the identifier is the record id of the record that depends on the queried record final byte[] nextIdentifier = queryResult.next(); if (nextIdentifier == null) { return null; } else { return serializationUtil.deserializeDependantRecordId(nextIdentifier); } }
@Override public byte[] next() throws IOException { byte[] key1 = result1.next(); byte[] key2 = result2.next(); if (key1 == null || key2 == null) { return null; } int cmp = Bytes.compareTo(key1, key2); while (cmp != 0) { if (cmp < 0) { while (cmp < 0) { key1 = result1.next(); if (key1 == null) { return null; } cmp = Bytes.compareTo(key1, key2); } } else if (cmp > 0) { while (cmp > 0) { key2 = result2.next(); if (key2 == null) { return null; } cmp = Bytes.compareTo(key1, key2); } } } currentQResult = result1; return key1; }
/** * Find the set of record ids (and corresponding version tags) on which a given record (in a given version tag) * depends. * * @param parentRecordId record id of the record to find dependencies for * @param vtag vtag of the record to find dependencies for * @return the record ids and vtags on which the given record depends */ Set<DependencyEntry> findDependencies(AbsoluteRecordId parentRecordId, SchemaId vtag) throws IOException { final Query query = new Query(); query.addEqualsCondition("dependant_recordid", parentRecordId.toBytes()); query.addEqualsCondition("dependant_vtag", vtag.getBytes()); final Set<DependencyEntry> result; final QueryResult queryResult = forwardDerefIndex.performQuery(query); if (queryResult.next() != null) { final byte[] serializedEntries = queryResult.getData(DEPENDENCIES_KEY); result = this.serializationUtil.deserializeDependenciesForward(serializedEntries); if (queryResult.next() != null) { throw new IllegalStateException( "Expected only a single matching entry in " + forwardDerefIndex.getDefinition().getName()); } } else { result = new HashSet<DependencyEntry>(); } // Not closed in finally block: avoid HBase contact when there could be connection problems. Closer.close(queryResult); return result; }
public Set<AbsoluteRecordId> getAbsoluteReferrers(AbsoluteRecordId record, SchemaId vtag, SchemaId sourceField) throws LinkIndexException, InterruptedException { long before = System.currentTimeMillis(); try { Query query = new Query(); query.addEqualsCondition("target", record.toBytes()); if (vtag != null) { query.addEqualsCondition("vtag", vtag.getBytes()); } if (sourceField != null) { query.addEqualsCondition("sourcefield", sourceField.getBytes()); } Set<AbsoluteRecordId> result = Sets.newHashSet(); QueryResult qr = backwardIndex.performQuery(query); byte[] id; while ((id = qr.next()) != null) { result.add(getIdGenerator().absoluteFromBytes(id)); } Closer.close( qr); // Not closed in finally block: avoid HBase contact when there could be connection problems. return result; } catch (IOException e) { throw new LinkIndexException("Error getting referrers for record '" + record + "', vtag '" + vtag + "', field '" + sourceField + "'", e); } finally { metrics.report(Action.GET_REFERRERS, System.currentTimeMillis() - before); } }
public Set<AbsoluteRecordId> getForwardLinks(AbsoluteRecordId record, SchemaId vtag, SchemaId sourceField) throws LinkIndexException, InterruptedException { long before = System.currentTimeMillis(); try { Query query = new Query(); query.addEqualsCondition("source", record.toBytes()); if (vtag != null) { query.addEqualsCondition("vtag", vtag.getBytes()); } if (sourceField != null) { query.addEqualsCondition("sourcefield", sourceField.getBytes()); } Set<AbsoluteRecordId> result = new HashSet<AbsoluteRecordId>(); QueryResult qr = forwardIndex.performQuery(query); byte[] id; while ((id = qr.next()) != null) { result.add(getIdGenerator().absoluteFromBytes(id)); } Closer.close( qr); // Not closed in finally block: avoid HBase contact when there could be connection problems. return result; } catch (IOException e) { throw new LinkIndexException("Error getting forward links for record '" + record + "', vtag '" + vtag + "', field '" + sourceField + "'", e); } finally { metrics.report(Action.GET_FW_LINKS, System.currentTimeMillis() - before); } }
public Set<FieldedLink> getFieldedForwardLinks(AbsoluteRecordId record, SchemaId vtag) throws LinkIndexException, InterruptedException { long before = System.currentTimeMillis(); try { Query query = new Query(); query.addEqualsCondition("source", record.toBytes()); if (vtag != null) { query.addEqualsCondition("vtag", vtag.getBytes()); } Set<FieldedLink> result = new HashSet<FieldedLink>(); QueryResult qr = forwardIndex.performQuery(query); byte[] id; while ((id = qr.next()) != null) { SchemaId sourceField = getIdGenerator().getSchemaId(qr.getData(SOURCE_FIELD_KEY)); result.add(new FieldedLink(getIdGenerator().absoluteFromBytes(id), sourceField)); } Closer.close( qr); // Not closed in finally block: avoid HBase contact when there could be connection problems. return result; } catch (IOException e) { throw new LinkIndexException("Error getting forward links for record '" + record + "', vtag '" + vtag + "'", e); } finally { metrics.report(Action.GET_FW_LINKS, System.currentTimeMillis() - before); } }
public Set<FieldedLink> getFieldedReferrers(RecordId record, SchemaId vtag) throws LinkIndexException, InterruptedException { long before = System.currentTimeMillis(); try { Query query = new Query(); query.addEqualsCondition("target", record.toBytes()); if (vtag != null) { query.addEqualsCondition("vtag", vtag.getBytes()); } Set<FieldedLink> result = new HashSet<FieldedLink>(); QueryResult qr = backwardIndex.performQuery(query); byte[] id; while ((id = qr.next()) != null) { SchemaId sourceField = getIdGenerator().getSchemaId(qr.getData(SOURCE_FIELD_KEY)); result.add(new FieldedLink(getIdGenerator().absoluteFromBytes(id), sourceField)); } Closer.close( qr); // Not closed in finally block: avoid HBase contact when there could be connection problems. return result; } catch (IOException e) { throw new LinkIndexException("Error getting referrers for record '" + record + "', vtag '" + vtag + "'", e); } finally { metrics.report(Action.GET_FIELDED_REFERRERS, System.currentTimeMillis() - before); } }
public Set<Pair<FieldedLink, SchemaId>> getAllForwardLinks(AbsoluteRecordId record) throws LinkIndexException, InterruptedException { long before = System.currentTimeMillis(); try { Query query = new Query(); query.addEqualsCondition("source", record.toBytes()); Set<Pair<FieldedLink, SchemaId>> result = new HashSet<Pair<FieldedLink, SchemaId>>(); QueryResult qr = forwardIndex.performQuery(query); byte[] id; while ((id = qr.next()) != null) { SchemaId sourceField = getIdGenerator().getSchemaId(qr.getData(SOURCE_FIELD_KEY)); SchemaId vtag = getIdGenerator().getSchemaId(qr.getData(VTAG_KEY)); result.add( new Pair<FieldedLink, SchemaId>(new FieldedLink(getIdGenerator().absoluteFromBytes(id), sourceField), vtag)); } Closer.close( qr); // Not closed in finally block: avoid HBase contact when there could be connection problems. return result; } catch (IOException e) { throw new LinkIndexException("Error getting forward links for record '" + record + "'", e); } finally { metrics.report(Action.GET_ALL_FW_LINKS, System.currentTimeMillis() - before); } }