etcdstore

package
v0.33.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package etcdstore stores resources using etcd. Our usage for etcd is optimized for the kinds of hierarchical and type-based queries common in a resource provider.

Our key prefix scheme builds a hierarchy using '|' as a separator as '|' is illegal in an UCP resource identifier. We take advantage of the natural usage of '/' in resource ids as a delimiter.

The key of a resource can be mechanically constructed from its resource id by replacing 'providers' with the '|' separator (for a non-extension resource). We have no current support for extension resources.

Keys are structured like the following example:

scope|/planes/radius/local/|/resourceGroups/cool-group/
resource|/planes/radius/local/resourceGroups/cool-group/|/Applications.Core/applications/cool-app/

As a special case for scopes (like resource groups) we treat the last segment as the routing scope.

The prefix (scope or resource) limits each query to either for scope or resources respectively. In our use cases for the store we never need to query scopes and resources at the same time. Separating these actions limits the number of results - we want to avoid cases where the query has to return a huge set of results.

For example, the following query will be commonly executed and we don't want it to list all resources in the database:

scope|/planes/

This scheme allows a variety of flexibility for querying/filtering with different scopes. We prefer query approaches that that involved client-side filtering to avoid the need for N+1 query strategies. Leading and trailing '/' characters are preserved on the key-segments to avoid ambiguity.

Index

Constants

View Source
const (
	SectionSeparator = "|"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ETCDClient

type ETCDClient struct {
	// contains filtered or unexported fields
}

func NewETCDClient

func NewETCDClient(c *etcdclient.Client) *ETCDClient

NewETCDClient creates a new ETCDClient instance with the given etcdclient.Client.

func (*ETCDClient) Client

func (c *ETCDClient) Client() *etcdclient.Client

Client returns the etcdclient.Client instance stored in the ETCDClient struct.

func (*ETCDClient) Delete

func (c *ETCDClient) Delete(ctx context.Context, id string, options ...store.DeleteOptions) error

Delete checks if the given resource ID is valid, and if so, deletes it from the store, returning an error if the resource does not exist or if an ETag is provided and does not match.

func (*ETCDClient) Get

func (c *ETCDClient) Get(ctx context.Context, id string, options ...store.GetOptions) (*store.Object, error)

Get checks if the provided context, id and options are valid, then retrieves the corresponding object from the store and returns it, or an error if the object is not found or an error occurs.

func (*ETCDClient) Query

func (c *ETCDClient) Query(ctx context.Context, query store.Query, options ...store.QueryOptions) (*store.ObjectQueryResult, error)

Query retrieves objects from the store that match the given query and filters, and returns them in a store.ObjectQueryResult.

func (*ETCDClient) Save

func (c *ETCDClient) Save(ctx context.Context, obj *store.Object, options ...store.SaveOptions) error

Save checks the context and object parameters, parses the object ID, marshals the object into JSON, saves the object to the store, and sets the object's ETag. If an ETag is provided, a transaction is executed to ensure concurrency.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL