aboutsummaryrefslogtreecommitdiff
path: root/weed/util/log_buffer/log_buffer.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-05-11 01:53:54 -0700
committerChris Lu <chris.lu@gmail.com>2020-05-11 01:53:54 -0700
commit4b7fa31468eb1b8e0af53543a7e760c517faf227 (patch)
treefad8928412dfbe35d9d5ef5efe64a409dfe3f3cc /weed/util/log_buffer/log_buffer.go
parentd5a8297a1cfeaa296cb160a6195ca9e14230048c (diff)
downloadseaweedfs-4b7fa31468eb1b8e0af53543a7e760c517faf227.tar.xz
seaweedfs-4b7fa31468eb1b8e0af53543a7e760c517faf227.zip
ensure montonically increasing tsNs
Diffstat (limited to 'weed/util/log_buffer/log_buffer.go')
-rw-r--r--weed/util/log_buffer/log_buffer.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/weed/util/log_buffer/log_buffer.go b/weed/util/log_buffer/log_buffer.go
index 67c44dc57..b02c45b52 100644
--- a/weed/util/log_buffer/log_buffer.go
+++ b/weed/util/log_buffer/log_buffer.go
@@ -34,6 +34,7 @@ type LogBuffer struct {
notifyFn func()
isStopping bool
flushChan chan *dataToFlush
+ lastTsNs int64
sync.RWMutex
}
@@ -64,8 +65,15 @@ func (m *LogBuffer) AddToBuffer(partitionKey, data []byte) {
// need to put the timestamp inside the lock
ts := time.Now()
+ tsNs := ts.UnixNano()
+ if m.lastTsNs >= tsNs {
+ // this is unlikely to happen, but just in case
+ tsNs = m.lastTsNs + 1
+ ts = time.Unix(0, tsNs)
+ }
+ m.lastTsNs = tsNs
logEntry := &filer_pb.LogEntry{
- TsNs: ts.UnixNano(),
+ TsNs: tsNs,
PartitionKeyHash: util.HashToInt32(partitionKey),
Data: data,
}