Blocks version of Flush handler. It force-compacts blocks, and triggers shipping.
(w http.ResponseWriter, r *http.Request)
| 3587 | |
| 3588 | // Blocks version of Flush handler. It force-compacts blocks, and triggers shipping. |
| 3589 | func (i *Ingester) flushHandler(w http.ResponseWriter, r *http.Request) { |
| 3590 | err := r.ParseForm() |
| 3591 | if err != nil { |
| 3592 | level.Warn(logutil.WithContext(r.Context(), i.logger)).Log("msg", "failed to parse HTTP request in flush handler", "err", err) |
| 3593 | w.WriteHeader(http.StatusBadRequest) |
| 3594 | return |
| 3595 | } |
| 3596 | |
| 3597 | tenants := r.Form[tenantParam] |
| 3598 | |
| 3599 | allowedUsers := users.NewAllowedTenants(tenants, nil) |
| 3600 | run := func() { |
| 3601 | ingCtx := i.ServiceContext() |
| 3602 | if ingCtx == nil || ingCtx.Err() != nil { |
| 3603 | level.Info(logutil.WithContext(r.Context(), i.logger)).Log("msg", "flushing TSDB blocks: ingester not running, ignoring flush request") |
| 3604 | return |
| 3605 | } |
| 3606 | |
| 3607 | compactionCallbackCh := make(chan struct{}) |
| 3608 | |
| 3609 | level.Info(logutil.WithContext(r.Context(), i.logger)).Log("msg", "flushing TSDB blocks: triggering compaction") |
| 3610 | select { |
| 3611 | case i.TSDBState.forceCompactTrigger <- requestWithUsersAndCallback{users: allowedUsers, callback: compactionCallbackCh}: |
| 3612 | // Compacting now. |
| 3613 | case <-ingCtx.Done(): |
| 3614 | level.Warn(logutil.WithContext(r.Context(), i.logger)).Log("msg", "failed to compact TSDB blocks, ingester not running anymore") |
| 3615 | return |
| 3616 | } |
| 3617 | |
| 3618 | // Wait until notified about compaction being finished. |
| 3619 | select { |
| 3620 | case <-compactionCallbackCh: |
| 3621 | level.Info(logutil.WithContext(r.Context(), i.logger)).Log("msg", "finished compacting TSDB blocks") |
| 3622 | case <-ingCtx.Done(): |
| 3623 | level.Warn(logutil.WithContext(r.Context(), i.logger)).Log("msg", "failed to compact TSDB blocks, ingester not running anymore") |
| 3624 | return |
| 3625 | } |
| 3626 | |
| 3627 | if i.cfg.BlocksStorageConfig.TSDB.IsBlocksShippingEnabled() { |
| 3628 | shippingCallbackCh := make(chan struct{}) // must be new channel, as compactionCallbackCh is closed now. |
| 3629 | |
| 3630 | level.Info(logutil.WithContext(r.Context(), i.logger)).Log("msg", "flushing TSDB blocks: triggering shipping") |
| 3631 | |
| 3632 | select { |
| 3633 | case i.TSDBState.shipTrigger <- requestWithUsersAndCallback{users: allowedUsers, callback: shippingCallbackCh}: |
| 3634 | // shipping now |
| 3635 | case <-ingCtx.Done(): |
| 3636 | level.Warn(logutil.WithContext(r.Context(), i.logger)).Log("msg", "failed to ship TSDB blocks, ingester not running anymore") |
| 3637 | return |
| 3638 | } |
| 3639 | |
| 3640 | // Wait until shipping finished. |
| 3641 | select { |
| 3642 | case <-shippingCallbackCh: |
| 3643 | level.Info(logutil.WithContext(r.Context(), i.logger)).Log("msg", "shipping of TSDB blocks finished") |
| 3644 | case <-ingCtx.Done(): |
| 3645 | level.Warn(logutil.WithContext(r.Context(), i.logger)).Log("msg", "failed to ship TSDB blocks, ingester not running anymore") |
| 3646 | return |
no test coverage detected