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