-
Notifications
You must be signed in to change notification settings - Fork 1
/
value_log.go
66 lines (54 loc) · 1.26 KB
/
value_log.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
63
64
65
66
package eagle
type Record struct {
SeqNumber uint64
Key []byte
Value []byte
}
type ValuePointer struct {
FileId uint32
valueOffset uint32
valueSize uint32
}
type valueLog struct {
*dbFile
fileId uint32
staleDataSize uint32
}
const valueLogFileExt = ".vlog"
func getValueLogFilename(path string, fileId uint32) string {
return path + "/" + getFileName(fileId) + valueLogFileExt
}
func createDataFile(path string, fileId uint32) (*valueLog, error) {
dbFile, err := createDBFile(getValueLogFilename(path, fileId))
if err != nil {
return nil, err
}
return &valueLog{
fileId: uint32(fileId),
dbFile: dbFile,
}, nil
}
func (file *valueLog) createRepairFile() (*valueLog, error) {
dbFile, err := file.dbFile.createRepairFile()
if err != nil {
return nil, err
}
return &valueLog{
fileId: uint32(file.fileId),
dbFile: dbFile,
}, nil
}
func openDataFile(path string, fileId uint32) (*valueLog, error) {
appendFile, err := openDBFile(getValueLogFilename(path, fileId))
if err != nil {
return nil, err
}
return &valueLog{
fileId: uint32(fileId),
dbFile: appendFile,
staleDataSize: 0,
}, nil
}
func recordSize(keySize int, valueSize int) uint32 {
return uint32(4 + entryHeaderSize + keySize + valueSize)
}