server

package
v0.0.0-...-fd5963e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuitHandler

func QuitHandler(w http.ResponseWriter, r *http.Request)

QuitHandler will shut down a process. Should be used for testing only.

func RaftAdminHandler

func RaftAdminHandler(r *raft.Raft, s *raft.Storage) http.Handler

RaftAdminHandler is an http.Handler for raft admin tasks. Currently it defines one sub-route:

/last_snapshot - serves the most recent snapshot directly from disk

func ReadOnlyHandler

func ReadOnlyHandler(w http.ResponseWriter, r *http.Request, h ROHandler)

ReadOnlyHandler implements /readonly for the master and curator. GET requests return the current read-only state, POST requests like /readonly?mode=true or false change it. If this node is not the raft leader, it will return a redirect to what it thinks the current leader is.

func SummaryString

func SummaryString(obs prometheus.Observer) string

Types

type AutoConfig

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

AutoConfig controls the membership of a raft cluster based on commands delivered over http and service membership information observed from discovery.

By default, an AutoConfig doesn't do anything. To install http handlers, use HTTPHandlers. To watch for changes from discovery, call WatchDiscovery.

func NewAutoConfig

func NewAutoConfig(spec string, handler RaftReconfig) *AutoConfig

NewAutoConfig creates an AutoConfig. spec should be empty to disable discovery, or a string of the form "cluster/service/user=n", where n is the expected number of members.

func (*AutoConfig) HTTPHandlers

func (ac *AutoConfig) HTTPHandlers() *http.ServeMux

HTTPHandlers returns a handler for reconfig endpoints. The paths handled are:

/add?node=host:port            adds a new node
/remove?node=host:port         removes a node
/initial                       proposes initial configuration from discovery
/initial?members=a,b,c         proposes initial configuration with explicit hosts
/inject_update?members=a,b,c   inject fake discovery update (for testing)

func (*AutoConfig) WatchDiscovery

func (ac *AutoConfig) WatchDiscovery() error

WatchDiscovery starts a goroutine to watch for changes to this service in discovery.

type FineGrainedLock

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

FineGrainedLock implements LockManager.

func (*FineGrainedLock) LockBlob

func (f *FineGrainedLock) LockBlob(blobID core.BlobID)

LockBlob locks a blob.

func (*FineGrainedLock) LockTract

func (f *FineGrainedLock) LockTract(tractID core.TractID)

LockTract locks a tract.

func (*FineGrainedLock) UnlockBlob

func (f *FineGrainedLock) UnlockBlob(blobID core.BlobID)

UnlockBlob unlocks a blob.

func (*FineGrainedLock) UnlockTract

func (f *FineGrainedLock) UnlockTract(tractID core.TractID)

UnlockTract unlocks a tract

type LockManager

type LockManager interface {
	// LockBlock acquires a lock of exclusive access to a given blob.
	LockBlob(core.BlobID)

	// UnlockBlob releases the lock on a given blob.
	UnlockBlob(core.BlobID)

	// LockTract  acquires a lock of exclusive access to a given tract.
	LockTract(core.TractID)

	// UnlockTract releases the lock on a given tract.
	UnlockTract(core.TractID)
}

LockManager provides exclusive access to a given blob or tract. We use leader continuity check to guard against conflict changes from different nodes, but within a same node we still need lock to guard against conflict changes from different goroutines.

func NewFineGrainedLock

func NewFineGrainedLock() LockManager

NewFineGrainedLock creates a new FineGrainedLock.

type OpFailure

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

OpFailure is used by failure service and maps operation names to their registered failure errors.

func NewOpFailure

func NewOpFailure() *OpFailure

NewOpFailure creates a new OpFailure.

func (*OpFailure) Get

func (f *OpFailure) Get(op string) core.Error

Get returns the registered error for the given operation 'op'. NoError is returned if no error is registered for 'op'.

func (*OpFailure) Handler

func (f *OpFailure) Handler(config json.RawMessage) error

Handler is the method to be registered with the failure service that handles the update of failure configurations.

type OpMetric

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

OpMetric is a wrapper around metric objects that helps with tracking counts and latencies for "operations". Operations for the purpose can be either things done by a server on behalf of a client (e.g. handling an RPC), or chunks of work initiated internally.

OpMetric will create three metric sets:

  • A CounterSet with the given name, label "result", and any additional labels. Using Start/End will increment this counter with "result"="all". Additionally you can call Failed or TooBusy on the op object to increment the counters with "result"="failed" and "too_busy".
  • A SketchSet with the given name + "_latency" and any additional labels. Using Start/End will add latencies to this sketch set, only if TooBusy/Failed was not called before End.
  • A IntGaugeSet with the given name + "_pending" and any additional labels. Using Start/End will ensure that this metric reflects the number of pending operations.

Suggested usage:

h.opMetricInstance = NewOpMetric("my_server_ops", "op")

func (h *myHandler) someOpHandler() {
    op := h.opMetricInstance.Start("some_op")
    defer op.End()
    ...
    if queueTooBig {
        op.TooBusy()
    }
    if err != nil {
        op.Failed()
    }
    return err
}

func NewOpMetric

func NewOpMetric(name string, labels ...string) *OpMetric

NewOpMetric returns a new op metric.

func (*OpMetric) Count

func (m *OpMetric) Count(result string, values ...string) uint64

Count returns how many times Start has been called on the OpMetric

func (*OpMetric) Start

func (m *OpMetric) Start(values ...string) *latencyMeasurer

Start marks that a new operation has started and begins measuring the latency.

func (*OpMetric) String

func (m *OpMetric) String(values ...string) string

String returns a nice string with latency information.

func (*OpMetric) Strings

func (m *OpMetric) Strings(keys ...string) map[string]string

Strings returns a map with results from String. Note that it only calls String with a single argument at a time, so it can only be used when the OpMetric has one label. But that is the common case.

type ROHandler

type ROHandler interface {
	ID() string
	LeaderID() string
	ReadOnlyMode() (bool, core.Error)
	SetReadOnlyMode(bool) core.Error
}

ROHandler is a subset of the master or curator state handler that's needed for controlling read-only mode.

type RaftReconfig

type RaftReconfig interface {
	// ID returns the Raft ID of the node.
	ID() string
	// LeaderID returns the Raft ID of the leader.
	LeaderID() string
	// AddNode addes a node to the cluster.
	AddNode(string) error
	// RemoveNode removes a node from the cluster.
	RemoveNode(string) error
	// GetMembership gets the current membership of the raft cluster.
	GetMembership() []string
	// ProposeInitialMembership proposes an initial configuration.
	ProposeInitialMembership([]string) error
}

RaftReconfig is the interface used by AutoConfig to reconfigure a cluster.

type Semaphore

type Semaphore chan struct{}

Semaphore implementation using Go channel.

func NewSemaphore

func NewSemaphore(max int) Semaphore

NewSemaphore creates a new semaphore with 'max' number of permits.

func (Semaphore) Acquire

func (s Semaphore) Acquire()

Acquire tries to acquire a permit from the semaphore, blocking until one becomes available.

func (Semaphore) Release

func (s Semaphore) Release()

Release releases a permit to the semaphore.

func (Semaphore) TryAcquire

func (s Semaphore) TryAcquire() bool

TryAcquire tries to acquire a permit from the semaphore. It succeeds if and only if one is available at the invocation time.

Jump to

Keyboard shortcuts

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