wp
This commit is contained in:
@@ -77,23 +77,20 @@ type Writer struct {
|
||||
isExited bool
|
||||
exitCh chan struct{}
|
||||
waitGroup *sync.WaitGroup
|
||||
//signalCh chan struct{}
|
||||
}
|
||||
|
||||
type WriterOptions struct {
|
||||
Inbox *inbox.Inbox
|
||||
WorkerInbox *inbox.Inbox
|
||||
Dir string
|
||||
DatabaseName string
|
||||
//SnapshotNumber int // номер журнала
|
||||
Inbox *inbox.Inbox
|
||||
WorkerInbox *inbox.Inbox
|
||||
Dir string
|
||||
DatabaseName string
|
||||
WAL string
|
||||
DataFreeList *freelist.FreeList
|
||||
IndexFreeList *freelist.FreeList
|
||||
DataFile *os.File
|
||||
IndexFile *os.File
|
||||
//Atree *atree.Atree
|
||||
ExitCh chan struct{}
|
||||
WaitGroup *sync.WaitGroup
|
||||
ExitCh chan struct{}
|
||||
WaitGroup *sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewWriter(opt WriterOptions) (*Writer, error) {
|
||||
@@ -245,17 +242,26 @@ func (s *Writer) packAndWrite() (err error) {
|
||||
fmt.Println("synced to wal")
|
||||
|
||||
// 4. Пишу в atree сторінки
|
||||
err = WriteDataPages(s.dataFile, prepared.WriteToData)
|
||||
if err != nil {
|
||||
return
|
||||
if len(prepared.WriteToData) > 0 {
|
||||
err = WriteDataPages(s.dataFile, prepared.WriteToData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.dataFile.Sync(); err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("written to data")
|
||||
}
|
||||
fmt.Println("written to data")
|
||||
err = WriteIndexPages(s.indexFile, prepared.WriteToIndex)
|
||||
if err != nil {
|
||||
return
|
||||
if len(prepared.WriteToIndex) > 0 {
|
||||
err = WriteIndexPages(s.indexFile, prepared.WriteToIndex)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.indexFile.Sync(); err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("written to index")
|
||||
}
|
||||
fmt.Println("written to index")
|
||||
|
||||
// 6. відправляю input - worker-у
|
||||
|
||||
var (
|
||||
@@ -413,62 +419,3 @@ func WriteIndexPages(file *os.File, pages []PageToWrite) (err error) {
|
||||
// TimestampsBuf []byte
|
||||
// ValuesBuf []byte
|
||||
// }
|
||||
|
||||
// Якщо (Pages) > 0 - незаповнену сторінку кодую в стисненому вигляді.
|
||||
// Якщо (Pages) = 0 - кодую просто пари timestamp / value
|
||||
// func (s *Writer) packWriteAppended(w *bytes.Buffer, req AppendedPagesReq) {
|
||||
// // завантажений path. Отже просто додаємо в дерево data сторінки, створюємо нові індексні
|
||||
// // без звернення до диску.
|
||||
// report := s.atree.AppendDataPages(atree.AppendDataPagesReq{
|
||||
// LastPageNo: req.LastPageNo,
|
||||
// Legs: req.Legs,
|
||||
// DataPages: req.Pages,
|
||||
// })
|
||||
|
||||
// m := AppendedPages{
|
||||
// MetricID: req.MetricID,
|
||||
// Timestamp: req.Timestamp,
|
||||
// Value: req.Value,
|
||||
// NewRootPageNo: report.NewRootPageNo,
|
||||
// LastPageNo: report.LastPageNo,
|
||||
// Pages: report.Pages,
|
||||
// TimestampsChunks: req.TimestampsChunks,
|
||||
// TimestampsSize: int(req.TimestampsSize),
|
||||
// ValuesChunks: req.ValuesChunks,
|
||||
// ValuesSize: int(req.ValuesSize),
|
||||
// }
|
||||
// m.Pack(w)
|
||||
// }
|
||||
|
||||
// helpers
|
||||
|
||||
// type Metric struct {
|
||||
// MetricID uint32
|
||||
// MetricType qb.MetricType
|
||||
// FracDigits byte
|
||||
// LastPageNo uint32
|
||||
// Since uint32
|
||||
// SinceValue float64
|
||||
// Until uint32
|
||||
// UntilValue float64
|
||||
// Timestamps []byte // payload FIX
|
||||
// Values []byte // payload FIX add lastDelta + h ?
|
||||
// }
|
||||
|
||||
// func writeChunks(dst io.Writer, chunks [][]byte, size int) (err error) {
|
||||
// remaining := size
|
||||
// for _, buf := range chunks {
|
||||
// if remaining < len(buf) {
|
||||
// buf = buf[:remaining]
|
||||
// }
|
||||
// _, err = dst.Write(buf)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// remaining -= len(buf)
|
||||
// if remaining == 0 {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user