2019
2019 , , , . DynamoDB. , Amazon: https://aws.amazon.com/blogs/database/simulating-amazon-dynamodb-unique-constraints-using-transactions/
, , , .
, , , instance_id = 2c5d0cc8d900 ,
"instance_id # 2c5d0cc8d900". , .
+--------------------------+-------------------------+--------+----------------
| id | instance_id | attr1 | other fields...
| | | |
| (primary key) | (a non-key field, | |
| | must be unique) | |
+--------------------------+-------------------------+--------+----------------
| instance_id#2c5d0cc8d900 | | |
| a9fd702a | 2c5d0cc8d900 | qwerty | ...
, , . , , , .
, , -.
( , instanceId
- , , ).
: , .
:
+----------------------------------------------+
| Servers |
+----------------------------------------------+
| * id the hash key |
| * instanceId non-key field, must be unique|
| |
| * ... |
| * other fields |
| * ... |
+----------------------------------------------+
instanceId -:
+----------------------------------------------+
| Instance |
+----------------------------------------------+
| * instanceId the hash key |
+----------------------------------------------+
,
, instanceId , (putItem) Instance, ConditionExpression, attribute_not_exists(instanceId)
.
put ConditionalCheckFailedException
, .
, instanceId imageId,
instanceId :
+----------------------------------------------+
| Instance_Image |
+----------------------------------------------+
| * instanceId_imageId the hash key |
+----------------------------------------------+