Search in sources :

Example 1 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method convertRecords2Links.

@Override
public boolean convertRecords2Links() {
    final Map<OIdentifiable, Change> newChangedValues = new HashMap<OIdentifiable, Change>();
    for (Map.Entry<OIdentifiable, Change> entry : changes.entrySet()) {
        OIdentifiable identifiable = entry.getKey();
        if (identifiable instanceof ORecord) {
            ORID identity = identifiable.getIdentity();
            ORecord record = (ORecord) identifiable;
            identity = record.getIdentity();
            newChangedValues.put(identity, entry.getValue());
        } else
            newChangedValues.put(entry.getKey().getIdentity(), entry.getValue());
    }
    for (Map.Entry<OIdentifiable, Change> entry : newChangedValues.entrySet()) {
        if (entry.getKey() instanceof ORecord) {
            ORecord record = (ORecord) entry.getKey();
            newChangedValues.put(record, entry.getValue());
        } else
            return false;
    }
    newEntries.clear();
    changes.clear();
    changes.putAll(newChangedValues);
    return true;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change) ORID(com.orientechnologies.orient.core.id.ORID) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 2 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method serialize.

@Override
public int serialize(byte[] stream, int offset, UUID ownerUuid) {
    for (Map.Entry<OIdentifiable, OModifiableInteger> entry : newEntries.entrySet()) {
        OIdentifiable identifiable = entry.getKey();
        assert identifiable instanceof ORecord;
        Change c = changes.get(identifiable);
        final int delta = entry.getValue().intValue();
        if (c == null)
            changes.put(identifiable, new DiffChange(delta));
        else
            c.applyDiff(delta);
    }
    newEntries.clear();
    final ORecordSerializationContext context;
    boolean remoteMode = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage() instanceof OStorageProxy;
    if (remoteMode) {
        context = null;
    } else
        context = ORecordSerializationContext.getContext();
    // make sure that we really save underlying record.
    if (collectionPointer == null) {
        if (context != null) {
            final int clusterId = getHighLevelDocClusterId();
            assert clusterId > -1;
            collectionPointer = ODatabaseRecordThreadLocal.INSTANCE.get().getSbTreeCollectionManager().createSBTree(clusterId, ownerUuid);
        }
    }
    OBonsaiCollectionPointer collectionPointer;
    if (this.collectionPointer != null)
        collectionPointer = this.collectionPointer;
    else {
        collectionPointer = OBonsaiCollectionPointer.INVALID;
    }
    OLongSerializer.INSTANCE.serializeLiteral(collectionPointer.getFileId(), stream, offset);
    offset += OLongSerializer.LONG_SIZE;
    OBonsaiBucketPointer rootPointer = collectionPointer.getRootPointer();
    OLongSerializer.INSTANCE.serializeLiteral(rootPointer.getPageIndex(), stream, offset);
    offset += OLongSerializer.LONG_SIZE;
    OIntegerSerializer.INSTANCE.serializeLiteral(rootPointer.getPageOffset(), stream, offset);
    offset += OIntegerSerializer.INT_SIZE;
    // Keep this section for binary compatibility with versions older then 1.7.5
    OIntegerSerializer.INSTANCE.serializeLiteral(size, stream, offset);
    offset += OIntegerSerializer.INT_SIZE;
    if (context == null) {
        ChangeSerializationHelper.INSTANCE.serializeChanges(changes, OLinkSerializer.INSTANCE, stream, offset);
    } else {
        ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
        for (Entry<OIdentifiable, Change> change : this.changes.entrySet()) {
            OIdentifiable key = change.getKey();
            if (db != null && db.getTransaction().isActive()) {
                if (!key.getIdentity().isPersistent()) {
                    OIdentifiable newKey = db.getTransaction().getRecord(key.getIdentity());
                    if (newKey != null) {
                        changes.remove(key);
                        changes.put(newKey, change.getValue());
                    }
                }
            }
        }
        this.collectionPointer = collectionPointer;
        context.push(new ORidBagUpdateSerializationOperation(changes, collectionPointer));
        // 0-length serialized list of changes
        OIntegerSerializer.INSTANCE.serializeLiteral(0, stream, offset);
        offset += OIntegerSerializer.INT_SIZE;
    }
    return offset;
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) ORecordSerializationContext(com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) ORidBagUpdateSerializationOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.ORidBagUpdateSerializationOperation) ORecord(com.orientechnologies.orient.core.record.ORecord) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 3 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method contains.

@Override
public boolean contains(OIdentifiable identifiable) {
    if (newEntries.containsKey(identifiable))
        return true;
    Change counter = changes.get(identifiable);
    if (counter != null) {
        AbsoluteChange absoluteValue = getAbsoluteValue(identifiable);
        if (counter.isUndefined()) {
            changes.put(identifiable, absoluteValue);
        }
        counter = absoluteValue;
    } else {
        counter = getAbsoluteValue(identifiable);
    }
    return counter.applyTo(0) > 0;
}
Also used : Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)

Example 4 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method getAbsoluteValue.

private AbsoluteChange getAbsoluteValue(OIdentifiable identifiable) {
    final OSBTreeBonsai<OIdentifiable, Integer> tree = loadTree();
    try {
        Integer oldValue;
        if (tree == null)
            oldValue = 0;
        else
            oldValue = tree.get(identifiable);
        if (oldValue == null)
            oldValue = 0;
        final Change change = changes.get(identifiable);
        return new AbsoluteChange(change == null ? oldValue : change.applyTo(oldValue));
    } finally {
        releaseTree();
    }
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)

Example 5 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method nextChangedNotRemovedSBTreeEntry.

private Map.Entry<OIdentifiable, Integer> nextChangedNotRemovedSBTreeEntry(Iterator<Map.Entry<OIdentifiable, Integer>> iterator) {
    while (iterator.hasNext()) {
        final Map.Entry<OIdentifiable, Integer> entry = iterator.next();
        final Change change = changes.get(entry.getKey());
        if (change == null)
            return entry;
        final int newValue = change.applyTo(entry.getValue());
        if (newValue > 0)
            return new Map.Entry<OIdentifiable, Integer>() {

                @Override
                public OIdentifiable getKey() {
                    return entry.getKey();
                }

                @Override
                public Integer getValue() {
                    return newValue;
                }

                @Override
                public Integer setValue(Integer value) {
                    throw new UnsupportedOperationException();
                }
            };
    }
    return null;
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Aggregations

Change (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)9 OModifiableInteger (com.orientechnologies.common.types.OModifiableInteger)6 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)4 ORecord (com.orientechnologies.orient.core.record.ORecord)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)1 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)1 ORecordSerializationContext (com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext)1 ORidBagUpdateSerializationOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.ORidBagUpdateSerializationOperation)1