Search in sources :

Example 11 with OModifiableInteger

use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.

the class OSBTreeRidBag method mergeChanges.

public void mergeChanges(OSBTreeRidBag treeRidBag) {
    for (Map.Entry<OIdentifiable, OModifiableInteger> entry : treeRidBag.newEntries.entrySet()) {
        mergeDiffEntry(entry.getKey(), entry.getValue().getValue());
    }
    for (Map.Entry<OIdentifiable, Change> entry : treeRidBag.changes.entrySet()) {
        final OIdentifiable rec = entry.getKey();
        final Change change = entry.getValue();
        final int diff;
        if (change instanceof DiffChange)
            diff = ((DiffChange) change).delta;
        else if (change instanceof AbsoluteChange)
            diff = ((AbsoluteChange) change).value - getAbsoluteValue(rec).value;
        else
            throw new IllegalArgumentException("change type is not supported");
        mergeDiffEntry(rec, diff);
    }
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 12 with OModifiableInteger

use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method getRealBagSize.

@Override
public int getRealBagSize(Map<K, OSBTreeRidBag.Change> changes) {
    startOperation();
    try {
        final Map<K, OSBTreeRidBag.Change> notAppliedChanges = new HashMap<K, OSBTreeRidBag.Change>(changes);
        final OModifiableInteger size = new OModifiableInteger(0);
        loadEntriesMajor(firstKey(), true, true, new RangeResultListener<K, V>() {

            @Override
            public boolean addResult(Map.Entry<K, V> entry) {
                final OSBTreeRidBag.Change change = notAppliedChanges.remove(entry.getKey());
                final int result;
                final Integer treeValue = (Integer) entry.getValue();
                if (change == null)
                    result = treeValue;
                else
                    result = change.applyTo(treeValue);
                size.increment(result);
                return true;
            }
        });
        for (OSBTreeRidBag.Change change : notAppliedChanges.values()) {
            size.increment(change.applyTo(0));
        }
        return size.intValue();
    } finally {
        completeOperation();
    }
}
Also used : OSBTreeRidBag(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag) OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger)

Example 13 with OModifiableInteger

use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.

the class OWALChangesTree method allBlackPathsAreEqual.

private boolean allBlackPathsAreEqual() {
    List<OModifiableInteger> paths = new ArrayList<OModifiableInteger>();
    OModifiableInteger currentPath = new OModifiableInteger();
    paths.add(currentPath);
    calculateBlackPathsFromNode(root, paths, currentPath);
    final int basePath = paths.get(0).getValue();
    for (OModifiableInteger path : paths) {
        if (path.getValue() != basePath)
            return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger)

Example 14 with OModifiableInteger

use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.

the class OWALChangesTree method calculateBlackPathsFromNode.

private void calculateBlackPathsFromNode(Node node, List<OModifiableInteger> paths, OModifiableInteger currentPath) {
    if (node.color == BLACK) {
        currentPath.increment();
    }
    if (node.right != null) {
        OModifiableInteger newPath = new OModifiableInteger(currentPath.getValue());
        paths.add(newPath);
        calculateBlackPathsFromNode(node.right, paths, newPath);
    }
    if (node.left != null) {
        calculateBlackPathsFromNode(node.left, paths, currentPath);
    }
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger)

Example 15 with OModifiableInteger

use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.

the class OSessionStoragePerformanceStatisticTest method testWriteInCache.

public void testWriteInCache() {
    final OModifiableInteger increment = new OModifiableInteger();
    OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = new OSessionStoragePerformanceStatistic(100, new OSessionStoragePerformanceStatistic.NanoTimer() {

        private long counter = 0;

        @Override
        public long getNano() {
            return counter += increment.getValue();
        }
    }, -1);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesWrittenInCache(), 0);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getWriteSpeedInCacheInPages(), -1);
    sessionStoragePerformanceStatistic.startCommitTimer();
    for (int i = 0; i < 50; i++) {
        increment.setValue(50);
        sessionStoragePerformanceStatistic.startComponentOperation("c1po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
        sessionStoragePerformanceStatistic.startComponentOperation("c1po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
        sessionStoragePerformanceStatistic.startPageWriteInCacheTimer();
        sessionStoragePerformanceStatistic.stopPageWriteInCacheTimer();
        increment.setValue(150);
        sessionStoragePerformanceStatistic.startComponentOperation("c2po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
        sessionStoragePerformanceStatistic.startPageWriteInCacheTimer();
        sessionStoragePerformanceStatistic.stopPageWriteInCacheTimer();
        sessionStoragePerformanceStatistic.completeComponentOperation();
        sessionStoragePerformanceStatistic.completeComponentOperation();
        sessionStoragePerformanceStatistic.completeComponentOperation();
    }
    increment.setValue(100);
    for (int i = 0; i < 50; i++) {
        sessionStoragePerformanceStatistic.startPageWriteInCacheTimer();
        sessionStoragePerformanceStatistic.stopPageWriteInCacheTimer();
    }
    sessionStoragePerformanceStatistic.stopCommitTimer();
    Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesWrittenInCache(), 150);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesWrittenInCache(null), 150);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesWrittenInCache("c1po"), 100);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesWrittenInCache("c2po"), 50);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesWrittenInCache("c3po"), -1);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getWriteSpeedInCacheInPages(), 10000000);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getWriteSpeedInCacheInPages(null), 10000000);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getWriteSpeedInCacheInPages("c1po"), 10000000);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getWriteSpeedInCacheInPages("c2po"), 6666666);
    Assert.assertEquals(sessionStoragePerformanceStatistic.getWriteSpeedInCacheInPages("c3po"), -1);
    ODocument doc = sessionStoragePerformanceStatistic.toDocument();
    Assert.assertEquals(doc.field("amountOfPagesWrittenInCache"), 150L);
    Assert.assertEquals(doc.field("writeSpeedInCacheInPages"), 10000000L);
    final ODocument docC1PO = doc.<Map<String, ODocument>>field("dataByComponent").get("c1po");
    Assert.assertEquals(docC1PO.field("amountOfPagesWrittenInCache"), 100L);
    Assert.assertEquals(docC1PO.field("writeSpeedInCacheInPages"), 10000000L);
    final ODocument docC2PO = doc.<Map<String, ODocument>>field("dataByComponent").get("c2po");
    Assert.assertEquals(docC2PO.field("amountOfPagesWrittenInCache"), 50L);
    Assert.assertEquals(docC2PO.field("writeSpeedInCacheInPages"), 6666666L);
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OModifiableInteger (com.orientechnologies.common.types.OModifiableInteger)17 Change (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OSBTreeRidBag (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag)1 OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1