From ed62f524524f557c9319f2199b2f3299866969cd Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 2 Sep 2020 10:09:49 -0700 Subject: [PATCH] fix sql insert with duplicated primary key --- weed/filer/abstract_sql/abstract_sql_store.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.go index e87ecb9fb..368bec973 100644 --- a/weed/filer/abstract_sql/abstract_sql_store.go +++ b/weed/filer/abstract_sql/abstract_sql_store.go @@ -8,6 +8,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/util" + "strings" ) type AbstractSqlStore struct { @@ -68,12 +69,9 @@ func (store *AbstractSqlStore) InsertEntry(ctx context.Context, entry *filer.Ent res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlInsert, util.HashStringToLong(dir), name, dir, meta) if err != nil { - return fmt.Errorf("insert %s: %s", entry.FullPath, err) - } - - affectedRows, err := res.RowsAffected() - if err == nil && affectedRows > 0 { - return nil + if !strings.Contains(strings.ToLower(err.Error()), "duplicate") { + return fmt.Errorf("kv insert: %s", err) + } } // now the insert failed possibly due to duplication constraints