service

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: GPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INDEX_SERVICE = "index_service"
)
View Source
const (
	SERVICE_ROOT_PATH = "/github.com/WlayRay/ElectricSearch/index" // etcd key的前缀
)

Variables

View Source
var (
	ErrInvalidLengthIndex        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowIndex          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupIndex = fmt.Errorf("proto: unexpected end of group")
)

Functions

func RegisterIndexServiceServer

func RegisterIndexServiceServer(s *grpc.Server, srv IndexServiceServer)

Types

type AffectedCount

type AffectedCount struct {
	Count uint32 `protobuf:"varint,1,opt,name=Count,proto3" json:"Count,omitempty"`
}

func (*AffectedCount) Descriptor

func (*AffectedCount) Descriptor() ([]byte, []int)

func (*AffectedCount) GetCount

func (m *AffectedCount) GetCount() uint32

func (*AffectedCount) Marshal

func (m *AffectedCount) Marshal() (dAtA []byte, err error)

func (*AffectedCount) MarshalTo

func (m *AffectedCount) MarshalTo(dAtA []byte) (int, error)

func (*AffectedCount) MarshalToSizedBuffer

func (m *AffectedCount) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*AffectedCount) ProtoMessage

func (*AffectedCount) ProtoMessage()

func (*AffectedCount) Reset

func (m *AffectedCount) Reset()

func (*AffectedCount) Size

func (m *AffectedCount) Size() (n int)

func (*AffectedCount) String

func (m *AffectedCount) String() string

func (*AffectedCount) Unmarshal

func (m *AffectedCount) Unmarshal(dAtA []byte) error

func (*AffectedCount) XXX_DiscardUnknown

func (m *AffectedCount) XXX_DiscardUnknown()

func (*AffectedCount) XXX_Marshal

func (m *AffectedCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*AffectedCount) XXX_Merge

func (m *AffectedCount) XXX_Merge(src proto.Message)

func (*AffectedCount) XXX_Size

func (m *AffectedCount) XXX_Size() int

func (*AffectedCount) XXX_Unmarshal

func (m *AffectedCount) XXX_Unmarshal(b []byte) error

type CountRequest

type CountRequest struct {
}

func (*CountRequest) Descriptor

func (*CountRequest) Descriptor() ([]byte, []int)

func (*CountRequest) Marshal

func (m *CountRequest) Marshal() (dAtA []byte, err error)

func (*CountRequest) MarshalTo

func (m *CountRequest) MarshalTo(dAtA []byte) (int, error)

func (*CountRequest) MarshalToSizedBuffer

func (m *CountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CountRequest) ProtoMessage

func (*CountRequest) ProtoMessage()

func (*CountRequest) Reset

func (m *CountRequest) Reset()

func (*CountRequest) Size

func (m *CountRequest) Size() (n int)

func (*CountRequest) String

func (m *CountRequest) String() string

func (*CountRequest) Unmarshal

func (m *CountRequest) Unmarshal(dAtA []byte) error

func (*CountRequest) XXX_DiscardUnknown

func (m *CountRequest) XXX_DiscardUnknown()

func (*CountRequest) XXX_Marshal

func (m *CountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CountRequest) XXX_Merge

func (m *CountRequest) XXX_Merge(src proto.Message)

func (*CountRequest) XXX_Size

func (m *CountRequest) XXX_Size() int

func (*CountRequest) XXX_Unmarshal

func (m *CountRequest) XXX_Unmarshal(b []byte) error

type DocId

type DocId struct {
	DocId string `protobuf:"bytes,1,opt,name=DocId,proto3" json:"DocId,omitempty"`
}

func (*DocId) Descriptor

func (*DocId) Descriptor() ([]byte, []int)

func (*DocId) GetDocId

func (m *DocId) GetDocId() string

func (*DocId) Marshal

func (m *DocId) Marshal() (dAtA []byte, err error)

func (*DocId) MarshalTo

func (m *DocId) MarshalTo(dAtA []byte) (int, error)

func (*DocId) MarshalToSizedBuffer

func (m *DocId) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*DocId) ProtoMessage

func (*DocId) ProtoMessage()

func (*DocId) Reset

func (m *DocId) Reset()

func (*DocId) Size

func (m *DocId) Size() (n int)

func (*DocId) String

func (m *DocId) String() string

func (*DocId) Unmarshal

func (m *DocId) Unmarshal(dAtA []byte) error

func (*DocId) XXX_DiscardUnknown

func (m *DocId) XXX_DiscardUnknown()

func (*DocId) XXX_Marshal

func (m *DocId) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DocId) XXX_Merge

func (m *DocId) XXX_Merge(src proto.Message)

func (*DocId) XXX_Size

func (m *DocId) XXX_Size() int

func (*DocId) XXX_Unmarshal

func (m *DocId) XXX_Unmarshal(b []byte) error

type IIndexer

type IIndexer interface {
	AddDoc(doc types.Document) (int, error)
	DeleteDoc(docId string) int
	Search(querys *types.TermQuery, onFlag, offFlag uint64, orFlags []uint64) []*types.Document
	Count() int
	Close() error
}

type IServiceHub

type IServiceHub interface {
	Regist(service, endpoint string, leaseID etcdv3.LeaseID) (etcdv3.LeaseID, error) // 注册服务
	UnRegist(service, endpoint string) error                                         // 注销服务
	GetServiceEndpoints(service string) []string                                     // 服务发现
	GetServiceEndpoint(service string) string                                        // 根据负载均衡获取一台服务的endpoint
	Close()                                                                          // 关闭etcd连接
}

type IndexServiceClient

type IndexServiceClient interface {
	DeleteDoc(ctx context.Context, in *DocId, opts ...grpc.CallOption) (*AffectedCount, error)
	AddDoc(ctx context.Context, in *types.Document, opts ...grpc.CallOption) (*AffectedCount, error)
	Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*SearchResponse, error)
	Count(ctx context.Context, in *CountRequest, opts ...grpc.CallOption) (*AffectedCount, error)
}

IndexServiceClient is the client API for IndexService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewIndexServiceClient

func NewIndexServiceClient(cc *grpc.ClientConn) IndexServiceClient

type IndexServiceServer

type IndexServiceServer interface {
	DeleteDoc(context.Context, *DocId) (*AffectedCount, error)
	AddDoc(context.Context, *types.Document) (*AffectedCount, error)
	Search(context.Context, *SearchRequest) (*SearchResponse, error)
	Count(context.Context, *CountRequest) (*AffectedCount, error)
}

IndexServiceServer is the server API for IndexService service.

type IndexServiceWorker

type IndexServiceWorker struct {
	Indexer *Indexer
	// contains filtered or unexported fields
}

IndexServiceWorker是一个grpc服务,用于索引文档

func (*IndexServiceWorker) AddDoc

func (service *IndexServiceWorker) AddDoc(ctx context.Context, doc *types.Document) (*AffectedCount, error)

向索引中添加文档,如果文档已存在则会覆盖

func (*IndexServiceWorker) Close

func (service *IndexServiceWorker) Close()

func (*IndexServiceWorker) Count

func (service *IndexServiceWorker) Count(ctx context.Context, request *CountRequest) (*AffectedCount, error)

func (*IndexServiceWorker) DeleteDoc

func (service *IndexServiceWorker) DeleteDoc(ctx context.Context, docId *DocId) (*AffectedCount, error)

从索引上删除文档

func (*IndexServiceWorker) Init

func (service *IndexServiceWorker) Init(workerIndex ...int) error

func (*IndexServiceWorker) Regist

func (service *IndexServiceWorker) Regist(etcdEndpoint []string, servicePort, heartRate int) error

func (*IndexServiceWorker) Search

func (service *IndexServiceWorker) Search(ctx context.Context, request *SearchRequest) (*SearchResponse, error)

检索,返回文档列表

type Indexer

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

外观模式,把正排和倒排索引2个子系统封装在一起

func (*Indexer) AddDoc

func (indexer *Indexer) AddDoc(doc types.Document) (int, error)

向索引中添加文档,如果文档已存在则会覆盖

func (*Indexer) Close

func (indexer *Indexer) Close() error

func (*Indexer) Count

func (Indexer *Indexer) Count() int

func (*Indexer) DeleteDoc

func (indexer *Indexer) DeleteDoc(docId string) int

func (*Indexer) Init

func (indexer *Indexer) Init(DocNumEstimate int, dbtype int, Data string) error

func (*Indexer) LoadFromIndexFile

func (indexer *Indexer) LoadFromIndexFile() int

倒排索引存储在内存中,系统重启时从正派索引里加载数据

func (*Indexer) Search

func (indexer *Indexer) Search(querys *types.TermQuery, onFlag, offFlag uint64, orFlags []uint64) []*types.Document

检索,返回文档列表

type LoadBalancer

type LoadBalancer interface {
	Take([]string) string
}

type RandomSelect

type RandomSelect struct{}

func (*RandomSelect) Take

func (rs *RandomSelect) Take(endPoints []string) string

type RoundRobin

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

func (*RoundRobin) Take

func (rr *RoundRobin) Take(endPoints []string) string

type SearchRequest

type SearchRequest struct {
	Query   *types.TermQuery `protobuf:"bytes,1,opt,name=Query,proto3" json:"Query,omitempty"`
	OnFlag  uint64           `protobuf:"varint,2,opt,name=OnFlag,proto3" json:"OnFlag,omitempty"`
	OffFlag uint64           `protobuf:"varint,3,opt,name=OffFlag,proto3" json:"OffFlag,omitempty"`
	OrFlags []uint64         `protobuf:"varint,4,rep,packed,name=OrFlags,proto3" json:"OrFlags,omitempty"`
}

func (*SearchRequest) Descriptor

func (*SearchRequest) Descriptor() ([]byte, []int)

func (*SearchRequest) GetOffFlag

func (m *SearchRequest) GetOffFlag() uint64

func (*SearchRequest) GetOnFlag

func (m *SearchRequest) GetOnFlag() uint64

func (*SearchRequest) GetOrFlags

func (m *SearchRequest) GetOrFlags() []uint64

func (*SearchRequest) GetQuery

func (m *SearchRequest) GetQuery() *types.TermQuery

func (*SearchRequest) Marshal

func (m *SearchRequest) Marshal() (dAtA []byte, err error)

func (*SearchRequest) MarshalTo

func (m *SearchRequest) MarshalTo(dAtA []byte) (int, error)

func (*SearchRequest) MarshalToSizedBuffer

func (m *SearchRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*SearchRequest) ProtoMessage

func (*SearchRequest) ProtoMessage()

func (*SearchRequest) Reset

func (m *SearchRequest) Reset()

func (*SearchRequest) Size

func (m *SearchRequest) Size() (n int)

func (*SearchRequest) String

func (m *SearchRequest) String() string

func (*SearchRequest) Unmarshal

func (m *SearchRequest) Unmarshal(dAtA []byte) error

func (*SearchRequest) XXX_DiscardUnknown

func (m *SearchRequest) XXX_DiscardUnknown()

func (*SearchRequest) XXX_Marshal

func (m *SearchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SearchRequest) XXX_Merge

func (m *SearchRequest) XXX_Merge(src proto.Message)

func (*SearchRequest) XXX_Size

func (m *SearchRequest) XXX_Size() int

func (*SearchRequest) XXX_Unmarshal

func (m *SearchRequest) XXX_Unmarshal(b []byte) error

type SearchResponse

type SearchResponse struct {
	Documents []*types.Document `protobuf:"bytes,1,rep,name=Documents,proto3" json:"Documents,omitempty"`
}

func (*SearchResponse) Descriptor

func (*SearchResponse) Descriptor() ([]byte, []int)

func (*SearchResponse) GetDocuments

func (m *SearchResponse) GetDocuments() []*types.Document

func (*SearchResponse) Marshal

func (m *SearchResponse) Marshal() (dAtA []byte, err error)

func (*SearchResponse) MarshalTo

func (m *SearchResponse) MarshalTo(dAtA []byte) (int, error)

func (*SearchResponse) MarshalToSizedBuffer

func (m *SearchResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*SearchResponse) ProtoMessage

func (*SearchResponse) ProtoMessage()

func (*SearchResponse) Reset

func (m *SearchResponse) Reset()

func (*SearchResponse) Size

func (m *SearchResponse) Size() (n int)

func (*SearchResponse) String

func (m *SearchResponse) String() string

func (*SearchResponse) Unmarshal

func (m *SearchResponse) Unmarshal(dAtA []byte) error

func (*SearchResponse) XXX_DiscardUnknown

func (m *SearchResponse) XXX_DiscardUnknown()

func (*SearchResponse) XXX_Marshal

func (m *SearchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SearchResponse) XXX_Merge

func (m *SearchResponse) XXX_Merge(src proto.Message)

func (*SearchResponse) XXX_Size

func (m *SearchResponse) XXX_Size() int

func (*SearchResponse) XXX_Unmarshal

func (m *SearchResponse) XXX_Unmarshal(b []byte) error

type Sentinel

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

func NewSentinel

func NewSentinel(etcdServers []string) *Sentinel

func (*Sentinel) AddDoc

func (sentinel *Sentinel) AddDoc(doc types.Document) (int, error)

func (*Sentinel) Close

func (sentinel *Sentinel) Close() (err error)

func (*Sentinel) Count

func (sentinel *Sentinel) Count() int

func (*Sentinel) DeleteDoc

func (sentinel *Sentinel) DeleteDoc(docId string) int

func (*Sentinel) GetGrpcConn

func (sentinal *Sentinel) GetGrpcConn(endpoint string) *grpc.ClientConn

func (*Sentinel) Search

func (sentinel *Sentinel) Search(querys *types.TermQuery, onFlag, offFlag uint64, orFlags []uint64) []*types.Document

type ServiceHub

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

服务注册中心

func GetServiceHub

func GetServiceHub(etcdEndpoints []string, heartRate int64) *ServiceHub

func (*ServiceHub) Close

func (hub *ServiceHub) Close()

关闭etcd客户端连接

func (*ServiceHub) GetServiceEndpoint

func (hub *ServiceHub) GetServiceEndpoint(service string) string

根据负载均衡,从众多endpoint中选择一个

func (*ServiceHub) GetServiceEndpoints

func (hub *ServiceHub) GetServiceEndpoints(service string) []string

服务发现,client每次进行RPC调用之前都查询etcd,获取server集合,然后采用负载均衡算法选择一台server。或者也可以把负载均衡的功能放到注册中心,即放到getServiceEndpoints函数里,让它只返回一个server

func (*ServiceHub) Regist

func (hub *ServiceHub) Regist(service, endpoint string, leaseID etcdv3.LeaseID) (etcdv3.LeaseID, error)

func (*ServiceHub) UnRegist

func (hub *ServiceHub) UnRegist(service, endpoint string) error

注销服务

type ServiceHubProxy

type ServiceHubProxy struct {
	*ServiceHub // ServiceHubProxy拥有ServiceHub的所有方法(匿名成员变量)
	// contains filtered or unexported fields
}

代理模式,对ServiceHub做一层代理,提供缓存和限流保护

func GetServiceHubProxy

func GetServiceHubProxy(etcdEndpoints []string, heartRate int64, qps int) *ServiceHubProxy

func (*ServiceHubProxy) GetServiceEndpoints

func (proxy *ServiceHubProxy) GetServiceEndpoints(service string) []string

type UnimplementedIndexServiceServer

type UnimplementedIndexServiceServer struct {
}

UnimplementedIndexServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedIndexServiceServer) AddDoc

func (*UnimplementedIndexServiceServer) Count

func (*UnimplementedIndexServiceServer) DeleteDoc

func (*UnimplementedIndexServiceServer) Search

Jump to

Keyboard shortcuts

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