rwregister

package module
v0.0.0-...-1532427 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 20 Imported by: 0

README

README

This README would briefly explain the usage of the Gorums rwregister.

To regenerate the .pb.go file

go generate

To run the tests

go test -v

To run server and client only

  1. startserver.sh in server folder can start 3 servers.

  2. startclient.sh in client folder can run a client.

  3. Need to start servers first

Run whole system and tests

  • quorumcalltests.sh in registerQspecs can run tests for the system.
  • quorumQCCoverage.sh in registerQspecs can run tests for the system and get coverages.
  • stop3servers.sh can stop servers.
  • results will be stored in results folder.

Run quorum functions tests

  • quorumQFtests.sh can run the tests for quorum functions
  • quorumQFCoverage.sh can run the tests and get coverages of quorum functions.

Other information

xmlReader.go in reader is the Go code to read test cases from xml files.

Quorum functions (ReadQF and WriteQF) are implemented in qspecs.go in the registerQspecs.

quorumcalltests.sh and quorumQFtests.sh can start tests. coverage.sh can run an example of the test and get the result of coverage.

Documentation

Overview

Package rwregister is a generated protocol buffer package.

It is generated from these files:

register.proto

It has these top-level messages:

Content
Value
WriteResponse
ReadRequest

Index

Constants

View Source
const LevelNotSet = -1

LevelNotSet is the zero value level used to indicate that no level (and thereby no reply) has been set for a correctable quorum call.

Variables

View Source
var (
	ErrInvalidLengthRegister = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRegister   = fmt.Errorf("proto: integer overflow")
)
View Source
var Error = func(n1, n2 *Node) bool {
	if n1.lastErr != nil && n2.lastErr == nil {
		return false
	}
	return true
}

Error sorts nodes by their LastErr() status in increasing order. A node with LastErr() != nil is larger than a node with LastErr() == nil.

View Source
var ID = func(n1, n2 *Node) bool {
	return n1.id < n2.id
}

ID sorts nodes by their identifier in increasing order.

View Source
var Latency = func(n1, n2 *Node) bool {
	if n1.latency < 0 {
		return false
	}
	return n1.latency < n2.latency

}

Latency sorts nodes by latency in increasing order. Latencies less then zero (sentinel value) are considered greater than any positive latency.

Functions

func Equal

func Equal(a, b *Configuration) bool

Equal returns a boolean reporting whether a and b represents the same configuration.

func ManagerCreationError

func ManagerCreationError(err error) error

ManagerCreationError returns an error reporting that a Manager could not be created due to err.

func RegisterRegisterServer

func RegisterRegisterServer(s *grpc.Server, srv RegisterServer)

Types

type ConfigNotFoundError

type ConfigNotFoundError uint32

A ConfigNotFoundError reports that a specified configuration could not be found.

func (ConfigNotFoundError) Error

func (e ConfigNotFoundError) Error() string

type Configuration

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

A Configuration represents a static set of nodes on which quorum remote procedure calls may be invoked.

func (*Configuration) ID

func (c *Configuration) ID() uint32

ID reports the identifier for the configuration.

func (*Configuration) NodeIDs

func (c *Configuration) NodeIDs() []uint32

NodeIDs returns a slice containing the local ids of all the nodes in the configuration. IDs are returned in the same order as they were provided in the creation of the Configuration.

func (*Configuration) Nodes

func (c *Configuration) Nodes() []*Node

Nodes returns a slice of each available node. IDs are returned in the same order as they were provided in the creation of the Configuration.

func (*Configuration) Read

func (c *Configuration) Read(ctx context.Context, arg *ReadRequest) (*Value, error)

Read is invoked as a quorum call on all nodes in configuration c, using the same argument arg, and returns the result.

func (*Configuration) Size

func (c *Configuration) Size() int

Size returns the number of nodes in the configuration.

func (*Configuration) String

func (c *Configuration) String() string

func (*Configuration) Write

func (c *Configuration) Write(ctx context.Context, arg *Value) (*WriteResponse, error)

Write is invoked as a quorum call on all nodes in configuration c, using the same argument arg, and returns the result.

type Content

type Content struct {
	Value     string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
	Timestamp int64  `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
}

func (*Content) Descriptor

func (*Content) Descriptor() ([]byte, []int)

func (*Content) GetTimestamp

func (m *Content) GetTimestamp() int64

func (*Content) GetValue

func (m *Content) GetValue() string

func (*Content) Marshal

func (m *Content) Marshal() (dAtA []byte, err error)

func (*Content) MarshalTo

func (m *Content) MarshalTo(dAtA []byte) (int, error)

func (*Content) ProtoMessage

func (*Content) ProtoMessage()

func (*Content) Reset

func (m *Content) Reset()

func (*Content) Size

func (m *Content) Size() (n int)

func (*Content) String

func (this *Content) String() string

func (*Content) Unmarshal

func (m *Content) Unmarshal(dAtA []byte) error

type IllegalConfigError

type IllegalConfigError string

An IllegalConfigError reports that a specified configuration could not be created.

func (IllegalConfigError) Error

func (e IllegalConfigError) Error() string

type Manager

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

Manager manages a pool of node configurations on which quorum remote procedure calls can be made.

func NewManager

func NewManager(nodeAddrs []string, opts ...ManagerOption) (*Manager, error)

NewManager attempts to connect to the given set of node addresses and if successful returns a new Manager containing connections to those nodes.

func (*Manager) AddNode

func (m *Manager) AddNode(addr string) error

AddNode attempts to dial to the provide node address. The node is added to the Manager's pool of nodes if a connection was established.

func (*Manager) Close

func (m *Manager) Close()

Close closes all node connections and any client streams.

func (*Manager) Configuration

func (m *Manager) Configuration(id uint32) (config *Configuration, found bool)

Configuration returns the configuration with the given global identifier if present.

func (*Manager) ConfigurationIDs

func (m *Manager) ConfigurationIDs() []uint32

ConfigurationIDs returns the identifier of each available configuration.

func (*Manager) Configurations

func (m *Manager) Configurations() []*Configuration

Configurations returns a slice of each available configuration.

func (*Manager) NewConfiguration

func (m *Manager) NewConfiguration(ids []uint32, qspec QuorumSpec) (*Configuration, error)

NewConfiguration returns a new configuration given quorum specification and a timeout.

func (*Manager) Node

func (m *Manager) Node(id uint32) (node *Node, found bool)

Node returns the node with the given identifier if present.

func (*Manager) NodeIDs

func (m *Manager) NodeIDs() []uint32

NodeIDs returns the identifier of each available node. IDs are returned in the same order as they were provided in the creation of the Manager.

func (*Manager) Nodes

func (m *Manager) Nodes() []*Node

Nodes returns a slice of each available node. IDs are returned in the same order as they were provided in the creation of the Manager.

func (*Manager) Size

func (m *Manager) Size() (nodes, configs int)

Size returns the number of nodes and configurations in the Manager.

type ManagerOption

type ManagerOption func(*managerOptions)

ManagerOption provides a way to set different options on a new Manager.

func WithGrpcDialOptions

func WithGrpcDialOptions(opts ...grpc.DialOption) ManagerOption

WithGrpcDialOptions returns a ManagerOption which sets any gRPC dial options the Manager should use when initially connecting to each node in its pool.

func WithLogger

func WithLogger(logger *log.Logger) ManagerOption

WithLogger returns a ManagerOption which sets an optional error logger for the Manager.

func WithNoConnect

func WithNoConnect() ManagerOption

WithNoConnect returns a ManagerOption which instructs the Manager not to connect to any of its nodes. Mainly used for testing purposes.

func WithTracing

func WithTracing() ManagerOption

WithTracing controls whether to trace qourum calls for this Manager instance using the golang.org/x/net/trace package. Tracing is currently only supported for regular quorum calls.

type Monitor

type Monitor interface {
	RI() int
	RR(i int, v string) (bool, []string)
	WI(v string) int
	WR(i int, v string)
}

func NewEventMonitor

func NewEventMonitor() Monitor

NewEventMonitor creates a new monitor.

type MultiSorter

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

MultiSorter implements the Sort interface, sorting the nodes within.

func OrderedBy

func OrderedBy(less ...lessFunc) *MultiSorter

OrderedBy returns a Sorter that sorts using the less functions, in order. Call its Sort method to sort the data.

func (*MultiSorter) Len

func (ms *MultiSorter) Len() int

Len is part of sort.Interface.

func (*MultiSorter) Less

func (ms *MultiSorter) Less(i, j int) bool

Less is part of sort.Interface. It is implemented by looping along the less functions until it finds a comparison that is either Less or !Less. Note that it can call the less functions twice per call. We could change the functions to return -1, 0, 1 and reduce the number of calls for greater efficiency: an exercise for the reader.

func (*MultiSorter) Sort

func (ms *MultiSorter) Sort(nodes []*Node)

Sort sorts the argument slice according to the less functions passed to OrderedBy.

func (*MultiSorter) Swap

func (ms *MultiSorter) Swap(i, j int)

Swap is part of sort.Interface.

type Node

type Node struct {
	RegisterClient RegisterClient
	// contains filtered or unexported fields
}

Node encapsulates the state of a node on which a remote procedure call can be made.

func (*Node) Address

func (n *Node) Address() string

Address returns network address of m.

func (*Node) ID

func (n *Node) ID() uint32

ID returns the ID of m.

func (*Node) LastErr

func (n *Node) LastErr() error

LastErr returns the last error encountered (if any) when invoking a remote procedure call on this node.

func (*Node) Latency

func (n *Node) Latency() time.Duration

Latency returns the latency of the last successful remote procedure call made to this node.

func (*Node) String

func (n *Node) String() string

type NodeNotFoundError

type NodeNotFoundError uint32

A NodeNotFoundError reports that a specified node could not be found.

func (NodeNotFoundError) Error

func (e NodeNotFoundError) Error() string

type QuoSpecQ

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

QuoSpecQ is the quorum specification for the RWRegister quorum algorithm.

func (QuoSpecQ) ReadQF

func (qq QuoSpecQ) ReadQF(replies []*Value) (*Value, bool)

ReadQF returns nil and false until enough replies have been receive so as to satisfy the quorum condition for a read quorum. Hence, once enough replies have been received, the highest value and true is returned.

func (QuoSpecQ) WriteQF

func (qq QuoSpecQ) WriteQF(replies []*WriteResponse) (*WriteResponse, bool)

WriteQF returns WRITENACK, that is nil and false, until enough replies have been received. When enough replies have been received, we return WRITEACK, that is the first reply and true.

type QuorumCallError

type QuorumCallError struct {
	Reason               string
	ErrCount, ReplyCount int
}

A QuorumCallError is used to report that a quorum call failed.

func (QuorumCallError) Error

func (e QuorumCallError) Error() string

type QuorumSpec

type QuorumSpec interface {
	// ReadQF is the quorum function for the Read
	// quorum call method.
	ReadQF(replies []*Value) (*Value, bool)

	// WriteQF is the quorum function for the Write
	// quorum call method.
	WriteQF(replies []*WriteResponse) (*WriteResponse, bool)
}

QuorumSpec is the interface that wraps every quorum function.

func NewQuoSpecQ

func NewQuoSpecQ(rqSize, wqSize int) QuorumSpec

NewQuoSpecQ returns a quorum specification with quorum sizes for read and write quorum functions.

type ReadRequest

type ReadRequest struct {
}

func (*ReadRequest) Descriptor

func (*ReadRequest) Descriptor() ([]byte, []int)

func (*ReadRequest) Marshal

func (m *ReadRequest) Marshal() (dAtA []byte, err error)

func (*ReadRequest) MarshalTo

func (m *ReadRequest) MarshalTo(dAtA []byte) (int, error)

func (*ReadRequest) ProtoMessage

func (*ReadRequest) ProtoMessage()

func (*ReadRequest) Reset

func (m *ReadRequest) Reset()

func (*ReadRequest) Size

func (m *ReadRequest) Size() (n int)

func (*ReadRequest) String

func (this *ReadRequest) String() string

func (*ReadRequest) Unmarshal

func (m *ReadRequest) Unmarshal(dAtA []byte) error

type RegisterClient

type RegisterClient interface {
	Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*Value, error)
	Write(ctx context.Context, in *Value, opts ...grpc.CallOption) (*WriteResponse, error)
}

func NewRegisterClient

func NewRegisterClient(cc *grpc.ClientConn) RegisterClient

type RegisterServer

type RegisterServer interface {
	Read(context.Context, *ReadRequest) (*Value, error)
	Write(context.Context, *Value) (*WriteResponse, error)
}

type RegisterServerBasic

type RegisterServerBasic struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RegisterServerBasic represents a single State register.

func NewRegisterBasic

func NewRegisterBasic() *RegisterServerBasic

NewRegisterBasic returns a new basic register server.

func (*RegisterServerBasic) Read

func (r *RegisterServerBasic) Read(ctx context.Context, rq *ReadRequest) (*Value, error)

Read can handle the reed request from the client.

func (*RegisterServerBasic) ReadExecuted

func (r *RegisterServerBasic) ReadExecuted()

ReadExecuted returns when r has has completed a read.

func (*RegisterServerBasic) Write

Write can handle the write request from the client.

func (*RegisterServerBasic) WriteExecuted

func (r *RegisterServerBasic) WriteExecuted()

WriteExecuted returns when r has has completed a write.

type RegisterTestServer

type RegisterTestServer interface {
	RegisterServer
	ReadExecuted()
	WriteExecuted()
}

RegisterTestServer is a basic register server that in addition also can signal when a read or write has completed.

type Value

type Value struct {
	C *Content `protobuf:"bytes,1,opt,name=c" json:"c,omitempty"`
}

func (*Value) Descriptor

func (*Value) Descriptor() ([]byte, []int)

func (*Value) GetC

func (m *Value) GetC() *Content

func (*Value) Marshal

func (m *Value) Marshal() (dAtA []byte, err error)

func (*Value) MarshalTo

func (m *Value) MarshalTo(dAtA []byte) (int, error)

func (*Value) ProtoMessage

func (*Value) ProtoMessage()

func (*Value) Reset

func (m *Value) Reset()

func (*Value) Size

func (m *Value) Size() (n int)

func (*Value) String

func (this *Value) String() string

func (*Value) Unmarshal

func (m *Value) Unmarshal(dAtA []byte) error

type WriteResponse

type WriteResponse struct {
	Ack bool `protobuf:"varint,1,opt,name=ack,proto3" json:"ack,omitempty"`
}

[Ack]

func (*WriteResponse) Descriptor

func (*WriteResponse) Descriptor() ([]byte, []int)

func (*WriteResponse) GetAck

func (m *WriteResponse) GetAck() bool

func (*WriteResponse) Marshal

func (m *WriteResponse) Marshal() (dAtA []byte, err error)

func (*WriteResponse) MarshalTo

func (m *WriteResponse) MarshalTo(dAtA []byte) (int, error)

func (*WriteResponse) ProtoMessage

func (*WriteResponse) ProtoMessage()

func (*WriteResponse) Reset

func (m *WriteResponse) Reset()

func (*WriteResponse) Size

func (m *WriteResponse) Size() (n int)

func (*WriteResponse) String

func (this *WriteResponse) String() string

func (*WriteResponse) Unmarshal

func (m *WriteResponse) Unmarshal(dAtA []byte) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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