rename variables and functions

This commit is contained in:
chrislu 2021-12-23 17:35:57 -08:00
parent 7bf48ee135
commit 2d1a1f5e03
5 changed files with 26 additions and 27 deletions

View file

@ -63,7 +63,7 @@ func (pages *TempFileDirtyPages) GetStorageOptions() (collection, replication st
func (pages *TempFileDirtyPages) saveChunkedFileToStorage() {
pages.chunkedFile.ProcessEachInterval(func(file *os.File, logicChunkIndex int, interval *page_writer.PageChunkWrittenInterval) {
pages.chunkedFile.ProcessEachInterval(func(file *os.File, logicChunkIndex int, interval *page_writer.ChunkWrittenInterval) {
reader := page_writer.NewFileIntervalReader(pages.chunkedFile, logicChunkIndex, interval)
pages.saveChunkedFileIntevalToStorage(reader, int64(logicChunkIndex)*pages.chunkedFile.ChunkSize, interval.Size())
})

View file

@ -12,7 +12,7 @@ type ChunkedFileWriter struct {
dir string
file *os.File
logicToActualChunkIndex map[int]int
chunkUsages []*PageChunkWrittenIntervalList
chunkUsages []*ChunkWrittenIntervalList
ChunkSize int64
sync.Mutex
}
@ -77,7 +77,7 @@ func (cw *ChunkedFileWriter) ReadDataAt(p []byte, off int64) (maxStop int64) {
return
}
func (cw *ChunkedFileWriter) toActualWriteOffset(logicOffset int64) (actualOffset int64, chunkUsage *PageChunkWrittenIntervalList) {
func (cw *ChunkedFileWriter) toActualWriteOffset(logicOffset int64) (actualOffset int64, chunkUsage *ChunkWrittenIntervalList) {
logicChunkIndex := int(logicOffset / cw.ChunkSize)
offsetRemainder := logicOffset % cw.ChunkSize
existingActualChunkIndex, found := cw.logicToActualChunkIndex[logicChunkIndex]
@ -85,12 +85,12 @@ func (cw *ChunkedFileWriter) toActualWriteOffset(logicOffset int64) (actualOffse
return int64(existingActualChunkIndex)*cw.ChunkSize + offsetRemainder, cw.chunkUsages[existingActualChunkIndex]
}
cw.logicToActualChunkIndex[logicChunkIndex] = len(cw.chunkUsages)
chunkUsage = newPageChunkWrittenIntervalList()
chunkUsage = newChunkWrittenIntervalList()
cw.chunkUsages = append(cw.chunkUsages, chunkUsage)
return int64(len(cw.chunkUsages)-1)*cw.ChunkSize + offsetRemainder, chunkUsage
}
func (cw *ChunkedFileWriter) toActualReadOffset(logicOffset int64) (actualChunkIndex int, chunkUsage *PageChunkWrittenIntervalList) {
func (cw *ChunkedFileWriter) toActualReadOffset(logicOffset int64) (actualChunkIndex int, chunkUsage *ChunkWrittenIntervalList) {
logicChunkIndex := int(logicOffset / cw.ChunkSize)
existingActualChunkIndex, found := cw.logicToActualChunkIndex[logicChunkIndex]
if found {
@ -99,7 +99,7 @@ func (cw *ChunkedFileWriter) toActualReadOffset(logicOffset int64) (actualChunkI
return 0, nil
}
func (cw *ChunkedFileWriter) ProcessEachInterval(process func(file *os.File, logicChunkIndex int, interval *PageChunkWrittenInterval)) {
func (cw *ChunkedFileWriter) ProcessEachInterval(process func(file *os.File, logicChunkIndex int, interval *ChunkWrittenInterval)) {
for logicChunkIndex, actualChunkIndex := range cw.logicToActualChunkIndex {
chunkUsage := cw.chunkUsages[actualChunkIndex]
for t := chunkUsage.head.next; t != chunkUsage.tail; t = t.next {
@ -123,7 +123,7 @@ type FileIntervalReader struct {
var _ = io.Reader(&FileIntervalReader{})
func NewFileIntervalReader(cw *ChunkedFileWriter, logicChunkIndex int, interval *PageChunkWrittenInterval) *FileIntervalReader {
func NewFileIntervalReader(cw *ChunkedFileWriter, logicChunkIndex int, interval *ChunkWrittenInterval) *FileIntervalReader {
actualChunkIndex, found := cw.logicToActualChunkIndex[logicChunkIndex]
if !found {
// this should never happen

View file

@ -1 +0,0 @@
package page_writer

View file

@ -2,31 +2,31 @@ package page_writer
import "math"
// PageChunkWrittenInterval mark one written interval within one page chunk
type PageChunkWrittenInterval struct {
// ChunkWrittenInterval mark one written interval within one page chunk
type ChunkWrittenInterval struct {
startOffset int64
stopOffset int64
prev *PageChunkWrittenInterval
next *PageChunkWrittenInterval
prev *ChunkWrittenInterval
next *ChunkWrittenInterval
}
func (interval *PageChunkWrittenInterval) Size() int64 {
func (interval *ChunkWrittenInterval) Size() int64 {
return interval.stopOffset - interval.startOffset
}
// PageChunkWrittenIntervalList mark written intervals within one page chunk
type PageChunkWrittenIntervalList struct {
head *PageChunkWrittenInterval
tail *PageChunkWrittenInterval
// ChunkWrittenIntervalList mark written intervals within one page chunk
type ChunkWrittenIntervalList struct {
head *ChunkWrittenInterval
tail *ChunkWrittenInterval
}
func newPageChunkWrittenIntervalList() *PageChunkWrittenIntervalList {
list := &PageChunkWrittenIntervalList{
head: &PageChunkWrittenInterval{
func newChunkWrittenIntervalList() *ChunkWrittenIntervalList {
list := &ChunkWrittenIntervalList{
head: &ChunkWrittenInterval{
startOffset: -1,
stopOffset: -1,
},
tail: &PageChunkWrittenInterval{
tail: &ChunkWrittenInterval{
startOffset: math.MaxInt64,
stopOffset: math.MaxInt64,
},
@ -36,14 +36,14 @@ func newPageChunkWrittenIntervalList() *PageChunkWrittenIntervalList {
return list
}
func (list *PageChunkWrittenIntervalList) MarkWritten(startOffset, stopOffset int64) {
interval := &PageChunkWrittenInterval{
func (list *ChunkWrittenIntervalList) MarkWritten(startOffset, stopOffset int64) {
interval := &ChunkWrittenInterval{
startOffset: startOffset,
stopOffset: stopOffset,
}
list.addInterval(interval)
}
func (list *PageChunkWrittenIntervalList) addInterval(interval *PageChunkWrittenInterval) {
func (list *ChunkWrittenIntervalList) addInterval(interval *ChunkWrittenInterval) {
p := list.head
for ; p.next != nil && p.next.startOffset <= interval.startOffset; p = p.next {
@ -81,7 +81,7 @@ func (list *PageChunkWrittenIntervalList) addInterval(interval *PageChunkWritten
}
// unlinkNodesBetween remove all nodes after start and before stop, exclusive
func unlinkNodesBetween(start *PageChunkWrittenInterval, stop *PageChunkWrittenInterval) {
func unlinkNodesBetween(start *ChunkWrittenInterval, stop *ChunkWrittenInterval) {
if start.next == stop {
return
}
@ -91,7 +91,7 @@ func unlinkNodesBetween(start *PageChunkWrittenInterval, stop *PageChunkWrittenI
stop.prev = start
}
func (list *PageChunkWrittenIntervalList) size() int {
func (list *ChunkWrittenIntervalList) size() int {
var count int
for t := list.head; t != nil; t = t.next {
count++

View file

@ -6,7 +6,7 @@ import (
)
func Test_PageChunkWrittenIntervalList(t *testing.T) {
list := newPageChunkWrittenIntervalList()
list := newChunkWrittenIntervalList()
assert.Equal(t, 0, list.size(), "empty list")