store

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ID                     string
	Dir                    string
	NetworkTransportConfig *raft.NetworkTransportConfig
	Enforcer               casbin.IDistributedEnforcer
	RaftConfig             *raft.Config
}

type FSM

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

FSM is state storage.

func NewFSM

func NewFSM(logger *zap.Logger, path string, enforcer casbin.IDistributedEnforcer) (*FSM, error)

NewFSM returns a FSM.

func (*FSM) Apply

func (f *FSM) Apply(log *raft.Log) interface{}

Apply applies log from raft. It will parse the command of casbin from log, and pass the command to casbin.

func (*FSM) Restore

func (f *FSM) Restore(rc io.ReadCloser) error

Restore is used to restore an FSM from a snapshot. It is not called concurrently with any other command. The FSM must discard all previous state. When Raft starts, if the local snapshot exists, call Restore, otherwise read log from logstore and pass it to Apply.

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot is used to support log compaction. This call should return an FSMSnapshot which can be used to save a point-in-time snapshot of the FSM. Apply and Snapshot are not called in multiple threads, but Apply will be called concurrently with Persist. This means the FSM should be implemented in a fashion that allows for concurrent updates while a snapshot is happening.

type PolicyOperator

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

PolicyOperator is used to update policies and provide persistence.

func NewPolicyOperator

func NewPolicyOperator(logger *zap.Logger, path string, e casbin.IDistributedEnforcer) (*PolicyOperator, error)

NewPolicyOperator returns a PolicyOperator.

func (*PolicyOperator) AddPolicies

func (p *PolicyOperator) AddPolicies(sec, pType string, rules [][]string) error

AddPolicies adds a set of rules.

func (*PolicyOperator) Backup

func (p *PolicyOperator) Backup() ([]byte, error)

Backup writes the database to bytes with gzip.

func (*PolicyOperator) ClearPolicy

func (p *PolicyOperator) ClearPolicy() error

ClearPolicy clears all rules.

func (*PolicyOperator) RemoveFilteredPolicy

func (p *PolicyOperator) RemoveFilteredPolicy(sec string, pType string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy removes a set of rules that match a pattern.

func (*PolicyOperator) RemovePolicies

func (p *PolicyOperator) RemovePolicies(sec, pType string, rules [][]string) error

RemovePolicies removes a set of rules.

func (*PolicyOperator) Restore

func (p *PolicyOperator) Restore(rc io.ReadCloser) error

Restore is used to restore a database from io.ReadCloser.

func (*PolicyOperator) UpdatePolicies

func (p *PolicyOperator) UpdatePolicies(sec, pType string, oldRules, newRules [][]string) error

UpdatePolicies replaces a set of existing rule.

func (*PolicyOperator) UpdatePolicy

func (p *PolicyOperator) UpdatePolicy(sec, pType string, oldRule, newRule []string) error

UpdatePolicy replaces an existing rule.

type Rule

type Rule struct {
	Sec   string   `json:"sec"`
	PType string   `json:"p_type"`
	Rule  []string `json:"rule"`
}

type Store

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

Store is responsible for synchronization policy and storage policy by Raft protocol.

func NewStore

func NewStore(logger *zap.Logger, config *Config) (*Store, error)

NewStore return a instance of Store.

func (*Store) AddPolicies

func (s *Store) AddPolicies(request *command.AddPoliciesRequest) error

AddPolicy implements the http.Store interface.

func (*Store) Address

func (s *Store) Address() string

Address returns the address of the current node.

func (*Store) ClearPolicy

func (s *Store) ClearPolicy() error

ClearPolicy implements the http.Store interface.

func (*Store) DataDir

func (s *Store) DataDir() string

DataDir returns the data directory of the current node.

func (*Store) ID

func (s *Store) ID() string

ID returns the id of the current node.

func (*Store) IsInitializedCluster

func (s *Store) IsInitializedCluster() bool

IsInitializedCluster checks whether the cluster has been initialized.

func (*Store) JoinNode

func (s *Store) JoinNode(serverID string, address string) error

JoinNode implements the http.Store interface.

func (*Store) Leader

func (s *Store) Leader() (bool, string)

Leader implements the http.Store interface.

func (*Store) RemoveFilteredPolicy

func (s *Store) RemoveFilteredPolicy(request *command.RemoveFilteredPolicyRequest) error

RemoveFilteredPolicy implements the http.Store interface.

func (*Store) RemoveNode

func (s *Store) RemoveNode(serverID string) error

RemoveNode implements the http.Store interface.

func (*Store) RemovePolicies

func (s *Store) RemovePolicies(request *command.RemovePoliciesRequest) error

RemovePolicies implements the http.Store interface.

func (*Store) Start

func (s *Store) Start(enableBootstrap bool) error

Start performs initialization and runs server

func (*Store) Stats added in v0.0.6

func (s *Store) Stats() (map[string]interface{}, error)

Leader implements the http.Store interface.

func (*Store) Stop

func (s *Store) Stop() error

Stop is used to close the raft node, which always returns nil.

func (*Store) UpdatePolicies

func (s *Store) UpdatePolicies(request *command.UpdatePoliciesRequest) error

UpdatePolicies implements the http.Store interface.

func (*Store) UpdatePolicy

func (s *Store) UpdatePolicy(request *command.UpdatePolicyRequest) error

UpdatePolicy implements the http.Store interface.

func (*Store) WaitLeader

func (s *Store) WaitLeader() error

WaitLeader detects the leader address in the current cluster.

type TCPStreamLayer

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

StreamLayer implements the raft.StreamLayer interface base on TCP.

func NewTCPStreamLayer

func NewTCPStreamLayer(ln net.Listener, tlsConfig *tls.Config) (*TCPStreamLayer, error)

NewStreamLayer returns a StreamLayer.

func (*TCPStreamLayer) Accept

func (t *TCPStreamLayer) Accept() (c net.Conn, err error)

Accept implements the net.Listener interface.

func (*TCPStreamLayer) Addr

func (t *TCPStreamLayer) Addr() net.Addr

Addr implements the net.Listener interface.

func (*TCPStreamLayer) Close

func (t *TCPStreamLayer) Close() (err error)

Close implements the net.Listener interface.

func (*TCPStreamLayer) Dial

func (t *TCPStreamLayer) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error)

Dial implements the StreamLayer interface.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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