use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class AbstractCypherResource method executeStatementsInNewTransaction.
@POST
public Response executeStatementsInNewTransaction(InputEventStream inputEventStream, @Context HttpServletRequest request, @Context HttpHeaders headers) {
try (var memoryTracker = createMemoryTracker()) {
InputEventStream inputStream = ensureNotNull(inputEventStream);
var graphDatabaseAPI = httpTransactionManager.getGraphDatabaseAPI(databaseName);
return graphDatabaseAPI.map(databaseAPI -> {
if (isDatabaseNotAvailable(databaseAPI)) {
return createNonAvailableDatabaseResponse(inputStream.getParameters());
}
memoryTracker.allocateHeap(Invocation.SHALLOW_SIZE);
final TransactionFacade transactionFacade = httpTransactionManager.createTransactionFacade(databaseAPI, memoryTracker);
TransactionHandle transactionHandle = createNewTransactionHandle(transactionFacade, request, headers, memoryTracker, false);
Invocation invocation = new Invocation(log, transactionHandle, uriScheme.txCommitUri(transactionHandle.getId()), memoryPool, inputStream, false);
OutputEventStreamImpl outputStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
return Response.created(transactionHandle.uri()).entity(outputStream).build();
}).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
}
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class TxStateTransactionDataSnapshotIT method countChangedRelationshipInTransactionStateSnapshot.
@Test
void countChangedRelationshipInTransactionStateSnapshot() {
long relationshipIdToChange;
int attachedPropertySize = (int) ByteUnit.mebiBytes(1);
int doublePropertySize = attachedPropertySize * 2;
final String property = "a";
final String doubleProperty = "b";
try (Transaction transaction = database.beginTx()) {
var start = transaction.createNode();
var end = transaction.createNode();
var relationship = start.createRelationshipTo(end, withName("relType"));
relationship.setProperty(property, randomAscii(attachedPropertySize));
relationship.setProperty(doubleProperty, randomAscii(doublePropertySize));
relationshipIdToChange = relationship.getId();
transaction.commit();
}
try (Transaction transaction = database.beginTx()) {
var relationship = transaction.getRelationshipById(relationshipIdToChange);
relationship.setProperty(doubleProperty, randomAscii(attachedPropertySize));
relationship.removeProperty(property);
var kernelTransaction = getKernelTransaction(transaction);
var transactionState = kernelTransaction.txState();
final MemoryTracker memoryTracker = kernelTransaction.memoryTracker();
// reset to count only snapshot memory
var trackingData = resetMemoryTracker(memoryTracker);
try (var snapshot = new TxStateTransactionDataSnapshot(transactionState, kernelTransaction.newStorageReader(), kernelTransaction)) {
assertThat(memoryTracker.usedNativeMemory()).isZero();
assertThat(memoryTracker.estimatedHeapMemory()).isGreaterThanOrEqualTo(emptySnapshotSize + (attachedPropertySize + doublePropertySize) + (2 * RelationshipPropertyEntryView.SHALLOW_SIZE));
} finally {
restoreMemoryTracker(memoryTracker, trackingData);
}
}
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class TxStateTransactionDataSnapshotIT method countEmptySnapshotSize.
private long countEmptySnapshotSize() {
try (Transaction transaction = database.beginTx()) {
var kernelTransaction = getKernelTransaction(transaction);
var transactionState = kernelTransaction.txState();
final MemoryTracker memoryTracker = kernelTransaction.memoryTracker();
// reset to count only snapshot memory
resetMemoryTracker(memoryTracker);
try (var snapshot = new TxStateTransactionDataSnapshot(transactionState, kernelTransaction.newStorageReader(), kernelTransaction)) {
return memoryTracker.estimatedHeapMemory();
}
}
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class MultipleIndexPopulator method createStoreScan.
StoreScan createStoreScan(PageCacheTracer cacheTracer) {
int[] entityTokenIds = entityTokenIds();
int[] propertyKeyIds = propertyKeyIds();
IntPredicate propertyKeyIdFilter = propertyKeyId -> contains(propertyKeyIds, propertyKeyId);
StoreScan storeScan;
if (type == EntityType.RELATIONSHIP) {
storeScan = storeView.visitRelationships(entityTokenIds, propertyKeyIdFilter, createPropertyScanConsumer(), createTokenScanConsumer(), false, true, cacheTracer, memoryTracker);
storeScan = new LoggingStoreScan(storeScan, false);
} else {
storeScan = storeView.visitNodes(entityTokenIds, propertyKeyIdFilter, createPropertyScanConsumer(), createTokenScanConsumer(), false, true, cacheTracer, memoryTracker);
storeScan = new LoggingStoreScan(storeScan, true);
}
storeScan.setPhaseTracker(phaseTracker);
return storeScan;
}
use of org.neo4j.memory.MemoryTracker in project neo4j by neo4j.
the class DistinctSet method createDistinctSet.
public static <T extends Measurable> DistinctSet<T> createDistinctSet(MemoryTracker memoryTracker) {
MemoryTracker scopedMemoryTracker = memoryTracker.getScopedMemoryTracker();
scopedMemoryTracker.allocateHeap(SHALLOW_SIZE + SCOPED_MEMORY_TRACKER_SHALLOW_SIZE);
return new DistinctSet<>(scopedMemoryTracker);
}
Aggregations