Package org.apache.jackrabbit.oak.spi.state

Examples of org.apache.jackrabbit.oak.spi.state.NodeState


    private class WrapChildEntryFunction implements Function<ChildNodeEntry, ChildNodeEntry> {
        @Nonnull
        @Override
        public ChildNodeEntry apply(@Nonnull ChildNodeEntry input) {
            String name = input.getName();
            NodeState child = input.getNodeState();
            TreePermission childContext = treePermission.getChildPermission(name, child);
            SecureNodeState secureChild = new SecureNodeState(child, childContext);
            if (child.getChildNodeCount(1) == 0
                    && secureChild.treePermission.canRead()
                    && secureChild.treePermission.canReadProperties()) {
                // Since this is an accessible leaf node whose all properties
                // are readable, we don't need the SecureNodeState wrapper
                // TODO: A further optimization would be to return the raw
View Full Code Here


        return name;
    }

    @Override @CheckForNull
    public NodeState retrieve(@Nonnull String checkpoint) {
        NodeState cp = head.get().getChildNode(checkpoint).getChildNode(ROOT);
        if (cp.exists()) {
            return cp;
        }
        return null;
    }
View Full Code Here

            throws IOException {
        long s = System.currentTimeMillis();

        // 1. create a new checkpoint with the current state
        String checkpoint = store.checkpoint(DEFAULT_LIFETIME);
        NodeState current = store.retrieve(checkpoint);
        if (current == null) {
            // unable to retrieve the checkpoint; use root state instead
            current = store.getRoot();
        }

        // 2. init filestore
        FileStore backup = new FileStore(destination, MAX_FILE_SIZE, false);
        try {
            Journal journal = backup.getJournal("root");

            SegmentNodeState state = new SegmentNodeState(
                    backup.getWriter().getDummySegment(), journal.getHead());
            SegmentNodeBuilder builder = state.builder();

            String beforeCheckpoint = state.getString("checkpoint");
            if (beforeCheckpoint == null) {
                // 3.1 no stored checkpoint, so do the initial full backup
                builder.setChildNode("root", current);
            } else {
                // 3.2 try to retrieve the previously backed up checkpoint
                NodeState before = store.retrieve(beforeCheckpoint);
                if (before != null) {
                    // the previous checkpoint is no longer available,
                    // so use the backed up state as the basis of the
                    // incremental backup diff
                    before = state.getChildNode("root");
View Full Code Here

    public boolean isIndexed(String propertyName, String path, Filter filter) {
        if (PathUtils.denotesRoot(path)) {
            return getIndexNode(root, propertyName, filter) != null;
        }

        NodeState node = root;
        Iterator<String> it = PathUtils.elements(path).iterator();
        while (it.hasNext()) {
            if (getIndexNode(node, propertyName, filter) != null) {
                return true;
            }
            node = node.getChildNode(it.next());
        }
        return false;
    }
View Full Code Here

        }
        return false;
    }

    public Iterable<String> query(Filter filter, String propertyName, PropertyValue value) {
        NodeState indexMeta = getIndexNode(root, propertyName, filter);
        if (indexMeta == null) {
            throw new IllegalArgumentException("No index for " + propertyName);
        }
        return getStrategy(indexMeta).query(filter, propertyName, indexMeta, encode(value));
    }
View Full Code Here

        }
        return MIRROR;
    }

    public double getCost(Filter filter, String propertyName, PropertyValue value) {
        NodeState indexMeta = getIndexNode(root, propertyName, filter);
        if (indexMeta == null) {
            return Double.POSITIVE_INFINITY;
        }
        return getStrategy(indexMeta).count(indexMeta, encode(value), MAX_COST);
    }
View Full Code Here

    @Nullable
    private static NodeState getIndexNode(
            NodeState node, String propertyName, Filter filter) {
        // keep a fallback to a matching index def that has *no* node type constraints
        // (initially, there is no fallback)
        NodeState fallback = null;

        NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME);
        for (ChildNodeEntry entry : state.getChildNodeEntries()) {
            NodeState index = entry.getNodeState();
            PropertyState type = index.getProperty(TYPE_PROPERTY_NAME);
            if (type == null || type.isArray() || !TYPE.equals(type.getValue(Type.STRING))) {
                continue;
            }
            if (contains(index.getNames(PROPERTY_NAMES), propertyName)) {
                NodeState indexContent = index.getChildNode(INDEX_CONTENT_NODE_NAME);
                if (!indexContent.exists()) {
                    continue;
                }
                Set<String> supertypes = getSuperTypes(filter);
                if (index.hasProperty(DECLARING_NODE_TYPES)) {
                    if (supertypes != null) {
View Full Code Here

    @Override
    public synchronized void run() {
        log.debug("Running background index task {}", name);
        String checkpoint = store.checkpoint(lifetime);
        NodeState after = store.retrieve(checkpoint);
        if (after == null) {
            log.debug("Unable to retrieve checkpoint {}", checkpoint);
            return;
        }

        if(isAlreadyRunning(store)){
            log.debug("Async job found to be already running. Skipping");
            return;
        }

        NodeBuilder builder = store.getRoot().builder();
        NodeBuilder async = builder.child(ASYNC);

        NodeState before = null;
        final PropertyState state = async.getProperty(name);
        if (state != null && state.getType() == STRING) {
            before = store.retrieve(state.getValue(STRING));
        }
        if (before == null) {
            before = MISSING_NODE;
        }

        AsyncUpdateCallback callback = new AsyncUpdateCallback();
        IndexUpdate indexUpdate = new IndexUpdate(provider, name, after,
                builder, callback);

        CommitFailedException exception = EditorDiff.process(indexUpdate,
                before, after);
        if (exception == null && callback.dirty) {
            async.setProperty(name, checkpoint);
            try {
                store.merge(builder, new CommitHook() {
                    @Override @Nonnull
                    public NodeState processCommit(NodeState before,
                            NodeState after) throws CommitFailedException {
                        // check for concurrent updates by this async task
                        PropertyState stateAfterRebase = before
                                .getChildNode(ASYNC).getProperty(name);
                        if (Objects.equal(state, stateAfterRebase)) {
                            return postAsyncRunStatus(after.builder(), indexStats)
                                    .getNodeState();
                        } else {
View Full Code Here

        else {
            NodeConflictHandler nodeConflictHandler = nodeConflictHandlers.get(conflictType);
            if (nodeConflictHandler != null) {
                for (ChildNodeEntry oursCNE : conflictInfo.getChildNodeEntries()) {
                    String name = oursCNE.getName();
                    NodeState ours = oursCNE.getNodeState();
                    NodeState theirs = parent.getChildNode(name);
                    Resolution resolution = nodeConflictHandler.resolve(name, ours, theirs);
                    applyResolution(resolution, conflictType, name, ours);
                }
            }
            else {
View Full Code Here

        preAsyncRunStatus(builder, stats);
        store.merge(builder, EmptyHook.INSTANCE, null);
    }

    private static boolean isAlreadyRunning(NodeStore store) {
        NodeState indexState = store.getRoot().getChildNode(IndexConstants.INDEX_DEFINITIONS_NAME);

        //Probably the first run
        if (!indexState.exists()) {
            return false;
        }

        //Check if already running or timed out
        if (STATUS_RUNNING.equals(indexState.getString("async-status"))) {
            PropertyState startTime = indexState.getProperty("async-start");
            Calendar start = Conversions.convert(startTime.getValue(Type.DATE)).toCalendar();
            Calendar now = Calendar.getInstance();
            long delta = now.getTimeInMillis() - start.getTimeInMillis();

            //Check if the job has timed out and we need to take over
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.spi.state.NodeState

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.