edge

package
v0.16.25 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: BSD-3-Clause Imports: 39 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRestProxy added in v0.10.0

func NewRestProxy(onClientMessage, onServerMessage RestHandler) *restProxy

Types

type Builtin added in v0.5.0

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

Builtin keep track of pages distribution over Edge servers.

type DefaultDispatcher added in v0.16.5

type DefaultDispatcher struct{}

DefaultDispatcher is a default implementation of Dispatcher. You only need to set OnMessageFunc with

func (*DefaultDispatcher) Decode added in v0.16.5

func (s *DefaultDispatcher) Decode(data []byte, me *rony.MessageEnvelope) error

func (*DefaultDispatcher) Done added in v0.16.5

func (s *DefaultDispatcher) Done(ctx *DispatchCtx)

func (*DefaultDispatcher) Encode added in v0.16.5

func (s *DefaultDispatcher) Encode(conn rony.Conn, streamID int64, me *rony.MessageEnvelope) error

func (*DefaultDispatcher) OnClose added in v0.16.5

func (s *DefaultDispatcher) OnClose(conn rony.Conn)

func (*DefaultDispatcher) OnOpen added in v0.16.5

func (s *DefaultDispatcher) OnOpen(conn rony.Conn, kvs ...*rony.KeyValue)

type DispatchCtx

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

DispatchCtx holds the context of the dispatcher's request. Each DispatchCtx could hold one or many RequestCtx. DispatchCtx lives until the last of its RequestCtx children.

func (*DispatchCtx) BufferPop added in v0.1.9

func (ctx *DispatchCtx) BufferPop(f func(envelope *rony.MessageEnvelope)) bool

func (*DispatchCtx) BufferPopAll added in v0.10.0

func (ctx *DispatchCtx) BufferPopAll(f func(envelope *rony.MessageEnvelope))

func (*DispatchCtx) BufferPush added in v0.1.9

func (ctx *DispatchCtx) BufferPush(m *rony.MessageEnvelope)

func (*DispatchCtx) BufferSize added in v0.1.9

func (ctx *DispatchCtx) BufferSize() int32

func (*DispatchCtx) Conn

func (ctx *DispatchCtx) Conn() rony.Conn

func (*DispatchCtx) Debug

func (ctx *DispatchCtx) Debug()

func (*DispatchCtx) Fill added in v0.14.1

func (ctx *DispatchCtx) Fill(
	requestID uint64, constructor uint64, p proto.Message, kv ...*rony.KeyValue,
)

func (*DispatchCtx) FillEnvelope

func (ctx *DispatchCtx) FillEnvelope(e *rony.MessageEnvelope)

func (*DispatchCtx) Get

func (ctx *DispatchCtx) Get(key string) interface{}

func (*DispatchCtx) GetBool

func (ctx *DispatchCtx) GetBool(key string) bool

func (*DispatchCtx) GetBytes

func (ctx *DispatchCtx) GetBytes(key string, defaultValue []byte) []byte

func (*DispatchCtx) GetInt64

func (ctx *DispatchCtx) GetInt64(key string, defaultValue int64) int64

func (*DispatchCtx) GetString

func (ctx *DispatchCtx) GetString(key string, defaultValue string) string

func (*DispatchCtx) Kind added in v0.1.4

func (ctx *DispatchCtx) Kind() MessageKind

Kind identifies that this dispatch context is generated from Tunnel or Gateway. This helps developer to apply different strategies based on the source of the incoming message

func (*DispatchCtx) ServerID added in v0.1.9

func (ctx *DispatchCtx) ServerID() string

func (*DispatchCtx) Set

func (ctx *DispatchCtx) Set(key string, v interface{})

func (*DispatchCtx) StreamID

func (ctx *DispatchCtx) StreamID() int64

type Dispatcher

type Dispatcher interface {
	// Encode will be called on the outgoing messages to encode them into the connection.
	// it is responsible for write data to conn
	Encode(conn rony.Conn, streamID int64, me *rony.MessageEnvelope) error
	// Decode decodes the incoming wire messages and converts it to a rony.MessageEnvelope
	Decode(data []byte, me *rony.MessageEnvelope) error
	// Done will be called when the context has been finished, this lets cleaning up, or in case you need to flush the
	// messages and updates in one go.
	Done(ctx *DispatchCtx)
	// OnOpen will be called when a new connection has been opened
	OnOpen(conn rony.Conn, kvs ...*rony.KeyValue)
	// OnClose will be called when a connection is closed
	OnClose(conn rony.Conn)
}

type DummyGatewayConfig added in v0.1.8

type DummyGatewayConfig = dummyGateway.Config

type GossipClusterConfig added in v0.1.8

type GossipClusterConfig struct {
	Bootstrap      bool
	ReplicaSet     uint64
	GossipIP       string
	GossipPort     int
	AdvertisedIP   string
	AdvertisedPort int
}

type Handler

type Handler = func(ctx *RequestCtx, in *rony.MessageEnvelope)

type HandlerOption added in v0.5.7

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

HandlerOption is a structure holds all the information required for a handler.

func NewHandlerOptions added in v0.3.12

func NewHandlerOptions() *HandlerOption

func (*HandlerOption) Append added in v0.5.7

func (ho *HandlerOption) Append(h ...Handler) *HandlerOption

Append adds the h handlers after already set handlers

func (*HandlerOption) GatewayOnly added in v0.5.7

func (ho *HandlerOption) GatewayOnly() *HandlerOption

GatewayOnly makes this method only available through gateway messages.

func (*HandlerOption) Prepend added in v0.5.7

func (ho *HandlerOption) Prepend(h ...Handler) *HandlerOption

Prepend adds the h handlers before already set handlers

func (*HandlerOption) SetConstructor added in v0.6.3

func (ho *HandlerOption) SetConstructor(constructors ...uint64) *HandlerOption

func (*HandlerOption) SetHandler added in v0.6.3

func (ho *HandlerOption) SetHandler(h ...Handler) *HandlerOption

SetHandler replaces the handlers for this constructor with h

func (*HandlerOption) SetMethodName added in v0.16.0

func (ho *HandlerOption) SetMethodName(methodName string) *HandlerOption

SetMethodName set the method name for this handler, this is mostly used for Tracing.

func (*HandlerOption) SetServiceName added in v0.16.0

func (ho *HandlerOption) SetServiceName(serviceName string) *HandlerOption

SetServiceName set the service name for this handler, this is mostly used for Tracing.

func (*HandlerOption) TunnelOnly added in v0.5.7

func (ho *HandlerOption) TunnelOnly() *HandlerOption

TunnelOnly makes this method only available through tunnel messages.

type InsertOption added in v0.10.0

type InsertOption func(*trieNode)

InsertOption is just a function which accepts a pointer to a trieNode which can alt its `Handler`, `Tag` and `Data` fields. See `WithHandler`, `WithTag` and `WithData`.

func WithProxyFactory added in v0.10.0

func WithProxyFactory(proxy RestProxy) InsertOption

WithProxyFactory sets the node's `Handler` field (useful for HTTP).

func WithTag added in v0.10.0

func WithTag(tag string) InsertOption

WithTag sets the node's `Tag` field (maybe useful for HTTP).

type JSONDispatcher added in v0.16.5

type JSONDispatcher struct{}

func (*JSONDispatcher) Decode added in v0.16.5

func (j *JSONDispatcher) Decode(data []byte, me *rony.MessageEnvelope) error

func (*JSONDispatcher) Done added in v0.16.5

func (j *JSONDispatcher) Done(ctx *DispatchCtx)

func (*JSONDispatcher) Encode added in v0.16.5

func (j *JSONDispatcher) Encode(conn rony.Conn, streamID int64, me *rony.MessageEnvelope) error

func (*JSONDispatcher) OnClose added in v0.16.5

func (j *JSONDispatcher) OnClose(conn rony.Conn)

func (*JSONDispatcher) OnOpen added in v0.16.5

func (j *JSONDispatcher) OnOpen(conn rony.Conn, kvs ...*rony.KeyValue)

type MessageKind added in v0.5.8

type MessageKind byte
const (
	GatewayMessage MessageKind
	TunnelMessage
)

func (MessageKind) String added in v0.5.8

func (c MessageKind) String() string

type Option

type Option func(edge *Server)

func WithCustomDispatcher added in v0.14.11

func WithCustomDispatcher(d Dispatcher) Option

WithCustomDispatcher enables custom dispatcher to write your specific event handlers.

func WithCustomGateway added in v0.16.0

func WithCustomGateway(gateway rony.Gateway) Option

func WithCustomRouter added in v0.14.1

func WithCustomRouter(r rony.Router) Option

func WithCustomerCluster added in v0.14.1

func WithCustomerCluster(c rony.Cluster) Option

func WithGossipCluster added in v0.1.5

func WithGossipCluster(clusterConfig GossipClusterConfig) Option

WithGossipCluster enables the cluster in gossip mode. This mod is eventually consistent mode but there is no need to a central key-value store or any other 3rd party service to run the cluster

func WithJSONDispatcher added in v0.16.5

func WithJSONDispatcher() Option

func WithScyllaRouter added in v0.14.1

func WithScyllaRouter(config ScyllaRouterConfig) Option

func WithSqlRouter added in v0.14.6

func WithSqlRouter(config SqlRouterConfig) Option

func WithTcpGateway

func WithTcpGateway(gatewayConfig TcpGatewayConfig) Option

WithTcpGateway set the gateway to tcp which can support http and/or websocket Only one gateway could be set and if you set another gateway it panics on runtime.

func WithTestGateway

func WithTestGateway(gatewayConfig DummyGatewayConfig) Option

WithTestGateway set the gateway to a dummy gateway which is useful for writing tests. Only one gateway could be set and if you set another gateway it panics on runtime.

func WithTracer added in v0.16.0

func WithTracer(tracer trace.Tracer) Option

func WithUdpTunnel added in v0.1.8

func WithUdpTunnel(config UdpTunnelConfig) Option

WithUdpTunnel set the tunnel to a udp based tunnel which provides communication channel between edge servers.

type ParamsSetter added in v0.10.0

type ParamsSetter interface {
	Set(string, interface{})
}

ParamsSetter is the interface which should be implemented by the params writer for `search` in order to store the found named path parameters, if any.

type RequestCtx

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

RequestCtx holds the context of an RPC handler

func (*RequestCtx) Cluster added in v0.2.10

func (ctx *RequestCtx) Cluster() rony.Cluster

func (*RequestCtx) ClusterEdges added in v0.9.0

func (ctx *RequestCtx) ClusterEdges(replicaSet uint64, edges *rony.Edges) (*rony.Edges, error)

func (*RequestCtx) Conn

func (ctx *RequestCtx) Conn() rony.Conn

func (*RequestCtx) ConnID

func (ctx *RequestCtx) ConnID() uint64

func (*RequestCtx) Context added in v0.16.1

func (ctx *RequestCtx) Context() context.Context

func (*RequestCtx) Error added in v0.14.30

func (ctx *RequestCtx) Error() *rony.Error

func (*RequestCtx) Get

func (ctx *RequestCtx) Get(key string) interface{}

func (*RequestCtx) GetBool

func (ctx *RequestCtx) GetBool(key string) bool

func (*RequestCtx) GetBytes

func (ctx *RequestCtx) GetBytes(key string, defaultValue []byte) []byte

func (*RequestCtx) GetInt64

func (ctx *RequestCtx) GetInt64(key string, defaultValue int64) int64

func (*RequestCtx) GetString

func (ctx *RequestCtx) GetString(key string, defaultValue string) string

func (*RequestCtx) Kind added in v0.1.4

func (ctx *RequestCtx) Kind() MessageKind

func (*RequestCtx) Log added in v0.3.18

func (ctx *RequestCtx) Log() log.Logger

Log returns a logger

func (*RequestCtx) NextCanGo added in v0.14.1

func (ctx *RequestCtx) NextCanGo()

NextCanGo is useful only if the main request is rony.MessageContainer with SyncRun flag set to TRUE. Then by calling this function it lets the next request (if any) executed concurrently.

func (*RequestCtx) PushCustomError

func (ctx *RequestCtx) PushCustomError(code, item string, desc string)

func (*RequestCtx) PushCustomMessage

func (ctx *RequestCtx) PushCustomMessage(
	requestID uint64, constructor uint64, message proto.Message, kvs ...*rony.KeyValue,
)

PushCustomMessage would do different actions based on the Conn. If connection is persistent (i.e. Websocket) then Rony sends the message down to the wire real time. If the connection is not persistent (i.e. HTTP) then Rony push the message into a temporary buffer and at the end of the life-time of the RequestCtx pushes the message as response. If there was multiple message in the buffer then Rony creates a MessageContainer and wrap all those messages in that container. Client needs to unwrap MessageContainer when ever they see it in the response.

func (*RequestCtx) PushError

func (ctx *RequestCtx) PushError(err *rony.Error)

func (*RequestCtx) PushMessage

func (ctx *RequestCtx) PushMessage(constructor uint64, proto proto.Message)

PushMessage is a wrapper func for PushCustomMessage.

func (*RequestCtx) PushRedirectRequest added in v0.2.10

func (ctx *RequestCtx) PushRedirectRequest(replicaSet uint64)

PushRedirectRequest redirects the client to another server with replicaSet for only this request. This function call StopExecution internally and further handlers would not be called.

func (*RequestCtx) PushRedirectSession added in v0.2.10

func (ctx *RequestCtx) PushRedirectSession(replicaSet uint64)

PushRedirectSession redirects the client to another server with replicaSet for the rest of the request for this session. The interpretation of session is defined by the application and does not have any side effect on internal states of the Edge server. This function call StopExecution internally and further handlers would not be called.

func (*RequestCtx) ReplicaSet added in v0.5.7

func (ctx *RequestCtx) ReplicaSet() uint64

func (*RequestCtx) ReqID

func (ctx *RequestCtx) ReqID() uint64

func (*RequestCtx) Router added in v0.14.1

func (ctx *RequestCtx) Router() rony.Router

func (*RequestCtx) ServerID added in v0.1.4

func (ctx *RequestCtx) ServerID() string

func (*RequestCtx) Set

func (ctx *RequestCtx) Set(key string, v interface{})

func (*RequestCtx) Span added in v0.16.0

func (ctx *RequestCtx) Span() trace.Span

Span returns a tracer span. Don't End the span, since it will be closed automatically at the end of RequestCtx lifecycle.

func (*RequestCtx) StopExecution

func (ctx *RequestCtx) StopExecution()

func (*RequestCtx) Stopped

func (ctx *RequestCtx) Stopped() bool

func (*RequestCtx) TryTunnelRequest added in v0.9.0

func (ctx *RequestCtx) TryTunnelRequest(
	attempts int, retryWait time.Duration, replicaSet uint64,
	req, res *rony.MessageEnvelope,
) error

func (*RequestCtx) TunnelRequest added in v0.9.0

func (ctx *RequestCtx) TunnelRequest(replicaSet uint64, req, res *rony.MessageEnvelope) error

type RestHandler added in v0.10.0

type RestHandler func(conn rony.RestConn, ctx *DispatchCtx) error

type RestProxy added in v0.10.0

type RestProxy interface {
	ClientMessage(conn rony.RestConn, ctx *DispatchCtx) error
	ServerMessage(conn rony.RestConn, ctx *DispatchCtx) error
}

type ScyllaRouterConfig added in v0.14.1

type ScyllaRouterConfig struct {
	DbSession gocqlx.Session
}

type Server

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

Server represents Edge serve. Edge server sticks all other parts of the system together.

func NewServer

func NewServer(serverID string, opts ...Option) *Server

func (*Server) Cluster added in v0.3.16

func (edge *Server) Cluster() rony.Cluster

Cluster returns a reference to the underlying cluster of the Edge server

func (*Server) Gateway added in v0.5.18

func (edge *Server) Gateway() rony.Gateway

Gateway returns a reference to the underlying gateway of the Edge server

func (*Server) GetGatewayConn added in v0.0.6

func (edge *Server) GetGatewayConn(connID uint64) rony.Conn

GetGatewayConn return the gateway connection identified by connID or returns nil if not found.

func (*Server) GetHandler added in v0.5.7

func (edge *Server) GetHandler(constructor uint64) *HandlerOption

GetHandler returns the handlers of the constructor

func (*Server) GetServerID

func (edge *Server) GetServerID() string

GetServerID return this server id, which MUST be unique in the cluster otherwise the behaviour is unknown.

func (*Server) SetCustomDispatcher added in v0.14.11

func (edge *Server) SetCustomDispatcher(d Dispatcher)

SetCustomDispatcher replace the default dispatcher with your custom dispatcher. Usually you don't need to use custom dispatcher, but in some rare cases you can implement your own custom dispatcher

func (*Server) SetGlobalPostHandlers added in v0.3.8

func (edge *Server) SetGlobalPostHandlers(handlers ...Handler)

SetGlobalPostHandlers set the handler which will be called after executing any request. These pre handlers are like middlewares which will be automatically triggered for each request. If you want to set post handler for specific request then you must use SetHandlers, PrependHandlers or AppendHandlers

func (*Server) SetGlobalPreHandlers added in v0.3.8

func (edge *Server) SetGlobalPreHandlers(handlers ...Handler)

SetGlobalPreHandlers set the handler which will be called before executing any request. These pre handlers are like middlewares which will be automatically triggered for each request. If you want to set pre handler for specific request then you must use SetHandlers, PrependHandlers or AppendHandlers

func (*Server) SetHandler added in v0.5.7

func (edge *Server) SetHandler(ho *HandlerOption)

SetHandler set the handlers for the constructor.

func (*Server) SetRestProxy added in v0.10.0

func (edge *Server) SetRestProxy(method string, path string, p RestProxy)

SetRestProxy set a REST wrapper to expose RPCs in REST (Representational State Transfer) format

func (*Server) Shutdown

func (edge *Server) Shutdown()

Shutdown gracefully shutdown the services

func (*Server) ShutdownWithSignal

func (edge *Server) ShutdownWithSignal(signals ...os.Signal) error

ShutdownWithSignal blocks until any of the signals has been called

func (*Server) Start added in v0.1.9

func (edge *Server) Start()

Start is a helper function which tries to start all three parts of the edge server This function does not return any error, if you need to make sure all the parts are started with no error, then you must start each section separately. i.e. use StartGateway, StartCluster and StartTunnel functions.

func (*Server) StartCluster

func (edge *Server) StartCluster() (err error)

StartCluster is non-blocking function which runs the cluster component of the Edge server.

func (*Server) StartGateway

func (edge *Server) StartGateway() error

StartGateway is non-blocking function runs the gateway in background, so we can accept clients requests

func (*Server) StartTunnel added in v0.1.9

func (edge *Server) StartTunnel() error

StartTunnel is non-blocking function runs the gateway in background, so we can accept other servers requests

func (*Server) Stats

func (edge *Server) Stats() Stats

Stats exports some internal metrics data packed in 'Stats' struct

func (*Server) TryTunnelRequest added in v0.9.0

func (edge *Server) TryTunnelRequest(
	attempts int, retryWait time.Duration, replicaSet uint64,
	req, res *rony.MessageEnvelope,
) error

func (*Server) Tunnel added in v0.9.0

func (edge *Server) Tunnel() rony.Tunnel

Tunnel returns a reference to the underlying tunnel of the Edge server

func (*Server) TunnelRequest added in v0.9.0

func (edge *Server) TunnelRequest(replicaSet uint64, req, res *rony.MessageEnvelope) error

TunnelRequest sends and receives a request through the Tunnel interface of the receiver Edge node.

func (*Server) WaitForSignal added in v0.12.15

func (edge *Server) WaitForSignal(signals ...os.Signal)

type SqlRouterConfig added in v0.14.6

type SqlRouterConfig struct {
	DB *gorm.DB
}

type Stats

type Stats struct {
	Address         string
	ReplicaSet      uint64
	Members         int
	MembershipScore int
	TunnelAddr      []string
	GatewayProtocol rony.GatewayProtocol
	GatewayAddr     []string
}

Stats exports some internal metrics data

type TcpGatewayConfig added in v0.1.8

type TcpGatewayConfig struct {
	Concurrency   int
	ListenAddress string
	MaxBodySize   int
	MaxIdleTime   time.Duration
	Protocol      rony.GatewayProtocol
	ExternalAddrs []string
	TextDataFrame bool
}

type UdpTunnelConfig added in v0.1.8

type UdpTunnelConfig struct {
	ListenAddress string
	MaxBodySize   int
	ExternalAddrs []string
}

Jump to

Keyboard shortcuts

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