Browse Source

rename variables and functions

pull/2534/head
chrislu 3 years ago
parent
commit
2d1a1f5e03
  1. 2
      weed/filesys/dirty_pages_temp_file.go
  2. 12
      weed/filesys/page_writer/chunked_file_writer.go
  3. 1
      weed/filesys/page_writer/page_chunk.go
  4. 36
      weed/filesys/page_writer/page_chunk_interval_list.go
  5. 2
      weed/filesys/page_writer/page_chunk_interval_list_test.go

2
weed/filesys/dirty_pages_temp_file.go

@ -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())
}) })

12
weed/filesys/page_writer/chunked_file_writer.go

@ -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

1
weed/filesys/page_writer/page_chunk.go

@ -1 +0,0 @@
package page_writer

36
weed/filesys/page_writer/page_chunk_interval_list.go

@ -2,31 +2,31 @@ package page_writer
import "math" 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 startOffset int64
stopOffset 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 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, 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) {
interval := &PageChunkWrittenInterval{
func (list *ChunkWrittenIntervalList) MarkWritten(startOffset, stopOffset int64) {
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++

2
weed/filesys/page_writer/page_chunk_interval_list_test.go

@ -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")

Loading…
Cancel
Save