The usual way to check for a missing string and insert it atomically?

I have a web application. The form processing flow in it is as follows:

  • Validate
  • List errors or Insert / update data

In this particular scenario, I am developing a user registration process, but I am trying to find a common solution for all types of form databases to check for the availability of a unique value in the database table.

In this user registration, the login must be unique. At the verification stage, the application checks its availability in the database table and, if available, inserts a row. There are other fields that also need to be checked, such as password confirmation and password. All validation is performed once in a single HTTP request.

The problem is that I can’t be sure that after , the application is checked for its availability, it is not executed by another user in the parallel process before . The first user process inserts it. I understand that there is very little chance that two users enter the same login in the same millisecond, but someday this can happen with a different form in which several thousand users enter data into any form at the same time.

If the check has already passed, the user should not see an error message stating that his username is already registered.

, , , , ​​ HTTP-. , , .

, , . . . ?


. , . , , , , , .

, , . :

, - . , , , , .

HTTP- , , .

. . :

  • ,
  • ,

, . , , ; .

, try-and-catch-the-exception , . , . , , , - .

, , . , , , .

+3
3

: . , - . , .

Try/catch - , . -, . , , , . , . , , , try/catch!

, , , . "" , - . .

, , . SELECT...FOR UPDATE , . try/catch, try/catch. , , , , .

+1

, " " , 1 , , .

- , , . , - , , .

0

AvailableUsers, : ID, ClaimedUserName, TimeStamp, SessionID .

, , .

0
source

Source: https://habr.com/ru/post/1730156/


All Articles