Skip to content

Commit 046c5eb

Browse files
committed
add more logs
1 parent ead4480 commit 046c5eb

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

diskcache/diskcache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ type DiskCache struct {
9494
pos *pos // current read fd position info
9595

9696
// specs of current diskcache
97-
size atomic.Int64 // current byte size
97+
size atomic.Int64 // current byte size
98+
9899
curBatchSize, // current writing file's size
99100
curReadSize, // current reading file's size
100101
batchSize, // current batch size(static)

diskcache/get.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ func (c *DiskCache) doGet(buf []byte, fn Fn, bfn BufFunc) error {
8282
if err = func() error {
8383
c.wlock.Lock()
8484
defer c.wlock.Unlock()
85+
8586
return c.rotate()
8687
}(); err != nil {
87-
return err
88+
return fmt.Errorf("wakeup error: %w", err)
8889
}
8990
}
9091

@@ -140,14 +141,15 @@ retry:
140141

141142
if len(readbuf) < nbytes {
142143
// seek to next read position
143-
if _, err := c.rfd.Seek(int64(nbytes), io.SeekCurrent); err != nil {
144+
if x, err := c.rfd.Seek(int64(nbytes), io.SeekCurrent); err != nil {
144145
return fmt.Errorf("rfd.Seek(%d): %w", nbytes, err)
145-
}
146+
} else {
147+
l.Warnf("got %d bytes to buffer with len %d, seek to new read position %d, drop %d bytes within file %s",
148+
nbytes, len(readbuf), x, nbytes, c.curReadfile)
146149

147-
l.Warnf("got %d bytes to read into buffer with length %d", nbytes, len(readbuf))
148-
149-
droppedDataVec.WithLabelValues(c.path, reasonTooSmallReadBuffer).Observe(float64(nbytes))
150-
return ErrTooSmallReadBuf
150+
droppedDataVec.WithLabelValues(c.path, reasonTooSmallReadBuffer).Observe(float64(nbytes))
151+
return ErrTooSmallReadBuf
152+
}
151153
}
152154

153155
if n, err := c.rfd.Read(readbuf[:nbytes]); err != nil {

diskcache/metric.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func setupMetrics() {
181181
prometheus.GaugeOpts{
182182
Namespace: ns,
183183
Name: "size",
184-
Help: "Current cache size that waiting to be consumed(get)",
184+
Help: "Current cache size that waiting to be consumed(get). The size include header bytes",
185185
},
186186
[]string{"path"},
187187
)

diskcache/open.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ func (c *DiskCache) doOpen() error {
142142
switch filepath.Base(path) {
143143
case ".lock", ".pos": // ignore them
144144
case "data": // not rotated writing file, do not count on sizeVec.
145-
c.size.Add(fi.Size())
146-
// NOTE: c.size not always equal to sizeVec. c.size used to limit
147-
// total bytes used for Put(), but sizeVec used to count size that
148-
// waiting to be Get().
149145
default:
150146
c.size.Add(fi.Size())
151147
sizeVec.WithLabelValues(c.path).Add(float64(fi.Size()))
@@ -158,6 +154,8 @@ func (c *DiskCache) doOpen() error {
158154
}
159155

160156
sort.Strings(c.dataFiles) // make file-name sorted for FIFO Get()
157+
l.Infof("on open loaded %d files", len(c.dataFiles))
158+
datafilesVec.WithLabelValues(c.path).Set(float64(len(c.dataFiles)))
161159

162160
// first get, try load .pos
163161
if !c.noPos {

diskcache/rotate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (c *DiskCache) rotate() error {
7373
return fmt.Errorf("rotate on Rename(%q, %q): %w", c.curWriteFile, newfile, err)
7474
}
7575

76-
// new file added, plus it's size to cache size
76+
// new file added, add it's size to cache size
7777
if fi, err := os.Stat(newfile); err == nil {
7878
if fi.Size() > dataHeaderLen {
7979
c.size.Add(fi.Size())

0 commit comments

Comments
 (0)