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
- Variables
- func NewServer(ctx context.Context, cells ...string) *topo.Server
- 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) GetVersion(ctx context.Context, filePath string, version int64) ([]byte, 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) LockName(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)
- func (c *Conn) LockWithTTL(ctx context.Context, dirPath, contents string, _ time.Duration) (topo.LockDescriptor, error)
- func (c *Conn) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
- func (c *Conn) TryLock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, 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, error)
- func (c *Conn) WatchRecursive(ctx context.Context, dirpath string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error)
- type Factory
- func (f *Factory) AddOperationError(op Operation, pathPattern string, err error)
- func (f *Factory) Create(cell, serverAddr, root string) (topo.Conn, error)
- func (f *Factory) GetCallStats() *stats.CountersWithMultiLabels
- func (f *Factory) HasGlobalReadOnlyCell(serverAddr, root string) bool
- func (f *Factory) Lock()
- func (f *Factory) SetError(err error)
- func (f *Factory) Unlock()
- type NodeVersion
- type Operation
Constants ¶
const ( ListDir = Operation(iota) Create Update Get List Delete Lock TryLock Watch WatchRecursive NewLeaderParticipation Close )
The following is the list of topo.Conn operations
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 ¶
var ErrConnectionClosed = errors.New("connection closed")
Functions ¶
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) GetVersion ¶ added in v0.20.0
GetVersion is part of topo.Conn interface.
func (*Conn) LockWithTTL ¶ added in v0.21.0
func (c *Conn) LockWithTTL(ctx context.Context, dirPath, contents string, _ time.Duration) (topo.LockDescriptor, error)
LockWithTTL is part of the topo.Conn interface. It behaves the same as Lock as TTLs are not supported in memorytopo.
func (*Conn) NewLeaderParticipation ¶ added in v0.13.0
func (c *Conn) NewLeaderParticipation(name, id string) (topo.LeaderParticipation, error)
NewLeaderParticipation is part of the topo.Conn interface.
func (*Conn) TryLock ¶ added in v0.16.0
TryLock is part of the topo.Conn interface. Its implementation is same as Lock
func (*Conn) Update ¶
func (c *Conn) Update(ctx context.Context, filePath string, contents []byte, version topo.Version) (topo.Version, error)
Update is part of topo.Conn interface.
func (*Conn) Watch ¶
func (c *Conn) Watch(ctx context.Context, filePath string) (*topo.WatchData, <-chan *topo.WatchData, error)
Watch is part of the topo.Conn interface.
func (*Conn) WatchRecursive ¶ added in v0.15.0
func (c *Conn) WatchRecursive(ctx context.Context, dirpath string) ([]*topo.WatchDataRecursive, <-chan *topo.WatchDataRecursive, error)
WatchRecursive is part of the topo.Conn 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) AddOperationError ¶ added in v0.19.4
func (*Factory) GetCallStats ¶ added in v0.19.0
func (f *Factory) GetCallStats() *stats.CountersWithMultiLabels
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