This commit is contained in:
2026-06-05 19:43:01 +00:00
parent db5ecd3dfd
commit 05eea3b279
16 changed files with 1187 additions and 724 deletions

View File

@@ -3,35 +3,34 @@ package database
import (
"gordenko.dev/dima/qb"
"gordenko.dev/dima/qb/atree"
"gordenko.dev/dima/qb/bin"
"gordenko.dev/dima/qb/txlog"
)
// METRIC
type IndexRec struct {
Since uint32
PageNo uint32
type IndexLevelTail struct {
Payload []byte
RecordsCount int
}
type _metric struct {
MetricType qb.MetricType
FracDigits byte
LastPageNo uint32
SinceValue float64
Since uint32
UntilValue float64
Until uint32
Timestamps qb.TimestampCompressor
Values qb.ValueCompressor
// fix - add index levels
XLock bool
RLocks int
WaitQueue []any
//IndexLevels [][]IndexRec // root - last element
IndexLevels [][]byte // root - last element
MetricType qb.MetricType
FracDigits byte
LastPageNo uint32
SinceValue float64
Since uint32
UntilValue float64
Until uint32
Timestamps qb.TimestampCompressor
Values qb.ValueCompressor
XLock bool
RLocks int
WaitQueue []any
IndexLevelTails []IndexLevelTail // root - last element
}
//IndexLevels [][]IndexRec // root - last element
func (s *_metric) ReinitBy(timestamp uint32, value float64) {
s.Timestamps.Renew()
s.Values.Renew()
@@ -74,8 +73,8 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
timestamps = s.Timestamps
values = s.Values
indexLevels []*atree.IndexLevel
dataPages []*atree.DataPage
indexLevels []atree.IndexLevelTail
dataPages []atree.DataPayload
//written int
//resultCode byte
@@ -135,12 +134,10 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
} else {
// сторінка заповнена
// prevPageNo - виставляю в txlog, коли забираю номер сторінки із freeList або генерую новий
dataPages = append(dataPages, &atree.DataPage{
PrevPageNo: 0, // ?
LowerTimestamp: s.Since,
Timestamps: timestamps.Chunks(),
dataPages = append(dataPages, atree.DataPayload{
Since: s.Since,
Content: nil,
TimestampsSize: timestamps.Size(),
Values: values.Chunks(),
ValuesSize: values.Size(),
})
@@ -163,28 +160,31 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
if len(dataPages) > 0 {
// пишу в txlog довгим шляхом через redo файл і запис в data файл
for _, unfilled := range s.IndexLevels {
indexLevels = append(indexLevels, &atree.IndexLevel{
Offset: len(unfilled),
LowerTimestamp: bin.GetUint32(unfilled),
Data: unfilled,
for _, tail := range s.IndexLevelTails {
indexLevels = append(indexLevels, atree.IndexLevelTail{
Payload: tail.Payload,
RecordsCount: tail.RecordsCount,
})
}
sendToStorage(txlog.AppendedMeasures{
MetricID: req.MetricID,
LastPageNo: s.LastPageNo,
TimestampsOffset: timestamps.Offset(), // state.Pos() з якої позиції дописувати дані на сторінку 0 (при відновленні)
ValuesOffset: values.Offset(), // state.Pos()
//Payload: s.payload, // fix - timestamps + values ? or timestamps and values (for WAL)
IndexLevelTails: indexLevels,
DataPages: dataPages,
Timestamps: nil,
Values: nil,
//ResultCode: resultCode,
//WrittenCount: wri,
ResultCh: nil,
})
} else {
// короткий шлях - запис лише в txlog
}
sendToStorage(txlog.AppendedMeasures{
MetricID: req.MetricID,
TimestampsOffset: timestamps.Offset(), // state.Pos() з якої позиції дописувати дані на сторінку 0 (при відновленні)
ValuesOffset: values.Offset(), // state.Pos()
Timestamps: timestamps.Chunks(),
TimestampsSize: timestamps.Size(),
Values: values.Chunks(),
ValuesSize: values.Size(),
IndexLevels: indexLevels,
DataPages: dataPages,
})
}
func (s *_metric) FinAppendMeasures(rec txlog.AppendMeasuresSummary) {