Search in sources :

Example 1 with MemoryPool

use of org.neo4j.memory.MemoryPool in project neo4j by neo4j.

the class AbstractCypherResource method commitNewTransaction.

@POST
@Path("/commit")
public Response commitNewTransaction(InputEventStream inputEventStream, @Context HttpServletRequest request, @Context HttpHeaders headers) {
    try (var memoryTracker = createMemoryTracker()) {
        InputEventStream inputStream = ensureNotNull(inputEventStream);
        Optional<GraphDatabaseAPI> 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, true);
            Invocation invocation = new Invocation(log, transactionHandle, null, memoryPool, inputStream, true);
            OutputEventStreamImpl outputStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
            return Response.ok(outputStream).build();
        }).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Neo4jError(org.neo4j.server.rest.Neo4jError) Log(org.neo4j.logging.Log) TransactionUriScheme(org.neo4j.server.http.cypher.format.api.TransactionUriScheme) Status(org.neo4j.kernel.api.exceptions.Status) Path(javax.ws.rs.Path) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) MemoryTracker(org.neo4j.memory.MemoryTracker) DELETE(javax.ws.rs.DELETE) HttpHeaderUtils.getTransactionTimeout(org.neo4j.server.web.HttpHeaderUtils.getTransactionTimeout) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) MemoryPool(org.neo4j.memory.MemoryPool) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AuthorizedRequestWrapper(org.neo4j.server.rest.dbms.AuthorizedRequestWrapper) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with MemoryPool

use of org.neo4j.memory.MemoryPool in project neo4j by neo4j.

the class AbstractCypherResource method executeInExistingTransaction.

private Response executeInExistingTransaction(long transactionId, InputEventStream inputEventStream, MemoryTracker memoryTracker, boolean finishWithCommit) {
    InputEventStream inputStream = ensureNotNull(inputEventStream);
    Optional<GraphDatabaseAPI> 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;
        try {
            transactionHandle = transactionFacade.findTransactionHandle(transactionId);
        } catch (TransactionLifecycleException e) {
            return invalidTransaction(e, inputStream.getParameters());
        }
        Invocation invocation = new Invocation(log, transactionHandle, uriScheme.txCommitUri(transactionHandle.getId()), memoryPool, inputStream, finishWithCommit);
        OutputEventStreamImpl outputEventStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
        return Response.ok(outputEventStream).build();
    }).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
}
Also used : PathParam(javax.ws.rs.PathParam) Neo4jError(org.neo4j.server.rest.Neo4jError) Log(org.neo4j.logging.Log) TransactionUriScheme(org.neo4j.server.http.cypher.format.api.TransactionUriScheme) Status(org.neo4j.kernel.api.exceptions.Status) Path(javax.ws.rs.Path) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) MemoryTracker(org.neo4j.memory.MemoryTracker) DELETE(javax.ws.rs.DELETE) HttpHeaderUtils.getTransactionTimeout(org.neo4j.server.web.HttpHeaderUtils.getTransactionTimeout) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) MemoryPool(org.neo4j.memory.MemoryPool) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AuthorizedRequestWrapper(org.neo4j.server.rest.dbms.AuthorizedRequestWrapper) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream)

Example 3 with MemoryPool

use of org.neo4j.memory.MemoryPool 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()));
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Neo4jError(org.neo4j.server.rest.Neo4jError) Log(org.neo4j.logging.Log) TransactionUriScheme(org.neo4j.server.http.cypher.format.api.TransactionUriScheme) Status(org.neo4j.kernel.api.exceptions.Status) Path(javax.ws.rs.Path) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) MemoryTracker(org.neo4j.memory.MemoryTracker) DELETE(javax.ws.rs.DELETE) HttpHeaderUtils.getTransactionTimeout(org.neo4j.server.web.HttpHeaderUtils.getTransactionTimeout) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) MemoryPool(org.neo4j.memory.MemoryPool) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AuthorizedRequestWrapper(org.neo4j.server.rest.dbms.AuthorizedRequestWrapper) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) POST(javax.ws.rs.POST)

Aggregations

URI (java.net.URI)3 Collections.emptyMap (java.util.Collections.emptyMap)3 Map (java.util.Map)3 Objects.requireNonNullElse (java.util.Objects.requireNonNullElse)3 Optional (java.util.Optional)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 DELETE (javax.ws.rs.DELETE)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 PathParam (javax.ws.rs.PathParam)3 Context (javax.ws.rs.core.Context)3 HttpHeaders (javax.ws.rs.core.HttpHeaders)3 Response (javax.ws.rs.core.Response)3 UriBuilder (javax.ws.rs.core.UriBuilder)3 UriInfo (javax.ws.rs.core.UriInfo)3 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)3 Status (org.neo4j.kernel.api.exceptions.Status)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 Log (org.neo4j.logging.Log)3 LocalMemoryTracker (org.neo4j.memory.LocalMemoryTracker)3