From 23280257dfb851ae645257c252bb1f66bcc59819 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 13 Dec 2020 19:45:47 -0800 Subject: [PATCH 1/2] sql put kv: avoid unnecessary update --- weed/filer/abstract_sql/abstract_sql_store_kv.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/weed/filer/abstract_sql/abstract_sql_store_kv.go b/weed/filer/abstract_sql/abstract_sql_store_kv.go index c368059df..49db8af65 100644 --- a/weed/filer/abstract_sql/abstract_sql_store_kv.go +++ b/weed/filer/abstract_sql/abstract_sql_store_kv.go @@ -5,11 +5,10 @@ import ( "database/sql" "encoding/base64" "fmt" - "strings" - "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) { @@ -17,10 +16,12 @@ func (store *AbstractSqlStore) KvPut(ctx context.Context, key []byte, value []by dirStr, dirHash, name := genDirAndName(key) res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlInsert, dirHash, name, dirStr, value) - if err != nil { - if !strings.Contains(strings.ToLower(err.Error()), "duplicate") { - return fmt.Errorf("kv insert: %s", err) - } + if err == nil { + return + } + + if !strings.Contains(strings.ToLower(err.Error()), "duplicate") { + return fmt.Errorf("kv insert: %s", err) } // now the insert failed possibly due to duplication constraints From 38fc89d04133ccb686ef4ec226b917070f74a941 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 13 Dec 2020 20:49:44 -0800 Subject: [PATCH 2/2] filer store: sql update if any insert error happens fix https://github.com/chrislusf/seaweedfs/issues/1673 --- weed/filer/abstract_sql/abstract_sql_store.go | 3 ++- weed/filer/abstract_sql/abstract_sql_store_kv.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.go index 7c95ffb57..da104358b 100644 --- a/weed/filer/abstract_sql/abstract_sql_store.go +++ b/weed/filer/abstract_sql/abstract_sql_store.go @@ -77,7 +77,8 @@ func (store *AbstractSqlStore) InsertEntry(ctx context.Context, entry *filer.Ent } if !strings.Contains(strings.ToLower(err.Error()), "duplicate") { - return fmt.Errorf("kv insert: %s", err) + // return fmt.Errorf("insert: %s", err) + // skip this since the error can be in a different language } // now the insert failed possibly due to duplication constraints diff --git a/weed/filer/abstract_sql/abstract_sql_store_kv.go b/weed/filer/abstract_sql/abstract_sql_store_kv.go index 49db8af65..81d105134 100644 --- a/weed/filer/abstract_sql/abstract_sql_store_kv.go +++ b/weed/filer/abstract_sql/abstract_sql_store_kv.go @@ -21,7 +21,8 @@ func (store *AbstractSqlStore) KvPut(ctx context.Context, key []byte, value []by } if !strings.Contains(strings.ToLower(err.Error()), "duplicate") { - return fmt.Errorf("kv insert: %s", err) + // return fmt.Errorf("kv insert: %s", err) + // skip this since the error can be in a different language } // now the insert failed possibly due to duplication constraints @@ -33,7 +34,7 @@ func (store *AbstractSqlStore) KvPut(ctx context.Context, key []byte, value []by } _, err = res.RowsAffected() - if err != nil { + if err != nil { return fmt.Errorf("kv upsert no rows affected: %s", err) } return nil