The zaqar.storage.mongodb.claims
module¶
Implements the MongoDB storage controller for claims.
- Field Mappings:
- In order to reduce the disk / memory space used, field names will be, most of the time, the first letter of their long name.
-
class
ClaimController
(driver)¶ Bases:
zaqar.storage.base.Claim
Implements claim resource operations using MongoDB.
No dedicated collection is being used for claims.
Claims are created in the messages collection and live within messages, that is, in the c field.
This implementation certainly uses more space on disk but reduces the number of queries to be executed and the time needed to retrieve claims and claimed messages.
As for the memory usage, this implementation requires less memory since a single index is required. The index is a compound index between the claim id and it’s expiration timestamp.
-
create
(*args, **kwargs)¶ Creates a claim.
This implementation was done in a best-effort fashion. In order to create a claim we need to get a list of messages that can be claimed. Once we have that list we execute a query filtering by the ids returned by the previous query.
Since there’s a lot of space for race conditions here, we’ll check if the number of updated records is equal to the max number of messages to claim. If the number of updated messages is lower than limit we’ll try to claim the remaining number of messages.
This 2 queries are required because there’s no way, as for the time being, to execute an update on a limited number of records.
-
delete
(*args, **kwargs)¶
-
get
(*args, **kwargs)¶
-
update
(*args, **kwargs)¶
-