wp
This commit is contained in:
145
worker/worker.go
145
worker/worker.go
@@ -7,7 +7,6 @@ import (
|
||||
qb "gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/enc"
|
||||
"gordenko.dev/dima/qb/inbox"
|
||||
"gordenko.dev/dima/qb/proto"
|
||||
"gordenko.dev/dima/qb/storage"
|
||||
"gordenko.dev/dima/qb/transform"
|
||||
)
|
||||
@@ -81,6 +80,8 @@ func New(opt Options) *Worker {
|
||||
values: values,
|
||||
indexLevelTails: x.IndexLevelTails,
|
||||
}
|
||||
|
||||
//fmt.Printf("index: %#v\n", x.IndexLevelTails)
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -109,25 +110,25 @@ func (s *Worker) doWork() {
|
||||
for _, untyped := range queue {
|
||||
switch req := untyped.(type) {
|
||||
case AppendMeasuresReq:
|
||||
s.AppendMeasures(req)
|
||||
s.appendMeasures(req)
|
||||
case ReleaseRLock:
|
||||
s.releaseRLock(req.MetricID)
|
||||
case storage.Changes:
|
||||
s.applyCommits(req) // all metrics only
|
||||
case ListCurrentValuesReq:
|
||||
s.ListCurrentValues(req) // all metrics only
|
||||
s.listCurrentValues(req) // all metrics only
|
||||
case RangeScanReq:
|
||||
s.RangeScan(req)
|
||||
s.rangeScan(req)
|
||||
case FullScanReq:
|
||||
s.FullScan(req)
|
||||
s.fullScan(req)
|
||||
case AddMetricReq:
|
||||
s.AddMetric(req)
|
||||
s.addMetric(req)
|
||||
case DeleteMetricReq:
|
||||
s.DeleteMetric(req)
|
||||
s.deleteMetric(req)
|
||||
case DeleteMeasuresReq:
|
||||
s.DeleteMeasures(req)
|
||||
s.deleteMeasures(req)
|
||||
case GetMetricReq:
|
||||
s.GetMetric(req)
|
||||
s.getMetric(req)
|
||||
default:
|
||||
qb.Abort(qb.UnknownWorkerQueueItemBug,
|
||||
fmt.Errorf("bug: unknown worker queue item type %T", req))
|
||||
@@ -149,7 +150,7 @@ type AddMetricReq struct {
|
||||
ResultCh chan byte
|
||||
}
|
||||
|
||||
func (s *Worker) AddMetric(req AddMetricReq) {
|
||||
func (s *Worker) addMetric(req AddMetricReq) {
|
||||
_, ok := s.metrics[req.MetricID]
|
||||
if ok {
|
||||
req.ResultCh <- MetricDuplicate
|
||||
@@ -175,30 +176,14 @@ func (s *Worker) AddMetric(req AddMetricReq) {
|
||||
})
|
||||
}
|
||||
|
||||
type GetMetricResult struct {
|
||||
MetricType qb.MetricType
|
||||
FracDigits byte
|
||||
ResultCode byte
|
||||
}
|
||||
|
||||
type GetMetricReq struct {
|
||||
MetricID uint32
|
||||
ResultCh chan GetMetricResult
|
||||
}
|
||||
|
||||
func (s *Worker) GetMetric(req GetMetricReq) {
|
||||
func (s *Worker) getMetric(req GetMetricReq) {
|
||||
metric, ok := s.metrics[req.MetricID]
|
||||
if ok {
|
||||
req.ResultCh <- GetMetricResult{
|
||||
ResultCode: Succeed,
|
||||
MetricType: metric.MetricType(),
|
||||
FracDigits: metric.FracDigits(),
|
||||
}
|
||||
} else {
|
||||
if !ok {
|
||||
req.ResultCh <- GetMetricResult{
|
||||
ResultCode: NoMetric,
|
||||
}
|
||||
}
|
||||
metric.GetMetric(req)
|
||||
}
|
||||
|
||||
type DeleteMetricReq struct {
|
||||
@@ -206,32 +191,16 @@ type DeleteMetricReq struct {
|
||||
ResultCh chan byte
|
||||
}
|
||||
|
||||
func (s *Worker) DeleteMetric(req DeleteMetricReq) {
|
||||
func (s *Worker) deleteMetric(req DeleteMetricReq) {
|
||||
metric, ok := s.metrics[req.MetricID]
|
||||
if !ok {
|
||||
req.ResultCh <- NoMetric
|
||||
return
|
||||
}
|
||||
if metric.xLock {
|
||||
metric.waitQueue = append(metric.waitQueue, req)
|
||||
} else {
|
||||
// collect all pages, than
|
||||
s.storageInbox.Push(storage.MetricDelete{
|
||||
MetricID: req.MetricID,
|
||||
FreeIndexPages: nil,
|
||||
FreeDataPages: nil,
|
||||
ResultCh: req.ResultCh,
|
||||
})
|
||||
}
|
||||
metric.DeleteMetric(req)
|
||||
}
|
||||
|
||||
type DeleteMeasuresReq struct {
|
||||
MetricID uint32
|
||||
Since uint32
|
||||
ResultCh chan byte
|
||||
}
|
||||
|
||||
func (s *Worker) DeleteMeasures(req DeleteMeasuresReq) {
|
||||
func (s *Worker) deleteMeasures(req DeleteMeasuresReq) {
|
||||
metric, ok := s.metrics[req.MetricID]
|
||||
if !ok {
|
||||
req.ResultCh <- NoMetric
|
||||
@@ -240,13 +209,7 @@ func (s *Worker) DeleteMeasures(req DeleteMeasuresReq) {
|
||||
metric.DeleteMeasures(req)
|
||||
}
|
||||
|
||||
type AppendMeasuresReq struct {
|
||||
MetricID uint32
|
||||
Measures []proto.Measure
|
||||
ResultCh chan storage.MeasuresAppendResult
|
||||
}
|
||||
|
||||
func (s *Worker) AppendMeasures(req AppendMeasuresReq) {
|
||||
func (s *Worker) appendMeasures(req AppendMeasuresReq) {
|
||||
metric, ok := s.metrics[req.MetricID]
|
||||
if !ok {
|
||||
req.ResultCh <- storage.MeasuresAppendResult{
|
||||
@@ -261,23 +224,7 @@ func (s *Worker) AppendMeasures(req AppendMeasuresReq) {
|
||||
}
|
||||
}
|
||||
|
||||
type RangeScanResult struct {
|
||||
ResultCode byte
|
||||
FracDigits byte
|
||||
LastPageNo uint32
|
||||
IsDataPage bool // for UntilNotFound only
|
||||
}
|
||||
|
||||
type RangeScanReq struct {
|
||||
MetricID uint32
|
||||
Since uint32
|
||||
Until uint32
|
||||
MetricType qb.MetricType
|
||||
ResponseWriter qb.WorkerMeasureConsumer
|
||||
ResultCh chan RangeScanResult
|
||||
}
|
||||
|
||||
func (s *Worker) RangeScan(req RangeScanReq) {
|
||||
func (s *Worker) rangeScan(req RangeScanReq) {
|
||||
metric, ok := s.metrics[req.MetricID]
|
||||
if !ok {
|
||||
req.ResultCh <- RangeScanResult{
|
||||
@@ -294,24 +241,11 @@ func (s *Worker) RangeScan(req RangeScanReq) {
|
||||
if metric.xLock {
|
||||
metric.waitQueue = append(metric.waitQueue, req)
|
||||
} else {
|
||||
metric.StartRangeScan(req)
|
||||
metric.RangeScan(req)
|
||||
}
|
||||
}
|
||||
|
||||
type FullScanResult struct {
|
||||
ResultCode byte
|
||||
FracDigits byte
|
||||
LastPageNo uint32
|
||||
}
|
||||
|
||||
type FullScanReq struct {
|
||||
MetricID uint32
|
||||
MetricType qb.MetricType
|
||||
ResponseWriter qb.WorkerMeasureConsumer
|
||||
ResultCh chan FullScanResult
|
||||
}
|
||||
|
||||
func (s *Worker) FullScan(req FullScanReq) {
|
||||
func (s *Worker) fullScan(req FullScanReq) {
|
||||
metric, ok := s.metrics[req.MetricID]
|
||||
if !ok {
|
||||
req.ResultCh <- FullScanResult{
|
||||
@@ -328,7 +262,7 @@ func (s *Worker) FullScan(req FullScanReq) {
|
||||
if metric.xLock {
|
||||
metric.waitQueue = append(metric.waitQueue, req)
|
||||
} else {
|
||||
metric.StartFullScan(req)
|
||||
metric.FullScan(req)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +272,7 @@ type ListCurrentValuesReq struct {
|
||||
ResultCh chan struct{}
|
||||
}
|
||||
|
||||
func (s *Worker) ListCurrentValues(req ListCurrentValuesReq) {
|
||||
func (s *Worker) listCurrentValues(req ListCurrentValuesReq) {
|
||||
for _, metricID := range req.MetricIDs {
|
||||
metric, ok := s.metrics[metricID]
|
||||
if ok {
|
||||
@@ -478,8 +412,31 @@ func (s *Worker) onMeasuresDeleteCommited(rec storage.MeasuresDeleteCommited) {
|
||||
//s.doAfterReleaseXLock(rec.MetricID, metric)
|
||||
}
|
||||
|
||||
// func (s *Database) doAfterReleaseXLock(metricID uint32, metric *_metric) {
|
||||
// if len(metric.WaitQueue) > 0 {
|
||||
// s.processMetricQueue(metricID, metric)
|
||||
// }
|
||||
// }
|
||||
// rLock сумісний із append measures,
|
||||
// xLock ні з чим
|
||||
// після xLock - вся черга
|
||||
// після rLock, якщо capturedState == nil - вся черга, оскільки rLock блокує лише xLock задачі
|
||||
// після capturedState = nil, якщо перша задача - appendMeasures - беру, інакше перевірка rLock
|
||||
|
||||
// суть у тому що треба запускати запити, пока не зустріну XLock
|
||||
func (s *Worker) ProcessQueue(metric *Metric, tmp []byte, storageInbox *inbox.Inbox) {
|
||||
// for _, untyped := range metric.waitQueue {
|
||||
// switch req := untyped.(type) {
|
||||
// case RangeScanReq:
|
||||
// metric.RangeScan(req)
|
||||
// case FullScanReq:
|
||||
// metric.FullScan(req)
|
||||
// case GetMetricReq:
|
||||
// metric.GetMetric(req)
|
||||
// case AppendMeasuresReq:
|
||||
// metric.AppendMeasures(req, tmp, s.storageInbox)
|
||||
// case DeleteMetricReq:
|
||||
// metric.DeleteMetric(req)
|
||||
// case DeleteMeasuresReq:
|
||||
// metric.DeleteMeasures(req)
|
||||
// default:
|
||||
// qb.Abort(qb.UnknownMetricWaitQueueItemBug,
|
||||
// fmt.Errorf("bug: unknown metric wait queue item type %T", req))
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user