Skip to content

Commit 0319625

Browse files
committed
Add advisory lock before creating label in merge operation
1 parent 04bde30 commit 0319625

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

src/backend/parser/cypher_clause.c

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
#include "catalog/ag_graph.h"
4343
#include "catalog/ag_label.h"
4444
#include "commands/label_commands.h"
45+
#include "common/hashfn.h"
4546
#include "parser/cypher_analyze.h"
4647
#include "parser/cypher_clause.h"
4748
#include "parser/cypher_expr.h"
4849
#include "parser/cypher_item.h"
4950
#include "parser/cypher_parse_agg.h"
5051
#include "parser/cypher_transform_entity.h"
52+
#include "storage/lock.h"
5153
#include "utils/ag_cache.h"
5254
#include "utils/ag_func.h"
5355
#include "utils/ag_guc.h"
@@ -7222,19 +7224,28 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, List **target_list,
72227224
/* check to see if the label exists, create the label entry if it does not. */
72237225
if (edge->label && !label_exists(edge->label, cpstate->graph_oid))
72247226
{
7227+
LOCKTAG tag;
7228+
uint32 key;
72257229
List *parent;
7226-
/*
7227-
* setup the default edge table as the parent table, that we
7228-
* will inherit from.
7229-
*/
7230-
rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid,
7231-
AG_DEFAULT_LABEL_EDGE);
72327230

7233-
parent = list_make1(rv);
7231+
key = hash_bytes((const unsigned char *)edge->label, strlen(edge->label));
7232+
SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key, cpstate->graph_oid, 3);
7233+
(void) LockAcquire(&tag, ExclusiveLock, false, false);
7234+
if (!label_exists(edge->label, cpstate->graph_oid))
7235+
{
7236+
/*
7237+
* setup the default edge table as the parent table, that we
7238+
* will inherit from.
7239+
*/
7240+
rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid,
7241+
AG_DEFAULT_LABEL_EDGE);
72347242

7235-
/* create the label */
7236-
create_label(cpstate->graph_name, edge->label, LABEL_TYPE_EDGE,
7237-
parent);
7243+
parent = list_make1(rv);
7244+
7245+
/* create the label */
7246+
create_label(cpstate->graph_name, edge->label, LABEL_TYPE_EDGE,
7247+
parent);
7248+
}
72387249
}
72397250

72407251
/* lock the relation of the label */
@@ -7357,20 +7368,28 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, List **target_list,
73577368
/* check to see if the label exists, create the label entry if it does not. */
73587369
if (node->label && !label_exists(node->label, cpstate->graph_oid))
73597370
{
7371+
LOCKTAG tag;
7372+
uint32 key;
73607373
List *parent;
73617374

7362-
/*
7363-
* setup the default vertex table as the parent table, that we
7364-
* will inherit from.
7365-
*/
7366-
rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid,
7367-
AG_DEFAULT_LABEL_VERTEX);
7375+
key = hash_bytes((const unsigned char *)node->label, strlen(node->label));
7376+
SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key, cpstate->graph_oid, 3);
7377+
(void) LockAcquire(&tag, ExclusiveLock, false, false);
7378+
if (!label_exists(node->label, cpstate->graph_oid))
7379+
{
7380+
/*
7381+
* setup the default vertex table as the parent table, that we
7382+
* will inherit from.
7383+
*/
7384+
rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid,
7385+
AG_DEFAULT_LABEL_VERTEX);
73687386

7369-
parent = list_make1(rv);
7387+
parent = list_make1(rv);
73707388

7371-
/* create the label */
7372-
create_label(cpstate->graph_name, node->label, LABEL_TYPE_VERTEX,
7373-
parent);
7389+
/* create the label */
7390+
create_label(cpstate->graph_name, node->label, LABEL_TYPE_VERTEX,
7391+
parent);
7392+
}
73747393
}
73757394

73767395
rel->flags |= CYPHER_TARGET_NODE_FLAG_INSERT;

0 commit comments

Comments
 (0)