mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
logging changes to debug
This commit is contained in:
parent
facaa36d22
commit
cc7714fdbe
|
@ -4,18 +4,20 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dir = flag.String("dir", "/tmp", "directory to create files")
|
dir = flag.String("dir", "/tmp", "directory to create files")
|
||||||
n = flag.Int("n", 100, "the number of metadata")
|
n = flag.Int("n", 100, "the number of metadata")
|
||||||
tailFiler = flag.String("filer", "localhost:8888", "the filer address")
|
tailFiler = flag.String("filer", "localhost:8888", "the filer address")
|
||||||
isWrite = flag.Bool("write", false, "only write")
|
isWrite = flag.Bool("write", false, "only write")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -33,7 +35,7 @@ func main() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
name := event.EventNotification.NewEntry.Name
|
name := event.EventNotification.NewEntry.Name
|
||||||
fmt.Printf("=> %s\n", name)
|
glog.V(0).Infof("=> %s ts:%+v", name, time.Unix(0, event.TsNs))
|
||||||
id := name[4:]
|
id := name[4:]
|
||||||
if x, err := strconv.Atoi(id); err == nil {
|
if x, err := strconv.Atoi(id); err == nil {
|
||||||
if x != expected {
|
if x != expected {
|
||||||
|
@ -43,6 +45,7 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -96,6 +99,7 @@ func startSubscribeMetadata(eachEntryFunc func(event *filer_pb.SubscribeMetadata
|
||||||
return listenErr
|
return listenErr
|
||||||
}
|
}
|
||||||
if err = eachEntryFunc(resp); err != nil {
|
if err = eachEntryFunc(resp); err != nil {
|
||||||
|
glog.V(0).Infof("tail last record:%+v", time.Unix(0, lastTsNs))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lastTsNs = resp.TsNs
|
lastTsNs = resp.TsNs
|
||||||
|
|
|
@ -53,7 +53,7 @@ func NewFiler(masters []string, grpcDialOption grpc.DialOption,
|
||||||
GrpcDialOption: grpcDialOption,
|
GrpcDialOption: grpcDialOption,
|
||||||
FilerConf: NewFilerConf(),
|
FilerConf: NewFilerConf(),
|
||||||
}
|
}
|
||||||
f.LocalMetaLogBuffer = log_buffer.NewLogBuffer(LogFlushInterval, f.logFlushFunc, notifyFn)
|
f.LocalMetaLogBuffer = log_buffer.NewLogBuffer("local", LogFlushInterval, f.logFlushFunc, notifyFn)
|
||||||
f.metaLogCollection = collection
|
f.metaLogCollection = collection
|
||||||
f.metaLogReplication = replication
|
f.metaLogReplication = replication
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func NewMetaAggregator(filers []string, grpcDialOption grpc.DialOption) *MetaAgg
|
||||||
grpcDialOption: grpcDialOption,
|
grpcDialOption: grpcDialOption,
|
||||||
}
|
}
|
||||||
t.ListenersCond = sync.NewCond(&t.ListenersLock)
|
t.ListenersCond = sync.NewCond(&t.ListenersLock)
|
||||||
t.MetaLogBuffer = log_buffer.NewLogBuffer(LogFlushInterval, nil, func() {
|
t.MetaLogBuffer = log_buffer.NewLogBuffer("aggr", LogFlushInterval, nil, func() {
|
||||||
t.ListenersCond.Broadcast()
|
t.ListenersCond.Broadcast()
|
||||||
})
|
})
|
||||||
return t
|
return t
|
||||||
|
@ -118,6 +118,7 @@ func (ma *MetaAggregator) subscribeToOneFiler(f *Filer, self string, peer string
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
glog.V(4).Infof("subscribing remote %s meta change: %v", peer, time.Unix(0, lastTsNs))
|
||||||
err := pb.WithFilerClient(peer, ma.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
err := pb.WithFilerClient(peer, ma.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (broker *MessageBroker) Subscribe(stream messaging_pb.SeaweedMessaging_Subs
|
||||||
lastReadTime = time.Unix(0, processedTsNs)
|
lastReadTime = time.Unix(0, processedTsNs)
|
||||||
}
|
}
|
||||||
|
|
||||||
lastReadTime, err = lock.logBuffer.LoopProcessLogData(lastReadTime, func() bool {
|
lastReadTime, err = lock.logBuffer.LoopProcessLogData("broker", lastReadTime, func() bool {
|
||||||
lock.Mutex.Lock()
|
lock.Mutex.Lock()
|
||||||
lock.cond.Wait()
|
lock.cond.Wait()
|
||||||
lock.Mutex.Unlock()
|
lock.Mutex.Unlock()
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (tm *TopicManager) buildLogBuffer(tl *TopicControl, tp TopicPartition, topi
|
||||||
glog.V(0).Infof("log write failed %s: %v", targetFile, err)
|
glog.V(0).Infof("log write failed %s: %v", targetFile, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logBuffer := log_buffer.NewLogBuffer(time.Minute, flushFn, func() {
|
logBuffer := log_buffer.NewLogBuffer("broker", time.Minute, flushFn, func() {
|
||||||
tl.cond.Broadcast()
|
tl.cond.Broadcast()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (fs *FilerServer) SubscribeMetadata(req *filer_pb.SubscribeMetadataRequest,
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
glog.V(0).Infof("read on disk %v aggregated subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)
|
glog.V(4).Infof("read on disk %v aggregated subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)
|
||||||
|
|
||||||
processedTsNs, err = fs.filer.ReadPersistedLogBuffer(lastReadTime, eachLogEntryFn)
|
processedTsNs, err = fs.filer.ReadPersistedLogBuffer(lastReadTime, eachLogEntryFn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,9 +45,9 @@ func (fs *FilerServer) SubscribeMetadata(req *filer_pb.SubscribeMetadataRequest,
|
||||||
lastReadTime = time.Unix(0, processedTsNs)
|
lastReadTime = time.Unix(0, processedTsNs)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(0).Infof("read in memory %v aggregated subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)
|
glog.V(4).Infof("read in memory %v aggregated subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)
|
||||||
|
|
||||||
lastReadTime, err = fs.filer.MetaAggregator.MetaLogBuffer.LoopProcessLogData(lastReadTime, func() bool {
|
lastReadTime, err = fs.filer.MetaAggregator.MetaLogBuffer.LoopProcessLogData("aggMeta:"+clientName, lastReadTime, func() bool {
|
||||||
fs.filer.MetaAggregator.ListenersLock.Lock()
|
fs.filer.MetaAggregator.ListenersLock.Lock()
|
||||||
fs.filer.MetaAggregator.ListenersCond.Wait()
|
fs.filer.MetaAggregator.ListenersCond.Wait()
|
||||||
fs.filer.MetaAggregator.ListenersLock.Unlock()
|
fs.filer.MetaAggregator.ListenersLock.Unlock()
|
||||||
|
@ -101,7 +101,7 @@ func (fs *FilerServer) SubscribeLocalMetadata(req *filer_pb.SubscribeMetadataReq
|
||||||
|
|
||||||
glog.V(0).Infof("read in memory %v local subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)
|
glog.V(0).Infof("read in memory %v local subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)
|
||||||
|
|
||||||
lastReadTime, err = fs.filer.LocalMetaLogBuffer.LoopProcessLogData(lastReadTime, func() bool {
|
lastReadTime, err = fs.filer.LocalMetaLogBuffer.LoopProcessLogData("localMeta:"+clientName, lastReadTime, func() bool {
|
||||||
fs.listenersLock.Lock()
|
fs.listenersLock.Lock()
|
||||||
fs.listenersCond.Wait()
|
fs.listenersCond.Wait()
|
||||||
fs.listenersLock.Unlock()
|
fs.listenersLock.Unlock()
|
||||||
|
|
|
@ -22,6 +22,7 @@ type dataToFlush struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogBuffer struct {
|
type LogBuffer struct {
|
||||||
|
name string
|
||||||
prevBuffers *SealedBuffers
|
prevBuffers *SealedBuffers
|
||||||
buf []byte
|
buf []byte
|
||||||
idx []int
|
idx []int
|
||||||
|
@ -39,8 +40,9 @@ type LogBuffer struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogBuffer(flushInterval time.Duration, flushFn func(startTime, stopTime time.Time, buf []byte), notifyFn func()) *LogBuffer {
|
func NewLogBuffer(name string, flushInterval time.Duration, flushFn func(startTime, stopTime time.Time, buf []byte), notifyFn func()) *LogBuffer {
|
||||||
lb := &LogBuffer{
|
lb := &LogBuffer{
|
||||||
|
name: name,
|
||||||
prevBuffers: newSealedBuffers(PreviousBufferCount),
|
prevBuffers: newSealedBuffers(PreviousBufferCount),
|
||||||
buf: make([]byte, BufferSize),
|
buf: make([]byte, BufferSize),
|
||||||
sizeBuf: make([]byte, 4),
|
sizeBuf: make([]byte, 4),
|
||||||
|
@ -93,6 +95,7 @@ func (m *LogBuffer) AddToBuffer(partitionKey, data []byte, eventTsNs int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.startTime.Add(m.flushInterval).Before(ts) || len(m.buf)-m.pos < size+4 {
|
if m.startTime.Add(m.flushInterval).Before(ts) || len(m.buf)-m.pos < size+4 {
|
||||||
|
// glog.V(4).Infof("%s copyToFlush1 start time %v, ts %v, remaining %d bytes", m.name, m.startTime, ts, len(m.buf)-m.pos)
|
||||||
m.flushChan <- m.copyToFlush()
|
m.flushChan <- m.copyToFlush()
|
||||||
m.startTime = ts
|
m.startTime = ts
|
||||||
if len(m.buf) < size+4 {
|
if len(m.buf) < size+4 {
|
||||||
|
@ -127,9 +130,10 @@ func (m *LogBuffer) Shutdown() {
|
||||||
func (m *LogBuffer) loopFlush() {
|
func (m *LogBuffer) loopFlush() {
|
||||||
for d := range m.flushChan {
|
for d := range m.flushChan {
|
||||||
if d != nil {
|
if d != nil {
|
||||||
// fmt.Printf("flush [%v, %v] size %d\n", d.startTime, d.stopTime, len(d.data.Bytes()))
|
// glog.V(4).Infof("%s flush [%v, %v] size %d", m.name, d.startTime, d.stopTime, len(d.data.Bytes()))
|
||||||
m.flushFn(d.startTime, d.stopTime, d.data.Bytes())
|
m.flushFn(d.startTime, d.stopTime, d.data.Bytes())
|
||||||
d.releaseMemory()
|
d.releaseMemory()
|
||||||
|
// local logbuffer is different from aggregate logbuffer here
|
||||||
m.lastFlushTime = d.stopTime
|
m.lastFlushTime = d.stopTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +147,6 @@ func (m *LogBuffer) loopInterval() {
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// println("loop interval")
|
|
||||||
toFlush := m.copyToFlush()
|
toFlush := m.copyToFlush()
|
||||||
m.flushChan <- toFlush
|
m.flushChan <- toFlush
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
|
@ -162,7 +165,6 @@ func (m *LogBuffer) copyToFlush() *dataToFlush {
|
||||||
data: copiedBytes(m.buf[:m.pos]),
|
data: copiedBytes(m.buf[:m.pos]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fmt.Printf("flusing [0,%d) with %d entries\n", m.pos, len(m.idx))
|
|
||||||
m.buf = m.prevBuffers.SealBuffer(m.startTime, m.stopTime, m.buf, m.pos)
|
m.buf = m.prevBuffers.SealBuffer(m.startTime, m.stopTime, m.buf, m.pos)
|
||||||
m.pos = 0
|
m.pos = 0
|
||||||
m.idx = m.idx[:0]
|
m.idx = m.idx[:0]
|
||||||
|
@ -200,12 +202,9 @@ func (m *LogBuffer) ReadFromBuffer(lastReadTime time.Time) (bufferCopy *bytes.Bu
|
||||||
}
|
}
|
||||||
if lastReadTime.Before(m.startTime) {
|
if lastReadTime.Before(m.startTime) {
|
||||||
// println("checking ", lastReadTime.UnixNano())
|
// println("checking ", lastReadTime.UnixNano())
|
||||||
for i, buf := range m.prevBuffers.buffers {
|
for _, buf := range m.prevBuffers.buffers {
|
||||||
if buf.startTime.After(lastReadTime) {
|
if buf.startTime.After(lastReadTime) {
|
||||||
if i == 0 {
|
// glog.V(4).Infof("%s return the %d sealed buffer %v", m.name, i, buf.startTime)
|
||||||
// println("return the earliest in memory", buf.startTime.UnixNano())
|
|
||||||
return copiedBytes(buf.buf[:buf.size]), nil
|
|
||||||
}
|
|
||||||
// println("return the", i, "th in memory", buf.startTime.UnixNano())
|
// println("return the", i, "th in memory", buf.startTime.UnixNano())
|
||||||
return copiedBytes(buf.buf[:buf.size]), nil
|
return copiedBytes(buf.buf[:buf.size]), nil
|
||||||
}
|
}
|
||||||
|
@ -215,7 +214,7 @@ func (m *LogBuffer) ReadFromBuffer(lastReadTime time.Time) (bufferCopy *bytes.Bu
|
||||||
return copiedBytes(buf.buf[pos:buf.size]), nil
|
return copiedBytes(buf.buf[pos:buf.size]), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// println("return the current buf", lastReadTime.UnixNano())
|
// glog.V(4).Infof("%s return the current buf %v", m.name, lastReadTime)
|
||||||
return copiedBytes(m.buf[:m.pos]), nil
|
return copiedBytes(m.buf[:m.pos]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewLogBufferFirstBuffer(t *testing.T) {
|
func TestNewLogBufferFirstBuffer(t *testing.T) {
|
||||||
lb := NewLogBuffer(time.Minute, func(startTime, stopTime time.Time, buf []byte) {
|
lb := NewLogBuffer("test", time.Minute, func(startTime, stopTime time.Time, buf []byte) {
|
||||||
|
|
||||||
}, func() {
|
}, func() {
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func TestNewLogBufferFirstBuffer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
receivedmessageCount := 0
|
receivedmessageCount := 0
|
||||||
lb.LoopProcessLogData(startTime, func() bool {
|
lb.LoopProcessLogData("test", startTime, func() bool {
|
||||||
// stop if no more messages
|
// stop if no more messages
|
||||||
return false
|
return false
|
||||||
}, func(logEntry *filer_pb.LogEntry) error {
|
}, func(logEntry *filer_pb.LogEntry) error {
|
||||||
|
|
|
@ -17,10 +17,7 @@ var (
|
||||||
ResumeFromDiskError = fmt.Errorf("resumeFromDisk")
|
ResumeFromDiskError = fmt.Errorf("resumeFromDisk")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (logBuffer *LogBuffer) LoopProcessLogData(
|
func (logBuffer *LogBuffer) LoopProcessLogData(readerName string, startTreadTime time.Time, waitForDataFn func() bool, eachLogDataFn func(logEntry *filer_pb.LogEntry) error) (lastReadTime time.Time, err error) {
|
||||||
startTreadTime time.Time,
|
|
||||||
waitForDataFn func() bool,
|
|
||||||
eachLogDataFn func(logEntry *filer_pb.LogEntry) error) (lastReadTime time.Time, err error) {
|
|
||||||
// loop through all messages
|
// loop through all messages
|
||||||
var bytesBuf *bytes.Buffer
|
var bytesBuf *bytes.Buffer
|
||||||
lastReadTime = startTreadTime
|
lastReadTime = startTreadTime
|
||||||
|
@ -39,7 +36,7 @@ func (logBuffer *LogBuffer) LoopProcessLogData(
|
||||||
if err == ResumeFromDiskError {
|
if err == ResumeFromDiskError {
|
||||||
return lastReadTime, ResumeFromDiskError
|
return lastReadTime, ResumeFromDiskError
|
||||||
}
|
}
|
||||||
// fmt.Printf("ReadFromBuffer by %v\n", lastReadTime)
|
// glog.V(4).Infof("%s ReadFromBuffer by %v", readerName, lastReadTime)
|
||||||
if bytesBuf == nil {
|
if bytesBuf == nil {
|
||||||
if waitForDataFn() {
|
if waitForDataFn() {
|
||||||
continue
|
continue
|
||||||
|
@ -49,7 +46,7 @@ func (logBuffer *LogBuffer) LoopProcessLogData(
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := bytesBuf.Bytes()
|
buf := bytesBuf.Bytes()
|
||||||
// fmt.Printf("ReadFromBuffer by %v size %d\n", lastReadTime, len(buf))
|
// fmt.Printf("ReadFromBuffer %s by %v size %d\n", readerName, lastReadTime, len(buf))
|
||||||
|
|
||||||
batchSize := 0
|
batchSize := 0
|
||||||
var startReadTime time.Time
|
var startReadTime time.Time
|
||||||
|
@ -59,7 +56,7 @@ func (logBuffer *LogBuffer) LoopProcessLogData(
|
||||||
size := util.BytesToUint32(buf[pos : pos+4])
|
size := util.BytesToUint32(buf[pos : pos+4])
|
||||||
if pos+4+int(size) > len(buf) {
|
if pos+4+int(size) > len(buf) {
|
||||||
err = ResumeError
|
err = ResumeError
|
||||||
glog.Errorf("LoopProcessLogData: read buffer %v read %d [%d,%d) from [0,%d)", lastReadTime, batchSize, pos, pos+int(size)+4, len(buf))
|
glog.Errorf("LoopProcessLogData: %s read buffer %v read %d [%d,%d) from [0,%d)", readerName, lastReadTime, batchSize, pos, pos+int(size)+4, len(buf))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entryData := buf[pos+4 : pos+4+int(size)]
|
entryData := buf[pos+4 : pos+4+int(size)]
|
||||||
|
@ -81,9 +78,10 @@ func (logBuffer *LogBuffer) LoopProcessLogData(
|
||||||
|
|
||||||
pos += 4 + int(size)
|
pos += 4 + int(size)
|
||||||
batchSize++
|
batchSize++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Printf("sent message ts[%d,%d] size %d\n", startReadTime.UnixNano(), lastReadTime.UnixNano(), batchSize)
|
// glog.V(4).Infof("%s sent messages ts[%+v,%+v] size %d\n", readerName, startReadTime, lastReadTime, batchSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue