wp
This commit is contained in:
@@ -28,7 +28,6 @@ type TimeDeltaCompressor struct {
|
||||
pos int
|
||||
lastUnixtime uint32
|
||||
lastDelta uint32
|
||||
state *TimeDeltaCapturedState
|
||||
}
|
||||
|
||||
// Початкове створення, коли даних немає
|
||||
@@ -61,11 +60,6 @@ func NewTimeDeltaCompressor(buf []byte, payloadSize int) *TimeDeltaCompressor {
|
||||
return s
|
||||
}
|
||||
|
||||
// FIX - restire lastUnixtime
|
||||
// func (s *TimeDeltaCompressor) RestoreState() {
|
||||
|
||||
// }
|
||||
|
||||
func (s *TimeDeltaCompressor) Evaluate(tmp []byte, timestamp uint32) qb.TimeEvaluationReport {
|
||||
var (
|
||||
delta = timestamp - s.lastUnixtime
|
||||
@@ -160,20 +154,10 @@ func (s *TimeDeltaCompressor) Append(offset int, change []byte, timestamp uint32
|
||||
|
||||
// }
|
||||
|
||||
type TimeDeltaCapturedState struct {
|
||||
H byte
|
||||
LastUnixtime uint32
|
||||
LastDelta uint32
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
// delta h
|
||||
func (s *TimeDeltaCompressor) CaptureState() {
|
||||
if s.state != nil {
|
||||
qb.Abort(qb.RepeatableLock, nil)
|
||||
}
|
||||
func (s *TimeDeltaCompressor) CaptureState() qb.TimeDeltaCapturedState {
|
||||
// позиція посувається вліво, отже може перескочити на попередній chunk
|
||||
s.state = &TimeDeltaCapturedState{
|
||||
return qb.TimeDeltaCapturedState{
|
||||
H: s.buf[s.pos],
|
||||
LastUnixtime: s.lastUnixtime,
|
||||
LastDelta: s.lastDelta,
|
||||
@@ -181,11 +165,6 @@ func (s *TimeDeltaCompressor) CaptureState() {
|
||||
}
|
||||
}
|
||||
|
||||
// fix - повернути в Pool буфери
|
||||
func (s *TimeDeltaCompressor) ForgetCapturedState() {
|
||||
s.state = nil
|
||||
}
|
||||
|
||||
// коли сторінка заповнена і відправляється в txlog, since замінюю на until
|
||||
func (s *TimeDeltaCompressor) ReplaceSinceWithUntil() uint32 {
|
||||
pos := len(s.buf) - 4
|
||||
@@ -218,34 +197,26 @@ func (s *TimeDeltaCompressor) Size() int {
|
||||
// }
|
||||
// }
|
||||
|
||||
func (s *TimeDeltaCompressor) WritePayloadTo(w io.Writer) (err error) {
|
||||
if s.state == nil {
|
||||
func (s *TimeDeltaCompressor) WritePayloadTo(w io.Writer, state *qb.TimeDeltaCapturedState) (err error) {
|
||||
if state == nil {
|
||||
_, err = w.Write(s.buf[:s.pos])
|
||||
return
|
||||
} else {
|
||||
_, err = w.Write(s.state.Payload)
|
||||
_, err = w.Write(state.Payload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = bin.WriteVarUint64(w, uint64(s.state.LastDelta))
|
||||
_, err = bin.WriteVarUint64(w, uint64(state.LastDelta))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = w.Write([]byte{
|
||||
s.state.H,
|
||||
state.H,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// func (s *TimeDeltaCompressor) encodeTail(lastUnixtime, lastDelta uint32, h byte) []byte {
|
||||
// tail := make([]byte, 9)
|
||||
// bin.PutUint32(tail, lastUnixtime)
|
||||
// tail[4] = h
|
||||
// n, _ := bin.PutVarUint64(tail[5:], uint64(lastDelta))
|
||||
// return tail[:n+5]
|
||||
// }
|
||||
|
||||
func (s *TimeDeltaCompressor) Rotate(newbuf []byte) {
|
||||
// УВАГА!
|
||||
// state не чіпаємо
|
||||
@@ -259,23 +230,11 @@ func (s *TimeDeltaCompressor) CreateDecompressor() qb.TimestampDecompressor {
|
||||
if s.pos == len(s.buf) {
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
h = s.buf[s.pos]
|
||||
lastUnixtime = s.lastUnixtime
|
||||
lastDelta = s.lastDelta
|
||||
payload = s.buf[s.pos:]
|
||||
)
|
||||
if s.state != nil {
|
||||
h = s.state.H
|
||||
lastUnixtime = s.state.LastUnixtime
|
||||
lastDelta = s.state.LastDelta
|
||||
payload = s.state.Payload
|
||||
}
|
||||
return NewTimeDeltaDecompressorFromState(TimeDeltaDecompressorFromStateOptions{
|
||||
H: h,
|
||||
LastUnixtime: lastUnixtime,
|
||||
LastDelta: lastDelta,
|
||||
Payload: payload,
|
||||
H: s.buf[s.pos],
|
||||
LastUnixtime: s.lastUnixtime,
|
||||
LastDelta: s.lastDelta,
|
||||
Payload: s.buf[s.pos:],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -306,7 +265,6 @@ func NewTimeDeltaDecompressor(buf []byte) *TimeDeltaDecompressor {
|
||||
log.Fatalf("bug: get last unixtime: %s", err)
|
||||
}
|
||||
s.pos += 4
|
||||
//fmt.Println("restored last unixtime", s.lastUnixtime)
|
||||
} else {
|
||||
s.done = true
|
||||
}
|
||||
@@ -329,15 +287,10 @@ func NewTimeDeltaDecompressorFromState(opt TimeDeltaDecompressorFromStateOptions
|
||||
s.lastDelta = opt.LastDelta
|
||||
s.decodeHeaderByte(opt.H)
|
||||
}
|
||||
//fmt.Println("-------------------")
|
||||
//fmt.Printf("restore from bound: isRun=%t, pending=%d, lastUnix=%d, lastDelta=%d\n",
|
||||
//s.isRun, s.pending, s.lastUnixtime, s.lastDelta)
|
||||
//fmt.Printf("buf: %d\n", s.buf)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TimeDeltaDecompressor) NextValue() (value uint32, done bool) {
|
||||
//fmt.Printf("NextValue(): pos: %d, isRegular: %t, pending: %d\n", s.pos, s.isRegular, s.pending)
|
||||
if s.done {
|
||||
return 0, true
|
||||
}
|
||||
@@ -346,7 +299,6 @@ func (s *TimeDeltaDecompressor) NextValue() (value uint32, done bool) {
|
||||
if s.lastDelta > 0 {
|
||||
s.lastUnixtime -= s.lastDelta
|
||||
s.pending--
|
||||
//fmt.Printf("lastUnix: %d, s.pending: %d\n", s.lastUnixtime, s.pending)
|
||||
if s.pending > 0 {
|
||||
// якщо в серії залишаються елементи
|
||||
if !s.isRun {
|
||||
@@ -358,7 +310,6 @@ func (s *TimeDeltaDecompressor) NextValue() (value uint32, done bool) {
|
||||
s.readHeader()
|
||||
s.readDelta()
|
||||
} else {
|
||||
//s.done = true
|
||||
s.lastDelta = 0
|
||||
}
|
||||
} else {
|
||||
@@ -372,12 +323,6 @@ func (s *TimeDeltaDecompressor) readHeader() {
|
||||
h := s.buf[s.pos]
|
||||
s.pos++
|
||||
s.decodeHeaderByte(h)
|
||||
// fmt.Println()
|
||||
// fmt.Println("read from pos:", s.pos)
|
||||
// fmt.Println("h:", h)
|
||||
// fmt.Println("isRun:", s.isRun)
|
||||
// fmt.Println("pending:", s.pending)
|
||||
// fmt.Println()
|
||||
}
|
||||
|
||||
func (s *TimeDeltaDecompressor) decodeHeaderByte(h byte) {
|
||||
@@ -394,11 +339,6 @@ func (s *TimeDeltaDecompressor) readDelta() {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
// fmt.Println()
|
||||
// fmt.Println("read from pos:", s.pos)
|
||||
// fmt.Println("read delta:", u64)
|
||||
// fmt.Println("read delta n:", n)
|
||||
// fmt.Println()
|
||||
s.pos += n
|
||||
s.lastDelta = uint32(u64)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user