Search in sources :

Example 1 with OBonsaiBucketPointer

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer 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 2 with OBonsaiBucketPointer

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer in project orientdb by orientechnologies.

the class OCollectionNetworkSerializer method readCollectionPointer.

public OBonsaiCollectionPointer readCollectionPointer(final OChannelBinary client) throws IOException {
    final long fileId = client.readLong();
    final OBonsaiBucketPointer rootPointer = readBonsaiBucketPointer(client);
    return new OBonsaiCollectionPointer(fileId, rootPointer);
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)

Example 3 with OBonsaiBucketPointer

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer in project orientdb by orientechnologies.

the class OSBTreeRidBag method deserialize.

@Override
public int deserialize(byte[] stream, int offset) {
    final long fileId = OLongSerializer.INSTANCE.deserializeLiteral(stream, offset);
    offset += OLongSerializer.LONG_SIZE;
    final long pageIndex = OLongSerializer.INSTANCE.deserializeLiteral(stream, offset);
    offset += OLongSerializer.LONG_SIZE;
    final int pageOffset = OIntegerSerializer.INSTANCE.deserializeLiteral(stream, offset);
    offset += OIntegerSerializer.INT_SIZE;
    // Cached bag size. Not used after 1.7.5
    offset += OIntegerSerializer.INT_SIZE;
    if (fileId == -1)
        collectionPointer = null;
    else
        collectionPointer = new OBonsaiCollectionPointer(fileId, new OBonsaiBucketPointer(pageIndex, pageOffset));
    this.size = -1;
    changes.putAll(ChangeSerializationHelper.INSTANCE.deserializeChanges(stream, offset));
    return offset;
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)

Example 4 with OBonsaiBucketPointer

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer in project orientdb by orientechnologies.

the class OStreamSerializerSBTreeIndexRIDContainer method serializeNativeObject.

@Override
public void serializeNativeObject(OIndexRIDContainer object, byte[] stream, int offset, Object... hints) {
    LONG_SERIALIZER.serializeNative(object.getFileId(), stream, offset + FILE_ID_OFFSET);
    final boolean embedded = object.isEmbedded();
    final boolean durable = object.isDurableNonTxMode();
    BOOLEAN_SERIALIZER.serializeNative(embedded, stream, offset + EMBEDDED_OFFSET);
    BOOLEAN_SERIALIZER.serializeNative(durable, stream, offset + DURABLE_OFFSET);
    if (embedded) {
        INT_SERIALIZER.serializeNative(object.size(), stream, offset + EMBEDDED_SIZE_OFFSET);
        int p = offset + EMBEDDED_VALUES_OFFSET;
        for (OIdentifiable ids : object) {
            LINK_SERIALIZER.serializeNativeObject(ids, stream, p);
            p += RID_SIZE;
        }
    } else {
        final OIndexRIDContainerSBTree underlying = (OIndexRIDContainerSBTree) object.getUnderlying();
        final OBonsaiBucketPointer rootPointer = underlying.getRootPointer();
        LONG_SERIALIZER.serializeNative(rootPointer.getPageIndex(), stream, offset + SBTREE_ROOTINDEX_OFFSET);
        INT_SERIALIZER.serializeNative(rootPointer.getPageOffset(), stream, offset + SBTREE_ROOTOFFSET_OFFSET);
    }
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) OIndexRIDContainerSBTree(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 5 with OBonsaiBucketPointer

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer in project orientdb by orientechnologies.

the class OStreamSerializerSBTreeIndexRIDContainer method deserializeFromByteBufferObject.

/**
   * {@inheritDoc}
   */
@Override
public OIndexRIDContainer deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset) {
    final long fileId = walChanges.getLongValue(buffer, offset + FILE_ID_OFFSET);
    final boolean durable = walChanges.getByteValue(buffer, offset + DURABLE_OFFSET) > 0;
    if (walChanges.getByteValue(buffer, offset + EMBEDDED_OFFSET) > 0) {
        final int size = walChanges.getIntValue(buffer, offset + EMBEDDED_SIZE_OFFSET);
        final Set<OIdentifiable> underlying = new HashSet<OIdentifiable>(Math.max((int) (size / .75f) + 1, 16));
        int p = offset + EMBEDDED_VALUES_OFFSET;
        for (int i = 0; i < size; i++) {
            underlying.add(LINK_SERIALIZER.deserializeFromByteBufferObject(buffer, walChanges, p));
            p += RID_SIZE;
        }
        return new OIndexRIDContainer(fileId, underlying, durable);
    } else {
        final long pageIndex = walChanges.getLongValue(buffer, offset + SBTREE_ROOTINDEX_OFFSET);
        final int pageOffset = walChanges.getIntValue(buffer, offset + SBTREE_ROOTOFFSET_OFFSET);
        final OBonsaiBucketPointer rootPointer = new OBonsaiBucketPointer(pageIndex, pageOffset);
        final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
        final OIndexRIDContainerSBTree underlying = new OIndexRIDContainerSBTree(fileId, rootPointer, durable, (OAbstractPaginatedStorage) db.getStorage().getUnderlying());
        return new OIndexRIDContainer(fileId, underlying, durable);
    }
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OIndexRIDContainerSBTree(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) HashSet(java.util.HashSet)

Aggregations

OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)8 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OIndexRIDContainerSBTree (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree)5 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)4 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)3 HashSet (java.util.HashSet)3 OModifiableInteger (com.orientechnologies.common.types.OModifiableInteger)1 OBonsaiCollectionPointer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)1 Change (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)1 ORecord (com.orientechnologies.orient.core.record.ORecord)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 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1