|
@ -6,6 +6,7 @@ import "math" |
|
|
type ChunkWrittenInterval struct { |
|
|
type ChunkWrittenInterval struct { |
|
|
StartOffset int64 |
|
|
StartOffset int64 |
|
|
stopOffset int64 |
|
|
stopOffset int64 |
|
|
|
|
|
flushed bool |
|
|
prev *ChunkWrittenInterval |
|
|
prev *ChunkWrittenInterval |
|
|
next *ChunkWrittenInterval |
|
|
next *ChunkWrittenInterval |
|
|
} |
|
|
} |
|
@ -18,6 +19,10 @@ func (interval *ChunkWrittenInterval) isComplete(chunkSize int64) bool { |
|
|
return interval.stopOffset-interval.StartOffset == chunkSize |
|
|
return interval.stopOffset-interval.StartOffset == chunkSize |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (interval *ChunkWrittenInterval) MarkFlushed() { |
|
|
|
|
|
interval.flushed = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// ChunkWrittenIntervalList mark written intervals within one page chunk
|
|
|
// ChunkWrittenIntervalList mark written intervals within one page chunk
|
|
|
type ChunkWrittenIntervalList struct { |
|
|
type ChunkWrittenIntervalList struct { |
|
|
head *ChunkWrittenInterval |
|
|
head *ChunkWrittenInterval |
|
@ -64,18 +69,21 @@ func (list *ChunkWrittenIntervalList) addInterval(interval *ChunkWrittenInterval |
|
|
if interval.StartOffset <= p.stopOffset && q.StartOffset <= interval.stopOffset { |
|
|
if interval.StartOffset <= p.stopOffset && q.StartOffset <= interval.stopOffset { |
|
|
// merge p and q together
|
|
|
// merge p and q together
|
|
|
p.stopOffset = q.stopOffset |
|
|
p.stopOffset = q.stopOffset |
|
|
|
|
|
p.flushed = false |
|
|
unlinkNodesBetween(p, q.next) |
|
|
unlinkNodesBetween(p, q.next) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if interval.StartOffset <= p.stopOffset { |
|
|
if interval.StartOffset <= p.stopOffset { |
|
|
// merge new interval into p
|
|
|
// merge new interval into p
|
|
|
p.stopOffset = interval.stopOffset |
|
|
p.stopOffset = interval.stopOffset |
|
|
|
|
|
p.flushed = false |
|
|
unlinkNodesBetween(p, q) |
|
|
unlinkNodesBetween(p, q) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if q.StartOffset <= interval.stopOffset { |
|
|
if q.StartOffset <= interval.stopOffset { |
|
|
// merge new interval into q
|
|
|
// merge new interval into q
|
|
|
q.StartOffset = interval.StartOffset |
|
|
q.StartOffset = interval.StartOffset |
|
|
|
|
|
q.flushed = false |
|
|
unlinkNodesBetween(p, q) |
|
|
unlinkNodesBetween(p, q) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|