// Process writes the data provided by iter to a tsm1 shard. func (c *Converter) Process(iter KeyIterator) error { // Ensure the tsm1 directory exists. if err := os.MkdirAll(c.path, 0777); err != nil { return err } // Iterate until no more data remains. var w tsm1.TSMWriter for iter.Next() { k, v, err := iter.Read() if err != nil { return err } scrubbed := c.scrubValues(v) if w == nil { w, err = c.nextTSMWriter() if err != nil { return err } } if err := w.Write(k, scrubbed); err != nil { return err } c.tracker.AddPointsRead(len(v)) c.tracker.AddPointsWritten(len(scrubbed)) // If we have a max file size configured and we're over it, start a new TSM file. if w.Size() > c.maxTSMFileSize { if err := w.WriteIndex(); err != nil && err != tsm1.ErrNoValues { return err } c.tracker.AddTSMBytes(w.Size()) if err := w.Close(); err != nil { return err } w = nil } } if w != nil { if err := w.WriteIndex(); err != nil && err != tsm1.ErrNoValues { return err } c.tracker.AddTSMBytes(w.Size()) if err := w.Close(); err != nil { return err } } return nil }
// Process writes the data provided by iter to a tsm1 shard. func (c *Converter) Process(iter KeyIterator) error { // Ensure the tsm1 directory exists. if err := os.MkdirAll(c.path, 0777); err != nil { return err } // Iterate until no more data remains. var w tsm1.TSMWriter var keyCount map[string]int for iter.Next() { k, v, err := iter.Read() if err != nil { return err } if w == nil { w, err = c.nextTSMWriter() if err != nil { return err } keyCount = map[string]int{} } if err := w.Write(k, v); err != nil { return err } keyCount[k]++ c.stats.AddPointsRead(len(v)) c.stats.AddPointsWritten(len(v)) // If we have a max file size configured and we're over it, start a new TSM file. if w.Size() > c.maxTSMFileSize || keyCount[k] == maxBlocksPerKey { if err := w.WriteIndex(); err != nil && err != tsm1.ErrNoValues { return err } c.stats.AddTSMBytes(w.Size()) if err := w.Close(); err != nil { return err } w = nil } } if w != nil { if err := w.WriteIndex(); err != nil && err != tsm1.ErrNoValues { return err } c.stats.AddTSMBytes(w.Size()) if err := w.Close(); err != nil { return err } } return nil }