model

package
v0.0.0-...-b45d6de Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeterministicModel = porcupine.Model{
	Init: func() interface{} {
		var s etcdState
		data, err := json.Marshal(s)
		if err != nil {
			panic(err)
		}
		return string(data)
	},
	Step: func(st interface{}, in interface{}, out interface{}) (bool, interface{}) {
		var s etcdState
		err := json.Unmarshal([]byte(st.(string)), &s)
		if err != nil {
			panic(err)
		}
		ok, s := s.Step(in.(EtcdRequest), out.(EtcdResponse))
		data, err := json.Marshal(s)
		if err != nil {
			panic(err)
		}
		return ok, string(data)
	},
	DescribeOperation: func(in, out interface{}) string {
		return fmt.Sprintf("%s -> %s", describeEtcdRequest(in.(EtcdRequest)), describeEtcdResponse(in.(EtcdRequest), out.(EtcdResponse)))
	},
}

DeterministicModel assumes that all requests succeed and have a correct response.

View Source
var NonDeterministicModel = porcupine.Model{
	Init: func() interface{} {
		var states nonDeterministicState
		data, err := json.Marshal(states)
		if err != nil {
			panic(err)
		}
		return string(data)
	},
	Step: func(st interface{}, in interface{}, out interface{}) (bool, interface{}) {
		var states nonDeterministicState
		err := json.Unmarshal([]byte(st.(string)), &states)
		if err != nil {
			panic(err)
		}
		ok, states := states.Step(in.(EtcdRequest), out.(EtcdNonDeterministicResponse))
		data, err := json.Marshal(states)
		if err != nil {
			panic(err)
		}
		return ok, string(data)
	},
	DescribeOperation: func(in, out interface{}) string {
		return fmt.Sprintf("%s -> %s", describeEtcdRequest(in.(EtcdRequest)), describeEtcdNonDeterministicResponse(in.(EtcdRequest), out.(EtcdNonDeterministicResponse)))
	},
}

NonDeterministicModel extends DeterministicModel to handle requests that have unknown or error response. Unknown/error response doesn't inform whether request was persisted or not, so model considers both cases. This is represented as multiple equally possible deterministic states. Failed requests fork the possible states, while successful requests merge and filter them.

Functions

func Match

func Match(r1, r2 EtcdNonDeterministicResponse) bool

func ValidateOperationHistoryAndReturnVisualize

func ValidateOperationHistoryAndReturnVisualize(t *testing.T, lg *zap.Logger, operations []porcupine.Operation) (visualize func(basepath string))

ValidateOperationHistoryAndReturnVisualize return visualize as porcupine.linearizationInfo used to generate visualization is private.

Types

type AppendableHistory

type AppendableHistory struct {
	History
	// contains filtered or unexported fields
}

AppendableHistory allows to collect history of sequential operations.

Ensures that operation history is compatible with porcupine library, by preventing concurrent requests sharing the same stream id. For failed requests, we don't know their return time, so generate new stream id.

Appending needs to be done in order of operation execution time (start, end time). Operations time should be calculated as time.Since common base time to ensure that Go monotonic time is used. More in https://github.com/golang/go/blob/96add980ad27faed627f26ef1ab09e8fe45d6bd1/src/time/time.go#L10.

func NewAppendableHistory

func NewAppendableHistory(ids identity.Provider) *AppendableHistory

func (*AppendableHistory) AppendDefragment

func (h *AppendableHistory) AppendDefragment(start, end time.Duration, resp *clientv3.DefragmentResponse, err error)

func (*AppendableHistory) AppendDelete

func (h *AppendableHistory) AppendDelete(key string, start, end time.Duration, resp *clientv3.DeleteResponse, err error)

func (*AppendableHistory) AppendLeaseGrant

func (h *AppendableHistory) AppendLeaseGrant(start, end time.Duration, resp *clientv3.LeaseGrantResponse, err error)

func (*AppendableHistory) AppendLeaseRevoke

func (h *AppendableHistory) AppendLeaseRevoke(id int64, start, end time.Duration, resp *clientv3.LeaseRevokeResponse, err error)

func (*AppendableHistory) AppendPut

func (h *AppendableHistory) AppendPut(key, value string, start, end time.Duration, resp *clientv3.PutResponse, err error)

func (*AppendableHistory) AppendPutWithLease

func (h *AppendableHistory) AppendPutWithLease(key, value string, leaseID int64, start, end time.Duration, resp *clientv3.PutResponse, err error)

func (*AppendableHistory) AppendRange

func (h *AppendableHistory) AppendRange(key string, withPrefix bool, start, end time.Duration, resp *clientv3.GetResponse)

func (*AppendableHistory) AppendTxn

func (h *AppendableHistory) AppendTxn(cmp []clientv3.Cmp, clientOnSuccessOps, clientOnFailure []clientv3.Op, start, end time.Duration, resp *clientv3.TxnResponse, err error)

type DefragmentRequest

type DefragmentRequest struct{}

type DefragmentResponse

type DefragmentResponse struct{}

type EtcdCondition

type EtcdCondition struct {
	Key              string
	ExpectedRevision int64
}

type EtcdLease

type EtcdLease struct {
	LeaseID int64
	Keys    map[string]struct{}
}

type EtcdNonDeterministicResponse

type EtcdNonDeterministicResponse struct {
	EtcdResponse
	Err           error
	ResultUnknown bool
}

type EtcdOperation

type EtcdOperation struct {
	Type       OperationType
	Key        string
	WithPrefix bool
	Limit      int64
	Value      ValueOrHash
	LeaseID    int64
}

type EtcdOperationResult

type EtcdOperationResult struct {
	KVs     []KeyValue
	Count   int64
	Deleted int64
}

type EtcdRequest

type EtcdRequest struct {
	Type        RequestType
	LeaseGrant  *LeaseGrantRequest
	LeaseRevoke *LeaseRevokeRequest
	Txn         *TxnRequest
	Defragment  *DefragmentRequest
}

type EtcdResponse

type EtcdResponse struct {
	Revision    int64
	Txn         *TxnResponse
	LeaseGrant  *LeaseGrantReponse
	LeaseRevoke *LeaseRevokeResponse
	Defragment  *DefragmentResponse
}

type History

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

func (History) Len

func (h History) Len() int

func (History) MaxRevision

func (h History) MaxRevision() int64

func (History) Merge

func (h History) Merge(h2 History) History

func (History) Operations

func (h History) Operations() []porcupine.Operation

type KeyValue

type KeyValue struct {
	Key string
	ValueRevision
}

type LeaseGrantReponse

type LeaseGrantReponse struct {
	LeaseID int64
}

type LeaseGrantRequest

type LeaseGrantRequest struct {
	LeaseID int64
}

type LeaseRevokeRequest

type LeaseRevokeRequest struct {
	LeaseID int64
}

type LeaseRevokeResponse

type LeaseRevokeResponse struct{}

type OperationType

type OperationType string
const (
	Range  OperationType = "range"
	Put    OperationType = "put"
	Delete OperationType = "delete"
)

type RequestType

type RequestType string
const (
	Txn         RequestType = "txn"
	LeaseGrant  RequestType = "leaseGrant"
	LeaseRevoke RequestType = "leaseRevoke"
	Defragment  RequestType = "defragment"
)

type TxnRequest

type TxnRequest struct {
	Conditions          []EtcdCondition
	OperationsOnSuccess []EtcdOperation
	OperationsOnFailure []EtcdOperation
}

type TxnResponse

type TxnResponse struct {
	Failure bool
	Results []EtcdOperationResult
}

type ValueOrHash

type ValueOrHash struct {
	Value string
	Hash  uint32
}

func ToValueOrHash

func ToValueOrHash(value string) ValueOrHash

type ValueRevision

type ValueRevision struct {
	Value       ValueOrHash
	ModRevision int64
}

Jump to

Keyboard shortcuts

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