Inconsistent data owing to non transactional writes to database. #469
Description
The applications in the pipeline that reduces usage, generates multiple output docs. One of the output docs is the duplicate detection doc and the others are the accumulated ones. With multiple DB partitions, the partition to which the every doc is written is based on the id of the doc. If one of these writes fail, the docs that written to the DB will cause the entity to be in inconsistent state.
For example, if we start the pipeline with the following configuration
export SAMPLING=86400000
export SLACK=5D
export DB_PARTITIONS=4
npm start
and submit the usage for November 30th on December 3d
{
"start": 1480464000000,
"end": 1480464000000,
"organization_id": "us-south:a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27",
"space_id": "aaeae239-f3f8-483c-9dd0-de5d41c38b6a",
"consumer_id": "app:bbeae239-f3f8-483c-9dd0-de6781c38bab",
"resource_id": "object-storage",
"plan_id": "basic",
"resource_instance_id": "0b39fa70-a65f-4183-bae8-385633ca5c87",
"measured_usage": [
{
"measure": "storage",
"quantity": 1073741824
},
{
"measure": "light_api_calls",
"quantity": 1000
},
{
"measure": "heavy_api_calls",
"quantity": 100
}
]
}
the aggregator will produce 3 documents with the following ids
-
k/us-south:a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27/t/0001480723200000
(written to database abacus-aggregator-aggregated-usage-2-201612) -
k/us-south:a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27/aaeae239-f3f8-483c-9dd0-de5d41c38b6a/app:bbeae239-f3f8-483c-9dd0-de6781c38bab/t/0001480723200000
(written to database abacus-aggregator-aggregated-usage-3-201612) -
k/us-south:a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27/0b39fa70-a65f-4183-bae8-385633ca5c87/app:bbeae239-f3f8-483c-9dd0-de6781c38bab/basic/basic-object-storage/object-rating-plan/object-pricing-basic/t/0001480464000000/0001480464000000
(written to database abacus-aggregator-aggregated-usage-3-201611)
If CouchDB is used as the backend database, the writes happen in 3 different HTTP requests. If some writes are successful and others aren't then this will result in inconsistent accumulated values.