Re: [Neo4j] Unique Constaint on Index
Not sure I understand this: A consistent, but hackish, attempt to acquire a cluster-wide lock is to remove a non-existent node; what does this mean, exactly; code sample? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of etc3 Sent: Thursday, July 07, 2011 11:49 AM To: 'Neo4j user discussions' Subject: Re: [Neo4j] Unique Constaint on Index I'm new to this framework, is there an example that demonstrates removing a non-existent property and how it would be used in this context? Thanks -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Chris Gioran Sent: Thursday, July 07, 2011 11:04 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
I see, that makes sense, ty Does this code work the same for embedded single node and cluster high availability graph db's? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Michael Hunger Sent: Sunday, August 07, 2011 1:04 PM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Just from my head. tx = graphdb.beginTransaction(); try { Node lockNode = graphdb.getReferenceNode(); // or another node that is used for locking this unique index lockNode.removeProperty(__non_existent_property__); index=graphdb.index().forNodes(unique-name); Node user = index.get(name,name).getSingle(); if (user==null) { user=graphdb.createNode(); user.setProperty(name,name); index.add(user,name,name); } tx.success(); } finally { tx.finish(); } Am 07.08.2011 um 17:40 schrieb etc1: Not sure I understand this: A consistent, but hackish, attempt to acquire a cluster-wide lock is to remove a non-existent node; what does this mean, exactly; code sample? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of etc3 Sent: Thursday, July 07, 2011 11:49 AM To: 'Neo4j user discussions' Subject: Re: [Neo4j] Unique Constaint on Index I'm new to this framework, is there an example that demonstrates removing a non-existent property and how it would be used in this context? Thanks -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Chris Gioran Sent: Thursday, July 07, 2011 11:04 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
Yeah it is the same code, locks are held across the cluster. An explicit locking API will make it in one of the future versions of Neo4j, it has not been decided when that will happen. Cheers Michael Am 07.08.2011 um 19:20 schrieb etc1: I see, that makes sense, ty Does this code work the same for embedded single node and cluster high availability graph db's? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Michael Hunger Sent: Sunday, August 07, 2011 1:04 PM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Just from my head. tx = graphdb.beginTransaction(); try { Node lockNode = graphdb.getReferenceNode(); // or another node that is used for locking this unique index lockNode.removeProperty(__non_existent_property__); index=graphdb.index().forNodes(unique-name); Node user = index.get(name,name).getSingle(); if (user==null) { user=graphdb.createNode(); user.setProperty(name,name); index.add(user,name,name); } tx.success(); } finally { tx.finish(); } Am 07.08.2011 um 17:40 schrieb etc1: Not sure I understand this: A consistent, but hackish, attempt to acquire a cluster-wide lock is to remove a non-existent node; what does this mean, exactly; code sample? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of etc3 Sent: Thursday, July 07, 2011 11:49 AM To: 'Neo4j user discussions' Subject: Re: [Neo4j] Unique Constaint on Index I'm new to this framework, is there an example that demonstrates removing a non-existent property and how it would be used in this context? Thanks -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Chris Gioran Sent: Thursday, July 07, 2011 11:04 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
Started a support discussion about this: http://help.neo4j.org/discussions/questions/8-re-neo4j-unique-constaint-on-index 2011/7/14 Mattias Persson matt...@neotechnology.com Creating a support discussion for this. 2011/7/7 Michael Hunger michael.hun...@neotechnology.com I'd second that for 1.5 Michael Sent from my iBrick4 Anfang der weitergeleiteten E‑Mail: *Von:* Aseem Kishore aseem.kish...@gmail.com *Datum:* 7. Juli 2011 18:14:59 MESZ *An:* Neo4j user discussions user@lists.neo4j.org *Betreff:* *Re: [Neo4j] Unique Constaint on Index* *Antwort an:* Neo4j user discussions user@lists.neo4j.org I'll strongly +1 that having a concept of unique index values should be built into Neo4j. It's just too common of a requirement. Aseem On Thu, Jul 7, 2011 at 11:48 AM, etc3 e...@nextideapartners.com wrote: I'm new to this framework, is there an example that demonstrates removing a non-existent property and how it would be used in this context? Thanks -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Chris Gioran Sent: Thursday, July 07, 2011 11:04 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.orguser-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user -- Mattias Persson, [matt...@neotechnology.com] Hacker, Neo Technology www.neotechnology.com -- Mattias Persson, [matt...@neotechnology.com] Hacker, Neo Technology www.neotechnology.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
Marko's solution works, because you roll back the transaction once you find a duplicate entry. Another solution to this problem is to use the SortedTree index in graph-collections https://github.com/peterneubauer/graph-collections, which has a setting that makes an index unique. This component is relatively new and could use some proper testing, though. Niels From: e...@nextideapartners.com To: user@lists.neo4j.org Date: Thu, 7 Jul 2011 10:53:20 -0400 Subject: Re: [Neo4j] Unique Constaint on Index How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
You can use Transactions. Marko. How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
I'm new to this framework, is there an example that demonstrates removing a non-existent property and how it would be used in this context? Thanks -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Chris Gioran Sent: Thursday, July 07, 2011 11:04 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Unique Constaint on Index
I'll strongly +1 that having a concept of unique index values should be built into Neo4j. It's just too common of a requirement. Aseem On Thu, Jul 7, 2011 at 11:48 AM, etc3 e...@nextideapartners.com wrote: I'm new to this framework, is there an example that demonstrates removing a non-existent property and how it would be used in this context? Thanks -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Chris Gioran Sent: Thursday, July 07, 2011 11:04 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, the ability to acquire locks cluster-wide exists, albeit in an ad hoc fashion. Grabbing a write lock on the node you want to ensure is uniquely indexed will ensure that the operations are serialized across all cluster members. The most simple way to get that lock currently is the (somewhat hackish but entirely correct) removal of a non-existing property. cheers, CG On Thu, Jul 7, 2011 at 5:53 PM, etc3 e...@nextideapartners.com wrote: How do I ensure another request is not performing the same operation on another node in the cluster? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of Marko Rodriguez Sent: Thursday, July 07, 2011 10:35 AM To: Neo4j user discussions Subject: Re: [Neo4j] Unique Constaint on Index Hi, We are testing Neo4J and need to support unique emails across all users. Is this possible with the current API? You can add such a constraint when updating the indices: if(index.get('email', address).hasNext()) { throw new RuntimeException(There are two nodes that share the same email address.); } else { index.put('email', address, node); } Marko. http://markorodriguez.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user