Documentation ¶
Overview ¶
Package gazette contains server components tied to the service lifetime, and clients.
Code generated by mockery v1.0.0
Index ¶
- Constants
- func MakeHttpTransport() *http.Transport
- type AppendOpHandler
- type CachedURL
- type Client
- func (c *Client) Create(name journal.Name) error
- func (c *Client) Do(request *http.Request) (*http.Response, error)
- func (c *Client) FragmentBeforeTime(name journal.Name, t time.Time) (journal.Fragment, error)
- func (c *Client) FragmentsInRange(name journal.Name, minOff, maxOff int64) ([]journal.Fragment, error)
- func (c *Client) Get(args journal.ReadArgs) (journal.ReadResult, io.ReadCloser)
- func (c *Client) GetDirect(args journal.ReadArgs) (journal.ReadResult, io.ReadCloser)
- func (c *Client) Head(args journal.ReadArgs) (journal.ReadResult, *url.URL)
- func (c *Client) Put(args journal.AppendArgs) journal.AppendResult
- type CreateAPI
- type JournalReplica
- type Persister
- type ReadAPI
- type ReadOpHandler
- type ReplicaFactory
- type ReplicateAPI
- type ReplicateClient
- type ReplicateOpHandler
- type Router
- type Runner
- func (r *Runner) FixedItems() []string
- func (r *Runner) InstanceKey() string
- func (r *Runner) ItemIsReadyForPromotion(item, state string) bool
- func (r *Runner) ItemRoute(item string, route consensus.Route, index int, tree *etcd.Node)
- func (r *Runner) ItemState(item string) string
- func (r *Runner) KeysAPI() etcd.KeysAPI
- func (r *Runner) PathRoot() string
- func (r *Runner) Replicas() int
- func (r *Runner) Run() error
- type WriteAPI
- type WriteService
- func (c *WriteService) ReadFrom(name journal.Name, r io.Reader) (*journal.AsyncAppend, error)
- func (c *WriteService) SetConcurrency(concurrency int)
- func (c *WriteService) Start()
- func (c *WriteService) Stop()
- func (c *WriteService) Write(name journal.Name, buf []byte) (*journal.AsyncAppend, error)
- func (c *WriteService) WriterFor(name journal.Name, sync bool) io.Writer
Examples ¶
Constants ¶
const ( PersisterLocksPrefix = "persister_locks/" PersisterLocksRoot = ServiceRoot + "/" + PersisterLocksPrefix )
const ( CommitDeltaHeader = "X-Commit-Delta" FragmentLastModifiedHeader = "X-Fragment-Last-Modified" FragmentLocationHeader = "X-Fragment-Location" FragmentNameHeader = "X-Fragment-Name" RouteTokenHeader = "X-Route-Token" WriteHeadHeader = "X-Write-Head" ReplicateClientIdlePoolSize = 6 )
const ServiceRoot = "/gazette/cluster"
Variables ¶
This section is empty.
Functions ¶
func MakeHttpTransport ¶
If you want to use your own |http.Transport| with Gazette, start with this one.
Types ¶
type AppendOpHandler ¶
type CachedURL ¶
type CachedURL struct { // Accessible, absolute URL of this endpoint. Base string // contains filtered or unexported fields }
A parsing DNS caching layer on a string URL.
func (*CachedURL) InvalidateResolution ¶
func (ep *CachedURL) InvalidateResolution()
func (*CachedURL) NewHTTPRequest ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient returns a new Client. To export metrics, register the prometheus.Collector instances in metrics.GazetteClientCollectors().
Example ¶
package main import ( "net/http" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" "github.com/LiveRamp/gazette/pkg/gazette" "github.com/LiveRamp/gazette/pkg/journal" "github.com/LiveRamp/gazette/pkg/metrics" ) func main() { // Register collectors and attach handler to expose metrics to Prometheus. prometheus.MustRegister(metrics.GazetteClientCollectors()...) http.Handle("/metrics", promhttp.Handler()) // Get a client. client, err := gazette.NewClient("192.168.0.1:8081") if err != nil { logrus.WithField("err", err).Fatal("Failed to connect to gazette") } // Use client. client.Get(journal.ReadArgs{Journal: "a/journal", Offset: 1234}) }
Output:
func NewClientWithHttpClient ¶
func (*Client) Do ¶
Thin layer upon http.Do(), which manages re-writes from and update to the Client.locationCache. Specifically, request.Path is mapped into a previously- stored Location re-write. If none is available, the request is re-written to reference the default endpoint. Cache entries are updated on successful redirect or response with a Location: header. On error, cache entries are expunged (eg, future requests are performed against the default endpoint).
func (*Client) FragmentBeforeTime ¶
Returns the |Fragment| whose Modified time is closest to but prior to the given |t|. Can return a zeroed Fragment structure, if no fragment matches.
func (*Client) FragmentsInRange ¶
func (c *Client) FragmentsInRange(name journal.Name, minOff, maxOff int64) ([]journal.Fragment, error)
Returns a list of |Fragment|s that service the given offset range in |journal|.
func (*Client) Get ¶
func (c *Client) Get(args journal.ReadArgs) (journal.ReadResult, io.ReadCloser)
func (*Client) GetDirect ¶
func (c *Client) GetDirect(args journal.ReadArgs) (journal.ReadResult, io.ReadCloser)
func (*Client) Put ¶
func (c *Client) Put(args journal.AppendArgs) journal.AppendResult
Performs a Gazette PUT operation, which appends content to the named journal. Put panics if |args.Content| does not implement io.ReadSeeker.
type CreateAPI ¶
type CreateAPI struct {
// contains filtered or unexported fields
}
API for creation of a new Journal. In particular, CreateAPI creates an Etcd item directory for the Journal under Gazette's consensus.Allocator root and responds to the client when the Journal is ready for transactions.
func NewCreateAPI ¶
func NewCreateAPI(cfs cloudstore.FileSystem, keysAPI etcd.KeysAPI, requiredReplicas int) *CreateAPI
type JournalReplica ¶
type JournalReplica interface { AppendOpHandler ReadOpHandler ReplicateOpHandler Shutdown() StartBrokeringWithPeers(journal.RouteToken, []journal.Replicator) StartReplicating(journal.RouteToken) }
See journal.Replica.
type Persister ¶
type Persister struct {
// contains filtered or unexported fields
}
func NewPersister ¶
func NewPersister(directory string, cfs cloudstore.FileSystem, keysAPI etcd.KeysAPI, routeKey string) *Persister
func (*Persister) IsShuttingDown ¶
func (*Persister) StartPersisting ¶
type ReadAPI ¶
type ReadAPI struct {
// contains filtered or unexported fields
}
func NewReadAPI ¶
func NewReadAPI(handler ReadOpHandler, cfs cloudstore.FileSystem) *ReadAPI
type ReadOpHandler ¶
type ReplicaFactory ¶
type ReplicaFactory func(journal.Name) JournalReplica
Builds a JournalReplica instance with the given journal.Name.
type ReplicateAPI ¶
type ReplicateAPI struct {
// contains filtered or unexported fields
}
func NewReplicateAPI ¶
func NewReplicateAPI(handler ReplicateOpHandler) *ReplicateAPI
func (*ReplicateAPI) Register ¶
func (h *ReplicateAPI) Register(router *mux.Router)
func (*ReplicateAPI) Replicate ¶
func (h *ReplicateAPI) Replicate(w http.ResponseWriter, r *http.Request)
type ReplicateClient ¶
type ReplicateClient struct {
// contains filtered or unexported fields
}
func NewReplicateClient ¶
func NewReplicateClient(ep *CachedURL) ReplicateClient
func (ReplicateClient) Replicate ¶
func (c ReplicateClient) Replicate(op journal.ReplicateOp)
type ReplicateOpHandler ¶
type ReplicateOpHandler interface {
Replicate(journal.ReplicateOp)
}
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Routes and dispatches Read, Append, and Replicate operations to a collection of responsible JournalReplicas.
func NewRouter ¶
func NewRouter(factory ReplicaFactory) *Router
func (*Router) BrokeredJournals ¶
Returns the set of Journals which are brokered by this Router.
func (*Router) HasServedAppend ¶
Returns whether |name| is both locally brokered and has successfully served an Append operation under the current route topology. This is an important indicator for consistency, as a successful Append ensures that all replicas reached agreement on the route token & write head during the transaction.
func (*Router) Replicate ¶
func (r *Router) Replicate(op journal.ReplicateOp)
func (*Router) ReplicatedJournals ¶
Returns the set of Journals which are replicated by this Router.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func (*Runner) FixedItems ¶
consumer.Allocator implementation.
func (*Runner) InstanceKey ¶
func (*Runner) ItemIsReadyForPromotion ¶
type WriteAPI ¶
type WriteAPI struct {
// contains filtered or unexported fields
}
func NewWriteAPI ¶
func NewWriteAPI(handler AppendOpHandler) *WriteAPI
type WriteService ¶
type WriteService struct {
// contains filtered or unexported fields
}
WriteService wraps a Client to provide asynchronous batching and automatic retries of writes to Gazette journals. Writes to each journal are spooled to local disk (and never memory), so back-pressure from slow or down brokers does not affect busy writers (at least, until disk runs out). Writes are retried indefinitely, until aknowledged by a broker.
func NewWriteService ¶
func NewWriteService(client *Client) *WriteService
func (*WriteService) ReadFrom ¶
func (c *WriteService) ReadFrom(name journal.Name, r io.Reader) (*journal.AsyncAppend, error)
Appends |r|'s content to |journal|, by reading until io.EOF. Either all of |r| is written, or none of it is. Returns an AsyncAppend which is resolved when the write has been fully committed.
func (*WriteService) SetConcurrency ¶
func (c *WriteService) SetConcurrency(concurrency int)
func (*WriteService) Start ¶
func (c *WriteService) Start()
Begins the write service loop. Be sure to invoke Stop() prior to process exit, to ensure that all pending writes have been flushed.
func (*WriteService) Stop ¶
func (c *WriteService) Stop()
Stops the write service loop. Returns only after all writes have completed.
func (*WriteService) Write ¶
func (c *WriteService) Write(name journal.Name, buf []byte) (*journal.AsyncAppend, error)
Appends |buffer| to |journal|. Either all of |buffer| is written, or none of it is. Returns a AsyncAppendwhich is resolved when the write has been fully committed.