Skip to content

Commit f32b06c

Browse files
committed
Protect meta page when it's being written
Signed-off-by: Benjamin Wang <[email protected]>
1 parent b8ccd81 commit f32b06c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tx.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,13 @@ func (tx *Tx) writeMeta() error {
561561
tx.meta.Write(p)
562562

563563
// Write the meta page to file.
564+
tx.db.metalock.Lock()
564565
if _, err := tx.db.ops.writeAt(buf, int64(p.Id())*int64(tx.db.pageSize)); err != nil {
566+
tx.db.metalock.Unlock()
565567
lg.Errorf("writeAt failed, pgid: %d, pageSize: %d, error: %v", p.Id(), tx.db.pageSize, err)
566568
return err
567569
}
570+
tx.db.metalock.Unlock()
568571
if !tx.db.NoSync || common.IgnoreNoSync {
569572
// gofail: var beforeSyncMetaPage struct{}
570573
if err := fdatasync(tx.db); err != nil {

0 commit comments

Comments
 (0)