1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-09-12 12:00:45 +02:00

ensure montonically increasing tsNs

This commit is contained in:
Chris Lu 2020-05-11 01:53:54 -07:00
parent d5a8297a1c
commit 4b7fa31468

View file

@ -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,
}