From 9c8678ded97dac7359349b553c15386db7d626ca Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 13 Oct 2022 23:15:00 -0700 Subject: [PATCH] ensure monotonic n.AppendAtNs fix https://github.com/seaweedfs/seaweedfs/issues/3852 --- weed/storage/volume_write.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/weed/storage/volume_write.go b/weed/storage/volume_write.go index 223e19577..2dc813216 100644 --- a/weed/storage/volume_write.go +++ b/weed/storage/volume_write.go @@ -157,7 +157,7 @@ func (v *Volume) doWriteRequest(n *needle.Needle, checkCookie bool) (offset uint } // append to dat file - n.AppendAtNs = uint64(time.Now().UnixNano()) + n.AppendAtNs = max(uint64(time.Now().UnixNano()), v.lastAppendAtNs+1) offset, size, _, err = n.Append(v.DataBackend, v.Version()) v.checkReadWriteError(err) if err != nil { @@ -330,3 +330,10 @@ func (v *Volume) WriteNeedleBlob(needleId NeedleId, needleBlob []byte, size Size return err } + +func max(x, y uint64) uint64 { + if x <= y { + return y + } + return x +}