wp
This commit is contained in:
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
qb "gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/atree"
|
||||
"gordenko.dev/dima/qb/chunkenc"
|
||||
"gordenko.dev/dima/qb/conbuf"
|
||||
"gordenko.dev/dima/qb/enc"
|
||||
"gordenko.dev/dima/qb/proto"
|
||||
"gordenko.dev/dima/qb/transform"
|
||||
"gordenko.dev/dima/qb/txlog"
|
||||
@@ -203,8 +202,8 @@ func (s *Database) tryGetMetric(req tryGetMetricReq) {
|
||||
if ok {
|
||||
req.ResultCh <- Metric{
|
||||
ResultCode: Succeed,
|
||||
MetricType: metric.MetricType,
|
||||
FracDigits: metric.FracDigits,
|
||||
MetricType: metric.metricType,
|
||||
FracDigits: metric.fracDigits,
|
||||
}
|
||||
} else {
|
||||
req.ResultCh <- Metric{
|
||||
@@ -343,7 +342,7 @@ func (s *Database) tryRangeScan(req tryRangeScanReq) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if metric.MetricType != req.MetricType {
|
||||
if metric.metricType != req.MetricType {
|
||||
req.ResultCh <- rangeScanResult{
|
||||
ResultCode: WrongMetricType,
|
||||
}
|
||||
@@ -373,7 +372,7 @@ func (s *Database) tryFullScan(req tryFullScanReq) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if metric.MetricType != req.MetricType {
|
||||
if metric.metricType != req.MetricType {
|
||||
req.ResultCh <- fullScanResult{
|
||||
ResultCode: WrongMetricType,
|
||||
}
|
||||
@@ -399,8 +398,8 @@ func (s *Database) tryListCurrentValues(req tryListCurrentValuesReq) {
|
||||
if ok {
|
||||
req.ResponseWriter.BufferValue(transform.CurrentValue{
|
||||
MetricID: metricID,
|
||||
Timestamp: metric.Until,
|
||||
Value: metric.UntilValue,
|
||||
Timestamp: metric.timestamps.LastTimestamp(),
|
||||
Value: metric.lastValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -413,7 +412,7 @@ func (s *Database) applyChanges(req txlog.Changes) {
|
||||
for _, untyped := range req.Records {
|
||||
switch rec := untyped.(type) {
|
||||
case txlog.AddedMetric:
|
||||
s.addMetric(rec)
|
||||
s.applyAddMetric(rec)
|
||||
|
||||
case txlog.DeletedMetric:
|
||||
s.deleteMetric(rec)
|
||||
@@ -432,37 +431,27 @@ func (s *Database) applyChanges(req txlog.Changes) {
|
||||
}
|
||||
}
|
||||
|
||||
if req.MetricsCh != nil {
|
||||
waitCh := make(chan struct{})
|
||||
req.MetricsCh <- txlog.MetricsState{
|
||||
Metrics: s.createMetricsState(),
|
||||
WaitCh: waitCh,
|
||||
if req.SnapshotNumberCh != nil {
|
||||
s.snapshotNumber++
|
||||
err := writeSnapshot(writeSnapshotIn{
|
||||
SnapshotNumber: s.snapshotNumber,
|
||||
Dir: s.dir,
|
||||
WriteBufferSize: 1 * 1024 * 1024, // 1mb
|
||||
Metrics: s.metrics,
|
||||
FrozenIndexPagesCount: req.FrozenIndexPagesCount,
|
||||
IndexPageNumbers: req.IndexPageNumbers,
|
||||
FrozenDataPagesCount: req.FrozenDataPagesCount,
|
||||
DataPageNumbers: req.DataPageNumbers,
|
||||
})
|
||||
if err != nil {
|
||||
qb.Abort(qb.WriteSnapshotFailed, err)
|
||||
}
|
||||
// чекаю поки txlog запише снапшот, а отже можна змінювати буфери
|
||||
<-waitCh
|
||||
|
||||
req.SnapshotNumberCh <- s.snapshotNumber
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Database) createMetricsState() (metrics []txlog.Metric) {
|
||||
for metricID, metric := range s.metrics {
|
||||
x := txlog.Metric{
|
||||
MetricID: metricID,
|
||||
MetricType: metric.MetricType,
|
||||
FracDigits: metric.FracDigits,
|
||||
LastPageNo: metric.LastPageNo,
|
||||
Since: metric.Since,
|
||||
SinceValue: metric.SinceValue,
|
||||
Until: metric.Until, // ?
|
||||
UntilValue: metric.UntilValue, // ?
|
||||
}
|
||||
x.Timestamps, x.TimestampsSize = metric.Timestamps.Snapshot()
|
||||
x.Values, x.ValuesSize = metric.Values.Snapshot()
|
||||
metrics = append(metrics, x)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Database) addMetric(rec txlog.AddedMetric) {
|
||||
func (s *Database) applyAddMetric(rec txlog.AddedMetric) {
|
||||
// fix lock
|
||||
_, ok := s.metrics[rec.MetricID]
|
||||
if ok {
|
||||
@@ -477,29 +466,29 @@ func (s *Database) addMetric(rec txlog.AddedMetric) {
|
||||
// rec.MetricID))
|
||||
// }
|
||||
|
||||
// lockEntry.XLock = false
|
||||
// delete(s.metricLockEntries, rec.MetricID)
|
||||
}
|
||||
|
||||
func (s *Database) addMetric(rec txlog.AddedMetric) {
|
||||
var (
|
||||
values qb.ValueCompressor
|
||||
timestampsBuf = conbuf.New(nil)
|
||||
valuesBuf = conbuf.New(nil)
|
||||
values qb.ValueCompressor
|
||||
buffer = make([]byte, minBufferSize)
|
||||
)
|
||||
|
||||
if rec.MetricType == qb.Cumulative {
|
||||
values = chunkenc.NewCumulativeDeltaCompressor(
|
||||
valuesBuf, 0, byte(rec.FracDigits))
|
||||
values = enc.NewCumulativeDeltaCompressor(buffer, byte(rec.FracDigits))
|
||||
} else {
|
||||
values = chunkenc.NewInstantDeltaCompressor(
|
||||
valuesBuf, 0, byte(rec.FracDigits))
|
||||
values = enc.NewInstantDeltaCompressor(buffer, byte(rec.FracDigits))
|
||||
}
|
||||
|
||||
s.metrics[rec.MetricID] = &_metric{
|
||||
MetricType: rec.MetricType,
|
||||
FracDigits: byte(rec.FracDigits),
|
||||
Timestamps: chunkenc.NewTimeDeltaCompressor(timestampsBuf, 0),
|
||||
Values: values,
|
||||
metricType: rec.MetricType,
|
||||
fracDigits: byte(rec.FracDigits),
|
||||
buffer: buffer,
|
||||
timestamps: enc.NewTimeDeltaCompressor(buffer),
|
||||
values: values,
|
||||
}
|
||||
|
||||
lockEntry.XLock = false
|
||||
delete(s.metricLockEntries, rec.MetricID)
|
||||
}
|
||||
|
||||
func (s *Database) deleteMetric(rec txlog.DeletedMetric) {
|
||||
|
||||
Reference in New Issue
Block a user