-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
documenation: unique constraint #3152
Comments
Duplicate #3059 |
Not sure how this issue is a duplicate of #3059 but to answer OP's question, the unique constraint is preserved and enforced because commits do not really happen at the same time. Each commit sends a request to the zero server and zero uses the RAFT algorithm (https://raft.github.io) to achieve consensus on what values should be stored. So after the first commit has been agreed to, the second transaction will fail because there's a consensus that another value already exists. I don't think the documentation is a good place for this kind of explanation so I won't add it there. |
Correct me if I am wrong. You are saying:
2a. DGraph can handle only 1 mutation at a time in ENTIRE cluster irrespective of how big the data set is and how many servers in cluster. OR I can see how 2a prevents unique constraint violations (albeit inefficiently). If 2b is correct, I can't see how it prevents unique constraints. If I attempt to create 2 nodes with a unique predicate, that aren't connected to another node, then how does DGraph recognise that I intend for it to be unique? |
I think unique keys are important. There should a separate section below "upsert" section to explain how to artificially create a unique key. |
This is why I called it dupe and closed. This is a new feature. Please check #3059 and let me know if that's what you're hoping to do. I would call it |
In #3059: It definitely seems to be on the right track - and perhaps can be used for my use case. Either way, with regard to 2a or 2b, which is correct? |
I checked the code and it seems like the proposals are processed in a linear manner. However, this means dgraph can process one proposal at a time, not one mutation at a time. Since a transaction can have multiple mutations, the effective performance of Dgraph is much faster than what this limitation would suggest. |
There should be more details on how to artificially create a unique constraint.
In the docs, the closest I can see is in the upsert section under conflicts.
In my use case, I don't want to upsert. I just want to insert if the email doesn't exist. Otherwise failed.
From the upsert section this is what I infer for my use-case:
It would be good if the docs explains how this is meant to work if 2 requests are occur at the same time.
Both requests do Step 1.
Both requests do Step 2 -> No node with email is found so both proceed to Step 3.
Both requests do Step 3 => Now there are 2 exact nodes violating the "unique constraint".
I don't understand from the "upsert" docs, how DGraph with transactions is meant to prevent that from happening. Could the docs explain what is going on.
The text was updated successfully, but these errors were encountered: