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() { 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) reader := page_writer.NewFileIntervalReader(pages.chunkedFile, logicChunkIndex, interval)
pages.saveChunkedFileIntevalToStorage(reader, int64(logicChunkIndex)*pages.chunkedFile.ChunkSize, interval.Size()) pages.saveChunkedFileIntevalToStorage(reader, int64(logicChunkIndex)*pages.chunkedFile.ChunkSize, interval.Size())
}) })

View file

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

View file

@ -1 +0,0 @@
package page_writer

View file

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

View file

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