storj/satellite/orders/window_endpoint_phase.go
Jeff Wendling 85a74b47e7 satellite/orders: 3-phase rollout
This adds a config flag orders.window-endpoint-rollout-phase
that can take on the values phase1, phase2 or phase3.

In phase1, the current orders endpoint continues to work as
usual, and the windowed orders endpoint uses the same backend
as the current one (but also does a bit extra).

In phase2, the current orders endpoint is disabled and the
windowed orders endpoint continues to use the same backend.

In phase3, the current orders endpoint is still disabled and
the windowed orders endpoint uses the new backend that requires
much less database traffic and state.

The intention is to deploy in phase1, roll out code to nodes
to have them use the windowed endpoint, switch to phase2, wait
a couple days for all existing orders to expire, then switch
to phase3.

Additionally, it fixes a bug where a node could submit a bunch
of orders and rack up charges for a bucket.

Change-Id: Ifdc10e09ae1645159cbec7ace687dcb2d594c76d
2020-08-03 17:01:42 +00:00

61 lines
1.7 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package orders
import (
"fmt"
"strings"
"github.com/zeebo/errs"
)
// WindowEndpointRolloutPhase controls the phase of the new orders endpoint rollout.
type WindowEndpointRolloutPhase int
const (
// WindowEndpointRolloutPhase1 is when both the old and new endpoint are enabled and
// the new endpoint places orders in the queue just like the old endpoint.
WindowEndpointRolloutPhase1 WindowEndpointRolloutPhase = 1 + iota
// WindowEndpointRolloutPhase2 is when the old endpoint is disabled and the new endpint
// places orders in the queue just like the old endpoint used to.
WindowEndpointRolloutPhase2
// WindowEndpointRolloutPhase3 is when the old endpoint is disabled and the new endpoint
// does not use a queue and just does direct insertion of rollup values.
WindowEndpointRolloutPhase3
)
// String provides a human readable form of the rollout phase.
func (phase WindowEndpointRolloutPhase) String() string {
switch phase {
case WindowEndpointRolloutPhase1:
return "phase1"
case WindowEndpointRolloutPhase2:
return "phase2"
case WindowEndpointRolloutPhase3:
return "phase3"
default:
return fmt.Sprintf("WindowEndpointRolloutPhase(%d)", int(phase))
}
}
// Set implements flag.Value interface.
func (phase *WindowEndpointRolloutPhase) Set(s string) error {
switch strings.ToLower(s) {
case "phase1":
*phase = WindowEndpointRolloutPhase1
case "phase2":
*phase = WindowEndpointRolloutPhase2
case "phase3":
*phase = WindowEndpointRolloutPhase3
default:
return errs.New("invalid window endpoint rollout phase: %q", s)
}
return nil
}
// Type implements pflag.Value.
func (WindowEndpointRolloutPhase) Type() string { return "orders.WindowEndpointRolloutPhase" }