kuzu: Bug: Adding Large number of edges causes database to crash without explanation

Kùzu version

v0.8.0

What operating system are you using?

macOS Sequoia 15.3.1

What happened?

I have an application where adding edges to the database will randomly cause kuzu to crash and the edge table needs to be deleted. The failure happens sporadically because the program will crash at different times throughout my data ingestion process and I will rerun the step where it failed and then the data ingestion process will work for that step only to fail at a later step or at a step that worked before. I have ruled out this being do to size or data types used because I have randomly generated nodes and edges of the same size and the database creation process has worked fine. I also ruled out this being due to parallelization. I added steps to reproduce below and if there is an error on schema definition or something like that, I think one improvement would be failing more gracefully than the current process which simply fails and seems to corrupt the database until the “ComponentOf” table is deleted.

Are there known steps to reproduce?

I was not able to upload the parquet files that lead to this issue (probably because they are large) but am happy to provide them. They are quite large; about 340M records in total:

Schema

# Num Table
CREATE NODE TABLE Num (id SERIAL,adsh STRING,tag STRING,version STRING,ddate INT32,qtrs INT32,uom STRING,dimh STRING,iprx INT32,value DOUBLE,footnote STRING,footlen INT32,dimn INT32,coreg STRING,durp DOUBLE,datp DOUBLE,dcml INT32,partition_name STRING, PRIMARY KEY(id));
# Cal Table
CREATE NODE TABLE Cal (id SERIAL,adsh STRING,grp INT32,arc INT32,negative INT8,ptag STRING,pversion STRING,ctag STRING,cversion STRING,partition_name STRING, PRIMARY KEY(id));
# Relationship table
CREATE REL TABLE ComponentOf (FROM Num TO Num, grp INT32,arc INT32,negative INT8,MANY_MANY);

Data Ingestion

import kuzu
import polars as pl
import numpy as np
import tqdm
new_db = kuzu.Database("test_db") # point to wherever db is created with schema from above
conn = kuzu.Connection(new_db)
conn.execute("COPY Num from 'num/*.parquet'")
conn.execute("COPY Cal from 'cal/*.parquet'")
all_partitions = (
    conn.execute(
        """
    MATCH (n:Num)
    return distinct n.partition_name
    """
    )
    .get_as_pl()
    .sort("n.partition_name")
)  # type: ignore
edge_partitions = conn.execute(
    """
    MATCH (n2:Num)-[c:ComponentOf]->(n1:Num)
    return distinct n1.partition_name
    """
).get_as_pl()  # type: ignore
missing_edge_partitions = all_partitions.filter(
    ~pl.col("n.partition_name").is_in([x for x in edge_partitions.to_numpy().flatten()])
).sort("n.partition_name")
for partition_name in tqdm.tqdm(missing_edge_partitions.to_numpy().flatten()):
    i += 1
    conn.execute(
        f"""
        MATCH (n1:Num{{partition_name:'{partition_name}'}}),
            (n2:Num{{partition_name:'{partition_name}'}}),
            (c:Cal{{partition_name:'{partition_name}'}})
        where n1.adsh = n2.adsh and n1.ddate = n2.ddate and n1.qtrs = n2.qtrs
        and n1.uom = n2.uom and n1.dimh = n2.dimh and n1.iprx = n2.iprx
        and n1.adsh = c.adsh
        and c.ptag = n2.tag and c.pversion = n2.version
        and c.ctag = n1.tag and c.cversion = n1.version
        MERGE (n1)-[ComponentOf{{grp: c.grp, arc: c.arc, negative: c.negative}}]->(n2)
        """
    )

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 30 (13 by maintainers)

Most upvoted comments

hi @DDoyle1066 @kollolsb can you give a try on our next dev build (0.8.3.dev7)? We had a patch for it.

Hey @ray6080 unfortunately the segfault is still occurring on 0.8.3.dev7. But I really appreciate the quick follow up on the issue. I am trying to dig into the core dumps, will keep you posted on my findings. Thanks!

Thanks! @kollolsb It might also be related to some other issues what @DDoyle1066 encountered. But thanks in advance for any help with core dumps.

Sure. I updated the files here: https://drive.google.com/drive/u/0/folders/1dl87P1Qzz0x8nAASw9A_GoGRryLL43qm. kuzu_db.py is the script to run. Just change the data_dir variable on line 231 to wherever you have unzipped the data and it should work. On my machine it took about 2 hrs/until year 2023 to hit the point where it gives up.

Hi @ray6080, the dataset and code are proprietary so I won’t be able to share them, but it appears the issue occurs under high memory pressure. The same table loads if other tables are removed. I am going try loading the graph on a instance with higher RAM to see if the issue goes away.

Hi @DDoyle1066,

We are looking at this bug. Meanwhile an alternative solution comes to my mind so I’ll post it here

COPY(
MATCH (n1:Num), (n2:Num), (c:Cal)
        where n1.adsh = n2.adsh and n1.ddate = n2.ddate and n1.qtrs = n2.qtrs
        and n1.uom = n2.uom and n1.dimh = n2.dimh and n1.iprx = n2.iprx
        and n1.adsh = c.adsh
        and n1.partition_name = '{partition_name}'
        and n2.partition_name = '{partition_name}'
        and c.partition_name = '{partition_name}'
        and c.ptag = n2.tag and c.pversion = n2.version
        and c.ctag = n1.tag and c.cversion = n1.version
        RETURN DISTINCT c.grp, c.arc, c.negative;
) TO 'tmp.csv';

And then bulk insert edges

COPY ComponentOf FROM 'tmp.csv'

From a performance point of view this should be order of magnitude faster than MERGE.