A high performance write-ahead log.
WAL file struct in storage:
┌───────────┬───────────┐
│ 1K header │ logs │
└───────────┴───────────┘
The file header struct:
┌───────────────┬─────────────────────────────┐
│ Length 8Bytes │ Data │
└───────────────┴─────────────────────────────┘
The log item struct:
┌───────────────┬──────────────┬─────────────────────────────────┐
│ Length 8Bytes │ Index 8Bytes │ Data │
└───────────────┴──────────────┴─────────────────────────────────┘
The log min index is 5, max index is 13
If start in (-,5] && end in [13,-)
Need truncate all log, so we remove this file
┌─┬─┬─┬─┬─┬──┬──┬──┬──┐
│5│6│7│8│9│10│11│12│13│
└─┴─┴─┴─┴─┴──┴──┴──┴──┘
The log min index is 5, max index is 13
If start in [5,13) && end in [13,-)
Need truncate from start to last log
┌─┬─┬─┬─┬─┬──┬──┬──┬──┐
│5│6│7│8│9│10│11│12│13│
└─┴─┴─┴─┴─┴──┴──┴──┴──┘
The log min index is 5, max index is 13
If start in (-,5] && end in [5,13]
Need truncate from the first log to end
Put these pos into TruncateArea
┌─┬─┬─┬─┬─┬──┬──┬──┬──┐
│5│6│7│8│9│10│11│12│13│
└─┴─┴─┴─┴─┴──┴──┴──┴──┘
The log min index is 5, max index is 13
If start in [5,13] && end in [5,13]
Need truncate from start to end
Put these pos into TruncateArea
┌─┬─┬─┬─┬─┬──┬──┬──┬──┐
│5│6│7│8│9│10│11│12│13│
└─┴─┴─┴─┴─┴──┴──┴──┴──┘
BatchWrite: 100bytes, 200 logs, loop 10000 1.6s
BatchWrite: 100bytes, 200 logs, loop 10000 5.6s