Documentation ¶
Overview ¶
Package memorytopo contains an implementation of the topo.Factory / topo.Conn interfaces based on an in-memory tree of data. It is constructed with an immutable set of cells.
Index ¶
- Constants
- func NewServer(cells ...string) *topo.Server
- func VersionFromInt(version int64) topo.Version
- type Conn
- func (c *Conn) Close()
- func (c *Conn) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error)
- func (c *Conn) Delete(ctx context.Context, filePath string, version topo.Version) error
- func (c *Conn) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error)
- func (c *Conn) List(ctx context.Context, filePathPrefix string) ([]topo.KVInfo, error)
- func (c *Conn) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error)
- func (c *Conn) Lock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
- func (c *Conn) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
- func (c *Conn) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error)
- func (c *Conn) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, topo.CancelFunc)
- type Factory
- type NodeVersion
Constants ¶
const ( // UnreachableServerAddr is a sentinel value for CellInfo.ServerAddr. // If a memorytopo topo.Conn is created with this serverAddr then every // method on that Conn which takes a context will simply block until the // context finishes, and return ctx.Err(), in order to simulate an // unreachable local cell for testing. UnreachableServerAddr = "unreachable" )
Variables ¶
This section is empty.
Functions ¶
func VersionFromInt ¶
VersionFromInt is used by old-style functions to create a proper Version: if version is -1, returns nil. Otherwise returns the NodeVersion object.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn implements the topo.Conn interface. It remembers the cell and serverAddr, and points at the Factory that has all the data.
func (*Conn) Close ¶
func (c *Conn) Close()
Close is part of the topo.Conn interface. It nils out factory, so any subsequent call will panic.
func (*Conn) NewLeaderParticipation ¶ added in v0.13.0
func (c *Conn) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
NewLeaderParticipation is part of the topo.Server interface
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory is a memory-based implementation of topo.Factory. It takes a file-system like approach, with directories at each level being an actual directory node. This is meant to be closer to file-system like servers, like ZooKeeper or Chubby. etcd or Consul implementations would be closer to a node-based implementation.
It contains a single tree of nodes. Each cell topo.Conn will use a sub-directory in that tree.
func NewServerAndFactory ¶
NewServerAndFactory returns a new MemoryTopo and the backing factory for all the cells. It will create one cell for each parameter passed in. It will log.Exit out in case of a problem.
func (*Factory) HasGlobalReadOnlyCell ¶
HasGlobalReadOnlyCell is part of the topo.Factory interface.
func (*Factory) Lock ¶
func (f *Factory) Lock()
Lock blocks all requests to the topo and is exposed to allow tests to simulate an unresponsive topo server
type NodeVersion ¶
type NodeVersion uint64
NodeVersion is the local topo.Version implementation
func (NodeVersion) String ¶
func (v NodeVersion) String() string