Best-effort cleanup of converter.

pull/5281/head
Philip O'Toole 2016-01-05 18:29:16 -08:00
parent 2a547b0db3
commit 9c916b0b76
1 changed files with 18 additions and 17 deletions

View File

@ -45,21 +45,21 @@ func (c *Converter) Process(iter KeyIterator) error {
return err return err
} }
w, err := c.nextTSMWriter()
if err != nil {
return err
}
atomic.AddUint64(&TsmFilesCreated, 1)
defer w.Close()
// Iterate until no more data remains. // Iterate until no more data remains.
var w tsm1.TSMWriter
for iter.Next() { for iter.Next() {
k, v, err := iter.Read() k, v, err := iter.Read()
if err != nil { if err != nil {
return err return err
} }
scrubbed := scrubValues(v) scrubbed := scrubValues(v)
if w == nil {
w, err = c.nextTSMWriter()
if err != nil {
return err
}
}
if err := w.Write(k, scrubbed); err != nil { if err := w.Write(k, scrubbed); err != nil {
return err return err
} }
@ -74,19 +74,19 @@ func (c *Converter) Process(iter KeyIterator) error {
if err := w.Close(); err != nil { if err := w.Close(); err != nil {
return err return err
} }
w = nil
w, err = c.nextTSMWriter()
if err != nil {
return err
}
atomic.AddUint64(&TsmFilesCreated, 1)
} }
} }
// All done! if w != nil {
if err := w.WriteIndex(); err != nil && err != tsm1.ErrNoValues { if err := w.WriteIndex(); err != nil && err != tsm1.ErrNoValues {
return err return err
}
if err := w.Close(); err != nil {
return err
}
} }
return nil return nil
} }
@ -106,6 +106,7 @@ func (c *Converter) nextTSMWriter() (tsm1.TSMWriter, error) {
return nil, err return nil, err
} }
atomic.AddUint64(&TsmFilesCreated, 1)
return w, nil return w, nil
} }