mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-24 08:46:54 +08:00
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:
committed by
GitHub
parent
7b90696601
commit
6253058d9d
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user