MCPcopy
hub / github.com/etcd-io/bbolt / writeMeta

Method writeMeta

tx.go:595–625  ·  view source on GitHub ↗

writeMeta writes the meta to the disk.

()

Source from the content-addressed store, hash-verified

593
594// writeMeta writes the meta to the disk.
595func (tx *Tx) writeMeta() error {
596 // gofail: var beforeWriteMetaError string
597 // return errors.New(beforeWriteMetaError)
598
599 // Create a temporary buffer for the meta page.
600 lg := tx.db.Logger()
601 buf := make([]byte, tx.db.pageSize)
602 p := tx.db.pageInBuffer(buf, 0)
603 tx.meta.Write(p)
604
605 // Write the meta page to file.
606 tx.db.metalock.Lock()
607 if _, err := tx.db.ops.writeAt(buf, int64(p.Id())*int64(tx.db.pageSize)); err != nil {
608 tx.db.metalock.Unlock()
609 lg.Errorf("writeAt failed, pgid: %d, pageSize: %d, error: %v", p.Id(), tx.db.pageSize, err)
610 return err
611 }
612 tx.db.metalock.Unlock()
613 if !tx.db.NoSync || common.IgnoreNoSync {
614 // gofail: var beforeSyncMetaPage struct{}
615 if err := fdatasync(tx.db); err != nil {
616 lg.Errorf("[GOOS: %s, GOARCH: %s] fdatasync failed: %w", runtime.GOOS, runtime.GOARCH, err)
617 return err
618 }
619 }
620
621 // Update statistics.
622 tx.stats.IncWrite(1)
623
624 return nil
625}
626
627// page returns a reference to the page with a given id.
628// If page has been written to then a temporary buffered page is returned.

Callers 1

CommitMethod · 0.95

Calls 7

LoggerMethod · 0.80
pageInBufferMethod · 0.80
IdMethod · 0.80
IncWriteMethod · 0.80
fdatasyncFunction · 0.70
WriteMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected