Search in sources :

Example 16 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class DebugTars method filterNodeStates.

private void filterNodeStates(Set<UUID> uuids, List<String> paths, SegmentNodeState state, String path) {
    Set<String> localPaths = newTreeSet();
    for (PropertyState ps : state.getProperties()) {
        if (ps instanceof SegmentPropertyState) {
            SegmentPropertyState sps = (SegmentPropertyState) ps;
            RecordId recordId = sps.getRecordId();
            UUID id = recordId.getSegmentId().asUUID();
            if (uuids.contains(id)) {
                if (ps.getType().tag() == PropertyType.STRING) {
                    String val = "";
                    if (ps.count() > 0) {
                        // only shows the first value, do we need more?
                        val = displayString(ps.getValue(Type.STRING, 0));
                    }
                    localPaths.add(getLocalPath(path, ps, val, recordId));
                } else {
                    localPaths.add(getLocalPath(path, ps, recordId));
                }
            }
            if (ps.getType().tag() == PropertyType.BINARY) {
                // look for extra segment references
                for (int i = 0; i < ps.count(); i++) {
                    Blob b = ps.getValue(Type.BINARY, i);
                    for (SegmentId sbid : SegmentBlob.getBulkSegmentIds(b)) {
                        UUID bid = sbid.asUUID();
                        if (!bid.equals(id) && uuids.contains(bid)) {
                            localPaths.add(getLocalPath(path, ps, recordId));
                        }
                    }
                }
            }
        }
    }
    RecordId stateId = state.getRecordId();
    if (uuids.contains(stateId.getSegmentId().asUUID())) {
        localPaths.add(path + " [SegmentNodeState@" + stateId + "]");
    }
    RecordId templateId = getTemplateId(state);
    if (uuids.contains(templateId.getSegmentId().asUUID())) {
        localPaths.add(path + "[Template@" + templateId + "]");
    }
    paths.addAll(localPaths);
    for (ChildNodeEntry ce : state.getChildNodeEntries()) {
        NodeState c = ce.getNodeState();
        if (c instanceof SegmentNodeState) {
            filterNodeStates(uuids, paths, (SegmentNodeState) c, path + ce.getName() + "/");
        }
    }
}
Also used : SegmentBlob(org.apache.jackrabbit.oak.segment.SegmentBlob) Blob(org.apache.jackrabbit.oak.api.Blob) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentPropertyState(org.apache.jackrabbit.oak.segment.SegmentPropertyState) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) RecordId(org.apache.jackrabbit.oak.segment.RecordId) UUID(java.util.UUID) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentPropertyState(org.apache.jackrabbit.oak.segment.SegmentPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 17 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class ConsistencyChecker method checkNodeAndDescendants.

/**
     * Recursively checks the consistency of a node and its descendants at the given path.
     * @param node          node to be checked
     * @param path          path of the node
     * @param checkBinaries if {@code true} full content of binary properties will be scanned
     * @return              {@code null}, if the node is consistent, 
     *                      or the path of the first inconsistency otherwise.
     */
private String checkNodeAndDescendants(NodeState node, String path, boolean checkBinaries) {
    String result = checkNode(node, path, checkBinaries);
    if (result != null) {
        return result;
    }
    try {
        for (ChildNodeEntry cne : node.getChildNodeEntries()) {
            String childName = cne.getName();
            NodeState child = cne.getNodeState();
            result = checkNodeAndDescendants(child, concat(path, childName), checkBinaries);
            if (result != null) {
                return result;
            }
        }
        return null;
    } catch (RuntimeException e) {
        printError("Error while traversing {0}: {1}", path, e.getMessage());
        return path;
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 18 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class Aggregate method collectAggregatesForDirectMatchers.

private static void collectAggregatesForDirectMatchers(NodeState nodeState, List<Matcher> matchers, ResultCollector collector) {
    Map<String, ChildNodeEntry> children = Maps.newHashMap();
    //Collect potentially matching child nodestates based on matcher name
    for (Matcher m : matchers) {
        String nodeName = m.getNodeName();
        NodeState child = nodeState.getChildNode(nodeName);
        if (child.exists()) {
            children.put(nodeName, new MemoryChildNodeEntry(nodeName, child));
        }
    }
    matchChildren(matchers, collector, children.values());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) MemoryChildNodeEntry(org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry) MemoryChildNodeEntry(org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)

Example 19 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class IndexDefinition method createIndexRules.

/**
     * Constructs IndexingRule based on earlier format of index configuration
     */
private static NodeBuilder createIndexRules(NodeState defn) {
    NodeBuilder builder = EMPTY_NODE.builder();
    Set<String> declaringNodeTypes = getMultiProperty(defn, DECLARING_NODE_TYPES);
    Set<String> includes = getMultiProperty(defn, INCLUDE_PROPERTY_NAMES);
    Set<String> excludes = toLowerCase(getMultiProperty(defn, EXCLUDE_PROPERTY_NAMES));
    Set<String> orderedProps = getMultiProperty(defn, ORDERED_PROP_NAMES);
    boolean fullTextEnabled = getOptionalValue(defn, FULL_TEXT_ENABLED, true);
    boolean storageEnabled = getOptionalValue(defn, EXPERIMENTAL_STORAGE, true);
    NodeState propNodeState = defn.getChildNode(LuceneIndexConstants.PROP_NODE);
    //If no explicit nodeType defined then all config applies for nt:base
    if (declaringNodeTypes.isEmpty()) {
        declaringNodeTypes = Collections.singleton(NT_BASE);
    }
    Set<String> propNamesSet = Sets.newHashSet();
    propNamesSet.addAll(includes);
    propNamesSet.addAll(excludes);
    propNamesSet.addAll(orderedProps);
    //Also include all immediate leaf propNode names
    for (ChildNodeEntry cne : propNodeState.getChildNodeEntries()) {
        if (!propNamesSet.contains(cne.getName()) && Iterables.isEmpty(cne.getNodeState().getChildNodeNames())) {
            propNamesSet.add(cne.getName());
        }
    }
    List<String> propNames = new ArrayList<String>(propNamesSet);
    final String includeAllProp = LuceneIndexConstants.REGEX_ALL_PROPS;
    if (fullTextEnabled && includes.isEmpty()) {
        //Add the regEx for including all properties at the end
        //for fulltext index and when no explicit includes are defined
        propNames.add(includeAllProp);
    }
    for (String typeName : declaringNodeTypes) {
        NodeBuilder rule = builder.child(typeName);
        markAsNtUnstructured(rule);
        List<String> propNodeNames = newArrayListWithCapacity(propNamesSet.size());
        NodeBuilder propNodes = rule.child(PROP_NODE);
        int i = 0;
        for (String propName : propNames) {
            String propNodeName = propName;
            //For proper propName use the propName as childNode name
            if (PropertyDefinition.isRelativeProperty(propName) || propName.equals(includeAllProp)) {
                propNodeName = "prop" + i++;
            }
            propNodeNames.add(propNodeName);
            NodeBuilder prop = propNodes.child(propNodeName);
            markAsNtUnstructured(prop);
            prop.setProperty(LuceneIndexConstants.PROP_NAME, propName);
            if (excludes.contains(propName)) {
                prop.setProperty(LuceneIndexConstants.PROP_INDEX, false);
            } else if (fullTextEnabled) {
                prop.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
                prop.setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
                prop.setProperty(LuceneIndexConstants.PROP_USE_IN_EXCERPT, storageEnabled);
                prop.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, false);
            } else {
                prop.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
                if (orderedProps.contains(propName)) {
                    prop.setProperty(LuceneIndexConstants.PROP_ORDERED, true);
                }
            }
            if (propName.equals(includeAllProp)) {
                prop.setProperty(LuceneIndexConstants.PROP_IS_REGEX, true);
            }
            //Copy over the property configuration
            NodeState propDefNode = getPropDefnNode(defn, propName);
            if (propDefNode != null) {
                for (PropertyState ps : propDefNode.getProperties()) {
                    prop.setProperty(ps);
                }
            }
        }
        //If no propertyType defined then default to UNKNOWN such that none
        //of the properties get indexed
        PropertyState supportedTypes = defn.getProperty(INCLUDE_PROPERTY_TYPES);
        if (supportedTypes == null) {
            supportedTypes = PropertyStates.createProperty(INCLUDE_PROPERTY_TYPES, TYPES_ALLOW_ALL_NAME);
        }
        rule.setProperty(supportedTypes);
        if (!NT_BASE.equals(typeName)) {
            rule.setProperty(LuceneIndexConstants.RULE_INHERITED, false);
        }
        propNodes.setProperty(OAK_CHILD_ORDER, propNodeNames, NAMES);
        markAsNtUnstructured(propNodes);
    }
    markAsNtUnstructured(builder);
    builder.setProperty(OAK_CHILD_ORDER, declaringNodeTypes, NAMES);
    return builder;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 20 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class SegmentParser method parseNode.

/**
     * Parse a node record
     * @param nodeId
     * @return
     */
public NodeInfo parseNode(RecordId nodeId) {
    int size = 0;
    int nodeCount = 0;
    int propertyCount = 0;
    Segment segment = nodeId.getSegment();
    String stableId = reader.readNode(nodeId).getStableId();
    RecordId templateId = segment.readRecordId(nodeId.getRecordNumber(), 0, 1);
    onTemplate(nodeId, templateId);
    Template template = reader.readTemplate(templateId);
    // Recurses into child nodes in this segment
    if (template.getChildName() == MANY_CHILD_NODES) {
        RecordId childMapId = segment.readRecordId(nodeId.getRecordNumber(), 0, 2);
        MapRecord childMap = reader.readMap(childMapId);
        onMap(nodeId, childMapId, childMap);
        for (ChildNodeEntry childNodeEntry : childMap.getEntries()) {
            NodeState child = childNodeEntry.getNodeState();
            if (child instanceof SegmentNodeState) {
                RecordId childId = ((Record) child).getRecordId();
                onNode(nodeId, childId);
                nodeCount++;
            }
        }
    } else if (template.getChildName() != ZERO_CHILD_NODES) {
        RecordId childId = segment.readRecordId(nodeId.getRecordNumber(), 0, 2);
        onNode(nodeId, childId);
        nodeCount++;
    }
    int ids = template.getChildName() == ZERO_CHILD_NODES ? 1 : 2;
    size += ids * RECORD_ID_BYTES;
    // Recurse into properties
    PropertyTemplate[] propertyTemplates = template.getPropertyTemplates();
    if (propertyTemplates.length > 0) {
        size += RECORD_ID_BYTES;
        RecordId id = segment.readRecordId(nodeId.getRecordNumber(), 0, ids + 1);
        ListRecord pIds = new ListRecord(id, propertyTemplates.length);
        for (int i = 0; i < propertyTemplates.length; i++) {
            RecordId propertyId = pIds.getEntry(i);
            onProperty(nodeId, propertyId, propertyTemplates[i]);
            propertyCount++;
        }
        onList(nodeId, id, propertyTemplates.length);
    }
    return new NodeInfo(nodeId, stableId, nodeCount, propertyCount, size);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Aggregations

ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)58 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)43 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)19 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)6 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)4 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)3 Clock (org.apache.jackrabbit.oak.stats.Clock)3 Map (java.util.Map)2 UUID (java.util.UUID)2 CheckForNull (javax.annotation.CheckForNull)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)2 JsopBuilder.prettyPrint (org.apache.jackrabbit.oak.commons.json.JsopBuilder.prettyPrint)2 MemoryChildNodeEntry (org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)2