@@ -25,6 +25,7 @@ import (
25
25
"strings"
26
26
"sync"
27
27
"sync/atomic"
28
+ "time"
28
29
29
30
"github.com/pingcap/errors"
30
31
"github.com/pingcap/log"
@@ -343,8 +344,24 @@ func (vlog *valueLog) write(reqs []*request) error {
343
344
var bufReqs []* request
344
345
vlog .buf .Reset ()
345
346
347
+ rotate := func () error {
348
+ err := curFile .finalize ()
349
+ if err != nil {
350
+ return errors .Annotatef (err , "finalize file %s failed" , curFile .path )
351
+ }
352
+
353
+ id := atomic .AddUint32 (& vlog .maxFid , 1 )
354
+ curFile , err = vlog .createLogFile (id )
355
+ if err != nil {
356
+ return errors .Annotatef (err , "create file id %d failed" , id )
357
+ }
358
+ return nil
359
+ }
360
+
346
361
toDisk := func () error {
362
+ writeT0 := time .Now ()
347
363
err := curFile .Write (vlog .buf .Bytes (), vlog .sync )
364
+ writeBinlogTimeHistogram .WithLabelValues ("to_disk" ).Observe (time .Since (writeT0 ).Seconds ())
348
365
if err != nil {
349
366
return errors .Trace (err )
350
367
}
@@ -357,15 +374,11 @@ func (vlog *valueLog) write(reqs []*request) error {
357
374
358
375
// rotate file
359
376
if curFile .GetWriteOffset () > vlog .opt .ValueLogFileSize {
360
- err := curFile .finalize ()
361
- if err != nil {
362
- return errors .Annotatef (err , "finalize file %s failed" , curFile .path )
363
- }
364
-
365
- id := atomic .AddUint32 (& vlog .maxFid , 1 )
366
- curFile , err = vlog .createLogFile (id )
377
+ rotateT0 := time .Now ()
378
+ err := rotate ()
379
+ writeBinlogTimeHistogram .WithLabelValues ("rotate" ).Observe (time .Since (rotateT0 ).Seconds ())
367
380
if err != nil {
368
- return errors . Annotatef ( err , "create file id %d failed" , id )
381
+ return err
369
382
}
370
383
}
371
384
return nil
0 commit comments