wp
This commit is contained in:
151
worker/metric.go
151
worker/metric.go
@@ -16,18 +16,14 @@ import (
|
||||
var ErrNoValueBug = errors.New("has timestamp but no value")
|
||||
|
||||
type CapturedState struct {
|
||||
LastTimestamp uint32
|
||||
LastValue float64
|
||||
LastValue float64
|
||||
}
|
||||
|
||||
type Metric struct {
|
||||
metricType qb.MetricType
|
||||
fracDigits byte
|
||||
lastPageNo uint32
|
||||
//SinceValue float64
|
||||
//Since uint32
|
||||
lastValue float64
|
||||
//Until uint32
|
||||
metricType qb.MetricType
|
||||
fracDigits byte
|
||||
lastPageNo uint32
|
||||
lastValue float64
|
||||
buffer []byte
|
||||
timestamps qb.TimestampCompressor
|
||||
values qb.ValueCompressor
|
||||
@@ -117,14 +113,42 @@ func (s *Metric) LastValue() float64 {
|
||||
return s.lastValue
|
||||
}
|
||||
|
||||
func (s *Metric) LastTimestamp() uint32 {
|
||||
if s.capturedState != nil {
|
||||
return s.capturedState.LastTimestamp
|
||||
// REQUESTS
|
||||
|
||||
func (s *Metric) ReleaseRLock() {
|
||||
s.rLocks--
|
||||
if s.rLocks == 0 {
|
||||
if len(s.waitQueue) > 0 {
|
||||
s.ProcessQueue()
|
||||
}
|
||||
}
|
||||
return s.timestamps.LastTimestamp()
|
||||
}
|
||||
|
||||
// REQUESTS
|
||||
// суть у тому що треба запускати запити, пока не зустріну XLock
|
||||
func (s *Metric) ProcessQueue(metricID uint32, tmp []byte) {
|
||||
if len(s.waitQueue) == 0 {
|
||||
return
|
||||
}
|
||||
for _, untyped := range s.waitQueue {
|
||||
switch req := untyped.(type) {
|
||||
case RangeScanReq:
|
||||
s.StartRangeScan(req)
|
||||
case FullScanReq:
|
||||
s.StartFullScan(req)
|
||||
case GetMetricReq:
|
||||
s.GetMetric(req)
|
||||
case AppendMeasuresReq:
|
||||
metric.AppendMeasures(req, tmp, s.storageInbox)
|
||||
case DeleteMetricReq:
|
||||
s.DeleteMetric(req)
|
||||
case DeleteMeasuresReq:
|
||||
metric.DeleteMeasures(req)
|
||||
default:
|
||||
qb.Abort(qb.UnknownMetricWaitQueueItemBug,
|
||||
fmt.Errorf("bug: unknown metric wait queue item type %T", req))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Metric) AppendMeasures(req AppendMeasuresReq, tmp []byte, storageInbox *inbox.Inbox) {
|
||||
if s.xLock || s.capturedState != nil {
|
||||
@@ -151,15 +175,14 @@ func (s *Metric) AppendMeasures(req AppendMeasuresReq, tmp []byte, storageInbox
|
||||
)
|
||||
|
||||
s.capturedState = &CapturedState{
|
||||
LastTimestamp: timestamps.LastTimestamp(),
|
||||
LastValue: s.lastValue,
|
||||
LastValue: s.lastValue,
|
||||
}
|
||||
|
||||
s.timestamps.CaptureState()
|
||||
s.values.CaptureState()
|
||||
|
||||
for idx, measure := range req.Measures {
|
||||
if measure.Timestamp <= s.timestamps.LastTimestamp() {
|
||||
if measure.Timestamp <= s.timestamps.Until() {
|
||||
resultCode = ExpiredMeasure
|
||||
break
|
||||
}
|
||||
@@ -270,15 +293,15 @@ func (s *Metric) AppendMeasures(req AppendMeasuresReq, tmp []byte, storageInbox
|
||||
}
|
||||
|
||||
func (s *Metric) DeleteMeasures(req DeleteMeasuresReq) {
|
||||
if s.xLock || s.capturedState != nil {
|
||||
s.waitQueue = append(s.waitQueue, req)
|
||||
return
|
||||
}
|
||||
since := s.timestamps.FirstTimestamp()
|
||||
until := s.timestamps.LastTimestamp()
|
||||
if since == 0 || (req.Since > 0 && until < req.Since) {
|
||||
req.ResultCh <- NoMeasuresToDelete
|
||||
}
|
||||
// if s.xLock || s.capturedState != nil {
|
||||
// s.waitQueue = append(s.waitQueue, req)
|
||||
// return
|
||||
// }
|
||||
// since := s.timestamps.FirstTimestamp()
|
||||
// until := s.timestamps.LastTimestamp()
|
||||
// if since == 0 || (req.Since > 0 && until < req.Since) {
|
||||
// req.ResultCh <- NoMeasuresToDelete
|
||||
// }
|
||||
// if s.RootPageNo > 0 {
|
||||
// req.ResultCh <- tryDeleteMeasuresResult{
|
||||
// ResultCode: DeleteFromAtreeRequired,
|
||||
@@ -296,36 +319,47 @@ func (s *Metric) StartRangeScan(req RangeScanReq) {
|
||||
s.waitQueue = append(s.waitQueue, req)
|
||||
return
|
||||
}
|
||||
// if s.timestamps.CommitedSize() == 0 {
|
||||
// req.ResultCh <- RangeScanResult{
|
||||
// ResultCode: QueryDone,
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// if req.Since > s.timestamps.LastTimestamp() {
|
||||
// req.ResultCh <- RangeScanResult{
|
||||
// ResultCode: QueryDone,
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// if req.Until < s.Since {
|
||||
// if s.RootPageNo > 0 {
|
||||
// req.ResultCh <- RangeScanResult{
|
||||
// ResultCode: UntilNotFound,
|
||||
// RootPageNo: s.RootPageNo,
|
||||
// FracDigits: s.fracDigits,
|
||||
// }
|
||||
// s.rLocks++
|
||||
// return
|
||||
// } else {
|
||||
// req.ResultCh <- RangeScanResult{
|
||||
// ResultCode: QueryDone,
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
since := s.timestamps.CommitedSince()
|
||||
if since == 0 {
|
||||
req.ResultCh <- RangeScanResult{
|
||||
ResultCode: QueryDone,
|
||||
}
|
||||
return
|
||||
}
|
||||
// range after
|
||||
if req.Since > s.timestamps.CommitedUntil() {
|
||||
req.ResultCh <- RangeScanResult{
|
||||
ResultCode: QueryDone,
|
||||
}
|
||||
return
|
||||
}
|
||||
// range before
|
||||
if req.Until < since {
|
||||
if len(s.indexLevelTails) > 0 {
|
||||
pageNo, isDataPage := storage.FindPageOnIndexLevelTails(s.indexLevelTails, req.Until)
|
||||
if pageNo > 0 {
|
||||
req.ResultCh <- RangeScanResult{
|
||||
ResultCode: UntilNotFound,
|
||||
FracDigits: s.fracDigits,
|
||||
LastPageNo: pageNo,
|
||||
IsDataPage: isDataPage,
|
||||
}
|
||||
s.rLocks++
|
||||
return
|
||||
} else {
|
||||
// range until before 1st measure timestamp
|
||||
req.ResultCh <- RangeScanResult{
|
||||
ResultCode: QueryDone,
|
||||
}
|
||||
return
|
||||
}
|
||||
} else {
|
||||
req.ResultCh <- RangeScanResult{
|
||||
ResultCode: QueryDone,
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
timestampDecompressor := s.timestamps.CreateDecompressor()
|
||||
valueDecompressor := s.values.CreateDecompressor(s.metricType, s.fracDigits)
|
||||
@@ -443,11 +477,6 @@ func (s *Metric) OnMeasuresDeleteCommited(rec storage.MeasuresDeleteCommited) {
|
||||
s.xLock = false
|
||||
// s.Timestamps.Renew()
|
||||
// s.Values.Renew()
|
||||
|
||||
// s.LastPageNo = 0
|
||||
// s.Since = 0
|
||||
// s.SinceValue = 0
|
||||
// s.Until = 0
|
||||
s.indexLevelTails = nil
|
||||
s.lastPageNo = 0
|
||||
s.lastValue = 0
|
||||
|
||||
Reference in New Issue
Block a user