Browse Source

wal/wal.go: modified WAL.SaveSnapshot to do the Marshal before aquiring the mutex

Vimal Kumar 9 years ago
parent
commit
f4ec303d1b
1 changed files with 2 additions and 1 deletions
  1. 2 1
      wal/wal.go

+ 2 - 1
wal/wal.go

@@ -567,10 +567,11 @@ func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error {
 }
 }
 
 
 func (w *WAL) SaveSnapshot(e walpb.Snapshot) error {
 func (w *WAL) SaveSnapshot(e walpb.Snapshot) error {
+	b := pbutil.MustMarshal(&e)
+
 	w.mu.Lock()
 	w.mu.Lock()
 	defer w.mu.Unlock()
 	defer w.mu.Unlock()
 
 
-	b := pbutil.MustMarshal(&e)
 	rec := &walpb.Record{Type: snapshotType, Data: b}
 	rec := &walpb.Record{Type: snapshotType, Data: b}
 	if err := w.encoder.encode(rec); err != nil {
 	if err := w.encoder.encode(rec); err != nil {
 		return err
 		return err