mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 06:30:07 +08:00
sql kv upsert
This commit is contained in:
parent
ed62f52452
commit
05a6e2dc7f
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (store *AbstractSqlStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
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)
|
res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlInsert, dirHash, name, dirStr, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("kv insert: %s", err)
|
if !strings.Contains(strings.ToLower(err.Error()), "duplicate") {
|
||||||
}
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now the insert failed possibly due to duplication constraints
|
// 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:])
|
name = string(key[8:])
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user