Skip to content

Commit

Permalink
Use reader in restore (#46)
Browse files Browse the repository at this point in the history
* Use reader in restore

* save
  • Loading branch information
kelindar committed Dec 28, 2021
1 parent e00421d commit 45c34f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions commit/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ func (w *Channel) Append(commit Commit) error {
// during a snapshot. It also supports reading a commit log back.
type Log struct {
lock sync.Mutex
source io.ReadWriter
source io.Reader
writer *iostream.Writer
reader *iostream.Reader
}

// Open opens a commit log stream for both read and write.
func Open(source io.ReadWriter) *Log {
return &Log{
func Open(source io.Reader) *Log {
log := &Log{
source: source,
writer: iostream.NewWriter(s2.NewWriter(source)),
reader: iostream.NewReader(s2.NewReader(source)),
}

if rw, ok := source.(io.Writer); ok {
log.writer = iostream.NewWriter(s2.NewWriter(rw))
}
return log
}

// OpenFile opens a specified commit log file in a read/write mode. If
Expand Down
2 changes: 1 addition & 1 deletion snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *Collection) Replay(change commit.Commit) error {

// Restore restores the collection from the underlying snapshot reader. This operation
// should be called before any of transactions, right after initialization.
func (c *Collection) Restore(snapshot io.ReadWriter) error {
func (c *Collection) Restore(snapshot io.Reader) error {
commits, err := c.readState(s2.NewReader(snapshot))
if err != nil {
return err
Expand Down

0 comments on commit 45c34f5

Please sign in to comment.