memorytopo

package
v0.20.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 15 Imported by: 5

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

View Source
const (
	ListDir = Operation(iota)
	Create
	Update
	Get
	List
	Delete
	Lock
	TryLock
	Watch
	WatchRecursive
	NewLeaderParticipation
	Close
)

The following is the list of topo.Conn operations

View Source
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

View Source
var ErrConnectionClosed = errors.New("connection closed")

Functions

func NewServer

func NewServer(ctx context.Context, cells ...string) *topo.Server

NewServer returns the new server

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.

func (*Conn) Create

func (c *Conn) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error)

Create is part of topo.Conn interface.

func (*Conn) Delete

func (c *Conn) Delete(ctx context.Context, filePath string, version topo.Version) error

Delete is part of topo.Conn interface.

func (*Conn) Get

func (c *Conn) Get(ctx context.Context, filePath string) ([]byte, topo.Version, error)

Get is part of topo.Conn interface.

func (*Conn) GetVersion added in v0.20.0

func (c *Conn) GetVersion(ctx context.Context, filePath string, version int64) ([]byte, error)

GetVersion is part of topo.Conn interface.

func (*Conn) List added in v0.13.0

func (c *Conn) List(ctx context.Context, filePathPrefix string) ([]topo.KVInfo, error)

List is part of the topo.Conn interface.

func (*Conn) ListDir

func (c *Conn) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error)

ListDir is part of the topo.Conn interface.

func (*Conn) Lock

func (c *Conn) Lock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)

Lock is part of the topo.Conn interface.

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

func (c *Conn) TryLock(ctx context.Context, dirPath, contents string) (topo.LockDescriptor, error)

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

func NewServerAndFactory(ctx context.Context, cells ...string) (*topo.Server, *Factory)

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 (f *Factory) AddOperationError(op Operation, pathPattern string, err error)

func (*Factory) Create

func (f *Factory) Create(cell, serverAddr, root string) (topo.Conn, error)

Create is part of the topo.Factory interface.

func (*Factory) GetCallStats added in v0.19.0

func (f *Factory) GetCallStats() *stats.CountersWithMultiLabels

func (*Factory) HasGlobalReadOnlyCell

func (f *Factory) HasGlobalReadOnlyCell(serverAddr, root string) bool

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

func (*Factory) SetError

func (f *Factory) SetError(err error)

SetError forces the given error to be returned from all calls and propagates the error to all active watches.

func (*Factory) Unlock

func (f *Factory) Unlock()

Unlock unblocks 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

type Operation added in v0.19.4

type Operation int

Operation is one of the operations defined by topo.Conn

Jump to

Keyboard shortcuts

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