Skip to content

Commit 5e27733

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

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,19 @@ func (tx *Tx) writeMeta() error {
509509
tx.meta.write(p)
510510

511511
// Write the meta page to file.
512+
tx.db.metalock.Lock()
512513
if _, err := tx.db.ops.writeAt(buf, int64(p.id)*int64(tx.db.pageSize)); err != nil {
514+
tx.db.metalock.Unlock()
513515
return err
514516
}
515517
if !tx.db.NoSync || IgnoreNoSync {
516518
// gofail: var beforeSyncMetaPage struct{}
517519
if err := fdatasync(tx.db); err != nil {
520+
tx.db.metalock.Unlock()
518521
return err
519522
}
520523
}
524+
tx.db.metalock.Unlock()
521525

522526
// Update statistics.
523527
tx.stats.IncWrite(1)

0 commit comments

Comments
 (0)