etcd

package module
v0.0.0-...-15722f1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

groupcache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DestroryGroup

func DestroryGroup(name string)

func NewClient

func NewClient(service string) *client

Types

type ByteView

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

func (ByteView) Bytes

func (bv ByteView) Bytes() []byte

func (ByteView) Len

func (bv ByteView) Len() int

实现 Value 接口

func (ByteView) String

func (bv ByteView) String() string

type Fetcher

type Fetcher interface {
	Fetch(group string, key string) ([]byte, error)
}

Fetcher 定义了从远端获取缓存的能力,所以每个 Peer 都应实现这个接口

type Group

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

Group 提供了命名管理缓存、填充缓存的能力

func GetGroup

func GetGroup(name string) *Group

GetGroup 获取对应命名空间的 Group 对象(对实际缓存进行管理)

func NewGroup

func NewGroup(name string, maxBytes int64, retriever Retriever) *Group

NewGroup 新创建一个缓存空间

func (*Group) Get

func (g *Group) Get(key string) (ByteView, error)

func (*Group) RegisterServer

func (g *Group) RegisterServer(p Picker)

RegisterServer 为 Group 注册 server

type Picker

type Picker interface {
	Pick(key string) (Fetcher, bool)
}

Picker 定义了获取分布式节点的能力

type RetrieveFunc

type RetrieveFunc func(key string) ([]byte, error)

type Retriever

type Retriever interface {
	// contains filtered or unexported methods
}

Retriever 要求对象实现从数据源获取数据的能力

type Server

type Server struct {
	pb.UnimplementedGroupCacheServer

	Addr   string // format: ip:port
	Status bool   // true: running false: stop
	// contains filtered or unexported fields
}

server 和 Group 是解耦合的,所以 server 要自己实现并发控制

func NewServer

func NewServer(addr string) (*Server, error)

NewServer 创建 cache 的 server,若 addr 为空,则使用 defaultAddr

func (*Server) Get

func (s *Server) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse, error)

Get 实现了 Groupcache service 的 Get 方法

func (*Server) Pick

func (s *Server) Pick(key string) (Fetcher, bool)

Pick 根据一致性哈希选举出 key 应该存放在的 cache return false 代表从本地获取 cache

func (*Server) SetPeers

func (s *Server) SetPeers(peersAddr []string)

SetPeers 将各个远端主机 IP 配置到 Server 里 这样 Server 就可以 Pick 它们了 注意:此操作是覆写操作,peersIP 必须满足 x.x.x.x:port 的格式

func (*Server) Start

func (s *Server) Start() error

Start 启动 Cache 服务

func (*Server) Stop

func (s *Server) Stop()

Stop 停止 server 运行,如果 server 没有运行,这将是一个 no-op

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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