From 2d1a1f5e0310e9228fe4e22b248b1d1c5ac97ec8 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 23 Dec 2021 17:35:57 -0800 Subject: [PATCH] rename variables and functions --- weed/filesys/dirty_pages_temp_file.go | 2 +- .../page_writer/chunked_file_writer.go | 12 +++---- weed/filesys/page_writer/page_chunk.go | 1 - .../page_writer/page_chunk_interval_list.go | 36 +++++++++---------- .../page_chunk_interval_list_test.go | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 weed/filesys/page_writer/page_chunk.go diff --git a/weed/filesys/dirty_pages_temp_file.go b/weed/filesys/dirty_pages_temp_file.go index cc6f4dc29..9690d6768 100644 --- a/weed/filesys/dirty_pages_temp_file.go +++ b/weed/filesys/dirty_pages_temp_file.go @@ -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()) }) diff --git a/weed/filesys/page_writer/chunked_file_writer.go b/weed/filesys/page_writer/chunked_file_writer.go index 180a2039d..9e98c6194 100644 --- a/weed/filesys/page_writer/chunked_file_writer.go +++ b/weed/filesys/page_writer/chunked_file_writer.go @@ -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 diff --git a/weed/filesys/page_writer/page_chunk.go b/weed/filesys/page_writer/page_chunk.go deleted file mode 100644 index b21e6acca..000000000 --- a/weed/filesys/page_writer/page_chunk.go +++ /dev/null @@ -1 +0,0 @@ -package page_writer diff --git a/weed/filesys/page_writer/page_chunk_interval_list.go b/weed/filesys/page_writer/page_chunk_interval_list.go index 09fc45bfb..9c518192f 100644 --- a/weed/filesys/page_writer/page_chunk_interval_list.go +++ b/weed/filesys/page_writer/page_chunk_interval_list.go @@ -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++ diff --git a/weed/filesys/page_writer/page_chunk_interval_list_test.go b/weed/filesys/page_writer/page_chunk_interval_list_test.go index f54b229d8..b22f5eb5d 100644 --- a/weed/filesys/page_writer/page_chunk_interval_list_test.go +++ b/weed/filesys/page_writer/page_chunk_interval_list_test.go @@ -6,7 +6,7 @@ import ( ) func Test_PageChunkWrittenIntervalList(t *testing.T) { - list := newPageChunkWrittenIntervalList() + list := newChunkWrittenIntervalList() assert.Equal(t, 0, list.size(), "empty list")