Kinto / kinto

A generic JSON document store with sharing and synchronisation capabilities.
http://docs.kinto-storage.org/
Other
4.33k stars 421 forks source link

Postgresql Storage Backend Integrity Error #1197

Open Natim opened 7 years ago

Natim commented 7 years ago

(psycopg2.IntegrityError) duplicate key value violates unique constraint \"idx_records_parent_id_collection_id_last_modified

Natim commented 7 years ago

Refs https://sentry.prod.mozaws.net/operations/kinto-webextensions-prod/issues/395349/

leplatrem commented 7 years ago

This occurred on a request on the records of the crypto collection (/v1/buckets/default/collections/storage-sync-crypto/records) while creating the underlying bucket:

WITH delete_potential_tombstone AS (
            DELETE FROM deleted
             WHERE id = '448cfa42-e013-a3f2-657b-XXXXXXXXXXX'
               AND parent_id = ''
               AND collection_id = 'bucket'
        )
        INSERT INTO records (id, parent_id, collection_id, data, last_modified)
        VALUES ('448cfa42-e013-a3f2-657b-XXXXXXXXXXX', '',
                'bucket', ('{}')::JSONB,
                from_epoch(NULL))

            ON CONFLICT (id, parent_id, collection_id) DO UPDATE
            SET last_modified = EXCLUDED.last_modified

        RETURNING id, as_epoch(last_modified) AS last_modified;
leplatrem commented 7 years ago

Related #602

glasserc commented 7 years ago

The behavior of the client is just to do a sync() on this collection, which only has this one record. This happens before any other access of the default bucket. After the keyring is synced, every extension's collection is synced (in parallel).

leplatrem commented 7 years ago

After the keyring is synced, every extension's collection is synced (in parallel).

Strange then that we ended up with overlaping requests. Let's see if it appears again :)