Skip to content

Commit 9b6f787

Browse files
committed
changes on comment lines
1 parent 8074787 commit 9b6f787

File tree

5 files changed

+17
-24
lines changed

5 files changed

+17
-24
lines changed

aof.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ type AOF struct {
4141
aofChan chan *AofCmd
4242
Options *AOFOptions
4343
listeners map[Listener]struct{}
44-
buffer []CmdLine
44+
buffer [][][]byte
4545
segment *os.File
4646
segments []*segment
4747

4848
reader *Reader
4949
}
5050

51+
type AofCmd struct {
52+
CmdLine [][]byte
53+
DbIndex int
54+
Wg *sync.WaitGroup
55+
}
56+
5157
func NewAOF(aofOptions *AOFOptions) (*AOF, error) {
5258
var err error
5359

@@ -74,15 +80,14 @@ func NewAOF(aofOptions *AOFOptions) (*AOF, error) {
7480
return nil, err
7581
}
7682

77-
// schedule fsync every 1 second to avoid data loss
7883
go func() {
7984
for {
8085
select {
8186
case <-aof.ctx.Done():
8287
return
8388
default:
8489
if FsyncEverySecond == aof.Options.Fsync {
85-
aof.fsync()
90+
aof.fsync() // fsync every second
8691
}
8792
aof.Retention()
8893
time.Sleep(time.Second * 1)
@@ -95,7 +100,7 @@ func NewAOF(aofOptions *AOFOptions) (*AOF, error) {
95100
}
96101

97102
// WriteAof writes a new entry to the Append-Only Log.
98-
func (aof *AOF) WriteAof(p *AofCmd) {
103+
func (aof *AOF) WriteAof(p *AofCmd) error {
99104
aof.sync.Lock()
100105
defer aof.sync.Unlock()
101106
aof.buffer = aof.buffer[:0] // clear the buffer
@@ -107,7 +112,7 @@ func (aof *AOF) WriteAof(p *AofCmd) {
107112

108113
// write to aof file in byte format
109114
if _, err := aof.segment.Write(bufferInBytes); err != nil {
110-
panic(err) // TODO: use a logger
115+
return err
111116
}
112117

113118
if FsyncAlways == aof.Options.Fsync {
@@ -118,6 +123,8 @@ func (aof *AOF) WriteAof(p *AofCmd) {
118123
for listener := range aof.listeners {
119124
listener.Callback(aof.buffer)
120125
}
126+
127+
return nil
121128
}
122129

123130
// bufferToBytes converts the buffer to bytes and adds a file header.

cmd.go

-11
This file was deleted.

file.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ func (aof *AOF) fsync() {
1818
aof.sync.Lock()
1919
defer aof.sync.Unlock()
2020

21-
if err := aof.segment.Sync(); err != nil {
22-
panic(err) // TODO: use a logger
23-
}
21+
aof.segment.Sync()
2422
}
2523

2624
func (aof *AOF) loadFiles() error {

listener.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package aof
22

3-
// Listener going to run after aofChan receive a command
4-
// and before the command is written to the aof file
3+
// Listener uns after aofChan receive a command
54
type Listener interface {
6-
Callback([]CmdLine)
5+
Callback([][][]byte)
76
}
87

98
func (aof *AOF) AddListener(listener Listener) {

retention.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package aof
22

3-
// we need retention to be able to check if size of the aof file is greater than 20MB
4-
// if it is, we need to create a new segment and write to it
3+
// Checks if the segment file is greater than the maximum size.
4+
// If it is, then create a new segment file and close the current one.
55
func (aof *AOF) Retention() error {
66
stat, err := aof.segment.Stat()
77
if err != nil {

0 commit comments

Comments
 (0)