From a9f7a1ac02892051e670cea8123d5ad41d875e82 Mon Sep 17 00:00:00 2001 From: Alexxxxxx <118710506+alexgao001@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:12:57 +0800 Subject: [PATCH] fix: fix db override (#1384) --- store/sqldb/object_integrity.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/store/sqldb/object_integrity.go b/store/sqldb/object_integrity.go index abe76ba49..d84d01774 100644 --- a/store/sqldb/object_integrity.go +++ b/store/sqldb/object_integrity.go @@ -410,9 +410,12 @@ func (s *SpDBImpl) SetReplicatePieceChecksum(objectID uint64, segmentIdx uint32, } result = s.db.Create(insertPieceHash) if result.Error != nil && MysqlErrCode(result.Error) == ErrDuplicateEntryCode { - //return nil - result = s.db.Save(insertPieceHash) - return result.Error + // If all columns are identical to previous, the db.Save will also encounter ErrDuplicateEntryCode, then it should skip. + err = s.db.Save(insertPieceHash).Error + if MysqlErrCode(err) == ErrDuplicateEntryCode { + return nil + } + return err } if result.Error != nil || result.RowsAffected != 1 { err = fmt.Errorf("failed to insert piece hash record: %s", result.Error)