Database constraints have changed error what is the actual behavior

25 views
Skip to first unread message

Lexia Fantasy

unread,
Apr 12, 2018, 11:34:13 PM4/12/18
to Neo4j
Hi all,

https://neo4j.com/developer/kb/explanation-of-error-database-constraints-have-changed-txid-84-after-this-transaction-txid-81-started/

I ran into this problem 
I have a constraint on label Tenant  id  is unique 

create constraint on (n:Tenant) assert n.id is unique

Now when I create a  Tenant node with with label Tenant I am trying to create a new unique constraint for another sets on nodes having labels tenantidPersons
create constraint on (n:<tenantId>Persons) assert n.ssn is unique 

I am getting the below error when I try to multiple tenants concurrently where each tenant creation try to create a constraint for its persons

org.neo4j.kernel.api.exceptions.TransactionFailureException: Database constraints have changed (txId=3937) after this transaction (txId=3936) started, which is not yet supported. Please retry your transaction to ensure all constraints are executed


As per the example the second constraint is only applicable for a person is created in a tenant. But I get the error while creating the tenant itself. 

Is this bug or expected behavior. IS the option only to retry the transaction which does not sound right.


George S


George & Sherin

unread,
Apr 12, 2018, 11:38:22 PM4/12/18
to ne...@googlegroups.com
Already present Constraint create constraint on (n:Tenant) assert n.id is unique
 each of this transaction contain  
Txn1 
create (n:Tenant {id:1234})
create constraint on (n:1234Person) assert n.ssn is unique
Txn2
create (n:Tenant {id:12356})
create constraint on (n:12356Person) assert n.ssn is unique

Txn3
create (n:Tenant {id:12345})
create constraint on (n:12345Person) assert n.ssn is unique

When I look at it the data in any of the transactions are not affected by the new constraints added in the transaction.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kamal Murthy

unread,
Apr 14, 2018, 12:37:28 AM4/14/18
to Neo4j
Hi George,

Here is my suggestion:

Create nodes: Tenant and Tenants (your tenantidPersons)

1. create constraint on (n:Tenant) assert n.id is unique

2. create constraint on (p:Tenants) assert p.ssn is unique

Data model:

-Kamal
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Apr 14, 2018, 6:52:36 PM4/14/18
to ne...@googlegroups.com
Would you mind creating a GitHub issue at github.com/neo4j/neo4j sharing your commands and error message 

You didn't share the actual queries that create the ` :12356Person`.

Michael

George & Sherin

unread,
Apr 14, 2018, 7:10:04 PM4/14/18
to ne...@googlegroups.com
Sure will do that later today or tommorow 

George & Sherin

unread,
Apr 23, 2018, 9:16:59 AM4/23/18
to ne...@googlegroups.com
Since I was using some code to generate dynamic indexes I could not extract the problematic piece easily from the unmanaged extension we have. 

I tried to create a simple utility which tries to do the same as the other code with and embedded db 
But the problem is that it times out on index creation

Meanwhile I have this question?

Is there a transaction log viewer or something which can show me what were the commands in a transaction?

org.neo4j.kernel.api.exceptions.TransactionFailureException: Database constraints have changed (txId=3937) after this transaction (txId=3936) started, which is not yet supported. Please retry your transaction to ensure all constraints are executed

In the above case basically I want to see what was the contents of the transaction 3937 .
Is there a way to do that ?

I will create a defect as well to see with the code but it does not reproduce the  original problem but stuck at a different place. 

George S

Mattias Finné

unread,
Apr 24, 2018, 2:06:59 AM4/24/18
to Neo4j
The exception is that the database schema changed from the point your "other" schema-changing transaction up to the time it wanted to commit. The exception has a transient status code, which at least from the embedded API results in a org.neo4j.graphdb.
TransientFailureException which means that it should just be retried and it'll likely succeed the next time. 
The transient nature of it means that there's a way forward and is not really a bug, it's intended behaviour.
The reason this limitation was introduced was originally for HA where it serves as a line of defence for preventing
uniqueness constraint violations from HA-slaves right when the constraint is being activated.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages