http

package
v0.5.11 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultPollTXIDInterval = 1 * time.Millisecond
	DefaultPollTXIDTimeout  = 5 * time.Second

	DefaultPrimaryRedirectTimeout = 5 * time.Second

	DefaultMaxLag = 10 * time.Second

	DefaultCookieExpiry = 5 * time.Minute

	DefaultReadTimeout       = 0
	DefaultReadHeaderTimeout = 10 * time.Second
	DefaultWriteTimeout      = 0
	DefaultIdleTimeout       = 30 * time.Second
)
View Source
const (
	HeaderNodeID    = "Litefs-Id"
	HeaderClusterID = "Litefs-Cluster-Id"
)

HTTP headers

View Source
const (
	DefaultAddr = ":20202"
)

Default settings

View Source
const (
	HeartbeatInterval = time.Second
)
View Source
const TXIDCookieName = "__txid"

TXIDCookieName is the name of the cookie that tracks transaction ID.

Variables

View Source
var ErrProxyServerClosed = fmt.Errorf("canceled, proxy server closed")
View Source
var ErrServerClosed = fmt.Errorf("canceled, http server closed")

Functions

func CompileMatch added in v0.4.0

func CompileMatch(s string) (*regexp.Regexp, error)

CompileMatch returns a regular expression on a simple asterisk-only wildcard.

func Error

func Error(w http.ResponseWriter, r *http.Request, err error, code int)

func ReadPosMapFrom

func ReadPosMapFrom(r io.Reader) (map[string]ltx.Pos, error)

func WritePosMapTo

func WritePosMapTo(w io.Writer, m map[string]ltx.Pos) error

Types

type Client

type Client struct {
	// Underlying HTTP client
	HTTPClient *http.Client
}

Client represents an client for a streaming LiteFS HTTP server.

func NewClient

func NewClient() *Client

NewClient returns an instance of Client.

func (*Client) AcquireHaltLock added in v0.4.0

func (c *Client) AcquireHaltLock(ctx context.Context, primaryURL string, nodeID uint64, name string, lockID int64) (_ *litefs.HaltLock, retErr error)

func (*Client) Commit added in v0.4.0

func (c *Client) Commit(ctx context.Context, primaryURL string, nodeID uint64, name string, lockID int64, r io.Reader) error

func (*Client) Export added in v0.4.0

func (c *Client) Export(ctx context.Context, primaryURL, name string) (io.ReadCloser, error)

Export downloads a SQLite database from the remote LiteFS server. Returned reader must be closed by caller.

func (*Client) Handoff added in v0.4.0

func (c *Client) Handoff(ctx context.Context, primaryURL string, nodeID uint64) error

Handoff requests that the current primary handoff leadership to a specific node.

func (*Client) Import added in v0.3.0

func (c *Client) Import(ctx context.Context, primaryURL, name string, r io.Reader) error

Import creates or replaces a SQLite database on the remote LiteFS server.

func (*Client) Info added in v0.4.0

func (c *Client) Info(ctx context.Context, baseURL string) (info litefs.NodeInfo, err error)

Info returns basic information about the node.

func (*Client) Promote added in v0.4.0

func (c *Client) Promote(ctx context.Context, baseURL string) error

Promote attempts to promote the current node to be the primary.

func (*Client) ReleaseHaltLock added in v0.4.0

func (c *Client) ReleaseHaltLock(ctx context.Context, primaryURL string, nodeID uint64, name string, lockID int64) error

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, primaryURL string, nodeID uint64, posMap map[string]ltx.Pos, filter []string) (litefs.Stream, error)

Stream returns a snapshot and continuous stream of WAL updates.

type ProxyServer added in v0.4.0

type ProxyServer struct {

	// Hostport of application that is being proxied.
	Target string

	// Name of database to use for TXID consistency tracking.
	DBName string

	// Bind address that the proxy listens on.
	Addr string

	// List of path expressions that will be passed through if matched.
	Passthroughs []*regexp.Regexp

	// List of path expressions that will always be redirected to the primary.
	AlwaysForward []*regexp.Regexp

	// If true, add verbose debug logging.
	Debug bool

	// Interval & timeout for ensuring read consistency.
	PollTXIDInterval time.Duration
	PollTXIDTimeout  time.Duration

	PrimaryRedirectTimeout time.Duration

	// Maximum allowable lag before the health endpoint returns an error code.
	MaxLag time.Duration

	// Time before cookie expires on client.
	CookieExpiry time.Duration

	// HTTP server timeouts
	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration

	HTTPTransport *http.Transport
	// contains filtered or unexported fields
}

ProxyServer represents a thin proxy in front of the user's application that can handle primary redirection and TXID consistency on replicas.

Exported fields must be set before calling Listen().

func NewProxyServer added in v0.4.0

func NewProxyServer(store *litefs.Store) *ProxyServer

NewProxyServer returns a new instance of ProxyServer.

func (*ProxyServer) Close added in v0.4.0

func (s *ProxyServer) Close() (err error)

func (*ProxyServer) Listen added in v0.4.0

func (s *ProxyServer) Listen() (err error)

func (*ProxyServer) Port added in v0.4.0

func (s *ProxyServer) Port() int

Port returns the port the listener is running on.

func (*ProxyServer) Serve added in v0.4.0

func (s *ProxyServer) Serve()

func (*ProxyServer) URL added in v0.4.0

func (s *ProxyServer) URL() string

URL returns the full base URL for the running server.

type RemoteTx added in v0.4.0

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

RemoteTx represents a remote transaction created by Client.Begin().

func (*RemoteTx) Commit added in v0.4.0

func (tx *RemoteTx) Commit(r io.Reader) error

Commit send the LTX data from r to the remote primary for commit.

func (*RemoteTx) ID added in v0.4.0

func (tx *RemoteTx) ID() uint64

ID returns the TXID of the transaction.

func (*RemoteTx) PreApplyChecksum added in v0.4.0

func (tx *RemoteTx) PreApplyChecksum() uint64

PreApplyChecksum returns checksum of the database before the transaction is applied.

func (*RemoteTx) Rollback added in v0.4.0

func (tx *RemoteTx) Rollback() error

Rollback closes the connection without sending a transaction, thus rolling back.

type Server

type Server struct {

	// Time allowed to write a single LTX snapshot in the stream.
	// This is meant to prevent slow snapshot downloads backing up the primary.
	SnapshotTimeout time.Duration
	// contains filtered or unexported fields
}

Server represents an HTTP API server for LiteFS.

func NewServer

func NewServer(store *litefs.Store, addr string) *Server

func (*Server) Close

func (s *Server) Close() (err error)

func (*Server) Listen

func (s *Server) Listen() (err error)

func (*Server) Port

func (s *Server) Port() int

Port returns the port the listener is running on.

func (*Server) Serve

func (s *Server) Serve()

func (*Server) URL

func (s *Server) URL() string

URL returns the full base URL for the running server.

type Stream added in v0.5.0

type Stream struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

Stream is a wrapper around the stream response body.

func (*Stream) ClusterID added in v0.5.0

func (s *Stream) ClusterID() string

ClusterID returns the cluster ID found in the response header.

Jump to

Keyboard shortcuts

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