|
|
@ -93,7 +93,7 @@ func (m *LogBuffer) AddToBuffer(partitionKey, data []byte) { |
|
|
|
copy(m.buf[m.pos+4:m.pos+4+size], logEntryData) |
|
|
|
m.pos += size + 4 |
|
|
|
|
|
|
|
// fmt.Printf("entry size %d total %d count %d\n", size, m.pos, len(m.idx))
|
|
|
|
// fmt.Printf("entry size %d total %d count %d, buffer:%p\n", size, m.pos, len(m.idx), m)
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -112,6 +112,7 @@ func (m *LogBuffer) Shutdown() { |
|
|
|
func (m *LogBuffer) loopFlush() { |
|
|
|
for d := range m.flushChan { |
|
|
|
if d != nil { |
|
|
|
// fmt.Printf("flush [%v, %v] size %d\n", d.startTime, d.stopTime, len(d.data.Bytes()))
|
|
|
|
m.flushFn(d.startTime, d.stopTime, d.data.Bytes()) |
|
|
|
d.releaseMemory() |
|
|
|
} |
|
|
@ -156,7 +157,12 @@ func (m *LogBuffer) ReadFromBuffer(lastReadTime time.Time) (bufferCopy *bytes.Bu |
|
|
|
m.RLock() |
|
|
|
defer m.RUnlock() |
|
|
|
|
|
|
|
// fmt.Printf("read from buffer: %v last stop time: %v\n", lastReadTime.UnixNano(), m.stopTime.UnixNano())
|
|
|
|
/* |
|
|
|
fmt.Printf("read buffer %p: %v last stop time: [%v,%v], pos %d, entries:%d, prevBufs:%d\n", m, lastReadTime, m.startTime, m.stopTime, m.pos, len(m.idx), len(m.prevBuffers.buffers)) |
|
|
|
for i, prevBuf := range m.prevBuffers.buffers { |
|
|
|
fmt.Printf(" prev %d : %s\n", i, prevBuf.String()) |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
if lastReadTime.Equal(m.stopTime) { |
|
|
|
return nil |
|
|
@ -173,6 +179,7 @@ func (m *LogBuffer) ReadFromBuffer(lastReadTime time.Time) (bufferCopy *bytes.Bu |
|
|
|
// println("return the earliest in memory", buf.startTime.UnixNano())
|
|
|
|
return copiedBytes(buf.buf[:buf.size]) |
|
|
|
} |
|
|
|
// println("return the", i, "th in memory", buf.startTime.UnixNano())
|
|
|
|
return copiedBytes(buf.buf[:buf.size]) |
|
|
|
} |
|
|
|
if !buf.startTime.After(lastReadTime) && buf.stopTime.After(lastReadTime) { |
|
|
@ -181,6 +188,7 @@ func (m *LogBuffer) ReadFromBuffer(lastReadTime time.Time) (bufferCopy *bytes.Bu |
|
|
|
return copiedBytes(buf.buf[pos:buf.size]) |
|
|
|
} |
|
|
|
} |
|
|
|
// println("return the current buf", lastReadTime.UnixNano())
|
|
|
|
return copiedBytes(m.buf[:m.pos]) |
|
|
|
} |
|
|
|
|
|
|
|