|
1 | 1 | package pilosalib |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "crypto/sha1" |
5 | 6 | "fmt" |
6 | 7 | "io" |
@@ -272,20 +273,21 @@ func (d *Driver) savePartition( |
272 | 273 | for colID = offset; err == nil; colID++ { |
273 | 274 | // commit each batch of objects (pilosa and boltdb) |
274 | 275 | if colID%sql.IndexBatchSize == 0 && colID != 0 { |
275 | | - d.saveBatch(ctx, idx.mapping, colID) |
| 276 | + if err = d.saveBatch(ctx, idx.mapping, colID); err != nil { |
| 277 | + return 0, err |
| 278 | + } |
276 | 279 | } |
277 | 280 |
|
278 | 281 | select { |
279 | | - case <-ctx.Done(): |
280 | | - return 0, ctx.Err() |
| 282 | + case <-ctx.Context.Done(): |
| 283 | + return 0, ctx.Context.Err() |
281 | 284 |
|
282 | 285 | default: |
283 | 286 | var ( |
284 | 287 | values []interface{} |
285 | 288 | location []byte |
286 | 289 | ) |
287 | | - values, location, err = kviter.Next() |
288 | | - if err != nil { |
| 290 | + if values, location, err = kviter.Next(); err != nil { |
289 | 291 | break |
290 | 292 | } |
291 | 293 |
|
@@ -332,6 +334,9 @@ func (d *Driver) Save( |
332 | 334 | return errInvalidIndexType.New(i) |
333 | 335 | } |
334 | 336 |
|
| 337 | + idx.wg.Add(1) |
| 338 | + defer idx.wg.Done() |
| 339 | + ctx.Context, idx.cancel = context.WithCancel(ctx.Context) |
335 | 340 | processingFile := d.processingFilePath(i.Database(), i.Table(), i.ID()) |
336 | 341 | if err := index.WriteProcessingFile( |
337 | 342 | processingFile, |
@@ -377,14 +382,18 @@ func (d *Driver) Save( |
377 | 382 |
|
378 | 383 | // Delete the given index for all partitions in the iterator. |
379 | 384 | func (d *Driver) Delete(i sql.Index, partitions sql.PartitionIter) error { |
380 | | - if err := os.RemoveAll(filepath.Join(d.root, i.Database(), i.Table(), i.ID())); err != nil { |
381 | | - return err |
382 | | - } |
383 | | - |
384 | 385 | idx, ok := i.(*pilosaIndex) |
385 | 386 | if !ok { |
386 | 387 | return errInvalidIndexType.New(i) |
387 | 388 | } |
| 389 | + if idx.cancel != nil { |
| 390 | + idx.cancel() |
| 391 | + idx.wg.Wait() |
| 392 | + } |
| 393 | + |
| 394 | + if err := os.RemoveAll(filepath.Join(d.root, i.Database(), i.Table(), i.ID())); err != nil { |
| 395 | + return err |
| 396 | + } |
388 | 397 |
|
389 | 398 | err := idx.index.Open() |
390 | 399 | if err != nil { |
@@ -435,8 +444,8 @@ func (d *Driver) savePilosa(ctx *sql.Context, colID uint64) error { |
435 | 444 |
|
436 | 445 | start := time.Now() |
437 | 446 |
|
438 | | - for i, frm := range d.fields { |
439 | | - err := frm.Import(d.bitBatches[i].rows, d.bitBatches[i].cols, nil) |
| 447 | + for i, fld := range d.fields { |
| 448 | + err := fld.Import(d.bitBatches[i].rows, d.bitBatches[i].cols, nil) |
440 | 449 | if err != nil { |
441 | 450 | span.LogKV("error", err) |
442 | 451 | return err |
|
0 commit comments