mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-30 23:29:02 +08:00
d4566d4aaa
* compare chunks by timestamp
* fix slab clearing error
* fix test compilation
* move oldest chunk to sealed, instead of by fullness
* lock on fh.entryViewCache
* remove verbose logs
* revert slat clearing
* less logs
* less logs
* track write and read by timestamp
* remove useless logic
* add entry lock on file handle release
* use mem chunk only, swap file chunk has problems
* comment out code that maybe used later
* add debug mode to compare data read and write
* more efficient readResolvedChunks with linked list
* small optimization
* fix test compilation
* minor fix on writer
* add SeparateGarbageChunks
* group chunks into sections
* turn off debug mode
* fix tests
* fix tests
* tmp enable swap file chunk
* Revert "tmp enable swap file chunk"
This reverts commit 985137ec47
.
* simple refactoring
* simple refactoring
* do not re-use swap file chunk. Sealed chunks should not be re-used.
* comment out debugging facilities
* either mem chunk or swap file chunk is fine now
* remove orderedMutex as *semaphore.Weighted
not found impactful
* optimize size calculation for changing large files
* optimize performance to avoid going through the long list of chunks
* still problems with swap file chunk
* rename
* tiny optimization
* swap file chunk save only successfully read data
* fix
* enable both mem and swap file chunk
* resolve chunks with range
* rename
* fix chunk interval list
* also change file handle chunk group when adding chunks
* pick in-active chunk with time-decayed counter
* fix compilation
* avoid nil with empty fh.entry
* refactoring
* rename
* rename
* refactor visible intervals to *list.List
* refactor chunkViews to *list.List
* add IntervalList for generic interval list
* change visible interval to use IntervalList in generics
* cahnge chunkViews to *IntervalList[*ChunkView]
* use NewFileChunkSection to create
* rename variables
* refactor
* fix renaming leftover
* renaming
* renaming
* add insert interval
* interval list adds lock
* incrementally add chunks to readers
Fixes:
1. set start and stop offset for the value object
2. clone the value object
3. use pointer instead of copy-by-value when passing to interval.Value
4. use insert interval since adding chunk could be out of order
* fix tests compilation
* fix tests compilation
328 lines
8.6 KiB
Go
328 lines
8.6 KiB
Go
package filer
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
type IntervalInt int
|
|
|
|
func (i IntervalInt) SetStartStop(start, stop int64) {
|
|
}
|
|
func (i IntervalInt) Clone() IntervalValue {
|
|
return i
|
|
}
|
|
|
|
func TestIntervalList_Overlay(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(0, 100, 1, 1)
|
|
list.Overlay(50, 150, 2, 2)
|
|
list.Overlay(200, 250, 3, 3)
|
|
list.Overlay(225, 250, 4, 4)
|
|
list.Overlay(175, 210, 5, 5)
|
|
list.Overlay(0, 25, 6, 6)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 6, list.Len())
|
|
println()
|
|
list.Overlay(50, 150, 7, 7)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 6, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay2(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(0, 50, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
}
|
|
|
|
func TestIntervalList_Overlay3(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
assert.Equal(t, 1, list.Len())
|
|
|
|
list.Overlay(0, 60, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay4(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(0, 100, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 1, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay5(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(0, 110, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 1, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay6(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(50, 110, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 1, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay7(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(50, 90, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay8(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(60, 90, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 3, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay9(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(60, 100, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay10(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(50, 100, 1, 1)
|
|
list.Overlay(60, 110, 2, 2)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_Overlay11(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.Overlay(0, 100, 1, 1)
|
|
list.Overlay(100, 110, 2, 2)
|
|
list.Overlay(0, 90, 3, 3)
|
|
list.Overlay(0, 80, 4, 4)
|
|
list.Overlay(0, 90, 5, 5)
|
|
list.Overlay(90, 90, 6, 6)
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 3, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval1(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(200, 250, 3, 3)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval2(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(0, 25, 3, 3)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval3(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(0, 75, 3, 3)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 3, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval4(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(0, 225, 3, 3)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval5(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(0, 225, 5, 5)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval6(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(0, 275, 1, 1)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 5, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval7(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(75, 275, 1, 1)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 4, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval8(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(75, 275, 3, 3)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 4, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval9(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
|
|
list.InsertInterval(50, 150, 2, 2)
|
|
list.InsertInterval(200, 250, 4, 4)
|
|
|
|
list.InsertInterval(50, 150, 3, 3)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 2, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval10(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
|
|
list.InsertInterval(50, 100, 2, 2)
|
|
|
|
list.InsertInterval(200, 300, 4, 4)
|
|
|
|
list.InsertInterval(100, 200, 5, 5)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 3, list.Len())
|
|
}
|
|
|
|
func TestIntervalList_insertInterval11(t *testing.T) {
|
|
list := NewIntervalList[IntervalInt]()
|
|
|
|
list.InsertInterval(0, 64, 1, 1)
|
|
|
|
list.InsertInterval(72, 136, 3, 3)
|
|
|
|
list.InsertInterval(64, 128, 2, 2)
|
|
|
|
list.InsertInterval(68, 72, 4, 4)
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 4, list.Len())
|
|
}
|
|
|
|
type IntervalStruct struct {
|
|
x int
|
|
start int64
|
|
stop int64
|
|
}
|
|
|
|
func newIntervalStruct(i int) IntervalStruct {
|
|
return IntervalStruct{
|
|
x: i,
|
|
}
|
|
}
|
|
|
|
func (i IntervalStruct) SetStartStop(start, stop int64) {
|
|
i.start, i.stop = start, stop
|
|
}
|
|
func (i IntervalStruct) Clone() IntervalValue {
|
|
return &IntervalStruct{
|
|
x: i.x,
|
|
start: i.start,
|
|
stop: i.stop,
|
|
}
|
|
}
|
|
|
|
func TestIntervalList_insertIntervalStruct(t *testing.T) {
|
|
list := NewIntervalList[IntervalStruct]()
|
|
|
|
list.InsertInterval(0, 64, 1, newIntervalStruct(1))
|
|
|
|
list.InsertInterval(64, 72, 2, newIntervalStruct(2))
|
|
|
|
list.InsertInterval(72, 136, 3, newIntervalStruct(3))
|
|
|
|
list.InsertInterval(64, 68, 4, newIntervalStruct(4))
|
|
|
|
for p := list.Front(); p != nil; p = p.Next {
|
|
fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
|
|
}
|
|
assert.Equal(t, 4, list.Len())
|
|
}
|