Documentation ¶
Index ¶
- Constants
- Variables
- func CfxUrlConfig() map[Group]UrlConfig
- func Config() *config
- func EthFactory() *factory
- func EthUrlConfig() map[Group]UrlConfig
- func Factory() *factory
- func MustNewServer(db *mysql.MysqlStore, nf nodeFactory, grpConf map[Group]UrlConfig) *rpc.Server
- type CfxClientProvider
- type CfxNode
- type EthClientProvider
- func (p *EthClientProvider) GetClient(key string, groups ...Group) (*Web3goClient, error)
- func (p *EthClientProvider) GetClientByIP(ctx context.Context, groups ...Group) (*Web3goClient, error)
- func (p *EthClientProvider) GetClientRandom() (*Web3goClient, error)
- func (p EthClientProvider) GetRouteGroup(key string) (grp Group, ok bool)
- type EthNode
- type Group
- type HealthMonitor
- type LocalRouter
- type Manager
- func (m *Manager) Add(nodes ...Node)
- func (m *Manager) Close()
- func (m *Manager) Distribute(key []byte) Node
- func (m *Manager) Get(nodeName string) (Node, bool)
- func (m *Manager) HealthyEpoch() uint64
- func (m *Manager) List() []Node
- func (m *Manager) Remove(nodeNames ...string)
- func (m *Manager) ReportEpoch(nodeName string, epoch uint64)
- func (m *Manager) ReportHealthy(nodeName string)
- func (m *Manager) ReportUnhealthy(nodeName string, remind bool, reason error)
- func (m *Manager) Route(key []byte) string
- func (m *Manager) String() string
- type Node
- type NodeRpcRouter
- type RedisRepartitionResolver
- type RedisRouter
- type RepartitionResolver
- type Router
- type SimpleRepartitionResolver
- type Status
- type UrlConfig
- type Web3goClient
Constants ¶
const ( RouteKeyCacheSize = 5000 RouteCacheExpirationTTL = 60 * time.Second )
Variables ¶
var (
)Functions ¶
func CfxUrlConfig ¶
func EthUrlConfig ¶
func MustNewServer ¶
MustNewServer creates node management RPC server
Types ¶
type CfxClientProvider ¶
type CfxClientProvider struct {
// contains filtered or unexported fields
}
CfxClientProvider provides core space client by router.
func NewCfxClientProvider ¶
func NewCfxClientProvider(db *mysql.MysqlStore, router Router) *CfxClientProvider
func (*CfxClientProvider) GetClient ¶
func (p *CfxClientProvider) GetClient(key string, groups ...Group) (sdk.ClientOperator, error)
GetClient gets client of specific group (or use normal HTTP group as default.
func (*CfxClientProvider) GetClientByIP ¶
func (p *CfxClientProvider) GetClientByIP(ctx context.Context, groups ...Group) (sdk.ClientOperator, error)
GetClientByIP gets client of specific group (or use normal HTTP group as default) by remote IP address.
func (CfxClientProvider) GetRouteGroup ¶
getRouteGroup get custom route group for specific route key
type CfxNode ¶
type CfxNode struct { sdk.ClientOperator // contains filtered or unexported fields }
CfxNode represents a core space fullnode with friendly name and health status.
func NewCfxNode ¶
func NewCfxNode(group Group, name, url string, hm HealthMonitor) (*CfxNode, error)
NewCfxNode creates an instance of core space fullnode and start to monitor node health in a separate goroutine until node closed.
func (*CfxNode) LatestEpochNumber ¶
LatestEpochNumber returns the latest epoch height of the core space fullnode
type EthClientProvider ¶
type EthClientProvider struct {
// contains filtered or unexported fields
}
EthClientProvider provides evm space client by router.
func NewEthClientProvider ¶
func NewEthClientProvider(db *mysql.MysqlStore, router Router) *EthClientProvider
func (*EthClientProvider) GetClient ¶
func (p *EthClientProvider) GetClient(key string, groups ...Group) (*Web3goClient, error)
GetClient gets client of specific group (or use normal HTTP group as default).
func (*EthClientProvider) GetClientByIP ¶
func (p *EthClientProvider) GetClientByIP(ctx context.Context, groups ...Group) (*Web3goClient, error)
GetClientByIP gets client of specific group (or use normal HTTP group as default) by remote IP address.
func (*EthClientProvider) GetClientRandom ¶
func (p *EthClientProvider) GetClientRandom() (*Web3goClient, error)
func (EthClientProvider) GetRouteGroup ¶
getRouteGroup get custom route group for specific route key
type EthNode ¶
EthNode represents an evm space node with friendly name and health status.
func NewEthNode ¶
func NewEthNode(group Group, name, url string, hm HealthMonitor) (*EthNode, error)
NewEthNode creates an instance of evm space node and start to monitor node health in a separate goroutine until node closed.
func (*EthNode) LatestEpochNumber ¶
LatestEpochNumber returns the latest block height of the evm space fullnode
type Group ¶
type Group string
Group allows to manage full nodes in multiple groups.
const ( // core space fullnode groups GroupCfxHttp Group = "cfxhttp" GroupCfxFullState Group = "cfxfullstate" GroupCfxWs Group = "cfxws" GroupCfxFilter Group = "cfxfilter" GroupCfxLogs Group = "cfxlog" GroupCfxArchives Group = "cfxarchives" // evm space fullnode groups GroupEthHttp Group = "ethhttp" GroupEthFullState Group = "ethfullstate" GroupEthWs Group = "ethws" GroupEthFilter Group = "ethfilter" GroupEthLogs Group = "ethlogs" )
type HealthMonitor ¶
type HealthMonitor interface { // HealthyEpoch returns the healthy epoch number among full nodes. // Usually, it is the middle epoch number of all full nodes. HealthyEpoch() uint64 // ReportEpoch fired when epoch changes. ReportEpoch(nodeName string, epoch uint64) // ReportUnhealthy fired when full node becomes unhealthy or unrecovered for a long time. ReportUnhealthy(nodeName string, remind bool, reason error) // ReportHealthy fired when full node becomes healthy. ReportHealthy(nodeName string) }
HealthMonitor is implemented by any objects that support to monitor full node health.
type LocalRouter ¶
type LocalRouter struct {
// contains filtered or unexported fields
}
LocalRouter routes RPC requests based on local hash ring.
func NewLocalRouter ¶
func NewLocalRouter(group2Urls map[Group][]string) *LocalRouter
func NewLocalRouterFromNodeRPC ¶
func NewLocalRouterFromNodeRPC(client *rpc.Client) (*LocalRouter, error)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages full node cluster, including: 1. Monitor node health and disable/enable full node automatically. 2. Implements Router interface to route RPC requests to different full nodes in manner of consistent hashing.
func NewManager ¶
func NewManagerWithRepartition ¶
func NewManagerWithRepartition(group Group, resolver RepartitionResolver) *Manager
func (*Manager) Distribute ¶
Distribute distributes a full node by specified key.
func (*Manager) HealthyEpoch ¶
HealthyEpoch returns the middle epoch height collected from managed cluster nodes, which is also regarded as the overall health epoch height.
func (*Manager) ReportEpoch ¶
ReportEpoch reports latest epoch height of managed node to manager.
func (*Manager) ReportHealthy ¶
ReportHealthy reports healthy status of managed node to manager.
func (*Manager) ReportUnhealthy ¶
ReportUnhealthy reports unhealthy status of managed node to manager.
type Node ¶
type Node interface { consistent.Member Name() string Url() string Status() Status LatestEpochNumber() (uint64, error) Close() }
Node represents a full node with friendly name and health status.
type NodeRpcRouter ¶
type NodeRpcRouter struct {
// contains filtered or unexported fields
}
NodeRpcRouter routes RPC requests via node management RPC service.
func NewNodeRpcRouter ¶
func NewNodeRpcRouter(client *rpc.Client) *NodeRpcRouter
type RedisRepartitionResolver ¶
type RedisRepartitionResolver struct {
// contains filtered or unexported fields
}
RedisRepartitionResolver implements RepartitionResolver
func NewRedisRepartitionResolver ¶
func NewRedisRepartitionResolver(client *redis.Client, ttl time.Duration, keyPrefix string) *RedisRepartitionResolver
func (*RedisRepartitionResolver) Get ¶
func (r *RedisRepartitionResolver) Get(key uint64) (string, bool)
func (*RedisRepartitionResolver) Put ¶
func (r *RedisRepartitionResolver) Put(key uint64, value string)
type RedisRouter ¶
type RedisRouter struct {
// contains filtered or unexported fields
}
RedisRouter routes RPC requests via redis. It should be used together with RedisRepartitionResolver.
func NewRedisRouter ¶
func NewRedisRouter(client *redis.Client) *RedisRouter
type RepartitionResolver ¶
RepartitionResolver is implemented to support repartition when item added or removed in the consistent hash ring.
type Router ¶
type Router interface { // Route returns the full node URL for specified group and key. Route(group Group, key []byte) string }
Router is used to route RPC requests to multiple full nodes.
func MustNewRouter ¶
MustNewRouter creates an instance of Router.
type SimpleRepartitionResolver ¶
type SimpleRepartitionResolver struct {
// contains filtered or unexported fields
}
func NewSimpleRepartitionResolver ¶
func NewSimpleRepartitionResolver(ttl time.Duration) *SimpleRepartitionResolver
func (*SimpleRepartitionResolver) Get ¶
func (r *SimpleRepartitionResolver) Get(key uint64) (string, bool)
func (*SimpleRepartitionResolver) Put ¶
func (r *SimpleRepartitionResolver) Put(key uint64, value string)
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status represents the node status, including current epoch number and health status.
func (*Status) MarshalJSON ¶
MarshalJSON marshals as JSON.
func (*Status) Update ¶
func (s *Status) Update(n Node, monitor HealthMonitor)
Update heartbeats with node and updates health status.
type Web3goClient ¶
func (*Web3goClient) NodeName ¶
func (w3c *Web3goClient) NodeName() string