Documentation
¶
Overview ¶
Package objectstore is the read port of the flag source that polls object stores: the small ObjectStore interface through which the relay reads flag set files and flag files, and the errors and types of its answers.
A store reads one object (a conditional read by ETag, a size limit, the errors of a missing, refused, throttled or oversized object), and a store that can list its keys also implements Lister, which returns the keys below a prefix a page at a time with a marker for each, so that a caller can tell that an object changed without reading it. The code that calls the port is the polling flag source (cmd/relayproxy/flagsource/polling), which is why the port lives under flagsource: the stores are adapters of it.
The port holds no store and imports no SDK. One package per store implements it: s3store (on the S3 client of a named connection), filestore (a local directory: a volume mount, a ConfigMap), httpstore, gcsstore and azurestore. The HTTP, Google Cloud Storage and Azure Blob stores pass the same conformance suite as the others; no connection kind wires them to a flag source yet. What several stores share (key rules, bounded body reads, the rules of the HTTP and cloud settings) is in storekit; storetest is the conformance suite every store passes; ratelimit is a decorator that limits the requests of a store.
Index ¶
Constants ¶
const ( // ReasonError is a failure that may pass by itself: network, timeout, throttling, 5xx. ReasonError = "error" // ReasonTimeout is a request that ran into the request timeout of the reader. ReasonTimeout = "timeout" // ReasonDenied is a failure that a retry does not fix without a change of configuration: 403 and other // client errors. ReasonDenied = "denied" )
Failure reasons set by the stores of this package, and used by the reader in its status. The set is closed.
const MaxPage = 1000
MaxPage is the largest page of a listing.
Variables ¶
var ( // ErrNotModified is returned by a conditional Get whose ETag is still current. It is not a failure. ErrNotModified = errors.New("objectstore: not modified") // ErrNotFound is returned when the object does not exist. ErrNotFound = errors.New("objectstore: object not found") // ErrTooLarge is returned when the object is larger than the limit of the call. The store never buffers // more than limit bytes. ErrTooLarge = errors.New("objectstore: object too large") )
Sentinel results of an ObjectStore call. Every other failure is a *FetchError.
var ErrHeadUnsupported = errors.New("objectstore: the store cannot describe one key")
ErrHeadUnsupported is the answer of Head for a store that has none.
var ErrInvalidConfig = errors.New("objectstore: invalid config")
ErrInvalidConfig is matched by the error of a store that is built from a configuration it cannot use.
Functions ¶
func PageSize ¶
PageSize is the number of entries of the page that a limit of a ListRequest asks for: MaxPage for a limit that is zero, negative or above it.
func ReleaseStores ¶
func ReleaseStores(stores []ObjectStore, onError func(error))
ReleaseStores releases the stores of an owner that stops using them: first the idle connections of every store, in the order given, then the client of every store (Close), in the same order. Each method runs once per store. A store that fails to close does not stop the others: onError receives each error, in order (nil drops them).
Types ¶
type FetchError ¶
type FetchError struct {
// Err is the cause. It may name the bucket or the key; the reader never logs or reports it, only Reason.
Err error
// Reason is the closed code the reader reports: [ReasonError] or [ReasonDenied].
Reason string
// Retryable tells whether trying again can succeed without a change of configuration.
Retryable bool
// Throttled marks a throttling answer (429, SlowDown): the reader backs off one step further than for
// another error.
Throttled bool
// RetryAfter is the wait the backend asked for (an HTTP Retry-After), already bounded by the store; zero for
// none. The reader waits at least that long (at most BackoffMax) before its next try.
RetryAfter time.Duration
}
FetchError is a failed Get that is neither ErrNotModified, ErrNotFound nor ErrTooLarge.
type GetRequest ¶
type GetRequest struct {
// Key is the key of the object.
Key string
// ETag makes the request conditional when not empty.
ETag string
// VersionID selects an object version when not empty.
VersionID string
// Limit is the largest body the store returns. It never returns, nor retains, more than Limit bytes of the
// body, and it may read one byte past Limit to tell an object of exactly Limit bytes from a larger one. A
// negative limit is a limit of zero: only an empty object is returned. Callers that know the size pass it,
// so a store can allocate the buffer once.
Limit int64
}
GetRequest is one Get. It is a struct so that it can grow without breaking the implementations.
type ListEntry ¶
type ListEntry struct {
// Modified is the modification time the store reports (an S3 LastModified, the mtime of a file); zero when the
// store does not say. It is the same for every reader of the store.
Modified time.Time
// Key is the absolute key, the one a Get takes.
Key string
// Marker changes when the object changes (an S3 ETag, or the size and modification time of a file). Equal
// markers of two listings mean an unchanged object. It is not the ETag of [Object] for every store: it is only
// compared with the marker of an earlier listing of the same store.
Marker string
// Size is the size in bytes the store reports.
Size int64
}
ListEntry is one key of a listing.
type ListPage ¶
type ListPage struct {
// Next is the token of the next page; empty when this was the last page.
Next string
// Entries are the keys of the page.
Entries []ListEntry
}
ListPage is the answer of one List: the entries of the page, sorted by key, and where the next page starts.
type ListRequest ¶
type ListRequest struct {
// Prefix is the key prefix whose keys are listed, below the root of the connection, with every key below it
// (a slash is only a character). Empty lists the whole connection.
Prefix string
// Delimiter, when "/", keeps the listing to the keys of the folder that Prefix names: a key with a slash after the
// prefix is below a sub-folder and is left out, and the sub-folders themselves are not listed. It is how a folder
// of flag files is listed without paging through the keys of its sub-folders. Empty lists every key below the prefix
// (a source prefix, found recursively). No other value is defined.
Delimiter string
// Token is where the page starts: empty for the first page, otherwise the Next of the page before it. A caller
// that lost a page (a request limit refused it) asks again with the token of the last page it got.
Token string
// Limit is the largest number of entries of the page. Zero or negative means the largest page the store has: 1000.
Limit int
}
ListRequest is one List: one page of a listing. It is a struct so that it can grow without breaking the implementations.
type Lister ¶
type Lister interface {
// List lists one page of the keys under req.Prefix, sorted by key. The cost of a page on S3 is one ListObjectsV2
// request. A missing prefix is an empty listing. Failures are a [*FetchError], like for Get.
List(ctx context.Context, req ListRequest) (ListPage, error)
// CanHead tells whether Head works on this store. A store that has no cheap request for the description of one key
// answers false (embed [NoHead]); the caller then asks with a listing of the one key.
CanHead() bool
// Head describes one key as a listing would, with no body: the entry has the key, the same marker, size and
// modification time that List gives for it. The cost on S3 is one HeadObject request (the price of a GET, about a
// twelfth of a list request); for a local directory a stat. A missing key is [ErrNotFound]; any other failure is
// a [*FetchError]. A store that cannot answer returns [ErrHeadUnsupported] (see CanHead).
Head(ctx context.Context, key string) (ListEntry, error)
}
Lister is the optional second capability of a store: the listing of the keys under a prefix. A store that cannot list (http, Google, Azure) has no Lister: the caller is told by the connection layer, never by a type assertion on the ObjectStore. The conformance of a Lister is the one of its tests: the pages together are all the keys under the prefix, sorted by key, each with the marker of the moment of the listing, and a page never has more than Limit entries.
type NoHead ¶
type NoHead struct{}
NoHead is the Head of a lister that has no cheap request for one key: embed it to give Lister its CanHead and Head, and define both when the store has them (a method of the store wins over the embedded one).
A wrapper of a lister never embeds it: it forwards both methods to the lister it wraps.
type NoLifecycle ¶
type NoLifecycle struct{}
NoLifecycle is the lifecycle of a store that holds nothing to release: embed it to give ObjectStore its Close and CloseIdleConnections, and define the one that the store has (a method of the store wins over the embedded one).
A wrapper of a store never embeds it: it forwards both methods to the store it wraps, so that a capability that is added to the port breaks the build of a wrapper that forgets it.
func (NoLifecycle) Close ¶
func (NoLifecycle) Close() error
Close does nothing: there is no client to release.
func (NoLifecycle) CloseIdleConnections ¶
func (NoLifecycle) CloseIdleConnections()
CloseIdleConnections does nothing: there is no pool of idle connections.
type Object ¶
type Object struct {
// Modified is the modification time the store reports for the object (an S3 or Azure LastModified, an HTTP
// Last-Modified, the mtime of a file); zero when the store does not say. It is the same for every reader of the
// store.
Modified time.Time
// ETag is the validator of the content as the store reports it; the reader sends it back on the next
// conditional Get of the same key. It is not an integrity check.
ETag string
// Bytes is the content, at most the limit of the call. The reader never changes it.
Bytes []byte
}
Object is the content of one Get.
type ObjectStore ¶
type ObjectStore interface {
// Get fetches req.Key and returns a body of at most req.Limit bytes (it may read one byte past the limit to
// detect an object that is larger, see [GetRequest.Limit]). With a non-empty req.ETag the request is
// conditional and an unchanged object is answered with [ErrNotModified]. A missing object (or version) is
// [ErrNotFound], a larger one [ErrTooLarge]. Any other failure is a [*FetchError]. Get honours ctx.
Get(ctx context.Context, req GetRequest) (Object, error)
// Close releases the client the store holds. A store that holds none returns nil (embed [NoLifecycle]). The
// owner of the store calls it once, when it stops using the store; a Get after it may fail.
Close() error
// CloseIdleConnections closes the idle connections of the pool the store keeps, and does nothing for a store
// without one (embed [NoLifecycle]). The owner calls it when it releases the store, before Close.
CloseIdleConnections()
}
ObjectStore is the seam between the reader and a backend. The conformance suite in the storetest package executes this contract; a store passes when storetest.Run passes on it.
The contract in short:
- The ETag of a result describes exactly the bytes returned with it, differs when the bytes differ, and a conditional Get that holds the current ETag is answered with ErrNotModified (and a zero Object). Equal bytes need not give an equal ETag: a row version, a commit SHA or a generation number is a valid ETag.
- A failed Get returns a zero Object. A Get that ended with its context returns an error that wraps the error of the context: context.Canceled for a cancellation, context.DeadlineExceeded for a deadline. The store ends a read when Done closes: Done is authoritative. A store may also use Deadline() to set a deadline on the I/O it starts, but that is an optimisation: a store that copies Deadline() into a one-shot deadline must still watch Done.
- A Get that starts after a write to the object has returned sees that write (read-after-write consistency).
- The size guarantee is the one of GetRequest.Limit: never a body of more than Limit bytes, though a store may read one byte past it. When Limit is below the size of the object, the answer is ErrTooLarge, or ErrNotModified if the request is conditional with the current ETag and the store answers before it looks at the size. Never a body.
- A negative Limit is a Limit of zero.
- The bytes returned are the caller's: a later write to the object never changes bytes already returned.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package azurestore is the objectstore.ObjectStore on Azure Blob Storage, over the Get Blob request.
|
Package azurestore is the objectstore.ObjectStore on Azure Blob Storage, over the Get Blob request. |
|
Package filestore is the objectstore.ObjectStore and objectstore.Lister on a directory of the local file system (a volume mount, a ConfigMap).
|
Package filestore is the objectstore.ObjectStore and objectstore.Lister on a directory of the local file system (a volume mount, a ConfigMap). |
|
Package gcsstore is the objectstore.ObjectStore on Google Cloud Storage, over the JSON API and the media download of one object.
|
Package gcsstore is the objectstore.ObjectStore on Google Cloud Storage, over the JSON API and the media download of one object. |
|
Package httpstore is the objectstore.ObjectStore on a plain HTTP server (static hosting, a CDN).
|
Package httpstore is the objectstore.ObjectStore on a plain HTTP server (static hosting, a CDN). |
|
Package ratelimit caps the requests the relay makes through one connection.
|
Package ratelimit caps the requests the relay makes through one connection. |
|
Package s3store is the objectstore.ObjectStore and objectstore.Lister on the S3 client of a named connection of the connection factory: GetObject for reads, ListObjectsV2 for listings and HeadObject for the description of one key.
|
Package s3store is the objectstore.ObjectStore and objectstore.Lister on the S3 client of a named connection of the connection factory: GetObject for reads, ListObjectsV2 for listings and HeadObject for the description of one key. |
|
Package storekit holds what several object stores share and that names no cloud SDK: the rules of a key, the bounded read of a body, the whole-second time rule of S3, and the rules and the transport of the HTTP and the cloud stores (settings limits, redirect policy, Retry-After, the mapping of a status to a result).
|
Package storekit holds what several object stores share and that names no cloud SDK: the rules of a key, the bounded read of a body, the whole-second time rule of S3, and the rules and the transport of the HTTP and the cloud stores (settings limits, redirect policy, Retry-After, the mapping of a status to a result). |
|
internal/bodyread
Package bodyread reads the body of an object store's answer into one buffer, within the limit of the call.
|
Package bodyread reads the body of an object store's answer into one buffer, within the limit of the call. |
|
Package storetest is the conformance suite of objectstore.ObjectStore: the contract of a store as executable cases.
|
Package storetest is the conformance suite of objectstore.ObjectStore: the contract of a store as executable cases. |