wp
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
|
||||
bin "gordenko.dev/dima/bin/little"
|
||||
"gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/enc"
|
||||
"gordenko.dev/dima/qb/util"
|
||||
)
|
||||
|
||||
type BackwardCursor struct {
|
||||
@@ -29,6 +31,7 @@ type BackwardCursorOptions struct {
|
||||
}
|
||||
|
||||
func NewBackwardCursor(opt BackwardCursorOptions) (*BackwardCursor, error) {
|
||||
fmt.Printf("footer: % x\n", opt.PageData[DataPageSize-DataPageFooterSize:])
|
||||
switch opt.MetricType {
|
||||
case qb.Instant, qb.Cumulative:
|
||||
// ok
|
||||
@@ -90,6 +93,7 @@ func (s *BackwardCursor) Prev() (uint32, float64, bool, error) {
|
||||
}
|
||||
|
||||
prevPageNo, _ := bin.GetUint32(s.pageData[prevPageIdx:])
|
||||
fmt.Printf("CURSOR: prev pageNo %d\n", prevPageNo)
|
||||
if prevPageNo == 0 {
|
||||
return 0, 0, true, nil
|
||||
}
|
||||
@@ -129,8 +133,51 @@ func (s *BackwardCursor) Close() {
|
||||
s.releasePage(s.pageNo)
|
||||
}
|
||||
|
||||
// HELPER
|
||||
func CreateTimestampDecompressor(page []byte) (qb.TimestampDecompressor, error) {
|
||||
size, _ := bin.GetUint16(page[timestampsSizeIdx:])
|
||||
if int(size) > DataPagePayloadSize {
|
||||
return nil, fmt.Errorf("bug: invalid timestamps size %d", size)
|
||||
}
|
||||
pos := DataPagePayloadSize - int(size)
|
||||
d := enc.NewTimeDeltaDecompressor()
|
||||
d.RestoreFromEnd(page[pos:DataPagePayloadSize])
|
||||
|
||||
//func (s *BackwardCursor) makeDecompressors() error {
|
||||
payload := page[pos:DataPagePayloadSize]
|
||||
|
||||
//}
|
||||
fmt.Printf("PAGE timestamps (CURSOR) %d:\n% x\n", len(payload), payload)
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func CreateValueDecompressor(page []byte, metricType qb.MetricType, fracDigits byte) (qb.ValueDecompressor, error) {
|
||||
size, _ := bin.GetUint16(page[valuesSizeIdx:])
|
||||
if int(size) > DataPagePayloadSize {
|
||||
return nil, fmt.Errorf("bug: invalid values size %d", size)
|
||||
}
|
||||
d := enc.NewValueDeltaDecompressor(metricType, fracDigits)
|
||||
d.RestoreFromEnd(page[:size])
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func VerifyDataPageCRC32(data []byte) error {
|
||||
var (
|
||||
calculatedCRC = util.CalculateCRC32(data[:dataCRC32Idx])
|
||||
writtenCRC, _ = bin.GetUint32(data[dataCRC32Idx:])
|
||||
)
|
||||
if calculatedCRC != writtenCRC {
|
||||
return fmt.Errorf("calculated CRC32 %d are not equal written CRC32 %d",
|
||||
calculatedCRC, writtenCRC)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func VerifyIndexPageCRC32(data []byte) error {
|
||||
var (
|
||||
calculatedCRC = util.CalculateCRC32(data[:indexCRC32Idx])
|
||||
writtenCRC, _ = bin.GetUint32(data[indexCRC32Idx:])
|
||||
)
|
||||
if calculatedCRC != writtenCRC {
|
||||
return fmt.Errorf("calculated CRC32 %d are not equal written CRC32 %d",
|
||||
calculatedCRC, writtenCRC)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user