24/3 09:50 [100] - error: [analytics] Encountered error while writing analytics to data store: E11000 duplicate key error index: 0.objects.$_key_1_value_-1 dup key: { : "analytics:pageviews:month", : "1456790400000" }
...
24/3 10:10 [100] - error: [analytics] Encountered error while writing analytics to data store: E11000 duplicate key error index: 0.objects.$_key_1_value_-1 dup key: { : "analytics:pageviews:month", : "1456790400000" }
...
24/3 12:10 [100] - error: [analytics] Encountered error while writing analytics to data store: E11000 duplicate key error index: 0.objects.$_key_1_value_-1 dup key: { : "analytics:pageviews:month", : "1456790400000" }
I'm pretty sure this is because the 4 instances all tried to write the analytics data as if they were the only instance.
Yeah each instance counts its own pageviews, and every 10mins they all try to increment the same key. Pretty sure this is caused by a mongodb bug Until that is fixed we can add some code so the updates don't run at the same time.
Let me know if it happens again, the mongodb docs suggest retrying failed upserts on unique indices.
https://docs.mongodb.org/manual/reference/command/findAndModify/#upsert-and-unique-index
To prevent the creation of multiple duplicate documents, create a unique index on the name field. With the unique index in place, then the multiple findAndModify commands will exhibit one of the following behaviors:
Exactly one findAndModify successfully inserts a new document.
Zero or more findAndModify commands update the newly inserted document.
Zero or more findAndModify commands fail when they attempt to insert a duplicate. If the command fails due to a unique index constraint violation, you can retry the command. Absent a delete of the document, the retry should not fail.
I guess that's why you only see 3 errors with 4 instances, 1 of them succeeded the other 3 failed so retrying the 3 will succeed since the document is now in the database.