mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-18 21:59:30 +00:00
renamed newMessagesCh to ringBufferBulkInCh
This commit is contained in:
parent
698706b41f
commit
ccd57dad10
4 changed files with 47 additions and 66 deletions
|
@ -52,7 +52,7 @@ func newErrorKernel(ctx context.Context, m *metrics) *errorKernel {
|
||||||
// process if it should continue or not based not based on how severe
|
// process if it should continue or not based not based on how severe
|
||||||
// the error where. This should be right after sending the error
|
// the error where. This should be right after sending the error
|
||||||
// sending in the process.
|
// sending in the process.
|
||||||
func (e *errorKernel) start(newMessagesCh chan<- []subjectAndMessage) error {
|
func (e *errorKernel) start(ringBufferBulkInCh chan<- []subjectAndMessage) error {
|
||||||
// NOTE: For now it will just print the error messages to the
|
// NOTE: For now it will just print the error messages to the
|
||||||
// console.
|
// console.
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ func (e *errorKernel) start(newMessagesCh chan<- []subjectAndMessage) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the message on the channel to the ringbuffer.
|
// Put the message on the channel to the ringbuffer.
|
||||||
newMessagesCh <- []subjectAndMessage{sam}
|
ringBufferBulkInCh <- []subjectAndMessage{sam}
|
||||||
|
|
||||||
e.metrics.promErrorMessagesSentTotal.Inc()
|
e.metrics.promErrorMessagesSentTotal.Inc()
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (s *server) readSocket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the SAM struct to be picked up by the ring buffer.
|
// Send the SAM struct to be picked up by the ring buffer.
|
||||||
s.newMessagesCh <- sams
|
s.ringBufferBulkInCh <- sams
|
||||||
|
|
||||||
}(conn)
|
}(conn)
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func (s *server) readTCPListener() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the SAM struct to be picked up by the ring buffer.
|
// Send the SAM struct to be picked up by the ring buffer.
|
||||||
s.newMessagesCh <- sam
|
s.ringBufferBulkInCh <- sam
|
||||||
|
|
||||||
}(conn)
|
}(conn)
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func (s *server) readHTTPlistenerHandler(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the SAM struct to be picked up by the ring buffer.
|
// Send the SAM struct to be picked up by the ring buffer.
|
||||||
s.newMessagesCh <- sam
|
s.ringBufferBulkInCh <- sam
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,10 @@ type ringBuffer struct {
|
||||||
permStore chan string
|
permStore chan string
|
||||||
// Name of node.
|
// Name of node.
|
||||||
nodeName Node
|
nodeName Node
|
||||||
// newMessagesCh from *server are also implemented here,
|
// ringBufferBulkInCh from *server are also implemented here,
|
||||||
// so the ringbuffer can send it's error messages the same
|
// so the ringbuffer can send it's error messages the same
|
||||||
// way as all messages are handled.
|
// way as all messages are handled.
|
||||||
newMessagesCh chan []subjectAndMessage
|
ringBufferBulkInCh chan []subjectAndMessage
|
||||||
metrics *metrics
|
metrics *metrics
|
||||||
configuration *Configuration
|
configuration *Configuration
|
||||||
errorKernel *errorKernel
|
errorKernel *errorKernel
|
||||||
|
@ -58,7 +58,7 @@ type ringBuffer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newringBuffer returns a push/pop storage for values.
|
// newringBuffer returns a push/pop storage for values.
|
||||||
func newringBuffer(ctx context.Context, metrics *metrics, configuration *Configuration, size int, dbFileName string, nodeName Node, newMessagesCh chan []subjectAndMessage, samValueBucket string, indexValueBucket string, errorKernel *errorKernel, processInitial process) *ringBuffer {
|
func newringBuffer(ctx context.Context, metrics *metrics, configuration *Configuration, size int, dbFileName string, nodeName Node, ringBufferBulkInCh chan []subjectAndMessage, samValueBucket string, indexValueBucket string, errorKernel *errorKernel, processInitial process) *ringBuffer {
|
||||||
|
|
||||||
// Check if socket folder exists, if not create it
|
// Check if socket folder exists, if not create it
|
||||||
if _, err := os.Stat(configuration.DatabaseFolder); os.IsNotExist(err) {
|
if _, err := os.Stat(configuration.DatabaseFolder); os.IsNotExist(err) {
|
||||||
|
@ -86,7 +86,7 @@ func newringBuffer(ctx context.Context, metrics *metrics, configuration *Configu
|
||||||
indexValueBucket: indexValueBucket,
|
indexValueBucket: indexValueBucket,
|
||||||
permStore: make(chan string),
|
permStore: make(chan string),
|
||||||
nodeName: nodeName,
|
nodeName: nodeName,
|
||||||
newMessagesCh: newMessagesCh,
|
ringBufferBulkInCh: ringBufferBulkInCh,
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
configuration: configuration,
|
configuration: configuration,
|
||||||
processInitial: processInitial,
|
processInitial: processInitial,
|
||||||
|
@ -141,7 +141,6 @@ func (r *ringBuffer) fillBuffer(ctx context.Context, inCh chan subjectAndMessage
|
||||||
er := fmt.Errorf("info: fillBuffer: retreival of values from k/v store failed, probaly empty database, and no previous entries in db to process: %v", err)
|
er := fmt.Errorf("info: fillBuffer: retreival of values from k/v store failed, probaly empty database, and no previous entries in db to process: %v", err)
|
||||||
log.Printf("%v\n", er)
|
log.Printf("%v\n", er)
|
||||||
return
|
return
|
||||||
//sendErrorLogMessage(r.newMessagesCh, node(r.nodeName), er)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range s {
|
for _, v := range s {
|
||||||
|
|
46
server.go
46
server.go
|
@ -40,17 +40,12 @@ type server struct {
|
||||||
processes *processes
|
processes *processes
|
||||||
// The name of the node
|
// The name of the node
|
||||||
nodeName string
|
nodeName string
|
||||||
// newMessagesCh are the channel where new messages to be handled
|
// ringBufferBulkInCh are the channel where new messages in a bulk
|
||||||
// by the system are put. So if any process want's to send a message
|
// format (slice) are put into the system.
|
||||||
// like an error message you just put the message on the newMessagesCh.
|
|
||||||
//
|
//
|
||||||
// In general the ringbuffer will read this
|
// In general the ringbuffer will read this
|
||||||
// channel for messages to put on the buffer.
|
// channel, unfold each slice, and put single messages on the buffer.
|
||||||
//
|
ringBufferBulkInCh chan []subjectAndMessage
|
||||||
// Example:
|
|
||||||
// A message is read from the socket, then put on the newMessagesCh
|
|
||||||
// and then put on the ringbuffer.
|
|
||||||
newMessagesCh chan []subjectAndMessage
|
|
||||||
// errorKernel is doing all the error handling like what to do if
|
// errorKernel is doing all the error handling like what to do if
|
||||||
// an error occurs.
|
// an error occurs.
|
||||||
errorKernel *errorKernel
|
errorKernel *errorKernel
|
||||||
|
@ -149,7 +144,7 @@ func NewServer(c *Configuration, version string) (*server, error) {
|
||||||
natsConn: conn,
|
natsConn: conn,
|
||||||
StewardSocket: stewardSocket,
|
StewardSocket: stewardSocket,
|
||||||
processes: newProcesses(ctx, metrics, tuiClient, errorKernel),
|
processes: newProcesses(ctx, metrics, tuiClient, errorKernel),
|
||||||
newMessagesCh: make(chan []subjectAndMessage),
|
ringBufferBulkInCh: make(chan []subjectAndMessage),
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
version: version,
|
version: version,
|
||||||
tui: tuiClient,
|
tui: tuiClient,
|
||||||
|
@ -214,7 +209,7 @@ func (s *server) Start() {
|
||||||
s.metrics.promVersion.With(prometheus.Labels{"version": string(s.version)})
|
s.metrics.promVersion.With(prometheus.Labels{"version": string(s.version)})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := s.errorKernel.start(s.newMessagesCh)
|
err := s.errorKernel.start(s.ringBufferBulkInCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v\n", err)
|
log.Printf("%v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -251,7 +246,7 @@ func (s *server) Start() {
|
||||||
//
|
//
|
||||||
// NB: The context of the initial process are set in processes.Start.
|
// NB: The context of the initial process are set in processes.Start.
|
||||||
sub := newSubject(REQInitial, s.nodeName)
|
sub := newSubject(REQInitial, s.nodeName)
|
||||||
s.processInitial = newProcess(context.TODO(), s.metrics, s.natsConn, s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, "", nil)
|
s.processInitial = newProcess(context.TODO(), s.metrics, s.natsConn, s.processes, s.ringBufferBulkInCh, s.configuration, sub, s.errorKernel.errorCh, "", nil)
|
||||||
// Start all wanted subscriber processes.
|
// Start all wanted subscriber processes.
|
||||||
s.processes.Start(s.processInitial)
|
s.processes.Start(s.processInitial)
|
||||||
|
|
||||||
|
@ -266,7 +261,7 @@ func (s *server) Start() {
|
||||||
|
|
||||||
if s.configuration.EnableTUI {
|
if s.configuration.EnableTUI {
|
||||||
go func() {
|
go func() {
|
||||||
err := s.tui.Start(s.ctx, s.newMessagesCh)
|
err := s.tui.Start(s.ctx, s.ringBufferBulkInCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v\n", err)
|
log.Printf("%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -308,26 +303,13 @@ func (s *server) Stop() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendErrorMessage will put the error message directly on the channel that is
|
|
||||||
// read by the nats publishing functions.
|
|
||||||
//
|
|
||||||
// Deprecated.
|
|
||||||
// func sendErrorLogMessage(conf *Configuration, metrics *metrics, newMessagesCh chan<- []subjectAndMessage, FromNode Node, theError error) {
|
|
||||||
// // NB: Adding log statement here for more visuality during development.
|
|
||||||
// log.Printf("%v\n", theError)
|
|
||||||
// sam := createErrorMsgContent(conf, FromNode, theError)
|
|
||||||
// newMessagesCh <- []subjectAndMessage{sam}
|
|
||||||
//
|
|
||||||
// metrics.promErrorMessagesSentTotal.Inc()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sendInfoMessage will put the error message directly on the channel that is
|
// sendInfoMessage will put the error message directly on the channel that is
|
||||||
// read by the nats publishing functions.
|
// read by the nats publishing functions.
|
||||||
func sendInfoLogMessage(conf *Configuration, metrics *metrics, newMessagesCh chan<- []subjectAndMessage, FromNode Node, theError error) {
|
func sendInfoLogMessage(conf *Configuration, metrics *metrics, ringBufferBulkInCh chan<- []subjectAndMessage, FromNode Node, theError error) {
|
||||||
// NB: Adding log statement here for more visuality during development.
|
// NB: Adding log statement here for more visuality during development.
|
||||||
log.Printf("%v\n", theError)
|
log.Printf("%v\n", theError)
|
||||||
sam := createErrorMsgContent(conf, FromNode, theError)
|
sam := createErrorMsgContent(conf, FromNode, theError)
|
||||||
newMessagesCh <- []subjectAndMessage{sam}
|
ringBufferBulkInCh <- []subjectAndMessage{sam}
|
||||||
|
|
||||||
metrics.promInfoMessagesSentTotal.Inc()
|
metrics.promInfoMessagesSentTotal.Inc()
|
||||||
}
|
}
|
||||||
|
@ -366,7 +348,7 @@ type samDBValueAndDelivered struct {
|
||||||
// routeMessagesToProcess takes a database name it's input argument.
|
// routeMessagesToProcess takes a database name it's input argument.
|
||||||
// The database will be used as the persistent k/v store for the work
|
// The database will be used as the persistent k/v store for the work
|
||||||
// queue which is implemented as a ring buffer.
|
// queue which is implemented as a ring buffer.
|
||||||
// The newMessagesCh are where we get new messages to publish.
|
// The ringBufferInCh are where we get new messages to publish.
|
||||||
// Incomming messages will be routed to the correct subject process, where
|
// Incomming messages will be routed to the correct subject process, where
|
||||||
// the handling of each nats subject is handled within it's own separate
|
// the handling of each nats subject is handled within it's own separate
|
||||||
// worker process.
|
// worker process.
|
||||||
|
@ -378,7 +360,7 @@ func (s *server) routeMessagesToProcess(dbFileName string) {
|
||||||
const samValueBucket string = "samValueBucket"
|
const samValueBucket string = "samValueBucket"
|
||||||
const indexValueBucket string = "indexValueBucket"
|
const indexValueBucket string = "indexValueBucket"
|
||||||
|
|
||||||
s.ringBuffer = newringBuffer(s.ctx, s.metrics, s.configuration, bufferSize, dbFileName, Node(s.nodeName), s.newMessagesCh, samValueBucket, indexValueBucket, s.errorKernel, s.processInitial)
|
s.ringBuffer = newringBuffer(s.ctx, s.metrics, s.configuration, bufferSize, dbFileName, Node(s.nodeName), s.ringBufferBulkInCh, samValueBucket, indexValueBucket, s.errorKernel, s.processInitial)
|
||||||
|
|
||||||
ringBufferInCh := make(chan subjectAndMessage)
|
ringBufferInCh := make(chan subjectAndMessage)
|
||||||
ringBufferOutCh := make(chan samDBValueAndDelivered)
|
ringBufferOutCh := make(chan samDBValueAndDelivered)
|
||||||
|
@ -391,7 +373,7 @@ func (s *server) routeMessagesToProcess(dbFileName string) {
|
||||||
// we loop here, unfold the slice, and put single subjectAndMessages's on
|
// we loop here, unfold the slice, and put single subjectAndMessages's on
|
||||||
// the channel to the ringbuffer.
|
// the channel to the ringbuffer.
|
||||||
go func() {
|
go func() {
|
||||||
for sams := range s.newMessagesCh {
|
for sams := range s.ringBufferBulkInCh {
|
||||||
for _, sam := range sams {
|
for _, sam := range sams {
|
||||||
ringBufferInCh <- sam
|
ringBufferInCh <- sam
|
||||||
}
|
}
|
||||||
|
@ -483,7 +465,7 @@ func (s *server) routeMessagesToProcess(dbFileName string) {
|
||||||
// log.Printf("info: processNewMessages: did not find that specific subject, starting new process for subject: %v\n", subjName)
|
// log.Printf("info: processNewMessages: did not find that specific subject, starting new process for subject: %v\n", subjName)
|
||||||
|
|
||||||
sub := newSubject(sam.Subject.Method, sam.Subject.ToNode)
|
sub := newSubject(sam.Subject.Method, sam.Subject.ToNode)
|
||||||
proc := newProcess(s.ctx, s.metrics, s.natsConn, s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, processKindPublisher, nil)
|
proc := newProcess(s.ctx, s.metrics, s.natsConn, s.processes, s.ringBufferBulkInCh, s.configuration, sub, s.errorKernel.errorCh, processKindPublisher, nil)
|
||||||
|
|
||||||
proc.spawnWorker(s.processes, s.natsConn)
|
proc.spawnWorker(s.processes, s.natsConn)
|
||||||
// log.Printf("info: processNewMessages: new process started, subject: %v, processID: %v\n", subjName, proc.processID)
|
// log.Printf("info: processNewMessages: new process started, subject: %v, processID: %v\n", subjName, proc.processID)
|
||||||
|
|
Loading…
Add table
Reference in a new issue