github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/survival_goal.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package tree
    12  
    13  import "github.com/cockroachdb/errors"
    14  
    15  // SurvivalGoal represents the desired survivability level
    16  // for a given database.
    17  type SurvivalGoal uint32
    18  
    19  const (
    20  	// SurvivalGoalDefault indicates default survive behavior.
    21  	// This will get translated to the appropriate value when persisted.
    22  	SurvivalGoalDefault SurvivalGoal = iota
    23  	// SurvivalGoalRegionFailure indicates a database being able to withstand
    24  	// an entire region failure.
    25  	SurvivalGoalRegionFailure
    26  	// SurvivalGoalZoneFailure indicates a database being able to
    27  	// withstand a failure of an availibility zone.
    28  	SurvivalGoalZoneFailure
    29  )
    30  
    31  // Format implements the NodeFormatter interface.
    32  func (node *SurvivalGoal) Format(ctx *FmtCtx) {
    33  	switch *node {
    34  	case SurvivalGoalRegionFailure:
    35  		ctx.WriteString("SURVIVE REGION FAILURE")
    36  	case SurvivalGoalZoneFailure:
    37  		ctx.WriteString("SURVIVE ZONE FAILURE")
    38  	default:
    39  		panic(errors.AssertionFailedf("unknown survival goal: %d", *node))
    40  	}
    41  }
    42  
    43  // TelemetryName returns a representation of SurvivalGoal suitable for telemetry
    44  func (node *SurvivalGoal) TelemetryName() string {
    45  	switch *node {
    46  	case SurvivalGoalDefault:
    47  		return "survive_default"
    48  	case SurvivalGoalRegionFailure:
    49  		return "survive_region_failure"
    50  	case SurvivalGoalZoneFailure:
    51  		return "survive_zone_failure"
    52  	default:
    53  		panic(errors.AssertionFailedf("unknown survival goal: %d", *node))
    54  	}
    55  }