You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.0 KiB

4 years ago
4 years ago
4 years ago
more solid weed mount (#4089) * 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 985137ec472924e4815f258189f6ca9f2168a0a7. * 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
2 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
more solid weed mount (#4089) * 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 985137ec472924e4815f258189f6ca9f2168a0a7. * 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
2 years ago
4 years ago
4 years ago
more solid weed mount (#4089) * 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 985137ec472924e4815f258189f6ca9f2168a0a7. * 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
2 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
more solid weed mount (#4089) * 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 985137ec472924e4815f258189f6ca9f2168a0a7. * 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
2 years ago
3 years ago
3 years ago
more solid weed mount (#4089) * 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 985137ec472924e4815f258189f6ca9f2168a0a7. * 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
2 years ago
more solid weed mount (#4089) * 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 985137ec472924e4815f258189f6ca9f2168a0a7. * 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
2 years ago
  1. package filer
  2. import (
  3. "bytes"
  4. "io"
  5. "math"
  6. "strconv"
  7. "testing"
  8. )
  9. type mockChunkCache struct {
  10. }
  11. func (m *mockChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) {
  12. x, _ := strconv.Atoi(fileId)
  13. data = make([]byte, minSize)
  14. for i := 0; i < int(minSize); i++ {
  15. data[i] = byte(x)
  16. }
  17. return data
  18. }
  19. func (m *mockChunkCache) ReadChunkAt(data []byte, fileId string, offset uint64) (n int, err error) {
  20. x, _ := strconv.Atoi(fileId)
  21. for i := 0; i < len(data); i++ {
  22. data[i] = byte(x)
  23. }
  24. return len(data), nil
  25. }
  26. func (m *mockChunkCache) SetChunk(fileId string, data []byte) {
  27. }
  28. func TestReaderAt(t *testing.T) {
  29. visibles := NewIntervalList[*VisibleInterval]()
  30. addVisibleInterval(visibles, &VisibleInterval{
  31. start: 1,
  32. stop: 2,
  33. fileId: "1",
  34. chunkSize: 9,
  35. })
  36. addVisibleInterval(visibles, &VisibleInterval{
  37. start: 3,
  38. stop: 4,
  39. fileId: "3",
  40. chunkSize: 1,
  41. })
  42. addVisibleInterval(visibles, &VisibleInterval{
  43. start: 5,
  44. stop: 6,
  45. fileId: "5",
  46. chunkSize: 2,
  47. })
  48. addVisibleInterval(visibles, &VisibleInterval{
  49. start: 7,
  50. stop: 9,
  51. fileId: "7",
  52. chunkSize: 2,
  53. })
  54. addVisibleInterval(visibles, &VisibleInterval{
  55. start: 9,
  56. stop: 10,
  57. fileId: "9",
  58. chunkSize: 2,
  59. })
  60. readerAt := &ChunkReadAt{
  61. chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64),
  62. fileSize: 10,
  63. readerCache: NewReaderCache(3, &mockChunkCache{}, nil),
  64. readerPattern: NewReaderPattern(),
  65. }
  66. testReadAt(t, readerAt, 0, 10, 10, io.EOF, nil, nil)
  67. testReadAt(t, readerAt, 0, 12, 12, io.EOF, nil, nil)
  68. testReadAt(t, readerAt, 2, 8, 8, io.EOF, nil, nil)
  69. testReadAt(t, readerAt, 3, 6, 6, nil, nil, nil)
  70. }
  71. func testReadAt(t *testing.T, readerAt *ChunkReadAt, offset int64, size int, expectedN int, expectedErr error, data, expectedData []byte) {
  72. if data == nil {
  73. data = make([]byte, size)
  74. }
  75. n, _, err := readerAt.doReadAt(data, offset)
  76. if expectedN != n {
  77. t.Errorf("unexpected read size: %d, expect: %d", n, expectedN)
  78. }
  79. if err != expectedErr {
  80. t.Errorf("unexpected read error: %v, expect: %v", err, expectedErr)
  81. }
  82. if expectedData != nil && !bytes.Equal(data, expectedData) {
  83. t.Errorf("unexpected read data: %v, expect: %v", data, expectedData)
  84. }
  85. }
  86. func TestReaderAt0(t *testing.T) {
  87. visibles := NewIntervalList[*VisibleInterval]()
  88. addVisibleInterval(visibles, &VisibleInterval{
  89. start: 2,
  90. stop: 5,
  91. fileId: "1",
  92. chunkSize: 9,
  93. })
  94. addVisibleInterval(visibles, &VisibleInterval{
  95. start: 7,
  96. stop: 9,
  97. fileId: "2",
  98. chunkSize: 9,
  99. })
  100. readerAt := &ChunkReadAt{
  101. chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64),
  102. fileSize: 10,
  103. readerCache: NewReaderCache(3, &mockChunkCache{}, nil),
  104. readerPattern: NewReaderPattern(),
  105. }
  106. testReadAt(t, readerAt, 0, 10, 10, io.EOF, nil, nil)
  107. testReadAt(t, readerAt, 3, 16, 7, io.EOF, nil, nil)
  108. testReadAt(t, readerAt, 3, 5, 5, nil, nil, nil)
  109. testReadAt(t, readerAt, 11, 5, 5, io.EOF, nil, nil)
  110. testReadAt(t, readerAt, 10, 5, 5, io.EOF, nil, nil)
  111. }
  112. func TestReaderAt1(t *testing.T) {
  113. visibles := NewIntervalList[*VisibleInterval]()
  114. addVisibleInterval(visibles, &VisibleInterval{
  115. start: 2,
  116. stop: 5,
  117. fileId: "1",
  118. chunkSize: 9,
  119. })
  120. readerAt := &ChunkReadAt{
  121. chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64),
  122. fileSize: 20,
  123. readerCache: NewReaderCache(3, &mockChunkCache{}, nil),
  124. readerPattern: NewReaderPattern(),
  125. }
  126. testReadAt(t, readerAt, 0, 20, 20, io.EOF, nil, nil)
  127. testReadAt(t, readerAt, 1, 7, 7, nil, nil, nil)
  128. testReadAt(t, readerAt, 0, 1, 1, nil, nil, nil)
  129. testReadAt(t, readerAt, 18, 4, 2, io.EOF, nil, nil)
  130. testReadAt(t, readerAt, 12, 4, 4, nil, nil, nil)
  131. testReadAt(t, readerAt, 4, 20, 16, io.EOF, nil, nil)
  132. testReadAt(t, readerAt, 4, 10, 10, nil, nil, nil)
  133. testReadAt(t, readerAt, 1, 10, 10, nil, nil, nil)
  134. }
  135. func TestReaderAtGappedChunksDoNotLeak(t *testing.T) {
  136. visibles := NewIntervalList[*VisibleInterval]()
  137. addVisibleInterval(visibles, &VisibleInterval{
  138. start: 2,
  139. stop: 3,
  140. fileId: "1",
  141. chunkSize: 5,
  142. })
  143. addVisibleInterval(visibles, &VisibleInterval{
  144. start: 7,
  145. stop: 9,
  146. fileId: "1",
  147. chunkSize: 4,
  148. })
  149. readerAt := &ChunkReadAt{
  150. chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64),
  151. fileSize: 9,
  152. readerCache: NewReaderCache(3, &mockChunkCache{}, nil),
  153. readerPattern: NewReaderPattern(),
  154. }
  155. testReadAt(t, readerAt, 0, 9, 9, io.EOF, []byte{2, 2, 2, 2, 2, 2, 2, 2, 2}, []byte{0, 0, 1, 0, 0, 0, 0, 1, 1})
  156. testReadAt(t, readerAt, 1, 8, 8, io.EOF, []byte{2, 2, 2, 2, 2, 2, 2, 2}, []byte{0, 1, 0, 0, 0, 0, 1, 1})
  157. }
  158. func TestReaderAtSparseFileDoesNotLeak(t *testing.T) {
  159. readerAt := &ChunkReadAt{
  160. chunkViews: ViewFromVisibleIntervals(NewIntervalList[*VisibleInterval](), 0, math.MaxInt64),
  161. fileSize: 3,
  162. readerCache: NewReaderCache(3, &mockChunkCache{}, nil),
  163. readerPattern: NewReaderPattern(),
  164. }
  165. testReadAt(t, readerAt, 0, 3, 3, io.EOF, []byte{2, 2, 2}, []byte{0, 0, 0})
  166. testReadAt(t, readerAt, 1, 2, 2, io.EOF, []byte{2, 2}, []byte{0, 0})
  167. }