mirror of
https://github.com/rancher/steve.git
synced 2025-09-18 00:08:17 +00:00
docs: Add docs for partition and proxy store
This commit is contained in:
@@ -9,12 +9,16 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
const defaultLimit = 100000
|
||||
|
||||
// Partitioner is an interface for interacting with partitions.
|
||||
type Partitioner interface {
|
||||
Lookup(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) (Partition, error)
|
||||
All(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) ([]Partition, error)
|
||||
Store(apiOp *types.APIRequest, partition Partition) (types.Store, error)
|
||||
}
|
||||
|
||||
// Store implements types.Store for partitions.
|
||||
type Store struct {
|
||||
Partitioner Partitioner
|
||||
}
|
||||
@@ -28,6 +32,7 @@ func (s *Store) getStore(apiOp *types.APIRequest, schema *types.APISchema, verb,
|
||||
return s.Partitioner.Store(apiOp, p)
|
||||
}
|
||||
|
||||
// Delete deletes an object from a store.
|
||||
func (s *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
|
||||
target, err := s.getStore(apiOp, schema, "delete", id)
|
||||
if err != nil {
|
||||
@@ -37,6 +42,7 @@ func (s *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id stri
|
||||
return target.Delete(apiOp, schema, id)
|
||||
}
|
||||
|
||||
// ByID looks up a single object by its ID.
|
||||
func (s *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
|
||||
target, err := s.getStore(apiOp, schema, "get", id)
|
||||
if err != nil {
|
||||
@@ -69,12 +75,14 @@ func (s *Store) listPartition(ctx context.Context, apiOp *types.APIRequest, sche
|
||||
return store.List(req, schema)
|
||||
}
|
||||
|
||||
// List returns a list of objects across all applicable partitions.
|
||||
// If pagination parameters are used, it returns a segment of the list.
|
||||
func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.APIObjectList, error) {
|
||||
var (
|
||||
result types.APIObjectList
|
||||
)
|
||||
|
||||
paritions, err := s.Partitioner.All(apiOp, schema, "list", "")
|
||||
partitions, err := s.Partitioner.All(apiOp, schema, "list", "")
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -84,7 +92,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
||||
return s.listPartition(ctx, apiOp, schema, partition, cont, revision, limit)
|
||||
},
|
||||
Concurrency: 3,
|
||||
Partitions: paritions,
|
||||
Partitions: partitions,
|
||||
}
|
||||
|
||||
resume := apiOp.Request.URL.Query().Get("continue")
|
||||
@@ -104,6 +112,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
||||
return result, lister.Err()
|
||||
}
|
||||
|
||||
// Create creates a single object in the store.
|
||||
func (s *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, data types.APIObject) (types.APIObject, error) {
|
||||
target, err := s.getStore(apiOp, schema, "create", "")
|
||||
if err != nil {
|
||||
@@ -113,6 +122,7 @@ func (s *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, data ty
|
||||
return target.Create(apiOp, schema, data)
|
||||
}
|
||||
|
||||
// Update updates a single object in the store.
|
||||
func (s *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, data types.APIObject, id string) (types.APIObject, error) {
|
||||
target, err := s.getStore(apiOp, schema, "update", id)
|
||||
if err != nil {
|
||||
@@ -122,6 +132,7 @@ func (s *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, data ty
|
||||
return target.Update(apiOp, schema, data, id)
|
||||
}
|
||||
|
||||
// Watch returns a channel of events for a list or resource.
|
||||
func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, wr types.WatchRequest) (chan types.APIEvent, error) {
|
||||
partitions, err := s.Partitioner.All(apiOp, schema, "watch", wr.ID)
|
||||
if err != nil {
|
||||
@@ -164,6 +175,9 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, wr types
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// getLimit extracts the limit parameter from the request or sets a default of 100000.
|
||||
// Since a default is always set, this implies that clients must always be
|
||||
// aware that the list may be incomplete.
|
||||
func getLimit(req *http.Request) int {
|
||||
limitString := req.URL.Query().Get("limit")
|
||||
limit, err := strconv.Atoi(limitString)
|
||||
@@ -171,7 +185,7 @@ func getLimit(req *http.Request) int {
|
||||
limit = 0
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = 100000
|
||||
limit = defaultLimit
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
Reference in New Issue
Block a user