ensure monotonic n.AppendAtNs in each place (#3880)

https://github.com/seaweedfs/seaweedfs/issues/3852

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
This commit is contained in:
Konstantin Lebedev
2022-10-24 06:24:52 +05:00
committed by GitHub
parent 7b90696601
commit 6253058d9d
2 changed files with 19 additions and 12 deletions

View File

@@ -142,6 +142,14 @@ func (n *Needle) ParsePath(fid string) (err error) {
return err
}
func GetAppendAtNs(volumeLastAppendAtNs uint64) uint64 {
return max(uint64(time.Now().UnixNano()), volumeLastAppendAtNs+1)
}
func (n *Needle) UpdateAppendAtNs(volumeLastAppendAtNs uint64) {
n.AppendAtNs = max(uint64(time.Now().UnixNano()), volumeLastAppendAtNs+1)
}
func ParseNeedleIdCookie(key_hash_string string) (NeedleId, Cookie, error) {
if len(key_hash_string) <= CookieSize*2 {
return NeedleIdEmpty, 0, fmt.Errorf("KeyHash is too short.")
@@ -164,3 +172,10 @@ func ParseNeedleIdCookie(key_hash_string string) (NeedleId, Cookie, error) {
func (n *Needle) LastModifiedString() string {
return time.Unix(int64(n.LastModified), 0).Format("2006-01-02T15:04:05")
}
func max(x, y uint64) uint64 {
if x <= y {
return y
}
return x
}