2023-10-13 09:43:27 +00:00
|
|
|
package pfile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-10-16 08:50:19 +00:00
|
|
|
|
2023-10-13 09:43:27 +00:00
|
|
|
"git.crumpington.com/public/jldb/lib/wal"
|
|
|
|
"git.crumpington.com/public/jldb/mdb/change"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type pFileState struct {
|
|
|
|
Data map[[2]uint64][]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type recBuilder struct {
|
|
|
|
changes []change.Change
|
|
|
|
rec wal.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRecBuilder(seqNum, timestamp int64) *recBuilder {
|
|
|
|
return &recBuilder{
|
|
|
|
rec: wal.Record{
|
|
|
|
SeqNum: seqNum,
|
|
|
|
TimestampMS: timestamp,
|
|
|
|
},
|
|
|
|
changes: []change.Change{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *recBuilder) Store(cID, iID uint64, data string) *recBuilder {
|
|
|
|
b.changes = append(b.changes, change.Change{
|
|
|
|
CollectionID: cID,
|
|
|
|
ItemID: iID,
|
|
|
|
Store: true,
|
|
|
|
Data: []byte(data),
|
|
|
|
})
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *recBuilder) Delete(cID, iID uint64) *recBuilder {
|
|
|
|
b.changes = append(b.changes, change.Change{
|
|
|
|
CollectionID: cID,
|
|
|
|
ItemID: iID,
|
|
|
|
Store: false,
|
|
|
|
})
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *recBuilder) Record() wal.Record {
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
change.Write(b.changes, buf)
|
|
|
|
b.rec.DataSize = int64(buf.Len())
|
|
|
|
b.rec.Reader = buf
|
|
|
|
return b.rec
|
|
|
|
}
|