src/server/Server.cxx File Reference

#include <CSql.h>
#include <SessionImpl.h>
#include <Debug.h>
#include <Process.h>
#include <Database.h>
#include <Transaction.h>
#include <Lock.h>
#include <CacheTableLoader.h>

Include dependency graph for Server.cxx:

Go to the source code of this file.

Functions

static void sigTermHandler (int sig)
bool checkDead (pid_t pid)
DbRetVal releaseAllResources (Database *sysdb, ThreadInfo *info)
DbRetVal cleanupDeadProcs (Database *sysdb)
DbRetVal logActiveProcs (Database *sysdb)
int main ()

Variables

int srvStop = 0


Function Documentation

bool checkDead ( pid_t  pid  ) 

Definition at line 32 of file Server.cxx.

References os::kill().

Referenced by cleanupDeadProcs(), and main().

00033 {
00034     int ret = os::kill(pid, 0);
00035     if (ret == -1) return true; else return false;
00036 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal cleanupDeadProcs ( Database sysdb  ) 

Definition at line 69 of file Server.cxx.

References checkDead(), Conf::config, Config::getMaxProcs(), os::getpid(), Database::getProcessTableMutex(), Database::getThreadInfo(), os::getthrid(), OK, ThreadInfo::pid_, printError, releaseAllResources(), and Database::releaseProcessTableMutex().

Referenced by main().

00070 {
00071     DbRetVal rv = sysdb->getProcessTableMutex(false);
00072     if (OK != rv)
00073     {
00074         printError(rv,"Unable to get process table mutex");
00075         return rv;
00076     }
00077     pid_t pid;
00078     pid = os::getpid();
00079     pthread_t thrid = os::getthrid();
00080 
00081 
00082     ThreadInfo* pInfo = sysdb->getThreadInfo(0);
00083     int i=0;
00084     ThreadInfo* freeSlot = NULL;
00085     for (; i < Conf::config.getMaxProcs(); i++)
00086     {
00087         //check whether it is alive
00088         if (pInfo->pid_ !=0 && checkDead(pInfo->pid_)) releaseAllResources(sysdb, pInfo);
00089         pInfo++;
00090     }
00091     sysdb->releaseProcessTableMutex(false);
00092     return OK;
00093 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal logActiveProcs ( Database sysdb  ) 

Definition at line 96 of file Server.cxx.

References Conf::config, Config::getMaxProcs(), Database::getProcessTableMutex(), Database::getThreadInfo(), logFine, logger, OK, ThreadInfo::pid_, printError, Database::releaseProcessTableMutex(), and ThreadInfo::thrid_.

Referenced by main().

00097 {
00098     DbRetVal rv = sysdb->getProcessTableMutex(false);
00099     if (OK != rv)
00100     {
00101         printError(rv,"Unable to get process table mutex");
00102         return rv;
00103     }
00104     ThreadInfo* pInfo = sysdb->getThreadInfo(0);
00105     int i=0;
00106     ThreadInfo* freeSlot = NULL;
00107     for (; i < Conf::config.getMaxProcs(); i++)
00108     {
00109         if (pInfo->pid_ !=0 )  logFine(logger, "Registered Procs: %d %lu\n", pInfo->pid_, pInfo->thrid_);
00110         pInfo++;
00111     }
00112     sysdb->releaseProcessTableMutex(false);
00113     return OK;
00114 }

Here is the call graph for this function:

Here is the caller graph for this function:

int main (  ) 

Definition at line 118 of file Server.cxx.

References cleanupDeadProcs(), Conf::config, SessionImpl::destroySystemDatabase(), SessionImpl::getSystemDatabase(), SessionImpl::initSystemDatabase(), logActiveProcs(), logFine, logger, OK, SessionImpl::readConfigFile(), os::select(), os::signal(), sigTermHandler(), srvStop, Logger::startLogger(), and Logger::stopLogger().

00119 {
00120     SessionImpl session;
00121     DbRetVal rv = session.readConfigFile();
00122     if (rv != OK)
00123     {
00124         printf("Unable to read the configuration file \n");
00125         return 1;
00126     }
00127     os::signal(SIGINT, sigTermHandler);
00128     os::signal(SIGTERM, sigTermHandler);
00129     rv = logger.startLogger(Conf::config.getLogFile(), true);
00130     if (rv != OK)
00131     {
00132         printf("Unable to start the logger\n");
00133         return 2;
00134     }
00135 
00136     logFine(logger, "Server Started");
00137     int ret  = session.initSystemDatabase();
00138     if (0  != ret)
00139     {
00140         printf(" System Database Initialization failed\n");
00141         return 3;
00142     }
00143     printf("System Database initialized\n");
00144 
00145 
00146     bool end = false;
00147 
00148     struct timeval timeout, tval;
00149     timeout.tv_sec = 5;
00150     timeout.tv_usec = 0;
00151     Database* sysdb = session.getSystemDatabase();
00152     printf("Database server recovering cached tables...\n");
00153    
00154     system("cachetable -u root -p manager -r");
00155 
00156     printf("Cached Tables recovered\n");
00157 
00158     printf("Database server started\n");
00159 
00160     while(!srvStop)
00161     {
00162         tval.tv_sec = timeout.tv_sec;
00163         tval.tv_usec = timeout.tv_usec;
00164         os::select(0, 0, 0, 0, &tval);
00165         
00166         //send signal to all the registered process..check they are alive
00167         cleanupDeadProcs(sysdb);
00168         
00169     }
00170    
00171     logFine(logger, "Server Exiting");
00172     logActiveProcs(sysdb);
00173     printf("Server Exiting\n");
00174     logFine(logger, "Server Ended");
00175     logger.stopLogger();
00176     session.destroySystemDatabase();
00177     return 0;
00178 }

Here is the call graph for this function:

DbRetVal releaseAllResources ( Database sysdb,
ThreadInfo info 
)

Definition at line 38 of file Server.cxx.

References ThreadInfo::has_, logFine, logger, MAX_MUTEX_PER_THREAD, Mutex::name, ThreadInfo::pid_, srvStop, and ThreadInfo::thrid_.

Referenced by cleanupDeadProcs().

00039 {
00040     printf("Releasing all the resources for process %d %lu\n", info->pid_, info->thrid_);
00041     //recover for all the mutexes in has_
00042     for (int i =0;  i < MAX_MUTEX_PER_THREAD; i++)
00043     {
00044         if (info->has_[i] != NULL) 
00045         {
00046             printf("Dead Procs: %d %lu holding mutex %x %s) \n", info->pid_, info->thrid_, info->has_[i], info->has_[i]->name);
00047             logFine(logger, "Dead Procs: %d %lu holding mutex %x %s) \n", info->pid_, info->thrid_, info->has_[i], info->has_[i]->name);
00048             //TODO::recovery of mutexes 
00049             //info->has_[i]->recoverMutex();
00050             srvStop = 1;
00051         }
00052     }
00053     TransactionManager *tm = new TransactionManager();
00054     LockManager *lm = new LockManager(sysdb);
00055     for (int i = 0 ;i < MAX_THREADS_PER_PROCESS; i++)
00056     {
00057         if (info->thrTrans_[i].trans_ != NULL && info->thrTrans_[i].trans_->status_ == TransRunning)
00058         {
00059             printf("Rollback Transaction %x\n", info->thrTrans_[i].trans_);
00060             tm->rollback(lm, info->thrTrans_[i].trans_);
00061         }
00062     }
00063     info->init();
00064     delete tm;
00065     delete lm;
00066     return OK;
00067 }

Here is the caller graph for this function:

static void sigTermHandler ( int  sig  )  [static]

Definition at line 26 of file Server.cxx.

References srvStop.

Referenced by main().

00027 {
00028     printf("Received signal %d\nStopping the server\n", sig);
00029     srvStop = 1;
00030 }

Here is the caller graph for this function:


Variable Documentation

int srvStop = 0

Definition at line 25 of file Server.cxx.

Referenced by main(), releaseAllResources(), and sigTermHandler().


Generated on Mon Jun 9 22:41:52 2008 for csql by  doxygen 1.4.7