wp
This commit is contained in:
211
database/api.go
211
database/api.go
@@ -94,13 +94,13 @@ func (s *Database) processRequest(conn net.Conn, r *bufreader.BufferedReader) (e
|
||||
}
|
||||
reply(conn, s.DeleteMetric(req))
|
||||
|
||||
case proto.TypeAppendMeasure:
|
||||
req, err := proto.ReadAppendMeasureReq(r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("proto.ReadAppendMeasureReq: %s", err)
|
||||
}
|
||||
//fmt.Println("append measure", req.MetricID, conn.RemoteAddr().String())
|
||||
reply(conn, s.AppendMeasure(req))
|
||||
// case proto.TypeAppendMeasure:
|
||||
// req, err := proto.ReadAppendMeasureReq(r)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("proto.ReadAppendMeasureReq: %s", err)
|
||||
// }
|
||||
// //fmt.Println("append measure", req.MetricID, conn.RemoteAddr().String())
|
||||
// reply(conn, s.AppendMeasure(req))
|
||||
|
||||
case proto.TypeAppendMeasures:
|
||||
req, err := proto.ReadAppendMeasuresReq(r)
|
||||
@@ -323,120 +323,120 @@ type FilledPage struct {
|
||||
ValuesSize uint16
|
||||
}
|
||||
|
||||
type tryAppendMeasureResult struct {
|
||||
MetricID uint32
|
||||
Timestamp uint32
|
||||
Value float64
|
||||
FilledPage *FilledPage
|
||||
ResultCode byte
|
||||
}
|
||||
// type tryAppendMeasureResult struct {
|
||||
// MetricID uint32
|
||||
// Timestamp uint32
|
||||
// Value float64
|
||||
// FilledPage *FilledPage
|
||||
// ResultCode byte
|
||||
// }
|
||||
|
||||
func (s *Database) AppendMeasure(req proto.AppendMeasureReq) uint16 {
|
||||
resultCh := make(chan tryAppendMeasureResult, 1)
|
||||
// func (s *Database) AppendMeasure(req proto.AppendMeasureReq) uint16 {
|
||||
// resultCh := make(chan tryAppendMeasureResult, 1)
|
||||
|
||||
s.appendJobToWorkerQueue(tryAppendMeasureReq{
|
||||
MetricID: req.MetricID,
|
||||
Timestamp: req.Timestamp,
|
||||
Value: req.Value,
|
||||
ResultCh: resultCh,
|
||||
})
|
||||
// s.appendJobToWorkerQueue(tryAppendMeasureReq{
|
||||
// MetricID: req.MetricID,
|
||||
// Timestamp: req.Timestamp,
|
||||
// Value: req.Value,
|
||||
// ResultCh: resultCh,
|
||||
// })
|
||||
|
||||
result := <-resultCh
|
||||
// result := <-resultCh
|
||||
|
||||
switch result.ResultCode {
|
||||
case CanAppend:
|
||||
waitCh := s.txlog.Append(txlog.AppendedMeasure{
|
||||
MetricID: req.MetricID,
|
||||
Timestamp: req.Timestamp,
|
||||
Value: req.Value,
|
||||
})
|
||||
<-waitCh
|
||||
// switch result.ResultCode {
|
||||
// case CanAppend:
|
||||
// waitCh := s.txlog.Append(txlog.AppendedMeasure{
|
||||
// MetricID: req.MetricID,
|
||||
// Timestamp: req.Timestamp,
|
||||
// Value: req.Value,
|
||||
// })
|
||||
// <-waitCh
|
||||
|
||||
case NewPage:
|
||||
filled := result.FilledPage
|
||||
// case NewPage:
|
||||
// filled := result.FilledPage
|
||||
|
||||
var path atree.PathToDataPage
|
||||
if filled.RootPageNo > 0 {
|
||||
path, err := s.atree.FindPathToLastPage(filled.RootPageNo)
|
||||
if err != nil {
|
||||
// FIX
|
||||
diploma.Abort(diploma.WriteToAtreeFailed, err)
|
||||
}
|
||||
// for _, leg := range path.Legs {
|
||||
// pagesToRelease = append(pagesToRelease, leg.PageNo)
|
||||
// }
|
||||
// var path atree.PathToDataPage
|
||||
// if filled.RootPageNo > 0 {
|
||||
// path, err := s.atree.FindPathToLastPage(filled.RootPageNo)
|
||||
// if err != nil {
|
||||
// // FIX
|
||||
// diploma.Abort(diploma.WriteToAtreeFailed, err)
|
||||
// }
|
||||
// // for _, leg := range path.Legs {
|
||||
// // pagesToRelease = append(pagesToRelease, leg.PageNo)
|
||||
// // }
|
||||
|
||||
if path.LastPageNo != filled.PrevPageNo {
|
||||
diploma.Abort(
|
||||
diploma.WrongPrevPageNo,
|
||||
fmt.Errorf("bug: last pageNo %d in tree != prev pageNo %d in _metric",
|
||||
path.LastPageNo, filled.PrevPageNo),
|
||||
)
|
||||
}
|
||||
}
|
||||
// if path.LastPageNo != filled.PrevPageNo {
|
||||
// diploma.Abort(
|
||||
// diploma.WrongPrevPageNo,
|
||||
// fmt.Errorf("bug: last pageNo %d in tree != prev pageNo %d in _metric",
|
||||
// path.LastPageNo, filled.PrevPageNo),
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
// report, err := s.atree.AppendDataPages(atree.AppendDataPageReq{
|
||||
// MetricID: req.MetricID,
|
||||
// Timestamp: req.Timestamp,
|
||||
// Value: req.Value,
|
||||
// Since: filled.Since,
|
||||
// RootPageNo: filled.RootPageNo,
|
||||
// PrevPageNo: filled.PrevPageNo,
|
||||
// TimestampsChunks: filled.TimestampsChunks,
|
||||
// TimestampsSize: filled.TimestampsSize,
|
||||
// ValuesChunks: filled.ValuesChunks,
|
||||
// ValuesSize: filled.ValuesSize,
|
||||
// })
|
||||
// if err != nil {
|
||||
// diploma.Abort(diploma.WriteToAtreeFailed, err)
|
||||
// }
|
||||
// _ = report
|
||||
// // report, err := s.atree.AppendDataPages(atree.AppendDataPageReq{
|
||||
// // MetricID: req.MetricID,
|
||||
// // Timestamp: req.Timestamp,
|
||||
// // Value: req.Value,
|
||||
// // Since: filled.Since,
|
||||
// // RootPageNo: filled.RootPageNo,
|
||||
// // PrevPageNo: filled.PrevPageNo,
|
||||
// // TimestampsChunks: filled.TimestampsChunks,
|
||||
// // TimestampsSize: filled.TimestampsSize,
|
||||
// // ValuesChunks: filled.ValuesChunks,
|
||||
// // ValuesSize: filled.ValuesSize,
|
||||
// // })
|
||||
// // if err != nil {
|
||||
// // diploma.Abort(diploma.WriteToAtreeFailed, err)
|
||||
// // }
|
||||
// // _ = report
|
||||
|
||||
//waitCh := s.txlog.WriteAppended(path, report)
|
||||
// //waitCh := s.txlog.WriteAppended(path, report)
|
||||
|
||||
waitCh := s.txlog.Append(txlog.AppendedPagesReq{
|
||||
Legs: path.Legs,
|
||||
MetricID: req.MetricID,
|
||||
Timestamp: req.Timestamp,
|
||||
Value: req.Value,
|
||||
LastPageNo: filled.PrevPageNo,
|
||||
//Pages: ,
|
||||
TimestampsChunks: filled.TimestampsChunks,
|
||||
TimestampsSize: filled.TimestampsSize,
|
||||
ValuesChunks: filled.ValuesChunks,
|
||||
ValuesSize: filled.ValuesSize,
|
||||
},
|
||||
)
|
||||
<-waitCh
|
||||
// waitCh := s.txlog.Append(txlog.AppendedPagesReq{
|
||||
// Legs: path.Legs,
|
||||
// MetricID: req.MetricID,
|
||||
// Timestamp: req.Timestamp,
|
||||
// Value: req.Value,
|
||||
// LastPageNo: filled.PrevPageNo,
|
||||
// //Pages: ,
|
||||
// TimestampsChunks: filled.TimestampsChunks,
|
||||
// TimestampsSize: filled.TimestampsSize,
|
||||
// ValuesChunks: filled.ValuesChunks,
|
||||
// ValuesSize: filled.ValuesSize,
|
||||
// },
|
||||
// )
|
||||
// <-waitCh
|
||||
|
||||
case NoMetric:
|
||||
return proto.ErrNoMetric
|
||||
// case NoMetric:
|
||||
// return proto.ErrNoMetric
|
||||
|
||||
case ExpiredMeasure:
|
||||
return proto.ErrExpiredMeasure
|
||||
// case ExpiredMeasure:
|
||||
// return proto.ErrExpiredMeasure
|
||||
|
||||
case NonMonotonicValue:
|
||||
return proto.ErrNonMonotonicValue
|
||||
// case NonMonotonicValue:
|
||||
// return proto.ErrNonMonotonicValue
|
||||
|
||||
default:
|
||||
diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
// default:
|
||||
// diploma.Abort(diploma.WrongResultCodeBug, ErrWrongResultCodeBug)
|
||||
// }
|
||||
// return 0
|
||||
// }
|
||||
|
||||
type tryAppendMeasuresResult struct {
|
||||
ResultCode byte
|
||||
MetricType diploma.MetricType
|
||||
FracDigits byte
|
||||
Since uint32
|
||||
Until uint32
|
||||
UntilValue float64
|
||||
RootPageNo uint32
|
||||
PrevPageNo uint32
|
||||
TimestampsBuf *conbuf.ContinuousBuffer
|
||||
ValuesBuf *conbuf.ContinuousBuffer
|
||||
Timestamps diploma.TimestampCompressor
|
||||
Values diploma.ValueCompressor
|
||||
ResultCode byte
|
||||
// MetricType diploma.MetricType
|
||||
// FracDigits byte
|
||||
// Since uint32
|
||||
// Until uint32
|
||||
// UntilValue float64
|
||||
// RootPageNo uint32
|
||||
// PrevPageNo uint32
|
||||
// TimestampsBuf *conbuf.ContinuousBuffer
|
||||
// ValuesBuf *conbuf.ContinuousBuffer
|
||||
// Timestamps diploma.TimestampCompressor
|
||||
// Values diploma.ValueCompressor
|
||||
}
|
||||
|
||||
func (s *Database) AppendMeasures(req proto.AppendMeasuresReq) uint16 {
|
||||
@@ -444,6 +444,7 @@ func (s *Database) AppendMeasures(req proto.AppendMeasuresReq) uint16 {
|
||||
|
||||
s.appendJobToWorkerQueue(tryAppendMeasuresReq{
|
||||
MetricID: req.MetricID,
|
||||
Measures: req.Measures,
|
||||
ResultCh: resultCh,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user