storage/postgreskv: Sort storage keys before delete (postgres)

Change-Id: I63599e142b387ded25d110458ae10c2c96cd8ea6
This commit is contained in:
Rafael Gomes 2020-07-09 12:51:04 -03:00 committed by Yingrong Zhao
parent 569b49768e
commit 24a1eac16c

View File

@ -6,6 +6,7 @@ package postgreskv
import (
"context"
"database/sql"
"sort"
"github.com/lib/pq"
"github.com/spacemonkeygo/monkit/v3"
@ -164,6 +165,11 @@ func (client *Client) Delete(ctx context.Context, key storage.Key) (err error) {
func (client *Client) DeleteMultiple(ctx context.Context, keys []storage.Key) (_ storage.Items, err error) {
defer mon.Task()(&ctx, len(keys))(&err)
// make sure deletes always happen in the same order
sort.Slice(keys, func(i, j int) bool {
return keys[i].Less(keys[j])
})
rows, err := client.db.QueryContext(ctx, `
DELETE FROM pathdata
WHERE fullpath = any($1::BYTEA[])