Atomic counters documentation missed
Bug #1374514 reported by
Ilya Sviridov
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MagnetoDB |
Fix Committed
|
Medium
|
Todd Gehrke |
Bug Description
The atomic counter functionality is not documented
Changed in magnetodb: | |
milestone: | juno-rc1 → kilo-1 |
Changed in magnetodb: | |
status: | New → Triaged |
Changed in magnetodb: | |
milestone: | kilo-1 → kilo-2 |
Changed in magnetodb: | |
milestone: | kilo-2 → kilo-3 |
Changed in magnetodb: | |
milestone: | kilo-3 → 2015.1 |
Changed in magnetodb: | |
milestone: | 2015.1 → l-1 |
Changed in magnetodb: | |
assignee: | nobody → Todd Gehrke (tgehrke) |
Changed in magnetodb: | |
status: | Triaged → Fix Committed |
To post a comment you must log in.
Draft
Atomic counters is a part of update_item
URL: }:{{PORT} }/v1/{{ PROJECT_ ID}}/data/ tables/ {{TABLE} }/update_ item
http://{{HOST}
Spec: /wiki.openstack .org/wiki/ MagnetoDB/ specs/data- api#Updateitem
https:/
User can specify action to perform on the item.
If action is "ADD" then MagnetoDB guarantees that operation will be performed
atomically. Sets and numbers are only valid types for ADD action.
If attribute type is number then this attribute can be used as atomic
counter.
Some examples with explanations:
1. Create table for forum threads. We have 4 attributes: name, subject, tags
and views count (we want to use it like atomic counter)
Request:
{ definitions" : [
"attribute _name": "ForumName",
"attribute _type": "S"
"attribute _name": "Subject",
"attribute _type": "S"
"attribute _name": "Tags",
"attribute _type": "SS"
"attribute _name": "ViewsCount",
"attribute _type": "N"
"attribute _name": "ForumName",
"key_ type": "HASH"
"attribute _name": "Subject",
"key_ type": "RANGE"
"table_name": "Thread",
"attribute_
{
},
{
},
{
},
{
}
],
"key_schema": [
{
},
{
}
]
}
2. Put new item into Thread table.
Request:
{ LastPostedBy" : {"S": "<email address hidden>"},
"item": {
"ForumName": {"S": "MagnetoDB"},
"Subject": {"S": "How do I delete an item?"},
"
"Tags": {"SS": ["Update", "Multiple Items"]},
"ViewsCount": {"N": "0"}
}
}
If we try to query an item now we'll see that ViewsCount = 0 and
Tags = ["Update", "Multiple Items"].
3. Use update_item to update Tags
Request:
{
"ForumName" : { updates" : {
"action" : "ADD",
"key": {
"S": "MagnetoDB"
},
"Subject": {
"S": "How do I delete an item?"
}
},
"attribute_
"Tags": {
"value": {
"SS": ["HelpMe"]
}
}
}
}
If we try to query an item now we'll see that ViewsCount = 0 and
Tags = ["Update", "Multiple Items", "HelpMe"]
4. Atomic counters
Different users looking the thread and we need to update ViewsCount
Request:
{
"ForumName" : { updates" : {
"ViewsCount" : {
"action" : "ADD",
"key": {
"S": "MagnetoDB"
},
"Subject": {
"S": "How do I delete an item?"
}
},
"attribute_
"value": {
"N": "1"
}
}
}
}
Any time when different users try to query our item, they shell see same value
of ViewsCount. After our request ViewsCount should be 1.
Different users can update this value simultaneously.