wp
This commit is contained in:
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
bin "gordenko.dev/dima/bin/little"
|
||||
"gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/atree"
|
||||
"gordenko.dev/dima/qb/txlog"
|
||||
"gordenko.dev/dima/qb/storage"
|
||||
)
|
||||
|
||||
// METRIC
|
||||
@@ -31,7 +30,7 @@ type _metric struct {
|
||||
XLock bool
|
||||
RLocks int
|
||||
WaitQueue []any
|
||||
indexLevelTails []txlog.IndexLevelTail // root - last element
|
||||
indexLevelTails []storage.IndexLevelTail // root - last element
|
||||
}
|
||||
|
||||
//IndexLevels [][]IndexRec // root - last element
|
||||
@@ -60,7 +59,7 @@ func (s *_metric) DeleteMeasures() {
|
||||
// s.UntilValue = 0
|
||||
}
|
||||
|
||||
// func (s *_metric) startAppendMeasures(req tryAppendMeasuresReq, sendToStorage func(txlog.AppendedMeasures)) {
|
||||
// func (s *_metric) startAppendMeasures(req tryAppendMeasuresReq, sendToStorage func(storage.AppendedMeasures)) {
|
||||
func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage func(any)) {
|
||||
var (
|
||||
// AppendedMeasures struct {
|
||||
@@ -78,7 +77,7 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
|
||||
timestamps = s.timestamps
|
||||
values = s.values
|
||||
|
||||
dataPages []txlog.DataPayload
|
||||
dataPages []storage.DataPayload
|
||||
|
||||
//written int
|
||||
//resultCode byte
|
||||
@@ -92,7 +91,7 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
|
||||
// s.Since = measure.Timestamp
|
||||
// } else {
|
||||
// FIX - у випадку помилки треба в транзакції зберегти що помилка, але також зафіксувати скільки елементів збережено.
|
||||
// якщо idx == 0 - одразу знімаю блокування і нічого не відправляю в txlog
|
||||
// якщо idx == 0 - одразу знімаю блокування і нічого не відправляю в storage
|
||||
if measure.Timestamp <= s.timestamps.LastTimestamp() {
|
||||
if idx == 0 {
|
||||
s.values.ForgetCapturedState()
|
||||
@@ -136,7 +135,7 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
|
||||
// накопичую
|
||||
timestamps.Compress(timestampCompressionWay, measure.Timestamp)
|
||||
values.Compress(valueCompressionWay, measure.Value)
|
||||
} else if len(s.buffer) < atree.DataPagePayloadSize {
|
||||
} else if len(s.buffer) < storage.DataPagePayloadSize {
|
||||
// allocate bigger buffer
|
||||
buffer := make([]byte, len(s.buffer)*2)
|
||||
// copy timestamps
|
||||
@@ -151,7 +150,7 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
|
||||
// сторінка заповнена
|
||||
since := s.timestamps.ReplaceSinceWithUntil()
|
||||
|
||||
dataPages = append(dataPages, txlog.DataPayload{
|
||||
dataPages = append(dataPages, storage.DataPayload{
|
||||
Since: since,
|
||||
Content: s.buffer,
|
||||
TimestampsSize: timestamps.Size(),
|
||||
@@ -180,8 +179,8 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
|
||||
// скопіювати. Причому можна скопіювати зрізи chunks
|
||||
|
||||
if len(dataPages) > 0 {
|
||||
// пишу в txlog довгим шляхом через redo файл і запис в data файл
|
||||
sendToStorage(txlog.AppendedMeasures{
|
||||
// пишу в storage довгим шляхом через redo файл і запис в data файл
|
||||
sendToStorage(storage.AppendedMeasures{
|
||||
MetricID: req.MetricID,
|
||||
LastPageNo: s.lastPageNo,
|
||||
TimestampsOffset: timestamps.Offset(), // state.Pos() з якої позиції дописувати дані на сторінку 0 (при відновленні)
|
||||
@@ -196,12 +195,12 @@ func (s *_metric) StartAppendMeasures(req tryAppendMeasuresReq, sendToStorage fu
|
||||
ResultCh: nil,
|
||||
})
|
||||
} else {
|
||||
// короткий шлях - запис лише в txlog
|
||||
// короткий шлях - запис лише в storage
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *_metric) FinAppendMeasures(rec txlog.AppendMeasuresSummary) {
|
||||
func (s *_metric) FinAppendMeasures(rec storage.AppendMeasuresSummary) {
|
||||
// Видаляю state. Оригінальні Timestamps і Values вже мають останню версію
|
||||
s.values.ForgetCapturedState()
|
||||
s.timestamps.ForgetCapturedState()
|
||||
@@ -209,7 +208,7 @@ func (s *_metric) FinAppendMeasures(rec txlog.AppendMeasuresSummary) {
|
||||
if rec.LastPageNo > 0 {
|
||||
s.lastPageNo = rec.LastPageNo
|
||||
}
|
||||
// В txlog я передав повний індекс. У нього додали елементи (можливо нові рівні).
|
||||
// В storage я передав повний індекс. У нього додали елементи (можливо нові рівні).
|
||||
// Тому проста заміна
|
||||
s.indexLevelTails = rec.Index
|
||||
}
|
||||
@@ -388,20 +387,6 @@ func (s *_metric) WriteTo(w io.Writer) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// var (
|
||||
// values qb.ValueCompressor
|
||||
// )
|
||||
// if s.metricType == qb.Cumulative {
|
||||
// values = enc.NewCumulativeDeltaCompressor(s.buffer, s.fracDigits)
|
||||
// } else {
|
||||
// values = enc.NewInstantDeltaCompressor(s.buffer, s.fracDigits)
|
||||
// }
|
||||
// values.RestoreState(valuesSize)
|
||||
// s.timestamps = enc.NewTimeDeltaCompressor(s.buffer)
|
||||
// s.timestamps.RestoreState(timestampsSize, until)
|
||||
// s.values = values
|
||||
// s.lastValue = s.values.LastValue()
|
||||
|
||||
// since - 4b
|
||||
// sinceValue - 8b -
|
||||
// untilValue - 8b
|
||||
|
||||
Reference in New Issue
Block a user