types

package
v0.0.0-...-705e2cb Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TASK_MSG_DESTROY    = iota //0 TASK_MSG_DESTROY enum of Message tpe starts with 0
	TASK_MSG_MAKEMASTER        //1
	TASK_MSG_SLAVEOF
)
View Source
const (
	ETC_BASE_DIR = "/MrRedis"
	ETC_INST_DIR = ETC_BASE_DIR + "/Instances"
	ETC_CONF_DIR = ETC_BASE_DIR + "/Config"
)

global Constants releated to ETCD

View Source
const (
	INST_STATUS_CREATING = "CREATING"
	INST_STATUS_RUNNING  = "RUNNING"
	INST_STATUS_DISABLED = "DISABLED"
	INST_STATUS_DELETED  = "DELETED"
)

Global constants for Instance Status CREATING/ACTIVE/DELETED/DISABLED

View Source
const (
	INST_TYPE_SINGLE       = "S"  //A Single instance redis-server
	INST_TYPE_MASTER_SLAVE = "MS" //A redis instance with master-slave
)

Const for instance type

View Source
const (
	PROC_TYPE_MASTER = "M"
	PROC_TYPE_SLAVE  = "S"
)

const for type of the redis-server

Variables

View Source
var (
	Gdb          store.DB //Gdb Golabal variables related to db connection/instace
	MemDb        *InMem   //In memory store
	IsRegistered bool     //Default flag

	OfferList *list.List        //list for having offer
	Cchan     chan TaskCreate   //Channel for Creator
	Mchan     chan *TaskUpdate  //Channel for Maintainer
	Dchan     chan TaskMsg      //Channel for Destroyer
	Agents    *agentstate.State //A Global View of aggents and the Instnaces book keeping
)

Functions

func Initialize

func Initialize(dbtype string, config string) (bool, error)

Initialize Initialize all the data strucutres in common package, should be called by the main program only and should be called only once per program

Types

type InMem

type InMem struct {
	I map[string]*Instance //Map of instances
}

InMem a structure for maintaining InMemory cache about all the instances, All the api's interactive with the DB should first check this MAP before actually reading form the DB. for changes it should also update this map first before updating the DB

func NewInMem

func NewInMem() *InMem

NewInMem is called when you want to initialize the In Memory cache for the first time

func (*InMem) Add

func (inMem *InMem) Add(name string, instance *Instance) (bool, error)

Add Use add to add a new Instance entry in the inmemory, throws error if the element already exist

func (*InMem) Delete

func (inMem *InMem) Delete(name string) (bool, error)

Delete use thsi to Delete an element from the cache

func (*InMem) Get

func (inMem *InMem) Get(name string) *Instance

Get get an Instance pointer from the cache

func (*InMem) IsValid

func (inMem *InMem) IsValid(name string) bool

IsValid A quick look up function to see if a key is available in the inmemory cache

func (*InMem) Update

func (inMem *InMem) Update(name string, instance *Instance) (bool, error)

Update use this to update an existing value, throws error otherwise

type Instance

type Instance struct {
	Name              string           //Name of the instance
	Type              string           //Type of the instance "Single Instance = S; Master-Slave  = MS; Cluster = C"
	Capacity          int              //Capacity of the Instance in MB
	Masters           int              //Number of masters in this Instance
	Slaves            int              //Number of slaves in this Instance
	ExpMasters        int              //Expected number of Masters
	ExpSlaves         int              //Expected number of Slaves
	Status            string           //Status of this instance "CREATING/RUNNING/DISABLED"
	Mname             string           //Name / task id of the master redis proc
	Snames            []string         //Name of the slave
	Procs             map[string]*Proc //An array of redis procs to be filled later
	DistributionValue int              //HOw many redis-server that belong to this proc can be started in a single slave, Default to 1
}

A Instance structure that will be able to store a tree of data, Everything related to a redis intance

func LoadInstance

func LoadInstance(Name string) *Instance

LoadInstance Load an instance from the store using Instance Name from the store if the instance is unavailable then return nil

func NewInstance

func NewInstance(Name string, Type string, Masters int, Slaves int, Cap int) *Instance

NewInstance Creates a new instance variable Fills up the structure and updates the central store Returns an instance pointer Returns nil if the instance already exists

func (*Instance) Load

func (I *Instance) Load() bool

Load Loads up the datastructure for the given Service Name to the struture If the Instance cannot be loaded the it returns an error

func (*Instance) LoadProcs

func (I *Instance) LoadProcs() bool

LoadProcs Should be called when all the PROCs need to be loaded to the lateest value, PS High DISK intensive function, should be used carefully

func (*Instance) Sync

func (I *Instance) Sync() bool

Sync Writes the entier content of an instance into store, an instance could have many keys to be updated this is a write intensive function should be used carefully, do not call this if you are planning to update only a single attribute of an instance

func (*Instance) SyncMasters

func (I *Instance) SyncMasters() bool

SyncMasters Flushes only the master attribute to the DB, used when a new redis master is choose.

func (*Instance) SyncSlaves

func (I *Instance) SyncSlaves() bool

SyncSlaves Flushes only the Slaves attribute to the DB, used when a Slave died or promoted as a master

func (*Instance) SyncStatus

func (I *Instance) SyncStatus() bool

SyncStatus Flushes only the status attribute to the DB

func (*Instance) SyncType

func (I *Instance) SyncType(string) bool

SyncType Write only the TYPE attribute to the DB/store

func (*Instance) ToJson

func (I *Instance) ToJson() string

ToJson Marshall the Instane to a JSON

func (*Instance) ToJson_Obj

func (I *Instance) ToJson_Obj() Instance_Json

ToJson_Obj Filtered elementes of an Instnace that will be sent as an HTTP response

type Instance_Json

type Instance_Json struct {
	Name     string
	Type     string
	Status   string
	Capacity int
	Master   *ProcJson
	Slaves   []*ProcJson
}

Instance_Json Filtered elementes of an Instnace that will be sent as an HTTP response

type Offer

type Offer struct {
	Name         string //Name of the instance
	Taskname     string //Name of the redis proc
	Cpu          int    //CPU default is one
	Mem          int    //Memory in MB
	DValue       int    //Distribution Value
	IsMaster     bool   //Is this instance a master
	MasterIpPort string //If this is slave then send the masters IP and prot number
}

Offer Structure that is used between creator and Mesos Scheduler

func NewOffer

func NewOffer(name string, tname string, cpu int, mem int, ismaster bool, masterIPPort string, dvalue int) Offer

NewOffer Returns a new offer which will be interpreted by the scheduler

type Proc

type Proc struct {
	Instance string //Name of the instance it belongs to
	Nodename string //Node name at which this should start syncing its details to
	MemCap   int    //Maximum Memory this instance can go to
	MemUsed  int    //Current usage of the memory
	Pid      int    //Unix Process id of this running instance
	ID       string //UUID that was generated for this PROC
	State    string //Current state of the process Active/Dead/Crashed etc.,
	Type     string //Type of the PROC master/Slave etc.,
	SlaveOf  string //Slave of which redis master
	Stats    string //All other statistics apart from Memory usage to be stored as a json/string
	Msg      string //Message we will revive fromt he scheduler and action to be taken on it
	IP       string //IP address of the slave at which this redis-server proc is running
	Port     string //Port number at which this PROC is bound to
	EID      string //Executor ID of this PROC  .. Just in case we need to send a framework messsage
	SID      string //Slave ID of this PROC .. Just in case we need to send a framework message

}

Proc A standalone redis KV store is usually started in any slave (Linux) like below $./redis-server -p <PORT> ..... {OPTIONS} This stand alone redis-server will be an actual unix process bound to a particular port witha PID A redis Master Slave setup will have two such "redis-server" processes running in either the same machine or two different machines A redis KV with one master and 3 slaves will have a total of 4 "redis-server" processes running The below structure "Proc" is a representation of such a running 'redis-server' process started via this framework This started/running "Proc" could be a Master/Standalone instance or could be a Slave of another "redis-server' running as a master

func LoadProc

func LoadProc(TskName string) *Proc

LoadProc Load a Proc information from the store and populate a structure

func NewProc

func NewProc(TskName string, Capacity int, Type string, SlaveOf string) *Proc

NewProc Constructor for a PROC struct, this does not sync anything to the DB

func (*Proc) Load

func (P *Proc) Load() bool

Load the latest from KV store

func (*Proc) LoadMsg

func (P *Proc) LoadMsg() bool

LoadMsg Get the latest MSG from the scheduler, usually called by the executor(RedMon)

func (*Proc) LoadStats

func (P *Proc) LoadStats() *Stats

LoadStats get the latest STATS info from the store, usually called by the scheduler to make a decision

func (*Proc) LoadType

func (P *Proc) LoadType() bool

LoadType Update what is the current type of a PROC, usually called by the scheduler

func (*Proc) Sync

func (P *Proc) Sync() bool

Sync everything thats in-memory to the KV store, should be used only when you have more attributes to be synced/written to the DB at the same time, Disk intensive operation

func (*Proc) SyncMsg

func (P *Proc) SyncMsg() bool

SyncMsg Should be used only to update a MSG with respect to a PROC

func (*Proc) SyncSlaveOf

func (P *Proc) SyncSlaveOf() bool

SyncSlaveOf should be used to make a slave (proc) point to a new master

func (*Proc) SyncStats

func (P *Proc) SyncStats(s Stats) bool

SyncStats Updates only the statistic related information to the disk, used by RedMon every second

func (*Proc) SyncType

func (P *Proc) SyncType() bool

SyncType should be used to only update the TYPE attribute of a PROC

func (*Proc) ToJson

func (P *Proc) ToJson() *ProcJson

ToJson Convert a PROC to json but only selected fileds

func (*Proc) ToJsonStats

func (P *Proc) ToJsonStats(stats Stats) string

ToJsonStats The stats are always store in JSON format in the DB/Store against a single key

type ProcJson

type ProcJson struct {
	IP                 string
	Port               string
	MemoryCapacity     int
	MemoryUsed         int64
	Uptime             int64
	ClientsConnected   int
	LastSyncedToMaster int
}

ProcJson Fields to be packed in a json when replied to a HTTP REST query.

type Rec

type Rec struct {
	Key           string
	Value         []byte
	Section       bool
	SectionValues []Rec
}

Rec Type that represents each Record

type Stats

type Stats struct {
	Uptime        int64
	Mem           int64
	Clients       int
	LastSyced     int
	SlaveOffset   int64 //Offset of the slave
	SlavePriority int
}

Stats the whole stats structure could be a json structure reflecting all the fields what redis info returns currently one field has many new line saperated values;ToDO will this work if returned in API?

type TaskCreate

type TaskCreate struct {
	M bool //Is this a master or slave
	I *Instance
	C int //count of number of instance to be created
}

TaskCreate Type that is interpreted by the Creator Thread

func CreateMaster

func CreateMaster(i *Instance) TaskCreate

CreateMaster Wrapper for Create a TaskCreate variable of type Master

func CreateSlaves

func CreateSlaves(i *Instance, c int) TaskCreate

CreateSlaves Wrapper for Create a TaskCreate variable of type Slave

func NewTaskCreate

func NewTaskCreate(m bool, i *Instance, c int) TaskCreate

NewTaskCreate Constructor of TaskCreate

type TaskMsg

type TaskMsg struct {
	MSG int
	P   *Proc
}

TaskMsg Type that is used to communicate with Destroyer

type TaskUpdate

type TaskUpdate struct {
	Name    string
	State   string
	SlaveId string
	Data    []byte
}

TaskUpdate type used to communicate with Maintainer goroutine

Jump to

Keyboard shortcuts

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