SQLSTATE: Integrity constraint violation: 1062 Duplicate entry '166-done' for key 'PRIMARY'
I don't know if this is the root cause or a contributing factor, but loadNextIdArchive() does not auto-increment. (klando's pgsql port uses a sequence object here. However, if archiving should fail, it results in an orphaned row.)
The quick fix is to add the IGNORE (discard) keyword to the INSERT.
Ideally, Multiple concurrent archiving processes should be avoidable...
Multiple concurrent archiving could be avoidable by a database-level lock, or by a simple file based lock.
However, agreed with you that Piwik should not fail while this lock system is not implemented. agreed on the quick fix using IGNORE (I believe it won't have side effects).
(In ) refs #987 - add IGNORE keyword (MySQL-ism)
closing.. we can create a ticket later for implementing a lock mechanism