Avoid ID clashes#75
Conversation
|
An ID clash is indeed an extreme issue but perhaps we can solve it differently by constructing an |
|
There exists a sqlite built-in function |
9c6821b to
0685193
Compare
cb5a690 to
6c7c60d
Compare
yes, i think this is the easiest and cleanest solution:
|
Currently the the ID for a new paste is randomly generated in the caller of the database insert() function. Then the insert() function tries to insert a new row into the database with that passed ID. There can however already exists a paste in the database with the same ID leading to an insert failure, due to a constraint violation due to the PRIMARY KEY attribute. Checking prior the the INSERT via a SELECT query would open the window for a race condition. A failure to push a new paste is quite severe, since the user might have spent some some to format the input. Generate the ID in a loop inside, until the INSERT succeeds.
| && extended_code == 1555 | ||
| && counter < 10 => | ||
| { | ||
| /* Retry if ID is already existent */ |
There was a problem hiding this comment.
Please change to standard Rust comments with //.
| }, | ||
| Some(ref _message), | ||
| )) if code == rusqlite::ErrorCode::ConstraintViolation | ||
| && extended_code == 1555 |
There was a problem hiding this comment.
Can you add a link to some documentation?
Currently the the ID for a new paste is randomly generated in the caller of the database insert() function. Then the insert() function tries to insert a new row into the database with that passed ID. There can however already exists a paste in the database with the same ID leading to an insert failure, due to a constraint violation due to the PRIMARY KEY attribute. Checking prior the the INSERT via a SELECT query would open the window for a race condition.
A failure to push a new paste is quite severe, since the user might have spent some some to format the input.
Generate the ID in a loop inside, until the INSERT succeeds.