Skip to content

Commit

Permalink
Fix global graph hashtable insert messaging
Browse files Browse the repository at this point in the history
Fixed the global graph hashtable routines to error out, instead of
crashing due to an assert, for duplicate ids.
  • Loading branch information
jrgemignani committed Apr 19, 2022
1 parent 10bfd02 commit 7340abb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/backend/utils/adt/age_global_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static bool insert_edge(GRAPH_global_context *ggctx, graphid edge_id,

/*
* Helper function to insert an entire vertex into the current GRAPH global
* vertex hashtable.
* vertex hashtable. It will return false if there is a duplicate.
*/
static bool insert_vertex_entry(GRAPH_global_context *ggctx, graphid vertex_id,
Oid vertex_label_table_oid,
Expand All @@ -270,8 +270,12 @@ static bool insert_vertex_entry(GRAPH_global_context *ggctx, graphid vertex_id,
/* search for the vertex */
ve = (vertex_entry *)hash_search(ggctx->vertex_hashtable,
(void *)&vertex_id, HASH_ENTER, &found);
/* we should never have duplicates */
Assert(!found);

/* we should never have duplicates, return false */
if (found)
{
return false;
}

/* again, MemSet may not be needed here */
MemSet(ve, 0, sizeof(vertex_entry));
Expand Down Expand Up @@ -417,10 +421,11 @@ static void load_vertex_hashtable(GRAPH_global_context *ggctx)
inserted = insert_vertex_entry(ggctx, vertex_id,
vertex_label_table_oid,
vertex_properties);
/* this insert must not fail */

/* this insert must not fail, it means there is a duplicate */
if (!inserted)
{
elog(ERROR, "insert_vertex_entry: failed to insert");
elog(ERROR, "insert_vertex_entry: failed due to duplicate");
}
}

Expand Down Expand Up @@ -528,6 +533,7 @@ static void load_edge_hashtable(GRAPH_global_context *ggctx)
inserted = insert_edge(ggctx, edge_id, edge_properties,
edge_vertex_start_id, edge_vertex_end_id,
edge_label_table_oid);

/* this insert must not fail */
if (!inserted)
{
Expand Down

0 comments on commit 7340abb

Please sign in to comment.