Package org.lilyproject.hbaseindex

Examples of org.lilyproject.hbaseindex.IndexEntry


        // the process would fail in between, there will never be left any state in the backward index which would not
        // be found via the forward index.

        // delete removed from bwd index
        for (DependencyEntry removed : removedDependencies) {
            final IndexEntry backwardEntry =
                    createBackwardEntry(removed.getDependency(), parentRecordId, parentVtagId, null,
                            removed.getMoreDimensionedVariants());
            backwardDerefIndex.removeEntry(backwardEntry);
        }

        // update fwd index (added and removed at the same time, it is a single row)
        final IndexEntry fwdEntry =
                createForwardEntry(parentRecordId, parentVtagId, newDependantEntries.keySet());
        forwardDerefIndex.addEntry(fwdEntry);

        // add added to bwd idx
        for (DependencyEntry added : addedDependencies) {
            final Set<SchemaId> fields = newDependantEntries.get(added);
            final IndexEntry backwardEntry =
                    createBackwardEntry(added.getDependency(), parentRecordId, parentVtagId, fields,
                            added.getMoreDimensionedVariants());
            backwardDerefIndex.addEntry(backwardEntry);
        }
    }
View Full Code Here


        return added;
    }

    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;
    }
View Full Code Here

        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;
    }
View Full Code Here

        public void run() {
            try {
                List<IndexEntry> entries = new ArrayList<IndexEntry>(amount);

                for (int i = 0; i < amount; i++) {
                    IndexEntry entry = new IndexEntry(index.getDefinition());
                    entry.addField("word", Words.get());
                    entry.addField("number", (long) Math.floor(Math.random() * Long.MAX_VALUE));
                    entry.setIdentifier(idGenerator.newRecordId().toBytes());
                    entries.add(entry);
                }

                long before = System.nanoTime();
                index.addEntries(entries);
View Full Code Here

            Set<Pair<FieldedLink, SchemaId>> oldLinks = getAllForwardLinks(sourceRecord);

            // Delete existing entries from the backwards table
            List<IndexEntry> entries = new ArrayList<IndexEntry>(oldLinks.size());
            for (Pair<FieldedLink, SchemaId> link : oldLinks) {
                IndexEntry entry = createBackwardIndexEntry(link.getV2(), link.getV1().getAbsoluteRecordId(),
                        link.getV1().getFieldTypeId());
                entry.setIdentifier(sourceAsBytes);
                entries.add(entry);
            }
            backwardIndex.removeEntries(entries);

            // Delete existing entries from the forwards table
            entries.clear();
            for (Pair<FieldedLink, SchemaId> link : oldLinks) {
                IndexEntry entry = createForwardIndexEntry(link.getV2(), sourceRecord, link.getV1().getFieldTypeId());
                entry.setIdentifier(link.getV1().getAbsoluteRecordId().toBytes());
                entries.add(entry);
            }
            forwardIndex.removeEntries(entries);
        } catch (LinkIndexException e) {
            throw new LinkIndexException("Error deleting links for record '" + sourceRecord + "'", e);
View Full Code Here

            Set<FieldedLink> oldLinks = getFieldedForwardLinks(sourceRecord, vtag);

            // Delete existing entries from the backwards table
            List<IndexEntry> entries = new ArrayList<IndexEntry>(oldLinks.size());
            for (FieldedLink link : oldLinks) {
                IndexEntry entry = createBackwardIndexEntry(vtag, link.getAbsoluteRecordId(), link.getFieldTypeId());
                entry.setIdentifier(sourceAsBytes);
                entries.add(entry);
            }
            backwardIndex.removeEntries(entries);

            // Delete existing entries from the forwards table
            entries.clear();
            for (FieldedLink link : oldLinks) {
                IndexEntry entry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId());
                entry.setIdentifier(link.getAbsoluteRecordId().toBytes());
                entries.add(entry);
            }
            forwardIndex.removeEntries(entries);
        } catch (LinkIndexException e) {
            throw new LinkIndexException("Error deleting links for record '" + sourceRecord + "', vtag '" + vtag + "'",
View Full Code Here

            List<IndexEntry> bkwdEntries = null;
            if (addedLinks.size() > 0) {
                fwdEntries = new ArrayList<IndexEntry>(Math.max(addedLinks.size(), removedLinks.size()));
                bkwdEntries = new ArrayList<IndexEntry>(fwdEntries.size());
                for (FieldedLink link : addedLinks) {
                    IndexEntry fwdEntry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId());
                    fwdEntry.setIdentifier(link.getAbsoluteRecordId().toBytes());
                    fwdEntries.add(fwdEntry);

                    IndexEntry bkwdEntry = createBackwardIndexEntry(vtag, link.getAbsoluteRecordId(), link.getFieldTypeId());
                    bkwdEntry.setIdentifier(sourceAsBytes);
                    bkwdEntries.add(bkwdEntry);
                }
                forwardIndex.addEntries(fwdEntries);
                backwardIndex.addEntries(bkwdEntries);
            }

            // Apply removed links
            if (removedLinks.size() > 0) {
                if (fwdEntries != null) {
                    fwdEntries.clear();
                    bkwdEntries.clear();
                } else {
                    fwdEntries = new ArrayList<IndexEntry>(removedLinks.size());
                    bkwdEntries = new ArrayList<IndexEntry>(fwdEntries.size());
                }

                for (FieldedLink link : removedLinks) {
                    IndexEntry bkwdEntry = createBackwardIndexEntry(vtag, link.getAbsoluteRecordId(), link.getFieldTypeId());
                    bkwdEntry.setIdentifier(sourceAsBytes);
                    bkwdEntries.add(bkwdEntry);

                    IndexEntry fwdEntry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId());
                    fwdEntry.setIdentifier(link.getAbsoluteRecordId().toBytes());
                    fwdEntries.add(fwdEntry);
                }
                backwardIndex.removeEntries(bkwdEntries);
                forwardIndex.removeEntries(fwdEntries);
            }
View Full Code Here

            metrics.report(Action.UPDATE_LINKS, System.currentTimeMillis() - before);
        }
    }

    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;
    }
View Full Code Here

        return entry;
    }

    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;
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.hbaseindex.IndexEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.