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