| 389 | } |
| 390 | |
| 391 | func HandleTruncateBlockFile(blockId string) error { |
| 392 | ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout) |
| 393 | defer cancelFn() |
| 394 | err := filestore.WFS.WriteFile(ctx, blockId, wavebase.BlockFile_Term, nil) |
| 395 | if err == fs.ErrNotExist { |
| 396 | return nil |
| 397 | } |
| 398 | if err != nil { |
| 399 | return fmt.Errorf("error truncating blockfile: %w", err) |
| 400 | } |
| 401 | err = filestore.WFS.DeleteFile(ctx, blockId, wavebase.BlockFile_Cache) |
| 402 | if err == fs.ErrNotExist { |
| 403 | err = nil |
| 404 | } |
| 405 | if err != nil { |
| 406 | log.Printf("error deleting cache file (continuing): %v\n", err) |
| 407 | } |
| 408 | wps.Broker.Publish(wps.WaveEvent{ |
| 409 | Event: wps.Event_BlockFile, |
| 410 | Scopes: []string{waveobj.MakeORef(waveobj.OType_Block, blockId).String()}, |
| 411 | Data: &wps.WSFileEventData{ |
| 412 | ZoneId: blockId, |
| 413 | FileName: wavebase.BlockFile_Term, |
| 414 | FileOp: wps.FileOp_Truncate, |
| 415 | }, |
| 416 | }) |
| 417 | return nil |
| 418 | |
| 419 | } |
| 420 | |
| 421 | func debugLog(ctx context.Context, fmtStr string, args ...interface{}) { |
| 422 | blocklogger.Infof(ctx, "[conndebug] "+fmtStr, args...) |