Documentation
¶
Index ¶
- Constants
- Variables
- func CreateModelFormEnforcerState(state EnforcerState) (model2.Model, error)
- func IsNewNode(raftDir string) bool
- type AssertionState
- type AssertionStateMap
- type BackupFormat
- type ClusterState
- type EnforcerState
- type FSMEnforceResponse
- type FSMResponse
- type Listener
- type ModelState
- type Server
- type Servers
- type Store
- func (s *Store) AddPolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) error
- func (s *Store) Addr() string
- func (s *Store) Apply(l *raft.Log) (e interface{})
- func (s *Store) ClearPolicy(ctx context.Context, ns string) error
- func (s *Store) Close(wait bool) error
- func (s *Store) CreateNamespace(ctx context.Context, ns string) error
- func (s *Store) Enforce(ctx context.Context, ns string, level command.EnforcePayload_Level, ...) (bool, error)
- func (s *Store) ID() string
- func (s *Store) IsLeader() bool
- func (s *Store) Join(id, addr string, voter bool, metadata map[string]string) error
- func (s *Store) LeaderAddr() string
- func (s *Store) LeaderID() (string, error)
- func (s *Store) Nodes() ([]*Server, error)
- func (s *Store) Open(enableBootstrap bool) error
- func (s *Store) Path() string
- func (s *Store) Remove(id string) error
- func (s *Store) RemoveFilteredPolicy(ctx context.Context, ns string, sec string, pType string, fi int32, ...) error
- func (s *Store) RemovePolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) error
- func (s *Store) Restore(closer io.ReadCloser) error
- func (s *Store) SetMetadata(md map[string]string) error
- func (s *Store) SetModelFromString(ctx context.Context, ns string, text string) error
- func (s *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) State() ClusterState
- func (s *Store) Stats() (map[string]interface{}, error)
- func (s *Store) UpdatePolicies(ctx context.Context, ns string, sec string, pType string, nr, or [][]string) error
- func (s *Store) UpdatePolicy(ctx context.Context, ns string, sec string, pType string, nr, or []string) error
- func (s *Store) WaitForApplied(timeout time.Duration) error
- func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
- type StoreConfig
- type Transport
Constants ¶
const ( // BackupBinary is a file backup format. BackupBinary = iota )
Variables ¶
var ( // NamespaceNotExist namespace not created NamespaceNotExist = errors.New("namespace not exist") // UnmarshalFail unmarshal failed UnmarshalFail = errors.New("unmarshal failed") )
var ( // ErrNotLeader is returned when a node attempts to execute a leader-only // operation. ErrNotLeader = errors.New("not leader") // ErrStaleRead is returned if the executing the query would violate the // requested freshness. ErrStaleRead = errors.New("stale read") // ErrOpenTimeout is returned when the Store does not apply its initial // logs within the specified time. ErrOpenTimeout = errors.New("timeout waiting for initial logs application") // ErrInvalidBackupFormat is returned when the requested backup format // is not valid. ErrInvalidBackupFormat = errors.New("invalid backup format") )
Functions ¶
func CreateModelFormEnforcerState ¶
func CreateModelFormEnforcerState(state EnforcerState) (model2.Model, error)
CreateModelFormEnforcerState create enforcer state and add links of rule groups
Types ¶
type AssertionState ¶
type AssertionStateMap ¶
type AssertionStateMap map[string]AssertionState
type ClusterState ¶
type ClusterState int
ClusterState defines the possible Raft states the current node can be in
const ( Leader ClusterState = iota Follower Candidate Shutdown Unknown )
Represents the Raft cluster states
type EnforcerState ¶
type EnforcerState struct {
Model ModelState
}
func CreateEnforcerState ¶
func CreateEnforcerState(e *casbin.DistributedEnforcer) (EnforcerState, error)
CreateEnforcerState transform enforce state to persisting state
type FSMEnforceResponse ¶
type FSMEnforceResponse struct {
// contains filtered or unexported fields
}
type FSMResponse ¶
type FSMResponse struct {
// contains filtered or unexported fields
}
type Listener ¶
type Listener interface { net.Listener Dial(address string, timeout time.Duration) (net.Conn, error) }
Listener is the interface expected by the Store for Transports.
type ModelState ¶
type ModelState map[string]AssertionStateMap
type Store ¶
type Store struct { ShutdownOnRemove bool SnapshotThreshold uint64 SnapshotInterval time.Duration LeaderLeaseTimeout time.Duration HeartbeatTimeout time.Duration ElectionTimeout time.Duration ApplyTimeout time.Duration RaftLogLevel string // contains filtered or unexported fields }
Store is casbin memory data, where all changes are made via Raft consensus.
func (*Store) AddPolicies ¶
func (s *Store) AddPolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) error
AddPolicy implements the casbin.Adapter interface.
func (*Store) ClearPolicy ¶
ClearPolicy implements the casbin.Adapter interface.
func (*Store) CreateNamespace ¶
CreateNamespace
func (*Store) Enforce ¶
func (s *Store) Enforce(ctx context.Context, ns string, level command.EnforcePayload_Level, freshness int64, params ...interface{}) (bool, error)
Enforce
func (*Store) Join ¶
Join joins a node, identified by id and located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) LeaderAddr ¶
LeaderAddr returns the address of the current leader. Returns a blank string if there is no leader.
func (*Store) LeaderID ¶
LeaderID returns the node ID of the Raft leader. Returns a blank string if there is no leader, or an error.
func (*Store) Open ¶
Open opens the Store. If enableBootstrap is set, then this node becomes a standalone node. If not set, then the calling layer must know that this node has pre-existing state, or the calling layer will trigger a join operation after opening the Store.
func (*Store) RemoveFilteredPolicy ¶
func (s *Store) RemoveFilteredPolicy(ctx context.Context, ns string, sec string, pType string, fi int32, fv []string) error
RemoveFilteredPolicy implements the casbin.Adapter interface.
func (*Store) RemovePolicies ¶
func (s *Store) RemovePolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) error
RemovePolicies implements the casbin.Adapter interface.
func (*Store) SetMetadata ¶
SetMetadata adds the metadata md to any existing metadata for this node.
func (*Store) SetModelFromString ¶
SetModelFromString
func (*Store) State ¶
func (s *Store) State() ClusterState
State returns the current node's Raft state
func (*Store) UpdatePolicies ¶
func (s *Store) UpdatePolicies(ctx context.Context, ns string, sec string, pType string, nr, or [][]string) error
UpdatePolicies implements the casbin.Adapter interface.
func (*Store) UpdatePolicy ¶
func (s *Store) UpdatePolicy(ctx context.Context, ns string, sec string, pType string, nr, or []string) error
UpdatePolicy implements the casbin.Adapter interface.
func (*Store) WaitForApplied ¶
WaitForApplied waits for all Raft log entries to to be applied to the underlying database.
func (*Store) WaitForAppliedIndex ¶
WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.
type StoreConfig ¶
type StoreConfig struct { Dir string // The working directory for raft. Tn Transport // The underlying Transport for raft. ID string // Node ID. Logger *log.Logger // The logger to use to log stuff. }
StoreConfig represents the configuration of the underlying Store.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the network service provided to Raft, and wraps a Listener.
func NewTransport ¶
NewTransport returns an initialized Transport.