age icon indicating copy to clipboard operation
age copied to clipboard

Error is reported when concurrently merging nodes/edges

Open mdianjun opened this issue 9 months ago • 3 comments

Describe the bug When multiple clients perform merge edges concurrently, there is error reported, "sequence already exists", or "relation already exists". Here is my code:

Image

I try to fix this issue in this PR: https://github.com/apache/age/pull/2178. But the issue still exists.

How are you accessing AGE (Command line, driver, etc.)?

  • python driver

What data setup do we need to do?

What is the necessary configuration info needed?

  • [e.g. Installed PostGIS]

What is the command that caused the error?


cq = f"""
--
  | MATCH (source:{source_node_label} {{doc_id:'{doc_id}'}})
  | MATCH (target:{target_node_label} {{doc_id:'{doc_id}'}})
  | WITH source, target
  | MERGE (source)-[r:DIRECTED]->(target)
  | SET {set_properties}
  | RETURN r
  | """
  | query = sql.SQL(
  | f"SELECT * FROM cypher('{self.graph_name}', $$ {cq} $$) as (result agtype)"
  | )


Error message is:

Key (relname, relnamespace)=(DIRECTED_id_seq, 42609) already exists.

Or

relation "DIRECTED" already exists

Expected behavior A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • Version: [e.g. 0.4.0]

Additional context Add any other context about the problem here.

mdianjun avatar May 22 '25 07:05 mdianjun

@protodef PTAL, thanks.

mdianjun avatar May 22 '25 09:05 mdianjun

I think I have found the root cause. The "merge" operation creates table( or sequence) with the same name concurrently, but in PG the behavior must raise error. Like the below transaction sequence:

-- TX1

begin;
create table demo(id int); -- success

-- TX2

begin;
create table demo(id int); -- blocked

-- TX1

commit;

-- TX2

-- create table failed

Therefore, I think AGE doesn't support concurrent merge operation.

mdianjun avatar May 26 '25 03:05 mdianjun

I have fixed this issue in PR https://github.com/apache/age/pull/2178.

mdianjun avatar May 27 '25 07:05 mdianjun