#include "dnxRegistrar.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxSleep.h"
#include "dnxLogging.h"
#include "dnxStats.h"
#include <assert.h>
#include <pthread.h>
Go to the source code of this file.
Data Structures | |
struct | iDnxRegistrar_ |
The internal registrar structure. More... | |
Defines | |
#define | DNX_REGISTRAR_REQUEST_TIMEOUT 5 |
Registrar dispatch channel timeout in seconds. | |
Typedefs | |
typedef struct iDnxRegistrar_ | iDnxRegistrar |
The internal registrar structure. | |
Functions | |
static DnxQueueResult | dnxCompareNodeReq (void *pLeft, void *pRight) |
Compare two node "request for work" requests for equality. | |
static int | dnxRegisterNode (iDnxRegistrar *ireg, DnxNodeRequest **ppMsg) |
Register a new client node "request for work" request. | |
static int | dnxDeregisterNode (iDnxRegistrar *ireg, DnxNodeRequest *pMsg) |
Deregister a node "request for work" request. | |
static void * | dnxRegistrar (void *data) |
The main thread entry point procedure for the registrar thread. | |
int | dnxGetNodeRequest (DnxRegistrar *reg, DnxNodeRequest **ppNode) |
Return an available node "request for work" object pointer. | |
int | dnxRegistrarCreate (DnxChannel *chan, unsigned queuesz, DnxRegistrar **preg) |
Create a new registrar object. | |
void | dnxRegistrarDestroy (DnxRegistrar *reg) |
Destroy a previously created registrar object. |
The purpose of this thread is to manage Worker Node registrations. When a Worker Node wants to receive service check jobs from the Scheduler Node, it must first register itself with the Scheduler Node by sending a UDP-based registration message to it.
The Registrar thread manages this registration process on behalf of the Scheduler.
Definition in file dnxRegistrar.c.
#define DNX_REGISTRAR_REQUEST_TIMEOUT 5 |
Registrar dispatch channel timeout in seconds.
Definition at line 48 of file dnxRegistrar.c.
Referenced by dnxRegistrar().
typedef struct iDnxRegistrar_ iDnxRegistrar |
The internal registrar structure.
static DnxQueueResult dnxCompareNodeReq | ( | void * | pLeft, | |
void * | pRight | |||
) | [static] |
Compare two node "request for work" requests for equality.
In the message exchange between the Registrar and client worker threads the XID.TYPE field will ALWAYS be DNX_OBJ_WORKER, so there is no need to compare this field because it will always be the same value. However, the XID.SERIAL field is configured as the worker's thread identifier, and the XID.SLOT field is configured as the worker's IP node address. Thus, the XID.SERIAL and XID.SLOT fields uniquely identify a given worker thread.
[in] | pLeft | - the left node to be compared. |
[in] | pRight | - the right node to be compared. |
Definition at line 76 of file dnxRegistrar.c.
References DNX_QRES_CONTINUE, DNX_QRES_FOUND, DnxXID::objSerial, and DnxXID::objSlot.
Referenced by dnxDeregisterNode(), and dnxRegisterNode().
static int dnxDeregisterNode | ( | iDnxRegistrar * | ireg, | |
DnxNodeRequest * | pMsg | |||
) | [static] |
Deregister a node "request for work" request.
Note that the found node is freed, but the search node remains valid on return from this routine.
[in] | ireg | - the registrar from which to deregister a client request. |
[in] | pMsg | - the dnx client request node to be deregistered. |
Definition at line 152 of file dnxRegistrar.c.
References DNX_OK, DNX_QRES_FOUND, dnxCompareNodeReq(), dnxQueueRemove(), iDnxRegistrar_::rqueue, and xfree.
Referenced by dnxRegistrar().
int dnxGetNodeRequest | ( | DnxRegistrar * | reg, | |
DnxNodeRequest ** | ppNode | |||
) |
Return an available node "request for work" object pointer.
[in] | reg | - the registrar from which a node request should be returned. |
[out] | ppNode | - the address of storage in which to return the located request node. |
Definition at line 236 of file dnxRegistrar.c.
Referenced by ehSvcCheck(), ProcessJobTransferMsg(), and processRequests().
static int dnxRegisterNode | ( | iDnxRegistrar * | ireg, | |
DnxNodeRequest ** | ppMsg | |||
) | [static] |
Register a new client node "request for work" request.
The message is either stored or used to find an existing node request that should be updated. If stored, ppMsg
is returned as zero so that it will be reallocated by the caller. In all other cases, the same message block can be reused by the caller for the next request.
[in] | ireg | - the registrar on which to register a new client request. |
[in] | ppMsg | - the address of the dnx client request node pointer. |
Definition at line 101 of file dnxRegistrar.c.
References DnxNodeRequest::address, DNX_OK, DNX_QRES_FOUND, dnxCompareNodeReq(), dnxDebug(), dnxErrorString(), dnxLog(), dnxQueueFind(), dnxQueuePut(), dnxStatsInc(), DnxNodeRequest::expires, REQUESTS_RECEIVED, iDnxRegistrar_::rqueue, and DnxNodeRequest::ttl.
Referenced by dnxRegistrar().
static void* dnxRegistrar | ( | void * | data | ) | [static] |
The main thread entry point procedure for the registrar thread.
This thread handles all inbound requests in a single-threaded fashion, so we can safely call dnxStatsInc here for new nodes.
[in] | data | - an opaque pointer to registrar thread data. This is actually a pointer to the dnx server global data structure. |
Definition at line 177 of file dnxRegistrar.c.
References DnxNodeRequest::address, iDnxRegistrar_::channel, DNX_ERR_TIMEOUT, DNX_ERR_UNSUPPORTED, DNX_OK, DNX_REGISTRAR_REQUEST_TIMEOUT, DNX_REQ_DEREGISTER, DNX_REQ_REGISTER, dnxCancelableSleep(), dnxDeregisterNode(), dnxErrorString(), dnxLog(), dnxRegisterNode(), dnxWaitForNodeRequest(), DnxNodeRequest::reqType, xfree, and xmalloc.
Referenced by dnxRegistrarCreate().
int dnxRegistrarCreate | ( | DnxChannel * | chan, | |
unsigned | queuesz, | |||
DnxRegistrar ** | preg | |||
) |
Create a new registrar object.
[in] | chan | - the dispatcher channel to use for receiving requests. |
[in] | queuesz | - the size of the queue to create in this registrar. |
[out] | preg | - the address of storage in which to return the newly created registrar. |
Definition at line 282 of file dnxRegistrar.c.
References iDnxRegistrar_::channel, DNX_ERR_MEMORY, DNX_ERR_THREAD, DNX_OK, dnxErrorString(), dnxLog(), dnxQueueCreate(), dnxQueueDestroy(), dnxRegistrar(), iDnxRegistrar_::rqueue, iDnxRegistrar_::tid, xfree, and xmalloc.
Referenced by dnxServerInit().
void dnxRegistrarDestroy | ( | DnxRegistrar * | reg | ) |
Destroy a previously created registrar object.
Signals the registrar thread, waits for it to stop, and frees allocated resources.
[in] | reg | - the registrar to be destroyed. |
Definition at line 318 of file dnxRegistrar.c.
Referenced by dnxServerDeInit().