From 05a6e2dc7f88131fd7f2e99ff283b4712a623cd3 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 2 Sep 2020 10:12:44 -0700 Subject: [PATCH] sql kv upsert --- weed/filer/abstract_sql/abstract_sql_store_kv.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/weed/filer/abstract_sql/abstract_sql_store_kv.go b/weed/filer/abstract_sql/abstract_sql_store_kv.go index 5084b6062..ace7c4e08 100644 --- a/weed/filer/abstract_sql/abstract_sql_store_kv.go +++ b/weed/filer/abstract_sql/abstract_sql_store_kv.go @@ -7,6 +7,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/util" + "strings" ) func (store *AbstractSqlStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) { @@ -15,14 +16,9 @@ func (store *AbstractSqlStore) KvPut(ctx context.Context, key []byte, value []by res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlInsert, dirHash, name, dirStr, value) if err != nil { - return fmt.Errorf("kv insert: %s", err) - } - - // TODO maybe it will throw error before coming here? - - 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 @@ -87,4 +83,4 @@ func genDirAndName(key []byte) (dirStr string, dirHash int64, name string) { name = string(key[8:]) return -} \ No newline at end of file +}