Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Out-of-memory when CREATE EDGE ... IF NOT EXISTS for existing edges with array of destination vertices #1763

Closed
gramian opened this issue Oct 18, 2024 · 12 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@gramian
Copy link
Collaborator

gramian commented Oct 18, 2024

ArcadeDB Version:

ArcadeDB Server v24.11.1-SNAPSHOT (build 4207821d055e37cbd74b76683e45073da759c2de/1729083296142/console)

OS and JDK Version:

Running on Mac OS X 12.7.6 - OpenJDK 64-Bit Server VM 17.0.12 (Homebrew)

When creating edges that already exists with the suffix IF NOT EXISTS and the destinition (TO part) is an array, then an out-of-memory error happens after some time.

Expected behavior

No out-of-memory (OOM) error.

Actual behavior

Error on command execution (PostCommandHandler)
java.lang.OutOfMemoryError: Java heap space

or:

Error on command execution (PostCommandHandler)
java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.Arrays.copyOf(Arrays.java:3481)
	at java.base/java.util.ArrayList.grow(ArrayList.java:237)
	at java.base/java.util.ArrayList.grow(ArrayList.java:244)
	at java.base/java.util.ArrayList.add(ArrayList.java:454)
	at java.base/java.util.ArrayList.add(ArrayList.java:467)
	at com.arcadedb.query.sql.executor.InsertExecutionPlan.executeInternal(InsertExecutionPlan.java:67)
	at com.arcadedb.query.sql.executor.ScriptLineStep.syncPull(ScriptLineStep.java:48)
	at com.arcadedb.query.sql.executor.ScriptExecutionPlan.doExecute(ScriptExecutionPlan.java:101)
	at com.arcadedb.query.sql.executor.ScriptExecutionPlan.fetchNext(ScriptExecutionPlan.java:62)
	at com.arcadedb.query.sql.parser.LocalResultSet.fetchNext(LocalResultSet.java:44)
	at com.arcadedb.query.sql.parser.LocalResultSet.<init>(LocalResultSet.java:40)
	at com.arcadedb.query.sql.SQLScriptQueryEngine.executeInternal(SQLScriptQueryEngine.java:218)
	at com.arcadedb.query.sql.SQLScriptQueryEngine.command(SQLScriptQueryEngine.java:108)
	at com.arcadedb.database.LocalDatabase.command(LocalDatabase.java:1348)
	at com.arcadedb.server.ServerDatabase.command(ServerDatabase.java:472)
	at com.arcadedb.server.http.handler.PostCommandHandler.executeCommand(PostCommandHandler.java:134)
	at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:113)
	at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:100)
	at com.arcadedb.server.http.handler.AbstractServerHttpHandler.handleRequest(AbstractServerHttpHandler.java:127)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:395)
	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
	at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
	at java.base/java.lang.Thread.run(Thread.java:840)

Steps to reproduce

  1. Create vertex and edge types
CREATE VERTEX TYPE vex;
CREATE EDGE TYPE edg;
  1. Add some vertices
CREATE VERTEX vex;
CREATE VERTEX vex;
CREATE VERTEX vex;
  1. Add new edges
CREATE EDGE edg FROM #1:0 TO [#4:0,#7:0]
  1. Try add same edges again with IF NOT EXISTS
CREATE EDGE edg FROM #1:0 TO [#4:0,#7:0] IF NOT EXISTS

This last statement causes the OOM error.

@lvca
Copy link
Contributor

lvca commented Oct 18, 2024

That's pretty awful, I'll look it up asap.

@gramian
Copy link
Collaborator Author

gramian commented Jan 7, 2025

Some more details and a more reduced test case:

  • This happens only if the source FROM ... or the target TO ... is an array of more than one element.
  • Another test case:
CREATE VERTEX TYPE vex;
CREATE EDGE TYPE edg;
CREATE VERTEX vex;
CREATE EDGE edg FROM #1:0 TO #1:0;
CREATE EDGE edg FROM [#1:0,#1:0] TO [#1:0,#1:0] IF NOT EXISTS;

BTW: Using CREATE EDGE edg FROM #1:0 TO [#1:0,#1:0] IF NOT EXISTS first, creates two edges; is this correct?

@robfrank robfrank self-assigned this Jan 10, 2025
@robfrank
Copy link
Collaborator

I was able to reproduce the problem on my side. Stay tuned

@robfrank robfrank added the bug Something isn't working label Jan 13, 2025
robfrank added a commit that referenced this issue Jan 14, 2025
mergify bot added a commit that referenced this issue Jan 14, 2025
## What does this PR do?
Reproduce and solve #1763
## Motivation
## Related issues
#1763
## Checklist
- [x] I have run the build using `mvn clean package` command
- [x] My unit tests cover both failure and success scenarios
robfrank added a commit that referenced this issue Jan 14, 2025
robfrank added a commit that referenced this issue Jan 14, 2025
robfrank added a commit that referenced this issue Jan 15, 2025
- add specific test for issue on  CreateEdgeStatementExecutionTest
- fix CreateEdgeExecutionPlanner
@robfrank
Copy link
Collaborator

Reworked and merged. Closing.

@gramian
Copy link
Collaborator Author

gramian commented Jan 15, 2025

@robfrank I am testing the latest head with the fix. The OOM is gone, but it seems the IF NOT EXISTS is somewhat ignored. For example the following commands keep on creating the same edges:

CREATE VERTEX TYPE vex;
CREATE EDGE TYPE edg;
CREATE VERTEX vex;
CREATE VERTEX vex;
CREATE VERTEX vex;
CREATE EDGE edg FROM #1:0 TO [#1:1,#1:2];
CREATE EDGE edg FROM #1:0 TO [#1:1,#1:2] IF NOT EXISTS;
CREATE EDGE edg FROM #1:0 TO [#1:1,#1:2] IF NOT EXISTS;
...

@gramian gramian reopened this Jan 15, 2025
@robfrank
Copy link
Collaborator

It returns the existing ones . Underneath is very hard to skip the existing ones, so we took the decision to return new created edges with previous in the same result set

@gramian
Copy link
Collaborator Author

gramian commented Jan 15, 2025

I will test again, but in the graph view it looked like each CREATE EDGE creates new edges, which should not happen for IF NOT EXISTS, if I am not wrong.

@robfrank
Copy link
Collaborator

do you mean, via studio?

@gramian
Copy link
Collaborator Author

gramian commented Jan 15, 2025

Yes. I tested the changes manually in studio with the example above. Everytime I call CREATE EDGE ... IF NOT EXISTS it seems new edges are created as new edges between the same vertices appear in the graph view.

@robfrank
Copy link
Collaborator

Let me talk with @lvca to find a proper solution. If you query the database, you should find the right amount of edges, this is what happens in the unit tests. The best solution would be to return only the newly created edges, but it is very tricky to implement that.

@gramian
Copy link
Collaborator Author

gramian commented Jan 15, 2025

IMHO the problem is not what is getting returned, but what is created: There should not be any new edges created if edges between the vertices already exists.

Sorry if I misunderstand you.

@gramian
Copy link
Collaborator Author

gramian commented Jan 15, 2025

@robfrank The latest changes fixed the problem. Great! Thanks

@gramian gramian closed this as completed Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants