server

package
v0.0.0-...-1fef4f5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RpcRequestTimeout   = 30 * time.Second
	AlwaysRetryBoundary = 0
)
View Source
const (
	ClientIDSplitChar = ":"
	DbkeysSplitChar   = ","
)
View Source
const (
	CronPeriod = 20e9
)
View Source
const IpPortSplitChar = ":"

Variables

This section is empty.

Functions

This section is empty.

Types

type ATCore

type ATCore struct {
	AbstractCore
}

func (*ATCore) LockQuery

func (core *ATCore) LockQuery(branchType meta.BranchType,
	resourceID string,
	xid string,
	lockKeys string) bool

type AbstractCore

type AbstractCore struct {
	MessageSender ServerMessageSender
}

*

  • +--------------------+-----------------------+--------------------+
  • | TC |Method(InBound) |Method(OutBound) |
  • +--------------------+-----------------------+--------------------+
  • | |Begin | |
  • | |BranchRegister | |
  • | AT&TCC |BranchReport |branchCommit |
  • | (DefaultCore) |Commit |branchRollback |
  • | |Rollback | |
  • | |GetStatus | |
  • +--------------------+-----------------------+--------------------+
  • | AT |LockQuery | |
  • +--------------------+-----------------------+--------------------+
  • | |(GlobalReport) | |
  • | |doGlobalCommit | |
  • | SAGA |doGlobalRollBack | |
  • | |doGlobalReport | |
  • +--------------------+-----------------------+--------------------+ *
  • 参考 [effective go 之 Embedding](#https://my.oschina.net/pengfeix/blog/109967)
  • Go does not provide the typical, type-driven notion of subclassing,
  • but it does have the ability to “borrow” pieces of an implementation
  • by embedding types within a struct or interface.
  • Go 没有像其它面向对象语言中的类继承概念,但是,它可以通过在结构体或者接口中嵌入
  • 其它的类型,来使用被嵌入类型的功能。 *
  • 原本 JAVA 版 Starfish Sever 设计了 Core 接口,AbstractCore 实现该接口,ATCore、
  • TccCore、SagaCore 都继承 AbstractCore。使 ATCore、TccCore、SagaCore 每一
  • 个类单独拿出来都是 Core 接口的实现。但 Go 版的 Starfish 我不打算这样设计。我们将
  • Core 接口里定义的接口方法拿出来,如上面的表格所示,一个全局事务的周期分别对应 Begin、
  • BranchRegister、BranchReport、Commit、Rollback 接口方法,这些接口方法适用于
  • AT 模式和 TCC 模式(SAGA 模式暂不了解,先不考虑)。AT 模式会多一个 LockQuery
  • 的接口。另外 OutBound 方向上有两个接口 branchCommit、branchRollback。JAVA 版
  • 的设计中 doGlobalCommit、doGlobalRollBack、doGlobalReport 其实是私有方法,
  • 这里用首字母小些开头的方法区分。那么 Go 版本的 DefaultCore 设计就出来了(暂不考虑 SAGA),
  • DefaultCore 内嵌入 ATCore。 *

type DefaultCoordinator

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

func NewDefaultCoordinator

func NewDefaultCoordinator(conf *config.ServerConfig) *DefaultCoordinator

func (*DefaultCoordinator) OnCheckMessage

func (coordinator *DefaultCoordinator) OnCheckMessage(rpcMessage protocal.RpcMessage, session getty.Session)

func (*DefaultCoordinator) OnClose

func (coordinator *DefaultCoordinator) OnClose(session getty.Session)

func (*DefaultCoordinator) OnCron

func (coordinator *DefaultCoordinator) OnCron(session getty.Session)

func (*DefaultCoordinator) OnError

func (coordinator *DefaultCoordinator) OnError(session getty.Session, err error)

func (*DefaultCoordinator) OnMessage

func (coordinator *DefaultCoordinator) OnMessage(session getty.Session, pkg interface{})

func (*DefaultCoordinator) OnOpen

func (coordinator *DefaultCoordinator) OnOpen(session getty.Session) error

func (*DefaultCoordinator) OnRegRmMessage

func (coordinator *DefaultCoordinator) OnRegRmMessage(rpcMessage protocal.RpcMessage, session getty.Session)

func (*DefaultCoordinator) OnRegTmMessage

func (coordinator *DefaultCoordinator) OnRegTmMessage(rpcMessage protocal.RpcMessage, session getty.Session)

func (*DefaultCoordinator) OnTrxMessage

func (coordinator *DefaultCoordinator) OnTrxMessage(rpcMessage protocal.RpcMessage, session getty.Session)

func (*DefaultCoordinator) SendASyncRequest

func (coordinator *DefaultCoordinator) SendASyncRequest(session getty.Session, message interface{}) error

func (*DefaultCoordinator) SendResponse

func (coordinator *DefaultCoordinator) SendResponse(request protocal.RpcMessage, session getty.Session, msg interface{})

func (*DefaultCoordinator) SendSyncRequest

func (coordinator *DefaultCoordinator) SendSyncRequest(resourceID string, clientID string, message interface{}) (interface{}, error)

func (*DefaultCoordinator) SendSyncRequestByGetty

func (coordinator *DefaultCoordinator) SendSyncRequestByGetty(session getty.Session, message interface{}) (interface{}, error)

func (*DefaultCoordinator) SendSyncRequestByGettyWithTimeout

func (coordinator *DefaultCoordinator) SendSyncRequestByGettyWithTimeout(session getty.Session, message interface{}, timeout time.Duration) (interface{}, error)

func (*DefaultCoordinator) SendSyncRequestWithTimeout

func (coordinator *DefaultCoordinator) SendSyncRequestWithTimeout(resourceID string, clientID string, message interface{}, timeout time.Duration) (interface{}, error)

func (*DefaultCoordinator) Stop

func (coordinator *DefaultCoordinator) Stop()

type DefaultCore

type DefaultCore struct {
	AbstractCore
	ATCore
	SAGACore
	// contains filtered or unexported fields
}

func (*DefaultCore) Begin

func (core *DefaultCore) Begin(applicationID string, transactionServiceGroup string, name string, timeout int32) (string, error)

func (*DefaultCore) BranchRegister

func (core *DefaultCore) BranchRegister(branchType meta.BranchType,
	resourceID string,
	clientID string,
	xid string,
	applicationData []byte,
	lockKeys string) (int64, error)

func (*DefaultCore) BranchReport

func (core *DefaultCore) BranchReport(branchType meta.BranchType,
	xid string,
	branchID int64,
	status meta.BranchStatus,
	applicationData []byte) error

func (*DefaultCore) Commit

func (core *DefaultCore) Commit(xid string) (meta.GlobalStatus, error)

func (*DefaultCore) GetStatus

func (core *DefaultCore) GetStatus(xid string) (meta.GlobalStatus, error)

func (*DefaultCore) GlobalReport

func (core *DefaultCore) GlobalReport(xid string, globalStatus meta.GlobalStatus) (meta.GlobalStatus, error)

func (*DefaultCore) LockQuery

func (core *DefaultCore) LockQuery(branchType meta.BranchType, resourceID string, xid string, lockKeys string) (bool, error)

func (*DefaultCore) Rollback

func (core *DefaultCore) Rollback(xid string) (meta.GlobalStatus, error)

type GettySessionManager

type GettySessionManager struct {
	TransactionServiceGroup string
	Version                 string
}
var SessionManager GettySessionManager

func (*GettySessionManager) GetContextFromIdentified

func (manager *GettySessionManager) GetContextFromIdentified(session getty.Session) *RpcContext

func (*GettySessionManager) GetGettySession

func (manager *GettySessionManager) GetGettySession(resourceID string, clientID string) (getty.Session, error)

func (*GettySessionManager) GetRmSessions

func (manager *GettySessionManager) GetRmSessions() map[string]getty.Session

func (*GettySessionManager) GetRoleFromGettySession

func (manager *GettySessionManager) GetRoleFromGettySession(session getty.Session) meta.TransactionRole

func (*GettySessionManager) GetSameClientGettySession

func (manager *GettySessionManager) GetSameClientGettySession(session getty.Session) getty.Session

func (*GettySessionManager) IsRegistered

func (manager *GettySessionManager) IsRegistered(session getty.Session) bool

func (*GettySessionManager) RegisterRmGettySession

func (manager *GettySessionManager) RegisterRmGettySession(request protocal.RegisterRMRequest, session getty.Session)

func (*GettySessionManager) RegisterTmGettySession

func (manager *GettySessionManager) RegisterTmGettySession(request protocal.RegisterTMRequest, session getty.Session)

func (*GettySessionManager) ReleaseGettySession

func (manager *GettySessionManager) ReleaseGettySession(session getty.Session)

type RpcContext

type RpcContext struct {
	Version                 string
	TransactionServiceGroup string
	ClientRole              meta.TransactionRole
	ApplicationID           string
	ClientID                string
	ResourceSets            *model.Set
	Session                 getty.Session
}

func NewRpcContext

func NewRpcContext(opts ...RpcContextOption) *RpcContext

func (*RpcContext) AddResource

func (context *RpcContext) AddResource(resource string)

func (*RpcContext) AddResources

func (context *RpcContext) AddResources(resources *model.Set)

type RpcContextOption

type RpcContextOption func(ctx *RpcContext)

func WithRpcContextApplicationID

func WithRpcContextApplicationID(applicationID string) RpcContextOption

func WithRpcContextClientID

func WithRpcContextClientID(clientID string) RpcContextOption

func WithRpcContextClientRole

func WithRpcContextClientRole(clientRole meta.TransactionRole) RpcContextOption

func WithRpcContextResourceSet

func WithRpcContextResourceSet(resourceSet *model.Set) RpcContextOption

func WithRpcContextSession

func WithRpcContextSession(session getty.Session) RpcContextOption

func WithRpcContextTxServiceGroup

func WithRpcContextTxServiceGroup(txServiceGroup string) RpcContextOption

func WithRpcContextVersion

func WithRpcContextVersion(version string) RpcContextOption

type SAGACore

type SAGACore struct {
	AbstractCore
}

type Server

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

func NewServer

func NewServer() *Server

func (*Server) Start

func (s *Server) Start(addr string)

func (*Server) Stop

func (s *Server) Stop()

type ServerMessageListener

type ServerMessageListener interface {
	OnTrxMessage(rpcMessage protocal.RpcMessage, session getty.Session)

	OnRegRmMessage(request protocal.RpcMessage, session getty.Session)

	OnRegTmMessage(request protocal.RpcMessage, session getty.Session)

	OnCheckMessage(request protocal.RpcMessage, session getty.Session)
}

type ServerMessageSender

type ServerMessageSender interface {

	// Send response.
	SendResponse(request protocal.RpcMessage, session getty.Session, msg interface{})

	// Sync call to RM
	SendSyncRequest(resourceID string, clientID string, message interface{}) (interface{}, error)

	// Sync call to RM with timeout.
	SendSyncRequestWithTimeout(resourceID string, clientID string, message interface{}, timeout time.Duration) (interface{}, error)

	// Send request with response object.
	SendSyncRequestByGetty(session getty.Session, message interface{}) (interface{}, error)

	// Send request with response object.
	SendSyncRequestByGettyWithTimeout(session getty.Session, message interface{}, timeout time.Duration) (interface{}, error)

	// ASync call to RM
	SendASyncRequest(session getty.Session, message interface{}) error
}

type TCInboundHandler

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

type TransactionCoordinator

type TransactionCoordinator interface {
	TransactionCoordinatorInbound
	TransactionCoordinatorOutbound
	// contains filtered or unexported methods
}

type TransactionCoordinatorInbound

type TransactionCoordinatorInbound interface {
	tm.TransactionManager
	rm.ResourceManagerOutbound
}

type TransactionCoordinatorOutbound

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

Jump to

Keyboard shortcuts

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