wp
This commit is contained in:
@@ -38,37 +38,51 @@ const (
|
||||
)
|
||||
|
||||
type Worker struct {
|
||||
//mutex sync.Mutex
|
||||
inbox *inbox.Inbox
|
||||
storageInbox *inbox.Inbox
|
||||
dir string
|
||||
snapshotNumber int
|
||||
tmp []byte
|
||||
metrics map[uint32]*Metric
|
||||
saveToStorage func(any)
|
||||
exitCh chan struct{}
|
||||
waitGroup *sync.WaitGroup
|
||||
}
|
||||
|
||||
type WorkerOptions struct {
|
||||
Inbox *inbox.Inbox
|
||||
StorageInbox *inbox.Inbox
|
||||
Metrics map[uint32]*Metric
|
||||
Dir string
|
||||
ExitCh chan struct{}
|
||||
WaitGroup *sync.WaitGroup
|
||||
type Options struct {
|
||||
Inbox *inbox.Inbox
|
||||
StorageInbox *inbox.Inbox
|
||||
ReplayMetrics map[uint32]*storage.ReplayMetric
|
||||
Dir string
|
||||
ExitCh chan struct{}
|
||||
WaitGroup *sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewWorker(opt WorkerOptions) *Worker {
|
||||
return &Worker{
|
||||
func New(opt Options) *Worker {
|
||||
s := &Worker{
|
||||
inbox: opt.Inbox,
|
||||
storageInbox: opt.StorageInbox,
|
||||
dir: opt.Dir,
|
||||
tmp: make([]byte, 26),
|
||||
metrics: opt.Metrics,
|
||||
metrics: make(map[uint32]*Metric),
|
||||
exitCh: opt.ExitCh,
|
||||
waitGroup: opt.WaitGroup,
|
||||
}
|
||||
|
||||
for metricID, x := range opt.ReplayMetrics {
|
||||
databuf := x.Buf[:storage.DataPagePayloadSize]
|
||||
values := enc.NewValueDeltaCompressor(x.MetricType, x.FracDigits, databuf, x.ValuesSize)
|
||||
s.metrics[metricID] = &Metric{
|
||||
metricType: x.MetricType,
|
||||
fracDigits: x.FracDigits,
|
||||
lastPageNo: x.LastPageNo,
|
||||
lastValue: values.LastValue(),
|
||||
buffer: x.Buf,
|
||||
timestamps: enc.NewTimeDeltaCompressor(databuf, x.TimestampsSize),
|
||||
values: values,
|
||||
indexLevelTails: x.IndexLevelTails,
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Worker) ReleaseRLock(metricID uint32) {
|
||||
@@ -182,7 +196,7 @@ func (s *Worker) processMetricQueue(metricID uint32, metric *Metric, tmp []byte)
|
||||
s.GetMetric(req)
|
||||
|
||||
case AppendMeasuresReq:
|
||||
metric.StartAppendMeasures(req, tmp, s.saveToStorage)
|
||||
metric.StartAppendMeasures(req, tmp, s.storageInbox)
|
||||
|
||||
case DeleteMetricReq:
|
||||
s.startDeleteMetric(metric, req)
|
||||
@@ -259,8 +273,8 @@ func (s *Worker) GetMetric(req GetMetricReq) {
|
||||
if ok {
|
||||
req.ResultCh <- GetMetricResult{
|
||||
ResultCode: Succeed,
|
||||
MetricType: metric.metricType,
|
||||
FracDigits: metric.fracDigits,
|
||||
MetricType: metric.MetricType(),
|
||||
FracDigits: metric.FracDigits(),
|
||||
}
|
||||
} else {
|
||||
req.ResultCh <- GetMetricResult{
|
||||
@@ -404,7 +418,7 @@ func (s *Worker) AppendMeasures(req AppendMeasuresReq) {
|
||||
metric.WaitQueue = append(metric.WaitQueue, req)
|
||||
return
|
||||
}
|
||||
metric.StartAppendMeasures(req, s.tmp, s.saveToStorage)
|
||||
metric.StartAppendMeasures(req, s.tmp, s.storageInbox)
|
||||
}
|
||||
|
||||
type RangeScanResult struct {
|
||||
@@ -431,7 +445,7 @@ func (s *Worker) RangeScan(req RangeScanReq) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if metric.metricType != req.MetricType {
|
||||
if metric.MetricType() != req.MetricType {
|
||||
req.ResultCh <- RangeScanResult{
|
||||
ResultCode: WrongMetricType,
|
||||
}
|
||||
@@ -467,7 +481,7 @@ func (s *Worker) tryFullScan(req FullScanReq) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if metric.metricType != req.MetricType {
|
||||
if metric.MetricType() != req.MetricType {
|
||||
req.ResultCh <- FullScanResult{
|
||||
ResultCode: WrongMetricType,
|
||||
}
|
||||
@@ -525,7 +539,7 @@ func (s *Worker) applyCommits(req storage.Changes) {
|
||||
|
||||
if req.SnapshotNumberCh != nil {
|
||||
s.snapshotNumber++
|
||||
err := storage.WriteSnapshot(storage.WriteSnapshotIn{
|
||||
err := WriteSnapshot(WriteSnapshotIn{
|
||||
SnapshotNumber: s.snapshotNumber,
|
||||
Dir: s.dir,
|
||||
WriteBufferSize: 4 * 1024 * 1024, // 1mb
|
||||
|
||||
Reference in New Issue
Block a user