private IndexEntry createForwardEntry(AbsoluteRecordId parentRecordId, SchemaId parentVtagId, Collection<DependencyEntry> newDependencies) throws IOException { final IndexEntry fwdEntry = new IndexEntry(forwardDerefIndex.getDefinition()); fwdEntry.addField("dependant_recordid", parentRecordId.toBytes()); fwdEntry.addField("dependant_vtag", parentVtagId.getBytes()); // we do not really use the identifier... all we are interested in is in the data of the entry fwdEntry.setIdentifier(DUMMY_IDENTIFIER); // the data contains the dependencies of the dependant (master record ids and vtags) fwdEntry.addData(DEPENDENCIES_KEY, this.serializationUtil.serializeDependenciesForward(newDependencies)); return fwdEntry; }
private Put createAddEntryPut(IndexEntry entry) throws IOException { byte[] indexKey = buildRowKey(entry); Put put = new Put(indexKey); Map<ByteArrayKey, byte[]> data = entry.getData(); if (data.size() > 0) { for (Map.Entry<ByteArrayKey, byte[]> item : data.entrySet()) { put.add(IndexDefinition.DATA_FAMILY, item.getKey().getKey(), item.getValue()); } } else { // HBase does not allow to create a row without columns, so add a dummy column put.add(IndexDefinition.DATA_FAMILY, DUMMY_QUALIFIER, DUMMY_VALUE); } return put; }
/** * Adds multiple entries to the index. Uses one HBase put so is more efficient * than adding each entry individually. */ public void addEntries(List<IndexEntry> entries) throws IOException { List<Put> puts = new ArrayList<Put>(); for (IndexEntry entry : entries) { entry.validate(); Put put = createAddEntryPut(entry); puts.add(put); } htable.put(puts); }
private IndexEntry createForwardIndexEntry(SchemaId vtag, AbsoluteRecordId source, SchemaId sourceField) { IndexEntry entry = new IndexEntry(forwardIndex.getDefinition()); entry.addField("vtag", vtag.getBytes()); entry.addField("source", source.toBytes()); entry.addField("sourcefield", sourceField.getBytes()); entry.addData(SOURCE_FIELD_KEY, sourceField.getBytes()); entry.addData(VTAG_KEY, vtag.getBytes()); return entry; }
for (FieldedLink link : addedLinks) { IndexEntry fwdEntry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId()); fwdEntry.setIdentifier(link.getAbsoluteRecordId().toBytes()); fwdEntries.add(fwdEntry); bkwdEntry.setIdentifier(sourceAsBytes); bkwdEntries.add(bkwdEntry); bkwdEntry.setIdentifier(sourceAsBytes); bkwdEntries.add(bkwdEntry); fwdEntry.setIdentifier(link.getAbsoluteRecordId().toBytes()); fwdEntries.add(fwdEntry);
/** * Build the index row key. * * <p>The format is as follows: * * <pre> * ([encoded value][terminator for variable length fields])*[identifier] * </pre> */ private byte[] buildRowKey(IndexEntry entry) throws IOException { final StructRowKey indexEntryRowKeySerializer = definition.asStructRowKey(); return indexEntryRowKeySerializer.serialize(entry.getFieldValuesInSerializationOrder()); }
private IndexEntry createBackwardIndexEntry(SchemaId vtag, AbsoluteRecordId target, SchemaId sourceField) { IndexEntry entry = new IndexEntry(backwardIndex.getDefinition()); entry.addField("vtag", vtag.getBytes()); entry.addField("target", target.toBytes()); entry.addField("sourcefield", sourceField.getBytes()); entry.addData(SOURCE_FIELD_KEY, sourceField.getBytes()); return entry; }
for (FieldedLink link : oldLinks) { IndexEntry entry = createBackwardIndexEntry(vtag, link.getAbsoluteRecordId(), link.getFieldTypeId()); entry.setIdentifier(sourceAsBytes); entries.add(entry); for (FieldedLink link : oldLinks) { IndexEntry entry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId()); entry.setIdentifier(link.getAbsoluteRecordId().toBytes()); entries.add(entry);
private IndexEntry createBackwardEntry(AbsoluteRecordId parentRecordId, AbsoluteRecordId dependantRecordId, SchemaId dependantVtagId, Set<SchemaId> fields, Set<String> moreDimensionedVariantProperties) throws IOException { final byte[] serializedVariantPropertiesPattern = this.serializationUtil.serializeVariantPropertiesPattern( this.serializationUtil.createVariantPropertiesPattern(parentRecordId.getRecordId().getVariantProperties(), moreDimensionedVariantProperties)); final IndexEntry bwdEntry = new IndexEntry(backwardDerefIndex.getDefinition()); bwdEntry.addField("dependency_masterrecordid", parentRecordId.getRecordId().getMaster().toBytes()); bwdEntry.addField("dependant_vtag", dependantVtagId.getBytes()); bwdEntry.addField("variant_properties_pattern", serializedVariantPropertiesPattern); // the identifier is the dependant which depends on the dependency bwdEntry.setIdentifier(dependantRecordId.toBytes()); // the fields which the dependant uses of the dependency (null if used for deleting the entry) if (fields != null) { bwdEntry.addData(FIELDS_KEY, this.serializationUtil.serializeFields(fields)); } return bwdEntry; }
IndexEntry entry = createBackwardIndexEntry(link.getV2(), link.getV1().getAbsoluteRecordId(), link.getV1().getFieldTypeId()); entry.setIdentifier(sourceAsBytes); entries.add(entry); for (Pair<FieldedLink, SchemaId> link : oldLinks) { IndexEntry entry = createForwardIndexEntry(link.getV2(), sourceRecord, link.getV1().getFieldTypeId()); entry.setIdentifier(link.getV1().getAbsoluteRecordId().toBytes()); entries.add(entry);
public void removeEntries(List<IndexEntry> entries) throws IOException { ArgumentValidator.notNull(entries, "entries"); List<Delete> deletes = new ArrayList<Delete>(); for (IndexEntry entry : entries) { entry.validate(); byte[] indexKey = buildRowKey(entry); Delete delete = new Delete(indexKey); deletes.add(delete); } htable.delete(deletes); }
/** * Removes an entry from the index. The contents of the supplied * entry and the identifier should exactly match those supplied * when creating the index entry. */ public void removeEntry(IndexEntry entry) throws IOException { ArgumentValidator.notNull(entry, "entry"); entry.validate(); byte[] indexKey = buildRowKey(entry); Delete delete = new Delete(indexKey); htable.delete(delete); }
/** * Adds an entry to this index. See {@link IndexEntry} for more information. * * @param entry the values to be part of the index key, should correspond to the fields * defined in the {@link IndexDefinition} */ public void addEntry(IndexEntry entry) throws IOException { ArgumentValidator.notNull(entry, "entry"); entry.validate(); Put put = createAddEntryPut(entry); htable.put(put); }