Exemple #1
0
GCD_CIB *
gcd_new_cib( u_i2 count )
{
    GCD_CIB	*cib = NULL;
    u_i2	len = sizeof( GCD_CIB ) + (sizeof(CONN_PARM) * (count - 1));

    if ( count < ARR_SIZE( GCD_global.cib_free ) )
	if (! (cib = (GCD_CIB *)QUremove(GCD_global.cib_free[count].q_next)))
	    if ( (cib = (GCD_CIB *)MEreqmem( 0, len, FALSE, NULL )) )
		cib->id = GCD_global.cib_total++;

    if ( ! cib )
	gcu_erlog(0, GCD_global.language, E_GC4808_NO_MEMORY, NULL, 0, NULL);
    else  
    {
	u_i4	id = cib->id;
	char	buff[16];

	MEfill( len, 0, (PTR)cib );
	cib->id = id;
	cib->parm_max = count;
	QUinit( &cib->caps );

	MOulongout( 0, (u_i8)cib->id, sizeof( buff ), buff );
	MOattach( MO_INSTANCE_VAR, GCD_MIB_DBMS, buff, (PTR)cib );

	GCD_global.cib_active++;

	if ( GCD_global.gcd_trace_level >= 6 )
	    TRdisplay( "%4d    GCD new CIB (%d)\n", -1, cib->id );
    }

    return( cib );
}
Exemple #2
0
/*
** Name: ddc_sess_attach - make an instance based on the session name.
**
** Description:
**
**      Wrapper for MOattach.  Create an instance of the WTS_SESSION.
**
** Inputs:
**
**      name            name of active session (unique key)
**      dbSession       pointer to a cached db session structure
**
** Outputs:
**
**      none
**
** Returns:
**      OK              function completed successfully
**
** History:
**      02-Mar-98 (fanra01)
**          Created.
**
*/
STATUS
ddc_sess_attach (PDB_CACHED_SESSION  dbSession)
{
	STATUS status;
	char name[80];

	status = MOptrout(0, (PTR)dbSession, sizeof(name), name);
	if (status == OK)
		status = MOattach (MO_INSTANCE_VAR, db_access_name, name, (PTR)dbSession);
return(status);
}
Exemple #3
0
static STATUS
tbl_attach( i4  nelem, MO_INSTANCE_DEF *idp )
{
    STATUS ret_val = OK;
    
    for( ; nelem-- && idp->classid != NULL ; idp++ )
	if( (ret_val = MOattach( idp->flags, idp->classid,
			     idp->instance, idp->idata ) ) != OK )
	    break;

    if( ret_val != OK )
	SIprintf("stat attaching %s:%s:\n%s\n",
		 idp->classid, idp->instance, er_decode( ret_val ));


    return( ret_val );
}
Exemple #4
0
VOID
CS_sampler(void)
{
	CS_SCB	*an_scb;
	i4 	sleeptime, elapsed, seconds, event;
	i4	starttime, stoptime;
	i4 	cs_thread_type;
	i4 	cs_state;
	bool	attached = FALSE;
	u_i4	bior, biow;
	u_i4	dior, diork, diow, diowk;
	u_i4	lior, liork, liow, liowk;

  /*
  ** This thread goes into a loop:
  **	1. Lock the sampler block
  **	2. Do sampling
  **	3. Sleep for the specified interval
  ** The thread will exit normally when the sampler block pointer is NULL.
  ** The thread exits abnormally if it cannot lock the block.
  */
  starttime = CS_checktime();
  elapsed = 0;

  /* Prime the local I/O, Transaction rate counters */
  bior  = Cs_srv_block.cs_wtstatistics.cs_bior_done;
  biow  = Cs_srv_block.cs_wtstatistics.cs_biow_done;
  dior  = Cs_srv_block.cs_wtstatistics.cs_dior_done;
  diork = Cs_srv_block.cs_wtstatistics.cs_dior_kbytes;
  diow  = Cs_srv_block.cs_wtstatistics.cs_diow_done;
  diowk = Cs_srv_block.cs_wtstatistics.cs_diow_kbytes;
  lior  = Cs_srv_block.cs_wtstatistics.cs_lior_done;
  liork = Cs_srv_block.cs_wtstatistics.cs_lior_kbytes;
  liow  = Cs_srv_block.cs_wtstatistics.cs_liow_done;
  liowk = Cs_srv_block.cs_wtstatistics.cs_liow_kbytes;

  /* Transaction rates cannot be determined */
  CsSamplerBlkPtr->txn[CURR] = 0;
  CsSamplerBlkPtr->txn[PEAK] = 0;

  for (;;)
  {
				 
    if (LockSamplerBlk(&hCsSamplerSem) != OK)
    {
    	ExitThread((DWORD)-1);
    }

    if (CsSamplerBlkPtr->shutdown)
    {
	/*
	** Detach the sampler block Managed Object
	*/
	if (attached)
	    MOdetach(CSsamp_index_name, "CsSamplerBlkPtr");

	MEfree((PTR)CsSamplerBlkPtr);
	CsSamplerBlkPtr = NULL;

	CSsamp_stopping = TRUE;
    	UnlockSamplerBlk(hCsSamplerSem);
	CloseHandle(hCsSamplerSem);
	hCsSamplerSem = NULL;

    	ExitThread(0);
    }

    if (!attached)
    {
	/*
	** Attach the sampler block Managed Object
	*/
	MOattach(MO_INSTANCE_VAR, CSsamp_index_name, "CsSamplerBlkPtr",
		 (PTR) CsSamplerBlkPtr);
	attached = TRUE;
    }

    ++CsSamplerBlkPtr->numsamples;   /* Count the number of times we sample */

    /* Loop thru all the SCBs in the server */
    for (an_scb = Cs_srv_block.cs_known_list->cs_next;
    	 an_scb && an_scb != Cs_srv_block.cs_known_list;
	 an_scb = an_scb->cs_next)
    {
	if (an_scb->cs_thread_type >= -1 && 
	    an_scb->cs_thread_type <= MAXSAMPTHREADS - 1)
	    cs_thread_type = an_scb->cs_thread_type;
	else
	    cs_thread_type = MAXSAMPTHREADS - 1; /* use the <invalid> thread */

	/* If Factotum thread, try to isolate which kind */
	if ( cs_thread_type == CS_FACTOTUM )
	{
	    if ( MEcmp((char *)&an_scb->cs_username, " <WriteBehind", 13) == 0 )
		cs_thread_type = CS_WRITE_BEHIND;
	    else if ( MEcmp((char *)&an_scb->cs_username, " <Sort", 6) == 0 )
		cs_thread_type = CS_SORT;
	}

	if (an_scb->cs_state >= 0 &&
	    an_scb->cs_state <= MAXSTATES - 1) 
	    cs_state = an_scb->cs_state;
	else
	    cs_state = MAXSTATES - 1;		/* use the <invalid> state */

	++CsSamplerBlkPtr->Thread[cs_thread_type].numthreadsamples;

	if ( cs_thread_type == CS_NORMAL )
	    ++CsSamplerBlkPtr->totusersamples;
	else
	    ++CsSamplerBlkPtr->totsyssamples;

	switch (cs_state)
	{
	    case CS_COMPUTABLE:		/* Count current facility */
	    {	
	    	i4  facility;

		++CsSamplerBlkPtr->Thread[cs_thread_type].state[cs_state];
		facility = (*Cs_srv_block.cs_facility)(an_scb);
		if (facility >= MAXFACS || facility < 0)
		    facility = MAXFACS - 1;
		++CsSamplerBlkPtr->Thread[cs_thread_type].facility[facility];
		break;
	    }

	    case CS_EVENT_WAIT:		/* Count event types */
		if ( an_scb->cs_memory & CS_BIO_MASK )
		    ++CsSamplerBlkPtr->Thread[cs_thread_type].evwait[EV_BIO];
		else if ( an_scb->cs_memory & CS_DIO_MASK )
		    ++CsSamplerBlkPtr->Thread[cs_thread_type].evwait[EV_DIO];
		else if ( an_scb->cs_memory & CS_LIO_MASK )
		    ++CsSamplerBlkPtr->Thread[cs_thread_type].evwait[EV_LIO];
		else if ( an_scb->cs_memory & CS_LOG_MASK )
		    ++CsSamplerBlkPtr->Thread[cs_thread_type].evwait[EV_LOG];
		else if (an_scb->cs_memory & CS_LOCK_MASK)
		{
		    ++CsSamplerBlkPtr->Thread[cs_thread_type].evwait[EV_LOCK];
		    AddLock( an_scb->cs_sync_obj ?
		    		*((LK_LOCK_KEY *)an_scb->cs_sync_obj) :
		    		dummy_lock,
			     cs_thread_type );
		}
		else
		    ++CsSamplerBlkPtr->Thread[cs_thread_type].state[cs_state];
		event = (an_scb->cs_memory & CS_DIO_MASK ?
			  an_scb->cs_memory & CS_IOR_MASK ?
			  0 : 1
			 :
			 an_scb->cs_memory & CS_LIO_MASK ?
			  an_scb->cs_memory & CS_IOR_MASK ?
			  2 : 3
			 :
			 an_scb->cs_memory & CS_BIO_MASK ?
			  an_scb->cs_memory & CS_IOR_MASK ?
			  4 : 5
			 :
			 an_scb->cs_memory & CS_LOG_MASK ?
			  6 :
			 an_scb->cs_memory & CS_LOCK_MASK ?
			  7 :
			 an_scb->cs_memory & CS_LGEVENT_MASK ?
			  8 :
			 an_scb->cs_memory & CS_LKEVENT_MASK ?
			  9 :
			 /* else it is ...   unknown */
			  10);

		switch (cs_thread_type)
		{
		    case CS_USER_THREAD:
			++CsSamplerBlkPtr->numusereventsamples;
			++CsSamplerBlkPtr->userevent[event]; /* count event type */
			break;
		    default:
			++CsSamplerBlkPtr->numsyseventsamples;
			++CsSamplerBlkPtr->sysevent[event]; /* count event type */
			break;
		} /* switch (cs_thread_type) */
		break;

	    case CS_MUTEX:
		++CsSamplerBlkPtr->Thread[cs_thread_type].state[cs_state];
		AddMutex( ((CS_SEMAPHORE *)an_scb->cs_sync_obj),
				cs_thread_type );
		break;

	    /* Uninteresting states */
	    default:
		++CsSamplerBlkPtr->Thread[cs_thread_type].state[cs_state];
		break;
	} /* switch (cs_state) */
    } /* for */

    /*
    ** If a second or more worth of intervals appear to have elapsed,
    ** compute current and peak per-second I/O, Transaction rates.
    */
    if ( (elapsed += CsSamplerBlkPtr->interval) >= 1000 )
    {
	/* Get the current time; the interval is not reliable! */
	stoptime = CS_checktime();

	if ( (seconds = stoptime - starttime) )
	{
	    if ( (CsSamplerBlkPtr->bior[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_bior_done - bior)
		       / seconds)
		    > CsSamplerBlkPtr->bior[PEAK] )
		CsSamplerBlkPtr->bior[PEAK] = CsSamplerBlkPtr->bior[CURR];

	    if ( (CsSamplerBlkPtr->biow[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_biow_done - biow)
		       / seconds)
		    > CsSamplerBlkPtr->biow[PEAK] )
		CsSamplerBlkPtr->biow[PEAK] = CsSamplerBlkPtr->biow[CURR];

	    if ( (CsSamplerBlkPtr->dior[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_dior_done - dior)
		       / seconds)
		    > CsSamplerBlkPtr->dior[PEAK] )
		CsSamplerBlkPtr->dior[PEAK] = CsSamplerBlkPtr->dior[CURR];

	    if ( (CsSamplerBlkPtr->diork[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_dior_kbytes - diork)
		       / seconds)
		    > CsSamplerBlkPtr->diork[PEAK] )
		CsSamplerBlkPtr->diork[PEAK] = CsSamplerBlkPtr->diork[CURR];

	    if ( (CsSamplerBlkPtr->diow[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_diow_done - diow)
		       / seconds)
		    > CsSamplerBlkPtr->diow[PEAK] )
		CsSamplerBlkPtr->diow[PEAK] = CsSamplerBlkPtr->diow[CURR];

	    if ( (CsSamplerBlkPtr->diowk[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_diow_kbytes - diowk)
		       / seconds)
		    > CsSamplerBlkPtr->diowk[PEAK] )
		CsSamplerBlkPtr->diowk[PEAK] = CsSamplerBlkPtr->diowk[CURR];

	    if ( (CsSamplerBlkPtr->lior[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_lior_done - lior)
			/ seconds)
		    > CsSamplerBlkPtr->lior[PEAK] )
		CsSamplerBlkPtr->lior[PEAK] = CsSamplerBlkPtr->lior[CURR];

	    if ( (CsSamplerBlkPtr->liork[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_lior_kbytes - liork)
			/ seconds)
		    > CsSamplerBlkPtr->liork[PEAK] )
		CsSamplerBlkPtr->liork[PEAK] = CsSamplerBlkPtr->liork[CURR];

	    if ( (CsSamplerBlkPtr->liow[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_liow_done - liow)
			/ seconds)
		    > CsSamplerBlkPtr->liow[PEAK] )
		CsSamplerBlkPtr->liow[PEAK] = CsSamplerBlkPtr->liow[CURR];

	    if ( (CsSamplerBlkPtr->liowk[CURR] =
		   (Cs_srv_block.cs_wtstatistics.cs_liow_kbytes - liowk)
			/ seconds)
		    > CsSamplerBlkPtr->liowk[PEAK] )
		CsSamplerBlkPtr->liowk[PEAK] = CsSamplerBlkPtr->liowk[CURR];

	    /* Transaction rate cannot be determined */
	}

	starttime = CS_checktime();
	elapsed = 0;
        bior  = Cs_srv_block.cs_wtstatistics.cs_bior_done;
        biow  = Cs_srv_block.cs_wtstatistics.cs_biow_done;
        dior  = Cs_srv_block.cs_wtstatistics.cs_dior_done;
        diork = Cs_srv_block.cs_wtstatistics.cs_dior_kbytes;
        diow  = Cs_srv_block.cs_wtstatistics.cs_diow_done;
        diowk = Cs_srv_block.cs_wtstatistics.cs_diow_kbytes;
	lior  = Cs_srv_block.cs_wtstatistics.cs_lior_done;
	liork = Cs_srv_block.cs_wtstatistics.cs_lior_kbytes;
	liow  = Cs_srv_block.cs_wtstatistics.cs_liow_done;
	liowk = Cs_srv_block.cs_wtstatistics.cs_liow_kbytes;
    }

    sleeptime = CsSamplerBlkPtr->interval;

    UnlockSamplerBlk(hCsSamplerSem);

    Sleep (sleeptime);
  } /* for (;;) */

} /* CS_sampler */
Exemple #5
0
STATUS
MOattach( i4  flags, char *classid, char *instance, PTR idata )
{
    MO_INSTANCE	*ip;
    MO_CLASS	*cp;
    STATUS	stat;

    stat = OK;

    if( MO_disabled )
	return( stat );

    MO_once();
    stat = MO_mutex();
    if( stat == OK )		/* got mutex */
    {
	do
	{
	    if( stat != OK )
		break;

	    MO_nattach++;

# ifdef xDEBUG
	    SIprintf("attach %s:%s object %p\n",
		     classid,
		     instance,
		     idata );
# endif

	    /* check for special error cases */

	    ip = MO_getinstance( classid, instance );
	    if( ip != NULL )
	    {
		stat = MO_ALREADY_ATTACHED;
		break;
	    }

	    /* Get class, error if missing */

	    if( OK != MO_getclass( classid, &cp ) )
	    {
		stat = MO_NO_CLASSID;
		break;
	    }

	    /* Release mutex to prevent deadlock in MO_alloc call */
	    (VOID) MO_unmutex();
	    ip = (MO_INSTANCE *)MO_alloc( sizeof(*ip), &stat );
            stat = MO_mutex();
	    if( NULL == ip )
		break;

	    ip->classdef = cp;
	    ip->iflags = flags;
	    if( (flags & MO_INSTANCE_VAR) == 0 )
	    {
		ip->instance = instance;
	    }
	    else
	    {
		ip->instance = MO_defstring( instance, &stat );
		if( ip->instance == NULL )
		{
		    MO_free( (PTR)ip, sizeof(*ip) );
		    break;
		}
	    }
	    ip->idata = idata;
	    ip->node.key = (PTR)ip;

	    (VOID) SPenq( &ip->node, MO_instances );

	} while( FALSE );

	(VOID) MO_unmutex();

	/* Attach twin if needed */

	if( stat == OK && cp->twin != NULL && !CMdigit( (char *)cp->node.key ) )
	    stat = MOattach( flags, cp->twin->node.key, instance, idata );
    }

# if xDEBUG
    if( stat != OK )
	TRdisplay("attach (%s:%s) failed status %d\n",
		  classid, instance, stat );
# endif

    if( stat == OK )
    {
	if ( (stat = MO_mutex()) == OK)
	{
	    (VOID) MO_tell_class( cp, instance, (char *)NULL, MO_ATTACH );
            MO_unmutex ();
	}
    }

    return( stat );
}
Exemple #6
0
STATUS
MO_oid_set(i4 offset,
	   i4  luserbuf,
	   char *userbuf,
	   i4  objsize,
	   PTR object )
{
    STATUS	cl_stat = OK;
    MO_CLASS	*cp = (MO_CLASS *)object;
    MO_CLASS	*twin_cp;
    MO_INSTANCE	*ip;
    MO_INSTANCE	*next_ip;

    MO_CLASS_DEF	mo_class;

    do
    {
	/* if it has a twin already, error */
	if( cp->twin != NULL )
	{
	    cl_stat = MO_NO_WRITE;
	    break;
	}

	mo_class.flags = MO_CLASSID_VAR | cp->cflags;
	mo_class.classid = userbuf;
	mo_class.size = cp->size;
	mo_class.perms = cp->perms;
	mo_class.index = cp->index;
	mo_class.get = cp->get;
	mo_class.set = cp->set;
	mo_class.cdata = cp->cdata;
	mo_class.idx = cp->idx;
	if( OK != (cl_stat = MOclassdef( 1, &mo_class ) ) )
	    break;

	if( OK != (cl_stat = MO_getclass( userbuf, &twin_cp ) ) )
	    break;

	cp->twin = twin_cp;
	twin_cp->twin = cp;
	twin_cp->monitor = cp->monitor;

	/* now attach all objects of the class as twins */

	for( ip = (MO_INSTANCE *)SPfhead( MO_instances ); ip != NULL ; ip = next_ip )
	{
	    next_ip = (MO_INSTANCE *)SPfnext( (SPBLK *)ip );
	    if( ip->classdef == cp )
	    {
		/* create one for the twin. */
		cl_stat = MOattach( 0, twin_cp->node.key, ip->instance, ip->idata );
		if( cl_stat != OK )
		    break;

		if( next_ip->classdef != cp )
		    break;
	    }
	}
    } while( FALSE );
    return( cl_stat );
}