Files
qb/storage/storage.go

129 lines
2.7 KiB
Go
Raw Normal View History

2026-06-10 06:18:45 +03:00
package storage
2026-06-13 08:01:42 +03:00
import "gordenko.dev/dima/qb"
var (
2026-06-10 06:18:45 +03:00
//PageNoSize = 4
// data page
2026-06-13 07:13:03 +00:00
DataPageSize = 8192
2026-06-10 06:18:45 +03:00
DataPagePayloadSize int = DataPageSize - DataPageFooterSize
dataCRC32Idx = DataPageSize - 4
timestampsSizeIdx = DataPageSize - 6
valuesSizeIdx = DataPageSize - 8
prevPageIdx = DataPageSize - 12
// index page
2026-06-13 07:13:03 +00:00
IndexPageSize = 1024
2026-06-13 08:01:42 +03:00
//indexPageIncSize = IndexPageIncSize
2026-06-13 07:13:03 +00:00
indexCRC32Idx = IndexPageSize - 4
indexRecordsCountIdx = IndexPageSize - 6
isZeroLevelIdx = IndexPageSize - 7
2026-06-10 06:18:45 +03:00
maxRecordsOnIndexPage = (IndexPageSize - IndexPageFooterSize) / indexRecordSize
// timestampSize = 4
// pairSize = timestampSize + PageNoSize
// indexFooterIdx = indexRecordsQtyIdx
// dataFooterIdx = timestampsSizeIdx
)
2026-06-13 08:01:42 +03:00
2026-06-13 07:13:03 +00:00
const (
DataPageFooterSize = 12
IndexPageFooterSize = 7
indexRecordSize = 8
)
2026-06-13 08:01:42 +03:00
type IndexRecord struct {
Timestamp uint32
PageNo uint32
}
// TASKS FROM WORKER
type MetricAdd struct {
MetricID uint32
MetricType qb.MetricType
FracDigits byte
ResultCh chan struct{}
}
type MetricDelete struct {
MetricID uint32
FreeIndexPages []uint32
FreeDataPages []uint32
ResultCh chan struct{}
}
type MeasuresAppendWithGrow struct {
MetricID uint32
LastPageNo uint32
TimestampsRewindOffset int // offset on 1st page
Timestamps []byte
ValuesRewindOffset int // offset on 1st page
Values []byte
DataPages []DataPayload
TailTimestamps []byte // data level tail
TailValues []byte // data level tail
IndexLevelTails []IndexLevelTail
ResultCode byte
WrittenCount int
ResultCh chan struct{}
}
type MeasuresAppend struct {
MetricID uint32
TimestampsRewindOffset int // offset on 1st page
Timestamps []byte
ValuesRewindOffset int // offset on 1st page
Values []byte
ResultCode byte
WrittenCount int
ResultCh chan struct{}
}
type MeasuresDelete struct {
MetricID uint32
FreeIndexPages []uint32
FreeDataPages []uint32
ResultCh chan struct{}
}
// WRITE RESULTS
// результат
type MeasuresAppendCommited struct {
MetricID uint32
ResultCode byte
WrittenCount int
ResultCh chan struct{}
}
type MeasuresAppendWithGrowCommited struct {
MetricID uint32
LastPageNo uint32
Index []IndexLevelTail
ResultCode byte
WrittenCount int
ResultCh chan struct{}
}
type MeasuresDeleteCommited struct {
MetricID uint32
ResultCh chan struct{}
}
type MetricAddCommited struct {
MetricID uint32
ResultCh chan struct{}
}
type MetricDeleteCommited struct {
MetricID uint32
ResultCh chan struct{}
}