This commit is contained in:
2026-05-21 23:38:52 +03:00
parent 793df29e11
commit e7ec6083cb
21 changed files with 1234 additions and 1017 deletions

View File

@@ -6,7 +6,7 @@ import (
"io"
"net"
diploma "gordenko.dev/dima/qb"
qb "gordenko.dev/dima/qb"
"gordenko.dev/dima/qb/atree"
"gordenko.dev/dima/qb/bin"
"gordenko.dev/dima/qb/bufreader"
@@ -192,11 +192,11 @@ func (s *Database) AddMetric(req proto.AddMetricReq) uint16 {
if req.MetricID == 0 {
return proto.ErrEmptyMetricID
}
if byte(req.FracDigits) > diploma.MaxFracDigits {
if byte(req.FracDigits) > qb.MaxFracDigits {
return proto.ErrWrongFracDigits
}
switch req.MetricType {
case diploma.Cumulative, diploma.Instant:
case qb.Cumulative, qb.Instant:
// ok
default:
return proto.ErrWrongMetricType
@@ -213,24 +213,24 @@ func (s *Database) AddMetric(req proto.AddMetricReq) uint16 {
switch resultCode {
case Succeed:
waitCh := s.txlog.Append(txlog.AddedMetric{
s.txlog.Append(txlog.AddedMetric{
MetricID: req.MetricID,
MetricType: req.MetricType,
FracDigits: req.FracDigits,
})
<-waitCh
//<-waitCh
case MetricDuplicate:
return proto.ErrDuplicate
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return 0
}
type Metric struct {
MetricType diploma.MetricType
MetricType qb.MetricType
FracDigits byte
ResultCode byte
}
@@ -264,7 +264,7 @@ func (s *Database) GetMetric(conn io.Writer, req proto.GetMetricReq) error {
reply(conn, proto.ErrNoMetric)
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return nil
}
@@ -293,20 +293,20 @@ func (s *Database) DeleteMetric(req proto.DeleteMetricReq) uint16 {
var err error
freePageNumbers, err = s.atree.GetAllPages(result.RootPageNo)
if err != nil {
diploma.Abort(diploma.FailedAtreeRequest, err)
qb.Abort(qb.FailedAtreeRequest, err)
}
}
waitCh := s.txlog.Append(txlog.DeletedMetric{
s.txlog.Append(txlog.DeletedMetric{
MetricID: req.MetricID,
FreePageNumbers: freePageNumbers,
})
<-waitCh
//<-waitCh
case NoMetric:
return proto.ErrNoMetric
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return 0
}
@@ -358,15 +358,15 @@ type FilledPage struct {
// path, err := s.atree.FindPathToLastPage(filled.RootPageNo)
// if err != nil {
// // FIX
// diploma.Abort(diploma.WriteToAtreeFailed, err)
// qb.Abort(qb.WriteToAtreeFailed, err)
// }
// // for _, leg := range path.Legs {
// // pagesToRelease = append(pagesToRelease, leg.PageNo)
// // }
// if path.LastPageNo != filled.PrevPageNo {
// diploma.Abort(
// diploma.WrongPrevPageNo,
// qb.Abort(
// qb.WrongPrevPageNo,
// fmt.Errorf("bug: last pageNo %d in tree != prev pageNo %d in _metric",
// path.LastPageNo, filled.PrevPageNo),
// )
@@ -386,7 +386,7 @@ type FilledPage struct {
// // ValuesSize: filled.ValuesSize,
// // })
// // if err != nil {
// // diploma.Abort(diploma.WriteToAtreeFailed, err)
// // qb.Abort(qb.WriteToAtreeFailed, err)
// // }
// // _ = report
@@ -417,7 +417,7 @@ type FilledPage struct {
// return proto.ErrNonMonotonicValue
// default:
// diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
// qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
// }
// return 0
// }
@@ -425,7 +425,7 @@ type FilledPage struct {
type tryAppendMeasuresResult struct {
ResultCode byte
Written int
// MetricType diploma.MetricType
// MetricType qb.MetricType
// FracDigits byte
// Since uint32
// Until uint32
@@ -434,8 +434,8 @@ type tryAppendMeasuresResult struct {
// PrevPageNo uint32
// TimestampsBuf *conbuf.ContinuousBuffer
// ValuesBuf *conbuf.ContinuousBuffer
// Timestamps diploma.TimestampCompressor
// Values diploma.ValueCompressor
// Timestamps qb.TimestampCompressor
// Values qb.ValueCompressor
}
func (s *Database) AppendMeasures(req proto.AppendMeasuresReq) uint16 {
@@ -454,7 +454,7 @@ func (s *Database) AppendMeasures(req proto.AppendMeasuresReq) uint16 {
// report, err := s.atree.AppendDataPage(atree.AppendDataPageReq{})
// if err != nil {
// diploma.Abort(diploma.WriteToAtreeFailed, err)
// qb.Abort(qb.WriteToAtreeFailed, err)
// }
// _ = report
@@ -473,7 +473,7 @@ func (s *Database) AppendMeasures(req proto.AppendMeasuresReq) uint16 {
return proto.ErrNoMetric
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return 0
}
@@ -500,29 +500,29 @@ func (s *Database) DeleteMeasures(req proto.DeleteMeasuresReq) uint16 {
case DeleteFromAtreeNotNeeded:
// регистрирую удаление в TransactionLog
waitCh := s.txlog.Append(txlog.DeletedMeasures{
s.txlog.Append(txlog.DeletedMeasures{
MetricID: req.MetricID,
})
<-waitCh
//<-waitCh
case DeleteFromAtreeRequired:
// собираю номера всех data и index страниц метрики (типа запись REDO лога).
pageNumbers, err := s.atree.GetAllPages(req.MetricID)
if err != nil {
diploma.Abort(diploma.FailedAtreeRequest, err)
qb.Abort(qb.FailedAtreeRequest, err)
}
// регистрирую удаление в TransactionLog
waitCh := s.txlog.Append(txlog.DeletedMeasures{
s.txlog.Append(txlog.DeletedMeasures{
MetricID: req.MetricID,
FreePageNumbers: pageNumbers,
})
<-waitCh
//<-waitCh
case NoMetric:
return proto.ErrNoMetric
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return 0
}
@@ -540,7 +540,7 @@ func (s *Database) ListAllInstantMeasures(conn net.Conn, req proto.ListAllInstan
return s.fullScan(fullScanReq{
MetricID: req.MetricID,
MetricType: diploma.Instant,
MetricType: qb.Instant,
Conn: conn,
ResponseWriter: responseWriter,
})
@@ -551,7 +551,7 @@ func (s *Database) ListAllCumulativeMeasures(conn io.Writer, req proto.ListAllCu
return s.fullScan(fullScanReq{
MetricID: req.MetricID,
MetricType: diploma.Cumulative,
MetricType: qb.Cumulative,
Conn: conn,
ResponseWriter: responseWriter,
})
@@ -567,7 +567,7 @@ func (s *Database) ListInstantMeasures(conn net.Conn, req proto.ListInstantMeasu
return s.rangeScan(rangeScanReq{
MetricID: req.MetricID,
MetricType: diploma.Instant,
MetricType: qb.Instant,
Since: req.Since,
Until: req.Until - 1,
Conn: conn,
@@ -585,7 +585,7 @@ func (s *Database) ListCumulativeMeasures(conn net.Conn, req proto.ListCumulativ
return s.rangeScan(rangeScanReq{
MetricID: req.MetricID,
MetricType: diploma.Cumulative,
MetricType: qb.Cumulative,
Since: req.Since,
Until: req.Until - 1,
Conn: conn,
@@ -620,7 +620,7 @@ func (s *Database) ListInstantPeriods(conn net.Conn, req proto.ListInstantPeriod
return s.rangeScan(rangeScanReq{
MetricID: req.MetricID,
MetricType: diploma.Instant,
MetricType: qb.Instant,
Since: uint32(since.Unix()),
Until: uint32(until.Unix()),
Conn: conn,
@@ -647,7 +647,7 @@ func (s *Database) ListCumulativePeriods(conn net.Conn, req proto.ListCumulative
return s.rangeScan(rangeScanReq{
MetricID: req.MetricID,
MetricType: diploma.Cumulative,
MetricType: qb.Cumulative,
Since: uint32(since.Unix()),
Until: uint32(until.Unix()),
Conn: conn,
@@ -657,7 +657,7 @@ func (s *Database) ListCumulativePeriods(conn net.Conn, req proto.ListCumulative
type rangeScanReq struct {
MetricID uint32
MetricType diploma.MetricType
MetricType qb.MetricType
Since uint32
Until uint32
Conn io.Writer
@@ -720,14 +720,14 @@ func (s *Database) rangeScan(req rangeScanReq) error {
reply(req.Conn, proto.ErrWrongMetricType)
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return nil
}
type fullScanReq struct {
MetricID uint32
MetricType diploma.MetricType
MetricType qb.MetricType
Conn io.Writer
ResponseWriter atree.PeriodsWriter
}
@@ -768,7 +768,7 @@ func (s *Database) fullScan(req fullScanReq) error {
reply(req.Conn, proto.ErrWrongMetricType)
default:
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
qb.Abort(qb.WrongResultCodeBug, ErrWrongResultCodeBug)
}
return nil
}