-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
62 lines (55 loc) · 1.19 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package wal
import (
"os"
"sync"
"sync/atomic"
)
const (
// MaxRecordSize is the maximum size of a record
MaxRecordSize = 1<<32 - 1
// SyncConcurrency is the number of concurrent syncs
SyncConcurrency = 1 << 10
// RecordHeaderSize is the size of the record header
RecordHeaderSize = 8
)
// Reader represents a reader for the write ahead log,
// Reader is thread-unsafe
type Reader struct {
w *Wal
// read position for the next record
pos int64
// size of the write ahead log
size int64
// data is the buffer for read write ahead log
data []byte
// recordHeader is the header of a record
h recordHeader
}
// WAL represents a write ahead log that provides durability
// and fault-tolerance for incoming writes
type Wal struct {
sync.RWMutex
name string
fp *os.File
// byte position where the record is writen
pos atomic.Int64
ch chan *request
}
type request struct {
// record position
pos int64
err error
data []byte
wg sync.WaitGroup
}
// recordHeader is the header of a record
type recordHeader struct {
sum uint32 // checksum of record
size uint32 // size of record
}
// any is used to avoid allocation
var reqPool = sync.Pool{
New: func() any {
return new(request)
},
}