Search in sources :

Example 11 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentNodeState method getMemory.

@Override
public int getMemory() {
    long size = // shallow
    40 + (lastRevision != null ? lastRevision.getMemory() : 0) + rootRevision.getMemory() + estimateMemoryUsage(path);
    // rough approximation for properties
    for (Map.Entry<String, PropertyState> entry : bundlingContext.getAllProperties().entrySet()) {
        // name
        size += estimateMemoryUsage(entry.getKey());
        PropertyState propState = entry.getValue();
        if (propState.getType() != Type.BINARY && propState.getType() != Type.BINARIES) {
            for (int i = 0; i < propState.count(); i++) {
                // size() returns length of string
                // shallow memory:
                // - 8 bytes per reference in values list
                // - 48 bytes per string
                // double useage per property because of parsed PropertyState
                size += (56 + propState.size(i) * 2) * 2;
            }
        } else {
            // calculate size based on blobId value
            // referencing the binary in the blob store
            // double the size because the parsed PropertyState
            // will have a similarly sized blobId as well
            size += (long) estimateMemoryUsage(getPropertyAsString(entry.getKey())) * 2;
        }
    }
    if (size > Integer.MAX_VALUE) {
        log.debug("Estimated memory footprint larger than Integer.MAX_VALUE: {}.", size);
        size = Integer.MAX_VALUE;
    }
    return (int) size;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 12 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentNodeState method fromString.

public static DocumentNodeState fromString(DocumentNodeStore store, String s) {
    JsopTokenizer json = new JsopTokenizer(s);
    String path = null;
    RevisionVector rootRev = null;
    RevisionVector lastRev = null;
    boolean hasChildren = false;
    HashMap<String, String> map = new HashMap<String, String>();
    while (true) {
        String k = json.readString();
        json.read(':');
        if ("path".equals(k)) {
            path = json.readString();
        } else if ("rev".equals(k)) {
            rootRev = RevisionVector.fromString(json.readString());
        } else if ("lastRev".equals(k)) {
            lastRev = RevisionVector.fromString(json.readString());
        } else if ("hasChildren".equals(k)) {
            hasChildren = json.read() == JsopReader.TRUE;
        } else if ("prop".equals(k)) {
            json.read('{');
            while (true) {
                if (json.matches('}')) {
                    break;
                }
                k = json.readString();
                json.read(':');
                String v = json.readString();
                map.put(k, v);
                json.matches(',');
            }
        }
        if (json.matches(JsopReader.END)) {
            break;
        }
        json.read(',');
    }
    List<PropertyState> props = Lists.newArrayListWithCapacity(map.size());
    for (Entry<String, String> e : map.entrySet()) {
        String value = e.getValue();
        if (value != null) {
            props.add(store.createPropertyState(e.getKey(), value));
        }
    }
    return new DocumentNodeState(store, path, rootRev, props, hasChildren, lastRev);
}
Also used : HashMap(java.util.HashMap) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 13 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentNodeStore method getBinarySize.

/**
     * Returns the binary size of a property value represented as a JSON or
     * {@code -1} if the property is not of type binary.
     *
     * @param json the property value.
     * @return the size of the referenced binary value(s); otherwise {@code -1}.
     */
private long getBinarySize(@Nullable String json) {
    if (json == null) {
        return -1;
    }
    PropertyState p = new DocumentPropertyState(DocumentNodeStore.this, "p", json);
    if (p.getType().tag() != PropertyType.BINARY) {
        return -1;
    }
    long size = 0;
    if (p.isArray()) {
        for (int i = 0; i < p.count(); i++) {
            size += p.size(i);
        }
    } else {
        size = p.size();
    }
    return size;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 14 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class MergingNodeStateDiff method resolveConflict.

//------------------------------------------------------------< private >---
private void resolveConflict(ConflictType conflictType, NodeState conflictInfo) {
    PropertyConflictHandler propertyConflictHandler = propertyConflictHandlers.get(conflictType);
    if (propertyConflictHandler != null) {
        for (PropertyState ours : conflictInfo.getProperties()) {
            PropertyState theirs = parent.getProperty(ours.getName());
            Resolution resolution = propertyConflictHandler.resolve(ours, theirs);
            applyResolution(resolution, conflictType, ours);
        }
    } 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);
                if (LOG.isDebugEnabled()) {
                    String diff = JsopDiff.diffToJsop(ours, theirs);
                    LOG.debug("{} resolved conflict of type {} with resolution {} on node {}, conflict trace {}", nodeConflictHandler, conflictType, resolution, name, diff);
                }
            }
        } else {
            LOG.warn("Ignoring unknown conflict '" + conflictType + '\'');
        }
    }
    NodeBuilder conflictMarker = getConflictMarker(conflictType);
    if (conflictMarker != null) {
        assert conflictMarker.getChildNodeCount(1) == 0;
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Resolution(org.apache.jackrabbit.oak.spi.commit.PartialConflictHandler.Resolution)

Example 15 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class MergingNodeStateDiff method removeChild.

private static void removeChild(NodeBuilder target, String name) {
    target.getChildNode(name).remove();
    PropertyState childOrder = target.getProperty(TreeConstants.OAK_CHILD_ORDER);
    if (childOrder != null) {
        PropertyBuilder<String> builder = PropertyBuilder.copy(NAME, childOrder);
        builder.removeValue(name);
        target.setProperty(builder.getPropertyState());
    }
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9