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() + "/");
}
}
}
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;
}
}
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());
}
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;
}
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);
}
Aggregations