Skip to content

Commit

Permalink
fixing of writing of snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
saromanov committed Mar 8, 2019
1 parent c99ef8b commit fd944a1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
40 changes: 40 additions & 0 deletions store/ligthstore.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set;
0
bar+0
end;
set;
1
bar+1
end;
set;
2
bar+2
end;
set;
3
bar+3
end;
set;
4
bar+4
end;
set;
5
bar+5
end;
set;
6
bar+6
end;
set;
7
bar+7
end;
set;
8
bar+8
end;
set;
9
bar+9
end;
10 changes: 9 additions & 1 deletion store/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ func (so *Snapshot) Write(w io.Writer) error {
Key: itm.Key(),
Value: itm.ValueData(),
}
err := binary.Write(buf, binary.LittleEndian, data)
err := binary.Write(w, binary.LittleEndian, uint64(data.Size()))
if err != nil {
return errors.Wrap(err, "unable to write size info")
}
bufWr, err := data.Marshal()
if err != nil {
return errors.Wrap(err, "unable to marshal data")
}
_, err = w.Write(bufWr)
if err != nil {
return errors.Wrap(err, "unable to write data")
}
Expand Down
8 changes: 7 additions & 1 deletion store/snapshot_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

import (
"os"
"testing"
)

Expand All @@ -21,8 +22,13 @@ func TestSnapshot(t *testing.T) {
t.Fatalf("unable to write data: %v", err)
}

f, err := os.Create("/tmp/dat2")
if err != nil {
t.Fatalf("unable to write data: %v", err)
}
defer f.Close()
snap := NewSnapshot(light.getStore(), "./snapshot1")
err = snap.Write(nil)
err = snap.Write(f)
if err != nil {
t.Fatalf("unable to write snapshot: %v", err)
}
Expand Down

0 comments on commit fd944a1

Please sign in to comment.