Skip to content

Commit

Permalink
[ju7btyJy] APOC UUID Install Failing in Cluster (#3484) (#3510)
Browse files Browse the repository at this point in the history
* [ju7btyJy] APOC UUID Install Failing in Cluster (#3484)

* [ju7btyJy] removed unused imports

* [ju7btyJy] Fixes for 5.x
  • Loading branch information
vga91 authored Mar 29, 2023
1 parent 0b43ecd commit 44fe779
Show file tree
Hide file tree
Showing 42 changed files with 1,923 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
¦signature
¦apoc.uuid.drop(label :: STRING?, databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.dropAll(databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.install(label :: STRING?, config = {} :: MAP?) :: (batchComputationResult :: MAP?, label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.list() :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.remove(label :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.removeAll() :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.setup(label :: STRING?, databaseName = neo4j :: STRING?, config = {} :: MAP?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
¦apoc.uuid.show(databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
¦Qualified Name¦Type
|xref::overview/apoc.uuid/apoc.uuid.adoc[apoc.uuid.drop icon:book[]]

CALL apoc.uuid.drop(databaseName, label) yield label, installed, properties \| eventually removes previously added UUID handler and returns uuid information
|label:procedure[]
|xref::overview/apoc.uuid/apoc.uuid.adoc[apoc.uuid.dropAll icon:book[]]

CALL apoc.uuid.dropAll(databaseName) yield label, installed, properties \| eventually removes all previously added UUID handlers and returns uuids' information
|label:procedure[]

|xref::overview/apoc.uuid/apoc.uuid.adoc[apoc.uuid.install icon:book[]]

CALL apoc.uuid.install(label, {addToExistingNodes: true/false, uuidProperty: 'uuid'}) yield label, installed, properties, batchComputationResult \| it will add the uuid transaction handler
Expand All @@ -16,3 +25,10 @@ CALL apoc.uuid.remove(label) yield label, installed, properties \| remove previo

CALL apoc.uuid.removeAll() yield label, installed, properties \| it removes all previously added uuid handlers and returns uuids information. All the existing uuid properties are left as-is
|label:procedure[]

CALL apoc.uuid.setup(databaseName, label, $config) \| eventually adds the uuid transaction handler for the provided `label` and `uuidProperty`, in case the UUID handler is already present it will be replaced by the new one
|label:procedure[]
|xref::overview/apoc.uuid/apoc.uuid.adoc[apoc.uuid.show icon:book[]]

CALL apoc.uuid.show(databaseName) \| it lists all eventually installed UUID handler for a database
|label:procedure[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
¦signature
¦apoc.uuid.drop(label :: STRING?, databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
¦xref::overview/apoc.uuid/apoc.uuid.drop.adoc[apoc.uuid.drop icon:book[]] +

`CALL apoc.uuid.drop(databaseName, label) yield label, installed, properties | eventually removes previously added UUID handler and returns uuid information`
¦label:procedure[]
¦label:apoc-extended[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
¦signature
¦apoc.uuid.dropAll(databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
¦xref::overview/apoc.uuid/apoc.uuid.dropAll.adoc[apoc.uuid.dropAll icon:book[]] +

`CALL apoc.uuid.dropAll(databaseName) yield label, installed, properties | eventually removes all previously added UUID handlers and returns uuids' information`
¦label:procedure[]
¦label:apoc-extended[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
¦signature
¦apoc.uuid.setup(label :: STRING?, databaseName = neo4j :: STRING?, config = {} :: MAP?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
¦xref::overview/apoc.uuid/apoc.uuid.setup.adoc[apoc.uuid.setup icon:book[]] +

`CALL apoc.uuid.setup(databaseName, label, $config) | eventually adds the uuid transaction handler for the provided `label` and `uuidProperty`, in case the UUID handler is already present it will be replaced by the new one`
¦label:procedure[]
¦label:apoc-extended[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
¦signature
¦apoc.uuid.show(databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
¦xref::overview/apoc.uuid/apoc.uuid.show.adoc[apoc.uuid.show icon:book[]] +

`CALL apoc.uuid.show(databaseName) | it lists all eventually installed UUID handler for a database`
¦label:procedure[]
¦label:apoc-extended[]
108 changes: 76 additions & 32 deletions docs/asciidoc/modules/ROOT/pages/graph-updates/uuid.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,82 +17,126 @@ There are also procedures that handle automatic adding of UUID properties, via t
The UUID handler is a transaction event handler that automatically adds the UUID property to a provided label and for the provided property name.
Please check the following documentation to an in-depth description.


include::partial$systemdbonly.note.adoc[]


[WARNING]
====
Installing, updating or removing an automatic UUID is an eventually consistent operation.
Therefore, they are not immediately added/updated/removed,
but they have a refresh rate handled by the Apoc configuration `apoc.uuid.refresh=<MILLISECONDS>`
====

Enable `apoc.uuid.enabled=true` or `apoc.uuid.enabled.[DATABASE_NAME]=true` in `$NEO4J_HOME/config/apoc.conf` first.

Configuration value `apoc.uuid.format` let you choose between different UUID encoding methods: `hex` (default option) or `base64`.

[separator=¦,opts=header,cols="5,1m,1m"]
|===
¦Qualified Name¦Type¦Release
include::example$generated-documentation/apoc.uuid.install.adoc[]
include::example$generated-documentation/apoc.uuid.remove.adoc[]
include::example$generated-documentation/apoc.uuid.removeAll.adoc[]
include::example$generated-documentation/apoc.uuid.setup.adoc[]
include::example$generated-documentation/apoc.uuid.drop.adoc[]
include::example$generated-documentation/apoc.uuid.dropAll.adoc[]
include::example$generated-documentation/apoc.uuid.list.adoc[]
|===

=== Config

|===
|*config* | *type* | *description*
|addToExistingNodes | Boolean (default: true) | when installed, for the label provided, adds the UUID to the nodes already existing in your graph
|uuidProperty | String (default: uuid) | the name of the UUID field
include::example$generated-documentation/apoc.uuid.show.adoc[]
|===


=== UUID Examples

First create a Constraint for the Label and the Property, if you try to add a `uuid` an error occured.
==== Create an Automatic UUID

This examples assume that we are on the `neo4j` database,
and we want to create the automatic UUIDs in that database.

[source,cypher]
----
CREATE CONSTRAINT FOR (person:Person)
REQUIRE person.uuid IS UNIQUE
----

Add the `uuid`:

[source,cypher]
----
CALL apoc.uuid.install('Person')
CALL apoc.uuid.setup('Person')
YIELD label, installed, properties
RETURN label, installed, properties
----

Note that the `apoc.uuid.setup`, as well as the `apoc.uuid.drop`, `apoc.uuid.dropAll`,
have to be executed in the system database.

The result is:

[opts="header",cols="1,1,1,1"]
[opts="header",cols="1,1,1"]
|===
| label | installed | properties | batchComputationResult
| "Person" | true | {uuidProperty -> "uuid", addToExistingNodes -> true} | {wasTerminated -> false, count -> 10, batches -> 1, successes -> 1, failedOps -> 0, timeTaken -> 0, operationErrors -> {}, failedBatches -> 0}
| label | installed | properties
| "Person" | true | `{uuidProperty -> "uuid", addToExistingNodes -> true}`
|===

The result is Node Person that has 2 properties:
[Note]
====
When an `apoc.uuid.setup` procedure is executed,
a query to create a constraint, if not exists, is automatically executed (also in this case, after a time defined by the `apoc.uuid.refresh` config):
`CREATE CONSTRAINT IF NOT EXISTS FOR (n:<label>) REQUIRE (n.<uuidProperty>) IS UNIQUE`
====


It is then possible to execute the following query, after a time defined by the configuration `apoc.uuid.refresh`:
[source,cypher]
----
CREATE (n:Person {name: 'Daniel'})-[:Work]->(:Company {name: 'Neo4j'})
----

and the result will be a node `:Person` with 2 properties:

image::apoc.uuid.result.png[width=800]

Get all the uuid installed, call the procedure as:
If the default configuration `addToExistingNodes: true` is chosen,
in background (via the `apoc.periodic.iterate` procedure) all existing nodes will also be populated with a property with uuid values.
and, when the execution is finished,
a log with the query result like the following will be printed:
```
Result of batch computation obtained from existing nodes for UUID handler with label `MyLabel`:
{failedParams={}, committedOperations=1, batch={total=10, committed=10, failed=0, errors={}}, wasTerminated=false, batches=1, timeTaken=0, retries=0, errorMessages={}, total=1, operations={total=10, committed=10, failed=0, errors={}}, failedOperations=0, updateStatistics={nodesDeleted=0, labelsAdded=0, relationshipsCreated=0, nodesCreated=0, propertiesSet=1, relationshipsDeleted=0, labelsRemoved=0}, failedBatches=0}
```


==== List of Automatic UUIDs

It is possible to return the full list of automatic UUIDS in a database. For example, if the UUID in the following query is created:
[source,cypher]
----
CALL apoc.uuid.list()
YIELD label, installed, properties
RETURN label, installed, properties
CALL apoc.uuid.setup('TestShow')
----

The result is:
It is then possible to run (also in this case, after a time defined by the configuration `apoc.uuid.refresh`):

[opts="header",cols="1,1,1"]
[source,cypher]
----
CALL apoc.uuid.show()
----

.Results

[opts="header",cols="1,1,1,1"]
|===
| label | installed | properties
| "Person" | true | {uuidProperty -> "uuid", addToExistingNodes -> true}
| "Person" | true | {uuidProperty -> "uuid", addToExistingNodes -> true} | {wasTerminated -> false, count -> 10, batches -> 1, successes -> 1, failedOps -> 0, timeTaken -> 0, operationErrors -> {}, failedBatches -> 0}
|===


Remove the uuid installed call the procedure as:
[WARNING]
====
Please note that, since the auto-UUID operations are eventually consistent (based on the `apoc.uuid.refresh` configuration),
the `apoc.uuid.show` may return some UUIDs not yet added/updated/removed.
To get the list of all of currently installed UUIDs,
use the xref::overview/apoc.uuid/apoc.uuid.list.adoc[apoc.uuid.list]
====


==== Remove Automatic UUIDs

[source,cypher]
----
CALL apoc.uuid.remove('Person')
CALL apoc.uuid.drop('Person')
YIELD label, installed, properties
RETURN label, installed, properties
----
Expand All @@ -110,7 +154,7 @@ You can also remove all the uuid installed call the procedure as:

[source,cypher]
----
CALL apoc.uuid.removeAll()
CALL apoc.uuid.dropAll()
YIELD label, installed, properties
RETURN label, installed, properties
----
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////
This file is generated by DocsTest, so don't change it!
////

= apoc.uuid.drop
:description: This section contains reference documentation for the apoc.uuid.drop procedure.

label:procedure[] label:apoc-extended[]

[.emphasis]
CALL apoc.uuid.drop(databaseName, label) yield label, installed, properties | eventually removes previously added UUID handler and returns uuid information

== Signature

[source]
----
apoc.uuid.drop(label :: STRING?, databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
----

== Input parameters
[.procedures, opts=header]
|===
| Name | Type | Default
|label|STRING?|null
|databaseName|STRING?|neo4j
|===

== Output parameters
[.procedures, opts=header]
|===
| Name | Type
|label|STRING?
|installed|BOOLEAN?
|properties|MAP?
|===

== Enable automatic UUIDs
include::partial$uuids.adoc[]

xref::graph-updates/uuid.adoc[More documentation of apoc.uuid.drop,role=more information]

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
////
This file is generated by DocsTest, so don't change it!
////

= apoc.uuid.dropAll
:description: This section contains reference documentation for the apoc.uuid.dropAll procedure.

label:procedure[] label:apoc-extended[]

[.emphasis]
CALL apoc.uuid.dropAll(databaseName) yield label, installed, properties | eventually removes all previously added UUID handlers and returns uuids' information

== Signature

[source]
----
apoc.uuid.dropAll(databaseName = neo4j :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
----

== Input parameters
[.procedures, opts=header]
|===
| Name | Type | Default
|databaseName|STRING?|neo4j
|===

== Output parameters
[.procedures, opts=header]
|===
| Name | Type
|label|STRING?
|installed|BOOLEAN?
|properties|MAP?
|===

== Enable automatic UUIDs
include::partial$uuids.adoc[]

xref::graph-updates/uuid.adoc[More documentation of apoc.uuid.dropAll,role=more information]

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This file is generated by DocsTest, so don't change it!
= apoc.uuid.install
:description: This section contains reference documentation for the apoc.uuid.install procedure.

label:procedure[] label:apoc-extended[]
label:procedure[] label:apoc-extended[] label:deprecated[]

[.emphasis]
CALL apoc.uuid.install(label, {addToExistingNodes: true/false, uuidProperty: 'uuid'}) yield label, installed, properties, batchComputationResult | it will add the uuid transaction handler
Expand All @@ -18,6 +18,8 @@ for the provided `label` and `uuidProperty`, in case the UUID handler is already
apoc.uuid.install(label :: STRING?, config = {} :: MAP?) :: (batchComputationResult :: MAP?, label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
----

include::partial$uuid/deprecated.adoc[]

[WARNING]
====
This procedure is not intended to be used in a cluster environment, and may act unpredictably.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This file is generated by DocsTest, so don't change it!
= apoc.uuid.remove
:description: This section contains reference documentation for the apoc.uuid.remove procedure.

label:procedure[] label:apoc-extended[]
label:procedure[] label:apoc-extended[] label:deprecated[]

[.emphasis]
CALL apoc.uuid.remove(label) yield label, installed, properties | remove previously added uuid handler and returns uuid information. All the existing uuid properties are left as-is
Expand All @@ -17,6 +17,8 @@ CALL apoc.uuid.remove(label) yield label, installed, properties | remove previou
apoc.uuid.remove(label :: STRING?) :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
----

include::partial$uuid/deprecated.adoc[]

[WARNING]
====
This procedure is not intended to be used in a cluster environment, and may act unpredictably.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This file is generated by DocsTest, so don't change it!
= apoc.uuid.removeAll
:description: This section contains reference documentation for the apoc.uuid.removeAll procedure.

label:procedure[] label:apoc-extended[]
label:procedure[] label:apoc-extended[] label:deprecated[]

[.emphasis]
CALL apoc.uuid.removeAll() yield label, installed, properties | it removes all previously added uuid handlers and returns uuids information. All the existing uuid properties are left as-is
Expand All @@ -17,6 +17,8 @@ CALL apoc.uuid.removeAll() yield label, installed, properties | it removes all p
apoc.uuid.removeAll() :: (label :: STRING?, installed :: BOOLEAN?, properties :: MAP?)
----

include::partial$uuid/deprecated.adoc[]

[WARNING]
====
This procedure is not intended to be used in a cluster environment, and may act unpredictably.
Expand Down
Loading

0 comments on commit 44fe779

Please sign in to comment.