forked from wal-g/wal-g
/
delta_no.go
55 lines (42 loc) · 1.36 KB
/
delta_no.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
package internal
import "strings"
type DeltaNo uint64
func NewDeltaNoFromWalSegmentNo(walSegmentNo WalSegmentNo) DeltaNo {
no := uint64(walSegmentNo) - (uint64(walSegmentNo) % WalFileInDelta)
return DeltaNo(no)
}
func NewDeltaNoFromLsn(lsn uint64) DeltaNo {
return NewDeltaNoFromWalSegmentNo(NewWalSegmentNo(lsn))
}
func NewDeltaNoFromFilename(filename string) (DeltaNo, error) {
filename = strings.TrimSuffix(filename, DeltaFilenameSuffix)
_, no, err := ParseWALFilename(filename)
return DeltaNo(no), err
}
func NewDeltaNoFromFilenameNoError(filename string) DeltaNo {
filename = strings.TrimSuffix(filename, DeltaFilenameSuffix)
_, no, _ := ParseWALFilename(filename)
return DeltaNo(no)
}
func (deltaNo DeltaNo) Next() DeltaNo {
return deltaNo.Add(1)
}
func (deltaNo DeltaNo) Previous() DeltaNo {
return deltaNo.Sub(1)
}
func (deltaNo DeltaNo) Add(n uint64) DeltaNo {
deltaNo = DeltaNo(uint64(deltaNo) + n*WalFileInDelta)
return deltaNo
}
func (deltaNo DeltaNo) Sub(n uint64) DeltaNo {
return DeltaNo(uint64(deltaNo) - n*WalFileInDelta)
}
func (deltaNo DeltaNo) FirstWalSegmentNo() WalSegmentNo {
return WalSegmentNo(deltaNo)
}
func (deltaNo DeltaNo) FirstLsn() uint64 {
return deltaNo.FirstWalSegmentNo().FirstLsn()
}
func (deltaNo DeltaNo) GetFilename(timeline uint32) string {
return deltaNo.FirstWalSegmentNo().GetFilename(timeline) + DeltaFilenameSuffix
}