aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2023-12-01 18:19:51 +0500
committerChris Lu <chrislusf@users.noreply.github.com>2023-12-09 10:18:18 -0800
commit125ad8fe63fd6cd78e35b7bcc328b2e8ffdcffb6 (patch)
tree3e45f011d48e1f631bec7041b13546d0dcbb4af4
parentc1a6e624e55a5b5dd57a21d02a6e91bb8a938dab (diff)
downloadseaweedfs-125ad8fe63fd6cd78e35b7bcc328b2e8ffdcffb6.tar.xz
seaweedfs-125ad8fe63fd6cd78e35b7bcc328b2e8ffdcffb6.zip
falls back to update only if error contains msg "duplicate entry"
https://github.com/seaweedfs/seaweedfs/issues/5062
-rw-r--r--weed/filer/abstract_sql/abstract_sql_store.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.go
index fdfe13d20..ee2afa30f 100644
--- a/weed/filer/abstract_sql/abstract_sql_store.go
+++ b/weed/filer/abstract_sql/abstract_sql_store.go
@@ -161,31 +161,24 @@ func (store *AbstractSqlStore) InsertEntry(ctx context.Context, entry *filer.Ent
if len(entry.GetChunks()) > filer.CountEntryChunksForGzip {
meta = util.MaybeGzipData(meta)
}
-
+ sqlInsert := "insert"
res, err := db.ExecContext(ctx, store.GetSqlInsert(bucket), util.HashStringToLong(dir), name, dir, meta)
- if err == nil {
- return
- }
-
- if !strings.Contains(strings.ToLower(err.Error()), "duplicate") {
- // return fmt.Errorf("insert: %s", err)
- // skip this since the error can be in a different language
+ if err != nil && strings.Contains(strings.ToLower(err.Error()), "duplicate entry") {
+ // now the insert failed possibly due to duplication constraints
+ sqlInsert = "falls back to update"
+ glog.V(1).Infof("insert %s %s: %v", entry.FullPath, sqlInsert, err)
+ res, err = db.ExecContext(ctx, store.GetSqlUpdate(bucket), meta, util.HashStringToLong(dir), name, dir)
}
-
- // now the insert failed possibly due to duplication constraints
- glog.V(1).Infof("insert %s falls back to update: %v", entry.FullPath, err)
-
- res, err = db.ExecContext(ctx, store.GetSqlUpdate(bucket), meta, util.HashStringToLong(dir), name, dir)
if err != nil {
- return fmt.Errorf("upsert %s: %s", entry.FullPath, err)
+ return fmt.Errorf("%s %s: %s", sqlInsert, entry.FullPath, err)
}
_, err = res.RowsAffected()
if err != nil {
- return fmt.Errorf("upsert %s but no rows affected: %s", entry.FullPath, err)
+ return fmt.Errorf("%s %s but no rows affected: %s", sqlInsert, entry.FullPath, err)
}
- return nil
+ return nil
}
func (store *AbstractSqlStore) UpdateEntry(ctx context.Context, entry *filer.Entry) (err error) {