Documentation ¶
Index ¶
- Variables
- func SendCountOpWithSession(ses *Session, sid, queryWithJSQ string, queryWithObj *tables.Object, ...) error
- func SendPutOpWithSession(ses *Session, sid string, data interface{}) error
- func SendQueryOp(ses *Session, queryWithJSQ string, queryWithObj *tables.Object, limit int, ...) error
- func SendQueryOpWithSession(ses *Session, sid, queryWithJSQ string, queryWithObj *tables.Object, limit int, ...) error
- type Agent
- type AgentInfo
- type ConsulRegistry
- type Op
- type OpType
- type RegItem
- type Session
- func (s *Session) Commit(id string)
- func (s *Session) CommitEnd(id string)
- func (s *Session) CreateSession(id, identityID string) (string, error)
- func (s *Session) CreateUnregisteredSession(id, identityID string) (sid string)
- func (s *Session) End(id string)
- func (s *Session) GetAgent(id string) *AgentInfo
- func (s *Session) GetAgents() map[string]*AgentInfo
- func (s *Session) HasSession(id string) bool
- func (s *Session) NumSessions() int
- func (s *Session) Rollback(id string)
- func (s *Session) RollbackEnd(id string)
- func (s *Session) SendOp(id string, op *Op) error
- func (s *Session) SetDB(db patchain.DB)
- func (s *Session) Stop()
- type SessionRegistry
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = fmt.Errorf("not found")
ErrNotFound indicates that a session was not found
var SessionTTL = "900s"
Functions ¶
func SendCountOpWithSession ¶
func SendCountOpWithSession(ses *Session, sid, queryWithJSQ string, queryWithObj *tables.Object, out interface{}) error
SendCountOpWithSession sends a query operation using an existing session id
func SendPutOpWithSession ¶
SendPutOpWithSession sends a PUT operation using an existing session id
Types ¶
type Agent ¶
Agent defines a structure for an agent that holds a database session
type ConsulRegistry ¶
type ConsulRegistry struct {
// contains filtered or unexported fields
}
ConsulRegistry implements a session registry based on consul. It satisfies SessionRegistry interface.
func NewConsulRegistry ¶
func NewConsulRegistry() (r *ConsulRegistry, err error)
NewConsulRegistry creates a new consul registry. Connection to consul is attempted, error is returned on failure to connect.
func (*ConsulRegistry) Add ¶
func (r *ConsulRegistry) Add(item RegItem) error
Add registers a new session
func (*ConsulRegistry) Del ¶
func (r *ConsulRegistry) Del(sid string) (err error)
Del deletes a session. Returns nil if the session was deleted successfully or it doesn't exists
type Op ¶
type Op struct { OpType OpType PutData interface{} QueryWithJSQ string QueryWithObject *tables.Object Out interface{} Done chan struct{} Limit int OrderBy string Error error }
Op represents an agent operation
type OpType ¶
type OpType int
OpType represents a db connection operation
var ( // OpPutObjects represents an object creation operation. OpPutObjects OpType = 1 // OpGetObjects represents a get object operation OpGetObjects OpType = 2 // OpCountObjects represents a count operation OpCountObjects OpType = 3 // MaxSessionIdleTime is the maximum duration a session can be idle before stopping MaxSessionIdleTime = 10 * time.Minute // ErrAgentBusy represents an agent in busy state ErrAgentBusy = fmt.Errorf("agent is busy") )
type RegItem ¶
type RegItem struct { Address string `json:"address"` Port int `json:"port"` SID string `json:"sid"` Meta map[string]interface{} `json:"meta"` }
RegItem defines a session registry item
type Session ¶
Session defines a structure for a partition chain session manager
func NewSession ¶
func NewSession(sessionReg SessionRegistry) *Session
NewSession creates a new partition chain session
func (*Session) CommitEnd ¶
CommitEnd commits the current transaction of an agent and removes the session/agent
func (*Session) CreateSession ¶
CreateSession creates a new session agent
func (*Session) CreateUnregisteredSession ¶
CreateUnregisteredSession creates a session that is not registered
func (*Session) HasSession ¶
HasSession checks whether a session exists
func (*Session) NumSessions ¶
NumSessions returns the number of active sessions
func (*Session) RollbackEnd ¶
RollbackEnd rolls back the current transaction of an agent and removes the session/agent