Skip to content

Commit 29e9906

Browse files
committed
Add helpful messages to the VLE subsystem (apache#1742)
Added helpful messaging to the VLE subsystem. These changes are due to issue 365 where there was an issue with the VLE that turned out to not be with the VLE. Basically, there is a way, apparently, to have a malformed edge or possibly one not fully removed. When the VLE subsystem does its load on the graph, it would error out on these edges as this was considered to be a potential data corruption issue. The changes added are to report and ignore these edges. Reporting them, so as to allow the user to take corrective action by removing them. Ignoring them, as they are likely not relevant to the query. Basically, leaving it up to the user to decide. No impact to current regression tests.
1 parent a69e5a2 commit 29e9906

File tree

1 file changed

+72
-28
lines changed

1 file changed

+72
-28
lines changed

src/backend/utils/adt/age_global_graph.c

+72-28
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static bool insert_edge(GRAPH_global_context *ggctx, graphid edge_id,
101101
graphid end_vertex_id, Oid edge_label_table_oid);
102102
static bool insert_vertex_edge(GRAPH_global_context *ggctx,
103103
graphid start_vertex_id, graphid end_vertex_id,
104-
graphid edge_id);
104+
graphid edge_id, char *edge_label_name);
105105
static bool insert_vertex_entry(GRAPH_global_context *ggctx, graphid vertex_id,
106106
Oid vertex_label_table_oid,
107107
Datum vertex_properties);
@@ -330,10 +330,11 @@ static bool insert_vertex_entry(GRAPH_global_context *ggctx, graphid vertex_id,
330330
*/
331331
static bool insert_vertex_edge(GRAPH_global_context *ggctx,
332332
graphid start_vertex_id, graphid end_vertex_id,
333-
graphid edge_id)
333+
graphid edge_id, char *edge_label_name)
334334
{
335335
vertex_entry *value = NULL;
336-
bool found = false;
336+
bool start_found = false;
337+
bool end_found = false;
337338
bool is_selfloop = false;
338339

339340
/* is it a self loop */
@@ -342,39 +343,70 @@ static bool insert_vertex_edge(GRAPH_global_context *ggctx,
342343
/* search for the start vertex of the edge */
343344
value = (vertex_entry *)hash_search(ggctx->vertex_hashtable,
344345
(void *)&start_vertex_id, HASH_FIND,
345-
&found);
346-
/* vertices were preloaded so it must be there */
347-
Assert(found);
348-
if (!found)
349-
{
350-
return found;
351-
}
346+
&start_found);
352347

353-
/* if it is a self loop, add the edge to edges_self and we're done */
354-
if (is_selfloop)
348+
/*
349+
* If we found the start_vertex_id and it is a self loop, add the edge to
350+
* edges_self and we're done
351+
*/
352+
if (start_found && is_selfloop)
355353
{
356354
value->edges_self = append_graphid(value->edges_self, edge_id);
357-
return found;
355+
return true;
356+
}
357+
/*
358+
* Otherwise, if we found the start_vertex_id add the edge to the edges_out
359+
* list of the start vertex
360+
*/
361+
else if (start_found)
362+
{
363+
value->edges_out = append_graphid(value->edges_out, edge_id);
358364
}
359-
360-
/* add the edge to the edges_out list of the start vertex */
361-
value->edges_out = append_graphid(value->edges_out, edge_id);
362365

363366
/* search for the end vertex of the edge */
364367
value = (vertex_entry *)hash_search(ggctx->vertex_hashtable,
365368
(void *)&end_vertex_id, HASH_FIND,
366-
&found);
367-
/* vertices were preloaded so it must be there */
368-
Assert(found);
369-
if (!found)
369+
&end_found);
370+
371+
/*
372+
* If we found the start_vertex_id and the end_vertex_id add the edge to the
373+
* edges_in list of the end vertex
374+
*/
375+
if (start_found && end_found)
370376
{
371-
return found;
377+
value->edges_in = append_graphid(value->edges_in, edge_id);
378+
return true;
379+
}
380+
/*
381+
* Otherwise we need to generate the appropriate warning message about the
382+
* dangling edge that we found.
383+
*/
384+
else if (!start_found && end_found)
385+
{
386+
ereport(WARNING,
387+
(errcode(ERRCODE_DATA_EXCEPTION),
388+
errmsg("edge: [id: %ld, start: %ld, end: %ld, label: %s] %s",
389+
edge_id, start_vertex_id, end_vertex_id,
390+
edge_label_name, "start vertex not found")));
391+
}
392+
else if (start_found && !end_found)
393+
{
394+
ereport(WARNING,
395+
(errcode(ERRCODE_DATA_EXCEPTION),
396+
errmsg("edge: [id: %ld, start: %ld, end: %ld, label: %s] %s",
397+
edge_id, start_vertex_id, end_vertex_id,
398+
edge_label_name, "end vertex not found")));
399+
}
400+
else
401+
{
402+
ereport(WARNING,
403+
(errcode(ERRCODE_DATA_EXCEPTION),
404+
errmsg("edge: [id: %ld, start: %ld, end: %ld, label: %s] %s",
405+
edge_id, start_vertex_id, end_vertex_id,
406+
edge_label_name, "start and end vertices not found")));
372407
}
373408

374-
/* add the edge to the edges_in list of the end vertex */
375-
value->edges_in = append_graphid(value->edges_in, edge_id);
376-
377-
return found;
409+
return false;
378410
}
379411

380412
/* helper routine to load all vertices into the GRAPH global vertex hashtable */
@@ -430,7 +462,12 @@ static void load_vertex_hashtable(GRAPH_global_context *ggctx)
430462
bool inserted = false;
431463

432464
/* something is wrong if this isn't true */
465+
if (!HeapTupleIsValid(tuple))
466+
{
467+
elog(ERROR, "load_vertex_hashtable: !HeapTupleIsValid");
468+
}
433469
Assert(HeapTupleIsValid(tuple));
470+
434471
/* get the vertex id */
435472
vertex_id = DatumGetInt64(column_get_datum(tupdesc, tuple, 0, "id",
436473
GRAPHIDOID, true));
@@ -533,7 +570,12 @@ static void load_edge_hashtable(GRAPH_global_context *ggctx)
533570
bool inserted = false;
534571

535572
/* something is wrong if this isn't true */
573+
if (!HeapTupleIsValid(tuple))
574+
{
575+
elog(ERROR, "load_edge_hashtable: !HeapTupleIsValid");
576+
}
536577
Assert(HeapTupleIsValid(tuple));
578+
537579
/* get the edge id */
538580
edge_id = DatumGetInt64(column_get_datum(tupdesc, tuple, 0, "id",
539581
GRAPHIDOID, true));
@@ -568,11 +610,13 @@ static void load_edge_hashtable(GRAPH_global_context *ggctx)
568610

569611
/* insert the edge into the start and end vertices edge lists */
570612
inserted = insert_vertex_edge(ggctx, edge_vertex_start_id,
571-
edge_vertex_end_id, edge_id);
572-
/* this insert must not fail */
613+
edge_vertex_end_id, edge_id,
614+
edge_label_name);
573615
if (!inserted)
574616
{
575-
elog(ERROR, "insert_vertex_edge: failed to insert");
617+
ereport(WARNING,
618+
(errcode(ERRCODE_DATA_EXCEPTION),
619+
errmsg("ignored malformed or dangling edge")));
576620
}
577621
}
578622

0 commit comments

Comments
 (0)