github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/chunk/table_client.go (about)

     1  package chunk
     2  
     3  import "context"
     4  
     5  // TableClient is a client for telling Dynamo what to do with tables.
     6  type TableClient interface {
     7  	ListTables(ctx context.Context) ([]string, error)
     8  	CreateTable(ctx context.Context, desc TableDesc) error
     9  	DeleteTable(ctx context.Context, name string) error
    10  	DescribeTable(ctx context.Context, name string) (desc TableDesc, isActive bool, err error)
    11  	UpdateTable(ctx context.Context, current, expected TableDesc) error
    12  	Stop()
    13  }
    14  
    15  // TableDesc describes a table.
    16  type TableDesc struct {
    17  	Name              string
    18  	UseOnDemandIOMode bool
    19  	ProvisionedRead   int64
    20  	ProvisionedWrite  int64
    21  	Tags              Tags
    22  	WriteScale        AutoScalingConfig
    23  	ReadScale         AutoScalingConfig
    24  }
    25  
    26  // Equals returns true if other matches desc.
    27  func (desc TableDesc) Equals(other TableDesc) bool {
    28  	if desc.WriteScale != other.WriteScale {
    29  		return false
    30  	}
    31  
    32  	if desc.ReadScale != other.ReadScale {
    33  		return false
    34  	}
    35  
    36  	// Only check provisioned read if auto scaling is disabled
    37  	if !desc.ReadScale.Enabled && desc.ProvisionedRead != other.ProvisionedRead {
    38  		return false
    39  	}
    40  
    41  	// Only check provisioned write if auto scaling is disabled
    42  	if !desc.WriteScale.Enabled && desc.ProvisionedWrite != other.ProvisionedWrite {
    43  		return false
    44  	}
    45  
    46  	// if the billing mode needs updating
    47  	if desc.UseOnDemandIOMode != other.UseOnDemandIOMode {
    48  		return false
    49  	}
    50  
    51  	if !desc.Tags.Equals(other.Tags) {
    52  		return false
    53  	}
    54  
    55  	return true
    56  }
    57  
    58  type byName []TableDesc
    59  
    60  func (a byName) Len() int           { return len(a) }
    61  func (a byName) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
    62  func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }