dnxRegistrar.c File Reference

Implements the DNX Registrar thread. More...

#include "dnxRegistrar.h"
#include "dnxNebMain.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxQueue.h"
#include "dnxSleep.h"
#include "dnxTransport.h"
#include "dnxSrvProt.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 (unsigned queuesz, DnxChannel *dispchan, DnxRegistrar **preg)
 Create a new registrar object.
void dnxRegistrarDestroy (DnxRegistrar *reg)
 Destroy a previously created registrar object.


Detailed Description

Implements the DNX Registrar thread.

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.

Author:
Robert W. Ingraham (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxRegistrar.c.


Define Documentation

#define DNX_REGISTRAR_REQUEST_TIMEOUT   5

Registrar dispatch channel timeout in seconds.

Definition at line 52 of file dnxRegistrar.c.


Typedef Documentation

typedef struct iDnxRegistrar_ iDnxRegistrar

The internal registrar structure.


Function Documentation

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.

Parameters:
[in] pLeft - the left node to be compared.
[in] pRight - the right node to be compared.
Returns:
DNX_QRES_FOUND on match; DNX_QRES_CONTINUE if no match.

Definition at line 80 of file dnxRegistrar.c.

References DNX_QRES_CONTINUE, DNX_QRES_FOUND, DnxXID::objSerial, and DnxXID::objSlot.

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.

Parameters:
[in] ireg - the registrar from which to deregister a client request.
[in] pMsg - the dnx client request node to be deregistered.
Returns:
Always returns zero.

Definition at line 156 of file dnxRegistrar.c.

References DNX_OK, DNX_QRES_FOUND, dnxCompareNodeReq(), dnxQueueRemove(), iDnxRegistrar_::rqueue, and xfree.

int dnxGetNodeRequest ( DnxRegistrar reg,
DnxNodeRequest **  ppNode 
)

Return an available node "request for work" object pointer.

Parameters:
[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.
Returns:
Zero on success, or a non-zero error value.

Definition at line 237 of file dnxRegistrar.c.

References DNX_ERR_TIMEOUT, DNX_OK, dnxDebug(), dnxErrorString(), dnxQueueGet(), dnxStatsInc(), JOBS_REJECTED_NO_NODES, REQUESTS_EXPIRED, iDnxRegistrar_::rqueue, and xfree.

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.

Parameters:
[in] ireg - the registrar on which to register a new client request.
[in] ppMsg - the address of the dnx client request node pointer.
Returns:
Zero on success, or a non-zero error value.

Definition at line 105 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.

static void* dnxRegistrar ( void *  data  )  [static]

The main thread entry point procedure for the registrar thread.

Parameters:
[in] data - an opaque pointer to registrar thread data. This is actually a pointer to the dnx server global data structure.
Returns:
Always returns NULL.

Definition at line 178 of file dnxRegistrar.c.

References DnxNodeRequest::address, iDnxRegistrar_::dispchan, 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.

int dnxRegistrarCreate ( unsigned  queuesz,
DnxChannel dispchan,
DnxRegistrar **  preg 
)

Create a new registrar object.

Parameters:
[in] queuesz - the size of the queue to create in this registrar.
[in] dispchan - a pointer to the dispatcher channel.
[out] preg - the address of storage in which to return the newly created registrar.
Returns:
Zero on success, or a non-zero error value.

Definition at line 285 of file dnxRegistrar.c.

References iDnxRegistrar_::dispchan, DNX_ERR_MEMORY, DNX_ERR_THREAD, DNX_OK, dnxErrorString(), dnxLog(), dnxQueueCreate(), dnxRegistrar(), iDnxRegistrar_::rqueue, iDnxRegistrar_::tid, xfree, and xmalloc.

void dnxRegistrarDestroy ( DnxRegistrar reg  ) 

Destroy a previously created registrar object.

Signals the registrar thread, waits for it to stop, and frees allocated resources.

Parameters:
[in] reg - the registrar to be destroyed.

Definition at line 319 of file dnxRegistrar.c.

References dnxQueueDestroy(), iDnxRegistrar_::rqueue, iDnxRegistrar_::tid, and xfree.


Generated on Tue Apr 13 15:48:08 2010 for DNX by  doxygen 1.5.6