From f86334d26280506e9b88b4b11f7f468b934ceafb Mon Sep 17 00:00:00 2001 From: prabatuty Date: Sun, 16 Aug 2009 07:26:04 +0000 Subject: [PATCH] submitting patch from enterprise version --- include/Config.h | 185 +++++++++++++++------ include/Debug.h | 37 ++--- include/Mutex.h | 126 ++++---------- include/os.h | 65 +++++--- src/network/NetworkTable.cxx | 6 +- src/storage/Config.cxx | 316 ++++++++++++++++++++++++++++++------ src/storage/Connection.cxx | 8 +- src/storage/DatabaseManagerImpl.cxx | 30 ++-- src/storage/Logger.cxx | 131 ++++++++++----- src/storage/Mutex.cxx | 148 +++++++++++++---- src/storage/TableImpl.cxx | 2 +- src/storage/os.cxx | 173 ++++++++++++++++---- src/tools/csqlcacheserver.cxx | 2 +- src/tools/csqlreplserver.cxx | 13 -- src/tools/csqlserver.cxx | 24 +-- 15 files changed, 864 insertions(+), 402 deletions(-) rewrite include/Mutex.h (85%) diff --git a/include/Config.h b/include/Config.h index 85d22595..1c1268b9 100644 --- a/include/Config.h +++ b/include/Config.h @@ -1,108 +1,154 @@ /*************************************************************************** - * Copyright (C) 2007 by www.databasecache.com * - * Contact: praba_tuty@databasecache.com * * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * Copyright (C) Lakshya Solutions Ltd. All rights reserved. * * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - ***************************************************************************/ + ***************************************************************************/ + #ifndef CONFIG_H #define CONFIG_H #include +#include + +enum CacheMode { + SYNC_MODE=0, + ASYNC_MODE=1, + UNKNOWN=100 +}; +enum TDBInfo +{ + mysql=0, + postgres, + oracle, + sybase, + db2, + sqlserver, +}; + class ConfigValues { public: //All the members of the configuration file - int pageSize; - int maxProcs; - long maxSysSize; - long maxDbSize; - int sysDbKey; - int userDbKey; char logFile[MAX_FILE_PATH_LEN]; char dbFile[MAX_FILE_PATH_LEN]; + char tableConfigFile[MAX_FILE_PATH_LEN]; + char dsConfigFile[MAX_FILE_PATH_LEN];// DSN Config file + char stderrFile[MAX_FILE_PATH_LEN]; + char replConfigFile[MAX_FILE_PATH_LEN]; + char conflResoFile[MAX_FILE_PATH_LEN]; + + bool isDurable; + bool mmap; + bool isCsqlSqlServer; + bool isCache; + bool isTwoWay; + bool isReplication; + + int siteID; + int sysDbKey; + int userDbKey; + long maxSysSize; + long maxDbSize; + int pageSize; + int maxProcs; + long mapAddr; + int mutexSecs; int mutexUSecs; int mutexRetries; int lockSecs; int lockUSecs; int lockRetries; + int logLevel; - int cacheId; - bool isCache; + int durableMode; char dsn[IDENTIFIER_LENGTH]; - char tableConfigFile[MAX_FILE_PATH_LEN]; - bool isTwoWay; - int cacheWaitSecs; - - bool isDurable; - bool isCsqlSqlServer; + CacheMode mode; + int cacheWaitSecs; + int port; - int networkID; - int cacheNetworkID; - int shmKeyForId; - long logStoreSize; int nwResponseTimeout; int nwConnectTimeout; + int maxReplSites; + + int msgKey; + int asyncMsgMax; + int shmKeyForId; + long maxQueueLogs; + int noOfProcessors; ConfigValues() { - pageSize = 8192; - maxProcs = 20; - maxSysSize = 10485760; - maxDbSize = 104857600; + strcpy(logFile, "/tmp/log/log.out"); + strcpy(dbFile, "/tmp/csql/db"); + strcpy(tableConfigFile, "/tmp/csql/csqltable.conf"); + strcpy(dsConfigFile,"/tmp/csql/csqlds.conf"); // DSN Config file + strcpy(stderrFile, "stderr"); + strcpy(replConfigFile, "/tmp/csql/csqlnw.conf"); + strcpy(conflResoFile, "/tmp/csql/ConflResoFile.txt"); + + isDurable = false; + mmap = false; + isCsqlSqlServer = false; + isCache = false; + isTwoWay=false; + isReplication = false; + + siteID=1; sysDbKey = 2222; userDbKey = 5555; - strcpy(logFile, "/tmp/log/log.out"); - strcpy(dbFile, "/tmp/csql/csql.db"); + maxSysSize = 10485760; + maxDbSize = 104857600; + pageSize = 8192; + maxProcs = 20; + mapAddr=400000000; + mutexSecs=0; mutexUSecs=10; mutexRetries = 10; lockSecs =0; lockUSecs = 10; lockRetries = 10; - cacheId=1; - isCache = false; - cacheNetworkID =-1; - strcpy(dsn, "myodbc3"); - strcpy(tableConfigFile, "/tmp/csql/csqltable.conf"); - isCsqlSqlServer = false; + logLevel = 0; + + durableMode=1; + strcpy(dsn,"myodbc3"); + mode = SYNC_MODE; + cacheWaitSecs =10; + port = 5678; - logStoreSize = 10485760; - networkID=-1; - shmKeyForId = -1; nwResponseTimeout=3; nwConnectTimeout=5; - isTwoWay=false; - cacheWaitSecs =10; + maxReplSites=1; + msgKey=-1; + asyncMsgMax = 8192; //default for linux + shmKeyForId = -1; + maxQueueLogs = 100; + noOfProcessors = 1; } }; class Config { ConfigValues cVal; + bool isLoaded; int readLine(FILE *fp, char * buffer); int storeKeyVal(char *key, char *val); int validateValues(); public: + Config() { isLoaded = false; } int readAllValues(char *filename); void print(); + void logConfig(); inline int getPageSize() { return cVal.pageSize; } inline int getMaxProcs() { return cVal.maxProcs; } inline long getMaxSysDbSize() { return cVal.maxSysSize; } inline long getMaxDbSize() { return cVal.maxDbSize; } inline int getSysDbKey() { return cVal.sysDbKey; } inline int getUserDbKey() { return cVal.userDbKey; } + inline bool useMmap() { return cVal.mmap; } inline char* getLogFile() { return cVal.logFile; } inline char* getDbFile() { return cVal.dbFile; } inline long getMapAddress() { return cVal.mapAddr; } @@ -112,28 +158,65 @@ class Config inline int getLockSecs() { return cVal.lockSecs; } inline int getLockUSecs() { return cVal.lockUSecs; } inline int getLockRetries() { return cVal.lockRetries; } - inline int getCacheID(){ return cVal.cacheId;} + inline int getSiteID(){ return cVal.siteID;} inline bool useCache() { return cVal.isCache; } + inline int getCacheMode() { return (int) cVal.mode; } inline char* getDSN() { return cVal.dsn; } + inline char* getDsConfigFile() { return cVal.dsConfigFile; } inline char* getTableConfigFile() { return cVal.tableConfigFile; } + inline char* getStderrFile() { return cVal.stderrFile; } + inline bool useReplication() { return cVal.isReplication; } inline bool useDurability() { return cVal.isDurable; } + inline int getDurableMode() { return cVal.durableMode; } inline bool useCsqlSqlServer() { return cVal.isCsqlSqlServer; } inline int getPort() { return cVal.port; } - inline long getMaxLogStoreSize() { return cVal.logStoreSize; } + inline char* getReplConfigFile() { return cVal.replConfigFile; } + inline char* getConflResoFile() { return cVal.conflResoFile; } + inline long getMaxQueueLogs() { return cVal.maxQueueLogs; } + inline int getNoOfReplSites() { return cVal.maxReplSites; } + inline int getMsgKey() { return cVal.msgKey; } + inline int getAsyncMsgMax() { return cVal.asyncMsgMax; } inline int getShmIDKey() { return cVal.shmKeyForId; } - inline int getNetworkID() { return cVal.networkID; } - inline int getCacheNetworkID() { return cVal.cacheNetworkID; } inline int getNetworkResponseTimeout() { return cVal.nwResponseTimeout; } inline int getNetworkConnectTimeout() { return cVal.nwConnectTimeout; } inline bool useTwoWayCache() { return cVal.isTwoWay; } inline int getCacheWaitSecs() { return cVal.cacheWaitSecs; } + inline int getLogLevel() { return cVal.logLevel; } + inline int getNoOfProcessors() { return cVal.noOfProcessors; } }; class Conf { public: static Config config; + static Logger logger; }; +class SiteInfoData +{ + public: + int siteId; + char hostName[IDENTIFIER_LENGTH]; + int port; + char mode[32]; + SiteInfoData() { siteId = -1; port = 0; hostName[0]='\0'; mode[0]='\0';}; +}; + + +class SiteInfo +{ + DbRetVal populateSiteInfoList(); + public: + List siteInfoList; + List asyncSiteList; + List syncSiteList; + bool isAsyncSitePresent(); + bool isSyncSitePresent(); + SiteInfo() { populateSiteInfoList(); } + ~SiteInfo(); + List & getSiteInfoList() { return siteInfoList; } + List & getSyncSiteInfoList() { return syncSiteList; } + List & getAsyncSiteInfoList() { return asyncSiteList; } +}; #endif diff --git a/include/Debug.h b/include/Debug.h index 4ae61bb0..6107ffba 100644 --- a/include/Debug.h +++ b/include/Debug.h @@ -1,18 +1,9 @@ /*************************************************************************** - * Copyright (C) 2007 by www.databasecache.com * - * Contact: praba_tuty@databasecache.com * * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * Copyright (C) Lakshya Solutions Ltd. All rights reserved. * * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - ***************************************************************************/ + ***************************************************************************/ + #ifndef DEBUG_H #define DEBUG_H #include @@ -36,8 +27,13 @@ extern int DebugDM_Network; extern int DebugDM_Gateway; extern int DebugDM_Adapter; extern int DebugDM_SqlLog; +extern int DebugDM_ReplServer; +extern int DebugDM_ReplTool; +extern int DebugDM_CacheServer; +extern int DebugDM_TEST; +extern int DebugDM_Warning; - +int printStackTrace(); extern int printError1(DbRetVal val, char* fname, int lno, char *format, ...); #define printError(a, ...) printError1(a, __FILE__, __LINE__, __VA_ARGS__) @@ -62,13 +58,19 @@ enum DebugModule DM_Network, DM_Gateway, DM_Adapter, - DM_SqlLog + DM_SqlLog, + DM_ReplServer, + DM_ReplTool, + DM_CacheServer, + DM_TEST, + DM_Warning }; static char moduleNames[][20] = { "Alloc", "VariableAlloc", "Lock", "Trans", "UndoLog", "RedoLog", "Index", "HashIndex", "TreeIndex", "SysDb", "Db", "Table", "Predicate", "Iter", - "Procmgmt", "Network", "Gateway", "Adapter", "SqlLog" + "Procmgmt", "Network", "Gateway", "Adapter", "SqlLog", "ReplServer", + "ReplTool", "CacheServer", "TEST", "Warning" }; extern int printDebug1(int module, char *fname, int lineno, char *format, ...); @@ -99,9 +101,9 @@ static char levelNames[][10] = #include class Logger { - Mutex mutex_; //guard in case of multi threaded programs int fdLog; //file descriptor LogLevel configLevel; //configuration file setting is cached here. + void rollOverIfRequired(); public: int log(LogLevel level, char* filename, int lineNo, char *format, ...); int createLogRecord(LogLevel level, char* filename, int lineNo, char* message, char **in); @@ -109,9 +111,6 @@ class Logger void stopLogger(); }; -//Global object -static Logger logger; - #define logFinest(logger, ...) \ {\ (logger).log(LogFinest, __FILE__, __LINE__, __VA_ARGS__);\ diff --git a/include/Mutex.h b/include/Mutex.h dissimilarity index 85% index 8f4edb79..cf2833f8 100644 --- a/include/Mutex.h +++ b/include/Mutex.h @@ -1,93 +1,33 @@ -/*************************************************************************** - * Copyright (C) 2007 by www.databasecache.com * - * Contact: praba_tuty@databasecache.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - ***************************************************************************/ -#ifndef MUTEX_H -#define MUTEX_H -#include - #if defined(sparc) - typedef unsigned char Lock; - #elif defined (i686) || defined(x86_64) - typedef unsigned int Lock; - #endif -class Mutex -{ - - #if defined(sparc) || defined(i686) || defined(x86_64) - Lock lock; - #else - pthread_mutex_t mutex_; - #endif - public: - char name[20]; - Mutex(); - int init(); - int init(char *name); - int tryLock(int tries=0, int waitmsecs=0); - int getLock(int procSlot, bool procAccount=true); - int releaseLock(int procSlot, bool procAccount=true); - int destroy(); - int recoverMutex(); - static int CAS(int *ptr, int oldVal, int newVal) - { - unsigned char ret; - __asm__ __volatile__ ( - " lock\n" - " cmpxchgl %2,%1\n" - " sete %0\n" - : "=q" (ret), "=m" (*ptr) - : "r" (newVal), "m" (*ptr), "a" (oldVal) - : "memory"); - - //above assembly returns 0 in case of failure - if (ret) return 0; - - struct timeval timeout; - timeout.tv_sec=0; - timeout.tv_usec=1000; - os::select(0,0,0,0, &timeout); - __asm__ __volatile__ ( - " lock\n" - " cmpxchgl %2,%1\n" - " sete %0\n" - : "=q" (ret), "=m" (*ptr) - : "r" (newVal), "m" (*ptr), "a" (oldVal) - : "memory"); - //if (ret) return 0; else {printf("DEBUG::CAS Fails %d-\n", ret); return 1; } - if (ret) return 0; else return 1; - - } - /*static int CASB(char *ptr, char oldVal, char newVal) - { - unsigned char ret; - __asm__ __volatile__ ("lock; cmpxchgb %b1, %2" - : "=a" (ret) - : "m" (*(ptr), "q" (newVal), "0" (oldVal) - : "memory"); - printf("Value of ret is %d\n", ret); - //above assembly returns 0 in case of failure - if (ret) return 0; - struct timeval timeout; - timeout.tv_sec=0; - timeout.tv_usec=500; - os::select(0,0,0,0, &timeout); - __asm__ __volatile__ ("lock; cmpxchgb %b1, %2" - : "=a" (ret) - : "m" (*(ptr), "q" (newVal), "0" (oldVal) - : "memory"); - if(!ret) { printf("DEBUG::CAS Fails\n"); return 1; } else return 0; - }*/ -}; - -#endif +/*************************************************************************** + * * + * Copyright (C) Lakshya Solutions Ltd. All rights reserved. * + * * + ***************************************************************************/ + +#ifndef MUTEX_H +#define MUTEX_H +#include +typedef unsigned int Lock; +class Mutex +{ + int noOfRead; + #if defined(sparc) || defined(i686) || defined (x86_64) + Lock lock; + #else + pthread_mutex_t mutex_; + #endif + public: + char name[20]; + Mutex(); + int init(); + int init(char *name); + int tryLock(int tries=0, int waitmsecs=0,bool share=false); + int getLock(int procSlot, bool procAccount=true,bool share=false); + int releaseLock(int procSlot, bool procAccount=true,bool share=false); + int destroy(); + int recoverMutex(); + static int CASL(long *ptr, long oldVal, long newVal); + static int CAS(int *ptr, int oldVal, int newVal); +}; + +#endif diff --git a/include/os.h b/include/os.h index 0c5cb9d6..cefc53dd 100644 --- a/include/os.h +++ b/include/os.h @@ -1,28 +1,19 @@ /*************************************************************************** - * Copyright (C) 2007 by www.databasecache.com * - * Contact: praba_tuty@databasecache.com * * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * Copyright (C) Lakshya Solutions Ltd. All rights reserved. * * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - ***************************************************************************/ + ***************************************************************************/ + #ifndef OS_H #define OS_H #include -#if defined(solaris) || defined(LINUX) +#if defined(SOLARIS) || defined(LINUX) #include #include +#include #include -#include #include #include #include @@ -32,18 +23,30 @@ #include #include #include -#include #include #include +#include #include #include -#include -#if defined(solaris) +#include +#include +#include +#include +#include +#include +#include +#if defined(SOLARIS) #include + #include + #include + #include + #include + //extern int errno; #endif #if defined(LINUX) - #include - #include + #include + #include + #include #endif typedef void (*sighandler_t)(int); @@ -52,7 +55,7 @@ enum FileOpenMode fileOpenReadOnly = O_RDONLY, fileOpenWriteOnly = O_WRONLY, fileOpenReadWrite = O_RDWR, - fileOpenAppend = O_APPEND |O_RDWR, + fileOpenAppend = O_CREAT| O_APPEND |O_RDWR, fileOpenCreat = O_CREAT |O_RDWR, // If set and fileOpenExcl is set, the // open will fail if the file already exists. @@ -88,9 +91,11 @@ enum MapMode #define IDENTIFIER_LENGTH 64 #define ERROR_STRING_LENGTH 128 #define DEFAULT_VALUE_BUF_LENGTH 32 +#define STATE_LENGTH 8 #define SYSTEMDB "SYSTEMDB" #define DBAUSER "root" #define DBAPASS "manager" +#define DEFAULT_CONFIG_FILE "/etc/csql/csql.conf" #define LOCK_BUCKET_SIZE 2048 #define STMT_BUCKET_SIZE 1023 #define MAX_CHUNKS 20 @@ -99,6 +104,7 @@ enum MapMode #define MAX_THREADS_PER_PROCESS 30 #define MAX_FILE_PATH_LEN 1024 #define CHUNK_NAME_LEN 64 +#define LOG_ROLLOVER_SIZE 20*1024*1024 #define BIT(x) (1 << (x)) #define SETBITS(x,y) ((x) |= (y)) @@ -113,22 +119,25 @@ typedef int shared_memory_id; #endif - class os { public: - static caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fildes, off_t off); + static void* mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off); static int munmap(caddr_t addr, size_t len); static int openFile(const char *name, FileOpenMode flags, size_t size); static int closeFile(int fd); + static int lockFile(int fd); + static int unlockFile(int fd); static off_t lseek(int fildes, off_t offset, int whence); + static int openFileForAppend(const char* fname, int flags); + static int getFileSize(const char* fname); static size_t write(int fildes, char *buf, size_t size); static int msync(caddr_t addr, size_t len, int flags); static int fsync(int fildes); inline static size_t alignLong(size_t size) { return ((size - 1) | (sizeof(long) - 1)) + 1;} inline static size_t align(size_t size) - { return ((size - 1) | (sizeof(long) - 1)) + 1;} + { return ((size - 1) | (sizeof(int) - 1)) + 1;} static char* encrypt(const char * key, const char *salt); static void* memset(void *src, int c, size_t size); static void* memcpy(void *src, const void *dest, size_t size); @@ -158,12 +167,20 @@ class os static int kill(pid_t pid, int sig); static bool atobool(char *value); - static pid_t createProcess(const char* cmdName, const char *arg0, ...); + static pid_t createProcess(const char* cmdName, const char *arg0); static pid_t fork(); static size_t send(int fd, const void *buf, size_t len, int flags); static size_t recv(int fd, void *buf, size_t len, int flags); static int gethostname(char *hostname, size_t len); static int strmatch(char *pattern, char *str); + static int msgget(key_t key, int oflag); + static int msgsnd(int msqid, const void *ptr, size_t len, int flag); + static ssize_t msgrcv(int msqid, void *ptr, size_t len, long type, int flag); + static int msgctl(int msqid, int cmd, struct msqid_ds *buff); + static int isValidIP(char ipstr[] ); + static bool fileExists(char *fileName); + static char* strcasestr(char *s1, const char *s2); + static int getNoOfProcessors(); }; #endif diff --git a/src/network/NetworkTable.cxx b/src/network/NetworkTable.cxx index fa86f2b0..12bbd069 100644 --- a/src/network/NetworkTable.cxx +++ b/src/network/NetworkTable.cxx @@ -55,12 +55,12 @@ DbRetVal NetworkTable::readNetworkConfig() fscanf(fp, "%d:%d:%s\n", &nwid, &port, hostname); printDebug(DM_Network, "%d:%d:%s\n", nwid, port, hostname); NetworkClient* nClient; - if (nwid == Conf::config.getNetworkID()) continue; + //if (nwid == Conf::config.getNetworkID()) continue; nClient = NetworkFactory::createClient(TCP); - printDebug(DM_Network, "nwid %d getCacheNetworkID %d\n", nwid, Conf::config.getCacheNetworkID()); - if (nwid == Conf::config.getCacheNetworkID()) nClient->setCacheClient(); + //printDebug(DM_Network, "nwid %d getCacheNetworkID %d\n", nwid, Conf::config.getCacheNetworkID()); + //if (nwid == Conf::config.getCacheNetworkID()) nClient->setCacheClient(); nClient->setHost(hostname, port, nwid); nwClient = nClient; count++; diff --git a/src/storage/Config.cxx b/src/storage/Config.cxx index 7ca4d32b..6ff154c4 100644 --- a/src/storage/Config.cxx +++ b/src/storage/Config.cxx @@ -34,65 +34,91 @@ int Config::readLine(FILE *fp, char * buffer) } int Config::storeKeyVal(char *key, char *value) { - if (strcasestr(key, "PAGE_SIZE") != NULL ) + if (os::os::strcasestr(key, "PAGE_SIZE") != NULL ) { cVal.pageSize = atoi(value); } - else if (strcasestr(key, "MAX_PROCS") != NULL) + else if (os::strcasestr(key, "MAX_PROCS") != NULL) { cVal.maxProcs = atoi(value); } - else if (strcasestr(key, "MAX_SYS_DB_SIZE") != NULL) + else if (os::strcasestr(key, "MAX_SYS_DB_SIZE") != NULL) { cVal.maxSysSize = atol(value); } - else if (strcasestr(key, "MAX_DB_SIZE") != NULL) + else if (os::strcasestr(key, "MAX_DB_SIZE") != NULL) { cVal.maxDbSize = atol(value); } - else if (strcasestr(key, "SYS_DB_KEY") != NULL) + else if (os::strcasestr(key, "MMAP") != NULL) + { cVal.mmap = os::atobool(value); } + else if (os::strcasestr(key, "SYS_DB_KEY") != NULL) { cVal.sysDbKey = atoi(value); } - else if (strcasestr(key, "USER_DB_KEY") != NULL) + else if (os::strcasestr(key, "USER_DB_KEY") != NULL) { cVal.userDbKey = atoi(value); } - else if (strcasestr(key, "LOG_FILE") != NULL) + else if (os::strcasestr(key, "LOG_FILE") != NULL) { strcpy(cVal.logFile , value); } - else if (strcasestr(key, "DATABASE_FILE") != NULL) + else if (os::strcasestr(key, "DATABASE_FILE") != NULL) { strcpy(cVal.dbFile , value); } - else if (strcasestr(key, "MAP_ADDRESS") != NULL) + else if (os::strcasestr(key, "MAP_ADDRESS") != NULL) { cVal.mapAddr = atol(value); } - else if (strcasestr(key, "MUTEX_TIMEOUT_SECS") != NULL) + else if (os::strcasestr(key, "MUTEX_TIMEOUT_SECS") != NULL) { cVal.mutexSecs = atoi(value); } - else if (strcasestr(key, "MUTEX_TIMEOUT_USECS") != NULL) + else if (os::strcasestr(key, "MUTEX_TIMEOUT_USECS") != NULL) { cVal.mutexUSecs = atoi(value); } - else if (strcasestr(key, "MUTEX_TIMEOUT_RETRIES") != NULL) + else if (os::strcasestr(key, "MUTEX_TIMEOUT_RETRIES") != NULL) { cVal.mutexRetries = atoi(value); } - else if (strcasestr(key, "LOCK_TIMEOUT_SECS") != NULL) + else if (os::strcasestr(key, "LOCK_TIMEOUT_SECS") != NULL) { cVal.lockSecs = atoi(value); } - else if (strcasestr(key, "LOCK_TIMEOUT_USECS") != NULL) + else if (os::strcasestr(key, "LOCK_TIMEOUT_USECS") != NULL) { cVal.lockUSecs = atoi(value); } - else if (strcasestr(key, "LOCK_TIMEOUT_RETRIES") != NULL) + else if (os::strcasestr(key, "LOCK_TIMEOUT_RETRIES") != NULL) { cVal.lockRetries = atoi(value); } - else if (strcasestr(key, "DSN") != NULL) + else if (os::strcasestr(key, "LOG_LEVEL") != NULL) + { cVal.logLevel = atoi(value); } + else if (os::strcasestr(key, "DSN") != NULL) { strcpy(cVal.dsn , value); } - else if (strcasestr(key, "TABLE_CONFIG_FILE") != NULL) + else if (os::strcasestr(key,"DS_CONFIG_FILE") !=NULL) + { strcpy(cVal.dsConfigFile,value);} + else if (os::strcasestr(key, "TABLE_CONFIG_FILE") != NULL) { strcpy(cVal.tableConfigFile , value); } - else if (strcasestr(key, "CACHE_TABLE") != NULL) + else if (os::strcasestr(key, "STDERR_FILE") != NULL) + { strcpy(cVal.stderrFile, value); } + else if (os::strcasestr(key, "CONFL_RESOL_FILE") != NULL) + { strcpy(cVal.conflResoFile , value); } + else if (os::strcasestr(key, "CACHE_TABLE") != NULL) { cVal.isCache = os::atobool(value); } - else if(strcasestr(key,"CACHE_ID")!=NULL) - { cVal.cacheId = atoi(value);} - else if (strcasestr(key, "DURABILITY") != NULL) + else if (os::strcasestr(key, "CACHE_MODE") != NULL) + { + if (strcmp(value, "SYNC") == 0) + { cVal.mode = SYNC_MODE; } + else if (strcmp(value, "ASYNC") == 0) + { cVal.mode = ASYNC_MODE; } + else cVal.mode = UNKNOWN; + } + else if(os::strcasestr(key,"SITE_ID")!=NULL) + { cVal.siteID = atoi(value);} + else if(os::strcasestr(key,"REPLICATION_SITES")!=NULL) + { cVal.maxReplSites = atoi(value);} + else if (os::strcasestr(key, "REPLICATION") != NULL) + { cVal.isReplication = os::atobool(value); } + else if (os::strcasestr(key, "DURABILITY") != NULL) { cVal.isDurable = os::atobool(value); } - else if (strcasestr(key, "CSQL_SQL_SERVER") != NULL) + else if (os::strcasestr(key, "DURABLE_MODE") != NULL) + { cVal.durableMode = ::atoi(value); } + else if (os::strcasestr(key, "CSQL_SQL_SERVER") != NULL) { cVal.isCsqlSqlServer = os::atobool(value); } - else if (strcasestr(key, "PORT") != NULL) + else if (os::strcasestr(key, "PORT") != NULL) { cVal.port = atoi(value); } - else if (strcasestr(key, "MAX_LOG_STORE_SIZE") != NULL) - { cVal.logStoreSize = atol(value); } - else if (strcasestr(key, "MY_NETWORK_ID") != NULL) - { cVal.networkID = atoi(value); } - else if (strcasestr(key, "ID_SHM_KEY") != NULL) + else if (os::strcasestr(key, "NETWORK_CONFIG_FILE") != NULL) + { strcpy(cVal.replConfigFile , value); } + else if (os::strcasestr(key, "MAX_QUEUE_LOGS") != NULL) + { cVal.maxQueueLogs = atol(value); } + else if (os::strcasestr(key, "MSG_KEY") != NULL) + { cVal.msgKey = atoi(value); } + else if (os::strcasestr(key, "ASYNC_MSGMAX") != NULL) + { cVal.asyncMsgMax = atoi(value); } + else if (os::strcasestr(key, "ID_SHM_KEY") != NULL) { cVal.shmKeyForId = atoi(value); } - else if (strcasestr(key, "CACHE_NETWORK_ID") != NULL) - { cVal.cacheNetworkID = atoi(value); } - else if (strcasestr(key, "NETWORK_RESPONSE_TIMEOUT") != NULL) + else if (os::strcasestr(key, "NETWORK_RESPONSE_TIMEOUT") != NULL) { cVal.nwResponseTimeout = atoi(value); } - else if (strcasestr(key, "NETWORK_CONNECT_TIMEOUT") != NULL) + else if (os::strcasestr(key, "NETWORK_CONNECT_TIMEOUT") != NULL) { cVal.nwConnectTimeout = atoi(value); } - else if (strcasestr(key, "ENABLE_BIDIRECTIONAL_CACHE") != NULL) + else if (os::strcasestr(key, "ENABLE_BIDIRECTIONAL_CACHE") != NULL) { cVal.isTwoWay = os::atobool(value); } - else if (strcasestr(key, "CACHE_RECEIVER_WAIT_SECS") != NULL) + else if (os::strcasestr(key, "CACHE_RECEIVER_WAIT_SECS") != NULL) { cVal.cacheWaitSecs = atoi(value); } else return 1; return 0; @@ -109,11 +135,20 @@ int Config::validateValues() printError(ErrBadArg, "PAGE_SIZE should be multiples of 1024"); return 1; } - if (cVal.maxProcs < 10 || cVal.maxProcs > 8192) +#if (defined TRIAL) || (defined BASIC) + if (cVal.maxProcs < 1 || cVal.maxProcs > 5) + { + printf("Trial license supports only 5 connections"); + printf("Contact sales@csqldb.com to get full license"); + return 1; + } +#else + if (cVal.maxProcs < 10 || cVal.maxProcs > 8192) { printError(ErrBadArg, "MAX_PROCS should be >= 10 and <= 8192"); return 1; } +#endif if (cVal.maxSysSize < 1024 * 1024 || cVal.maxSysSize > 1024 *1024 *1024) { printError(ErrBadArg, "MAX_SYS_DB_SIZE should be >= 1 MB and <= 1 GB"); @@ -125,11 +160,39 @@ int Config::validateValues() return 1; } - if (cVal.maxDbSize < 1024 * 1024 || cVal.maxDbSize > (1024*1024*1024)) +#ifdef TRIAL + if (cVal.maxDbSize < 1024 * 1024 || cVal.maxDbSize > (20 * 1024*1024)) { - printError(ErrBadArg, "MAX_DB_SIZE should be >= 1 MB and <= 2 GB"); + printf("Trial license supports only 20 MB db size"); + printf("Contact sales@csqldb.com to get full license"); return 1; } +#else +#ifdef BASIC + if (cVal.maxDbSize < 1024 * 1024 || cVal.maxDbSize > (100 * 1024*1024)) + { + printf("Basic subscription supports only 100 MB db size"); + printf("Contact sales@csqldb.com to upgrade"); + return 1; + } + +#else + #ifdef x86_64 + if (cVal.maxDbSize < 1024 * 1024 || cVal.maxDbSize > ( 100*1024*1024*1024L)) + { + printError(ErrBadArg, "MAX_DB_SIZE should be >= 1 MB and <= 100 GB"); + return 1; + } + #else + unsigned long maxVal = 2*1024*1024*1024L; + if (cVal.maxDbSize < 1024 * 1024 || ((unsigned long)cVal.maxDbSize) > maxVal) + { + printError(ErrBadArg, "MAX_DB_SIZE should be >= 1 MB and <= 2 GB"); + return 1; + } + #endif +#endif +#endif if (cVal.maxDbSize % 8192 !=0) { printError(ErrBadArg, "MAX_DB_SIZE should be multiples of 8192"); @@ -197,6 +260,25 @@ int Config::validateValues() printError(ErrBadArg, "LOCK_TIMEOUT_RETRY should be >= 0 and <= 100"); return 1; } + if (cVal.logLevel < 0 || cVal.logLevel > 3) + { + printError(ErrBadArg, "LOG_LEVEL should be >= 0 and <= 3"); + return 1; + } +#ifdef NOREPL + if (cVal.isReplication) { + printf("This version does not support replication.\n"); + printf("Please contact sales@csqldb.com to upgrade\n"); + return 1; + } +#endif +/* if (cVal.isCache && cVal.isReplication) { + printError(ErrBadArg, "Either caching or replication option should be set." + " Both options are not supported together"); + return 1; + }*/ + + //printf("Debug:Config=%s\n",cVal.dsn); if (cVal.isCache) { if (0 == strcmp(cVal.dsn,"")) { @@ -204,6 +286,40 @@ int Config::validateValues() return 1; } } + + if (cVal.isReplication || cVal.isCache) { + if (0 == strcmp(cVal.replConfigFile,"")) + { + //TODO::check whether file exists + printError(ErrBadArg, "NETWORK_CONFIG_FILE is set to NULL"); + return 1; + } + if (0 == strcmp(cVal.tableConfigFile,"")) + { + //TODO::check whether file exists + printError(ErrBadArg, "TABLE_CONFIG_FILE is set to NULL"); + return 1; + } + /*FILE *fp = fopen(cVal.replConfigFile,"r"); + if( fp == NULL ) { + printError(ErrSysInit, "Invalid path/filename for NETWORK_CONFIG_FILE.\n"); + return 1; + } + int count =0; + int nwid, port; + char hostname[IDENTIFIER_LENGTH]; + char nwmode; + + while(!feof(fp)) { + fscanf(fp, "%d:%d:%s\n", &nwid, &port, hostname); + count++; + } + if (count >2) { + printError(ErrSysInit, "NETWORK_CONFIG_FILE has more than 2 entries\n"); + return 1; + }*/ + + } /*if (cVal.isCache) { @@ -230,16 +346,6 @@ int Config::validateValues() if (!found) return 1; } }*/ - if (cVal.logStoreSize < 1024 * 1024 || cVal.logStoreSize > 1024 *1024 *1024) - { - printError(ErrBadArg, "MAX_LOG_STORE_SIZE should be >= 1 MB and <= 1 GB"); - return 1; - } - if (cVal.logStoreSize % 8192 !=0) - { - printError(ErrBadArg, "MAX_LOG_STORE_SIZE should be multiples of 8192"); - return 1; - } if (cVal.nwResponseTimeout <0 || cVal.nwResponseTimeout > 60) { printError(ErrBadArg, "NETWORK_RESPONSE_TIMEOUT should be 0 to 60"); @@ -260,13 +366,23 @@ int Config::validateValues() printError(ErrBadArg, "Invalid Port Number"); return 1; } + if (cVal.durableMode < 1 || cVal.durableMode >4) + { + if (!cVal.isDurable) { + printError(ErrBadArg, "Durability is not enabled but mode is set"); + } else { + printError(ErrBadArg, "Durable Mode should be 1 to 4"); + } + return 1; + } return 0; } int Config::readAllValues(char *fileName) { + if (isLoaded) return 0; FILE *fp; - + if (fileName == NULL) fileName = DEFAULT_CONFIG_FILE; fp = fopen(fileName,"r"); if( fp == NULL ) { printError(ErrSysInit, "Invalid path/filename in CSQL_CONFIG_FILE."); @@ -305,9 +421,35 @@ int Config::readAllValues(char *fileName) { return 1; } - + cVal.noOfProcessors = os::getNoOfProcessors(); + isLoaded = true; + logConfig(); return 0; } +void Config::logConfig() +{ + /* + logFinest(Conf::logger, "Config: MAX_SYS_DB_SIZE %d", getMaxSysDbSize()); + logFinest(Conf::logger, "Config: MAX_DB_SIZE %d", getMaxDbSize()); + logFinest(Conf::logger, "Config: SYS_DB_KEY %d", getSysDbKey()); + logFinest(Conf::logger, "Config: USER_DB_KEY %d", getUserDbKey()); + logFinest(Conf::logger, "Config: MAP_ADDRESS %ld", getMapAddress()); + logFinest(Conf::logger, "Config: DATABASE_FILE %s", getDbFile()); + //TODO:: for cache/sql/nw section + */ + + logFinest(Conf::logger, "Config: LOG_FILE %s", getLogFile()); + logFinest(Conf::logger, "Config: LOG_LEVEL %d", getLogLevel()); + logFinest(Conf::logger, "Config: DURABILITY %d", useDurability()); + logFinest(Conf::logger, "Config: MMAP %d", useMmap()); + logFinest(Conf::logger, "Config: DURABLE_MODE %d", getDurableMode()); + logFinest(Conf::logger, "Config: MUTEX_TIMEOUT_SECS %d", getMutexSecs()); + logFinest(Conf::logger, "Config: MUTEX_TIMEOUT_USECS %d", getMutexUSecs()); + logFinest(Conf::logger, "Config: MUTEX_TIMEOUT_RETRIES %d", getMutexRetries()); + logFinest(Conf::logger, "Config: LOCK_TIMEOUT_SECS %d", getLockSecs()); + logFinest(Conf::logger, "Config: LOCK_TIMEOUT_USECS %d", getLockUSecs()); + logFinest(Conf::logger, "Config: LOCK_TIMEOUT_RETRIES %d", getLockRetries()); +} void Config::print() { printf("ConfigValues\n"); @@ -318,6 +460,7 @@ void Config::print() printf(" getSysDbKey %d\n", getSysDbKey()); printf(" getUserDbKey %d\n", getUserDbKey()); printf(" getLogFile %s\n", getLogFile()); + printf(" getLogLevel %d\n", getLogLevel()); printf(" getDatabaseFile %s\n", getDbFile()); printf(" getMapAddress %ld\n", getMapAddress()); printf(" getMutexSecs %d\n", getMutexSecs()); @@ -326,17 +469,82 @@ void Config::print() printf(" getLockSecs %d\n", getLockSecs()); printf(" getLockUSecs %d\n", getLockUSecs()); printf(" getLockRetries %d\n", getLockRetries()); - printf(" isDurable %d\n", useDurability()); printf(" useCache %d\n", useCache()); - printf(" getCacheID %d\n", getCacheID()); printf(" getDSN %s\n", getDSN()); + printf(" getDsConfigFile %s\n",getDsConfigFile()); printf(" getTableConfigFile %s\n", getTableConfigFile()); printf(" isTwoWayCache %d\n", useTwoWayCache()); + printf(" getCacheMode %d\n", getCacheMode()); printf(" getCacheWaitSecs %d\n", getCacheWaitSecs()); printf(" useCsqlSqlServer %d\n", useCsqlSqlServer()); printf(" getPort %d\n", getPort()); + printf(" useReplication %d\n", useReplication()); + printf(" isDurable %d\n", useDurability()); + printf(" getReplConfigFile %s\n", getReplConfigFile()); + printf(" getSiteID %d\n", getSiteID()); + printf(" getMsgKey %d\n", getMsgKey()); printf(" getShmIDKey %d\n", getShmIDKey()); - //printf(" getMaxLogStoreSize %ld\n", getMaxLogStoreSize()); - //printf(" getNetworkID %d\n", getNetworkID()); - //printf(" getCacheNetworkID %d\n", getCacheNetworkID()); +} + +DbRetVal SiteInfo::populateSiteInfoList() +{ + if (!Conf::config.useReplication()) return OK; + FILE *fp = fopen( Conf::config.getReplConfigFile(), "r"); + if (fp == NULL) { + printError(ErrSysInit, "Invalid path/filename for REPL_CONFIG_FILE.\n"); + return ErrSysInit; + } + char line[128]; + while(fgets(line, sizeof (line), fp) != NULL) { + SiteInfoData *sInfo = new SiteInfoData(); + char *token = strtok(line, ":"); + sInfo->siteId = atoi(token); + if ((token = strtok(NULL, ":")) != NULL) + strncpy(sInfo->hostName, token, IDENTIFIER_LENGTH); + if ((token = strtok(NULL, ":")) != NULL) sInfo->port = atoi(token); + if ((token = strtok(NULL, ":")) != NULL) + strncpy(sInfo->mode, token, 32); + siteInfoList.append(sInfo); + if(strncasecmp(sInfo->mode, "ASYNC", 5)==0) asyncSiteList.append(sInfo); + if(strncasecmp(sInfo->mode, "SYNC", 4)==0) syncSiteList.append(sInfo); + } + fclose(fp); + return OK; +} + +bool SiteInfo::isAsyncSitePresent() +{ + bool async = false; + if (!Conf::config.useReplication()) return false; + ListIterator it = siteInfoList.getIterator(); + while (it.hasElement()) { + SiteInfoData *data = (SiteInfoData *) it.nextElement(); + if (strncmp(data->mode, "ASYNC", 5) == 0) { async = true; break; } + } + return async; +} + +bool SiteInfo::isSyncSitePresent() +{ + bool sync = false; + if (!Conf::config.useReplication()) return false; + ListIterator it = siteInfoList.getIterator(); + while (it.hasElement()) { + SiteInfoData *data = (SiteInfoData *) it.nextElement(); + if (strncmp(data->mode, "SYNC", 4) == 0) { sync = true; break; } + } + return sync; +} + +SiteInfo::~SiteInfo() +{ +// ListIterator it = siteInfoList.getIterator(); +// while(it.hasElement()) delete (SiteInfoData *) it.nextElement(); +// siteInfoList.reset(); + ListIterator it = asyncSiteList.getIterator(); + while(it.hasElement()) delete (SiteInfoData *) it.nextElement(); + asyncSiteList.reset(); + it = syncSiteList.getIterator(); + while(it.hasElement()) delete (SiteInfoData *) it.nextElement(); + syncSiteList.reset(); } diff --git a/src/storage/Connection.cxx b/src/storage/Connection.cxx index ce3eaf2e..2f77ef55 100644 --- a/src/storage/Connection.cxx +++ b/src/storage/Connection.cxx @@ -45,9 +45,9 @@ DbRetVal Connection::open(const char *username, const char *password) } DbRetVal rv = session->open(username, password); if (rv != OK) { delete session; session = NULL; return rv; } - rv = logger.startLogger(Conf::config.getLogFile()); + rv = Conf::logger.startLogger(Conf::config.getLogFile()); if (rv != OK) { delete session; session = NULL; return rv; } - logFinest(logger, "User logged in %s",username); + logFinest(Conf::logger, "User logged in %s",username); Index::init(); return OK; } @@ -55,8 +55,8 @@ DbRetVal Connection::open(const char *username, const char *password) DbRetVal Connection::close() { if (session == NULL) return ErrNoConnection; - logFinest(logger, "User logged out"); - logger.stopLogger(); + logFinest(Conf::logger, "User logged out"); + Conf::logger.stopLogger(); session->rollback(); delete session; // this inturn calls session->close session = NULL; diff --git a/src/storage/DatabaseManagerImpl.cxx b/src/storage/DatabaseManagerImpl.cxx index a397b2c1..f1251545 100644 --- a/src/storage/DatabaseManagerImpl.cxx +++ b/src/storage/DatabaseManagerImpl.cxx @@ -65,7 +65,7 @@ DbRetVal DatabaseManagerImpl::openSystemDatabase() systemDatabase_ = db_; db_ = NULL; printDebug(DM_Database, "Opened system database"); - logFinest(logger, "Opened system database"); + logFinest(Conf::Conf::logger, "Opened system database"); return OK; } @@ -78,7 +78,7 @@ DbRetVal DatabaseManagerImpl::closeSystemDatabase() closeDatabase(); db_ = db; printDebug(DM_Database, "Closed system database"); - logFinest(logger, "Closed System database"); + logFinest(Conf::logger, "Closed System database"); return OK; } @@ -164,7 +164,7 @@ DbRetVal DatabaseManagerImpl::createDatabase(const char *name, size_t size) chunkInfo); db_->setHashIndexChunk(chunkInfo);*/ - logFinest(logger, "Created database %s" , name); + logFinest(Conf::logger, "Created database %s" , name); return OK; } @@ -184,7 +184,7 @@ DbRetVal DatabaseManagerImpl::deleteDatabase(const char *name) delete db_; db_ = NULL; } - logFinest(logger, "Deleted database %s" , name); + logFinest(Conf::logger, "Deleted database %s" , name); return OK; } @@ -279,7 +279,7 @@ DbRetVal DatabaseManagerImpl::openDatabase(const char *name) if (firstThread) ProcessManager::systemDatabase = db_; printDebug(DM_Database, "Opening database: %s", name); - logFinest(logger, "Opened database %s" , name); + logFinest(Conf::logger, "Opened database %s" , name); return OK; } @@ -304,7 +304,7 @@ DbRetVal DatabaseManagerImpl::closeDatabase() } } ProcessManager::mutex.releaseLock(-1, false); - logFinest(logger, "Closed database"); + logFinest(Conf::logger, "Closed database"); delete db_; db_ = NULL; return OK; @@ -492,7 +492,7 @@ DbRetVal DatabaseManagerImpl::createTable(const char *name, TableDef &def) printDebug(DM_Database,"Inserted into FIELD:%s",name); systemDatabase_->releaseDatabaseMutex(); printDebug(DM_Database,"Table Created:%s",name); - logFinest(logger, "Table Created %s" , name); + logFinest(Conf::logger, "Table Created %s" , name); return OK; } @@ -564,7 +564,7 @@ DbRetVal DatabaseManagerImpl::dropTable(const char *name) chunkNode->free(systemDatabase_, (Chunk *) chunk); systemDatabase_->releaseDatabaseMutex(); printDebug(DM_Database, "Deleted Table %s" , name); - logFinest(logger, "Deleted Table %s" , name); + logFinest(Conf::logger, "Deleted Table %s" , name); rv = lMgr_->releaseLock(chunk); if (rv !=OK) { @@ -708,7 +708,7 @@ Table* DatabaseManagerImpl::openTable(const char *name) // lMgr-> tTuple->chunkPtr_ printDebug(DM_Database,"Opening table handle name:%s chunk:%x numIndex:%d", name, chunk, table->numIndexes_); - logFinest(logger, "Opening Table %s" , name); + logFinest(Conf::logger, "Opening Table %s" , name); tableHandleList.append(table); @@ -746,7 +746,7 @@ void DatabaseManagerImpl::closeTable(Table *table) //table->unlock(); tableHandleList.remove(table, false); if (table) delete table; table = NULL; - logFinest(logger, "Closing Table"); + logFinest(Conf::logger, "Closing Table"); } DbRetVal DatabaseManagerImpl::createIndex(const char *indName, IndexInitInfo *info) @@ -930,7 +930,7 @@ DbRetVal DatabaseManagerImpl::createHashIndex(const char *indName, const char *t TableImpl *tbl = (TableImpl *) openTable(tblName); if (! tbl->numTuples()) { printDebug(DM_Database, "Creating Hash Index Name:%s tblname:%s buckets:%x", indName, tblName, buckets); - logFinest(logger, "Creating HashIndex %s on %s with bucket size %d", indName, tblName, buckets); + logFinest(Conf::logger, "Creating HashIndex %s on %s with bucket size %d", indName, tblName, buckets); closeTable(tbl); return OK; } @@ -954,7 +954,7 @@ DbRetVal DatabaseManagerImpl::createHashIndex(const char *indName, const char *t } closeTable(tbl); printDebug(DM_Database, "Creating Hash Index Name:%s tblname:%s buckets:%x", indName, tblName, buckets); - logFinest(logger, "Creating HashIndex %s on %s with bucket size %d", indName, tblName, buckets); + logFinest(Conf::logger, "Creating HashIndex %s on %s with bucket size %d", indName, tblName, buckets); return OK; } @@ -1061,7 +1061,7 @@ DbRetVal DatabaseManagerImpl::createTreeIndex(const char *indName, const char *t TableImpl *tbl = (TableImpl *) openTable(tblName); if (! tbl->numTuples()) { printDebug(DM_Database, "Creating Tree Index Name:%s tblname:%s node size:%x",indName, tblName, nodeSize); - logFinest(logger, "Creating TreeIndex %s on %s with node size %d",indName, tblName, nodeSize); + logFinest(Conf::logger, "Creating TreeIndex %s on %s with node size %d",indName, tblName, nodeSize); return OK; } HashIndexInfo *indxInfo = NULL; @@ -1085,7 +1085,7 @@ DbRetVal DatabaseManagerImpl::createTreeIndex(const char *indName, const char *t closeTable(tbl); printDebug(DM_Database, "Creating Tree Index Name:%s tblname:%s node size:%x", indName, tblName, nodeSize); - logFinest(logger, "Creating TreeIndex %s on %s with node size %d", + logFinest(Conf::logger, "Creating TreeIndex %s on %s with node size %d", indName, tblName, nodeSize); return OK; } @@ -1176,7 +1176,7 @@ DbRetVal DatabaseManagerImpl::dropIndexInt(const char *name, bool takeLock) //Take table lock printDebug(DM_Database, "Dropped hash index %s",name); - logFinest(logger, "Deleted Index %s", name); + logFinest(Conf::logger, "Deleted Index %s", name); return OK; } DbRetVal DatabaseManagerImpl::printIndexInfo(char *name) diff --git a/src/storage/Logger.cxx b/src/storage/Logger.cxx index 42f1d138..7e9b854d 100644 --- a/src/storage/Logger.cxx +++ b/src/storage/Logger.cxx @@ -14,6 +14,8 @@ * * ***************************************************************************/ #include +#include +Logger Conf::logger; int Logger::createLogRecord(LogLevel level, char* filename, int lineNo, char* message, char **buffer) { @@ -21,24 +23,64 @@ int Logger::createLogRecord(LogLevel level, char* filename, struct timeval timeStamp; os::gettimeofday(&timeStamp); struct tm* tempTm = os::localtime(&timeStamp.tv_sec); - strftime(tempBuffer, 25, "%d/%m/%Y %H:%M:%S.", tempTm); - snprintf(*buffer, MAX_TRACE_LOG_LENGTH, "%s::%s:%d::%s::%d::%d::%lu::%s\n", - levelNames[level], tempBuffer, timeStamp.tv_usec, - filename, lineNo, +#if defined(SOLARIS) && defined(REMOTE_SOLARIS) + strftime(tempBuffer, 25, "%d/%m/%Y %H:%M:%S", (struct std::tm*) tempTm); +#else + strftime(tempBuffer, 25, "%d/%m/%Y %H:%M:%S", tempTm); +#endif + snprintf(*buffer, MAX_TRACE_LOG_LENGTH, "%s.%6d:%5d:%10lu:%s:%d:%s\n", + tempBuffer, timeStamp.tv_usec, os::getpid(), os::getthrid(), + filename, lineNo, message); return 0; } +void Logger::rollOverIfRequired() +{ + char *fileName = Conf::config.getLogFile(); + int fileSize = os::getFileSize(fileName); + char cmd[MAX_FILE_LEN]; + int ret =0; + int tries=0, totalTries=3; + while (tries < totalTries) { + ret = os::lockFile(fdLog); + if (ret ==0) break; + os::usleep(10000); + tries++; + } + if (tries == totalTries) + { + printError(ErrLockTimeOut,"Unable to lock log file for rollover"); + return ; + } + + if (fileSize > LOG_ROLLOVER_SIZE) { + time_t cnow = ::time(NULL); + struct tm *tmval = localtime(&cnow); + sprintf(cmd, "cp %s %s.%d-%d-%d:%d:%d:%d", fileName, fileName, + tmval->tm_year+1900, + tmval->tm_mon+1, tmval->tm_mday, tmval->tm_hour, + tmval->tm_min, tmval->tm_sec); + ret = system(cmd); + if (ret != 0) { + printError(ErrWarning, "Unable to rollover the log file"); + } + truncate(fileName, 0); + } + os::unlockFile(fdLog); + return; +} -//TODO::Multiple files: If it exceeeds some configured size, it rolls over to -//next with suffix like file.1, file.2, ... int Logger::log(LogLevel level, char* filename, int lineNo, char *format, ...) { + int configLevel = Conf::config.getLogLevel(); if (LogOff == configLevel) return 0; + int ret =0; if (level <= configLevel ) { + rollOverIfRequired(); va_list ap; char mesgBuf[1024]; va_start(ap, format); @@ -49,64 +91,65 @@ int Logger::log(LogLevel level, char* filename, } char *buffer = new char[MAX_TRACE_LOG_LENGTH]; createLogRecord(level, filename, lineNo, mesgBuf, &buffer); - //TODO::There is some issue in locking. Need to look into this and then - //uncomment the below lines - //int ret = mutex_.tryLock(5, 100000); - int ret = 0; - if (ret != 0) + int tries=0, totalTries=3; + while (tries < totalTries) { + ret = os::lockFile(fdLog); + if (ret ==0) break; + os::usleep(10000); + tries++; + } + if (tries == totalTries) { - printError(ErrLockTimeOut,"Unable to acquire logger Mutex"); + printError(ErrLockTimeOut,"Unable to lock log file %d", ret); delete[] buffer; return -1; } - os::write(fdLog, buffer, strlen(buffer)); - os::fsync(fdLog); - //mutex_.releaseLock(); + int bytesWritten = os::write(fdLog, buffer, strlen(buffer)); + if (bytesWritten != strlen(buffer)) + { + printf("Unable to write log entry"); + ret = -1; + } + os::unlockFile(fdLog); delete[] buffer; } - return 0; + return ret; } DbRetVal Logger::startLogger(char *filename, bool isCreate) { - char file[256]; - int i =0; - if (isCreate) + configLevel= (LogLevel) Conf::config.getLogLevel(); + if (LogOff == configLevel) return OK; + char cmd[MAX_FILE_LEN]; + int ret =0; + if (isCreate) { - while (true) - { - sprintf(file, "%s.%d", filename, i); - //check if file exists. If not create it - if (::access(file, F_OK) != 0 ) break; - i++; - } - fdLog = os::openFile(file, fileOpenCreat,0); - } - else - { - int newlyCreatedID =0; - while (true) - { - sprintf(file, "%s.%d", filename, i); - //check if file exists. If not create it - if (::access(file, F_OK) != 0 ) break; - newlyCreatedID = i; - i++; - } - sprintf(file, "%s.%d", filename, newlyCreatedID ); - fdLog = os::openFile(file, fileOpenAppend,0); + if (::access(filename, F_OK) == 0 ) { + //move the existing log file with timestamp and create new file + time_t cnow = ::time(NULL); + struct tm *tmval = localtime(&cnow); + sprintf(cmd, "cp %s %s.%d-%d-%d:%d:%d:%d", filename, filename, + tmval->tm_year+1900, + tmval->tm_mon+1, tmval->tm_mday, tmval->tm_hour, + tmval->tm_min, tmval->tm_sec); + ret = system(cmd); + if (ret != 0) { + printError(ErrWarning, "Unable to copy old log file"); + } + truncate(filename, 0); + } } + fdLog = os::openFile(filename, fileOpenAppend,0); if (fdLog == -1) { - printError(ErrSysInit,"Unable to create log file. Check whether server started\n"); + printError(ErrSysInit,"Unable to open log file"); return ErrSysInit; } - //TODO::get this value from configuration file - configLevel= LogFinest; return OK; } void Logger::stopLogger() { + if (configLevel == 0) return ; os::closeFile(fdLog); } diff --git a/src/storage/Mutex.cxx b/src/storage/Mutex.cxx index 4321cfb5..0bf31b05 100644 --- a/src/storage/Mutex.cxx +++ b/src/storage/Mutex.cxx @@ -21,7 +21,8 @@ #include Mutex::Mutex() { -#if defined(sparc) || defined(i686) || defined(x86_64) + noOfRead = -1; +#if defined(sparc) || defined(i686) || defined (x86_64) lock =0; #else pthread_mutexattr_t attr; @@ -33,7 +34,8 @@ Mutex::Mutex() int Mutex::init() { -#if defined(sparc) || defined(i686) || defined(x86_64) + noOfRead = -1; +#if defined(sparc) || defined(i686) || defined (x86_64) lock = 0; #else pthread_mutexattr_t attr; @@ -47,14 +49,14 @@ int Mutex::init() } int Mutex::init(char *mname) { - if (strlen(mname) > 19 ) return 0; init(); + if (strlen(mname) > 19 ) return 0; strcpy(name, mname); return 0; } -#if defined(sparc) || defined(i686) || defined(x86_64) +#if defined(sparc) || defined(i686) || defined (x86_64) int TSL(Lock *lock) { /* @@ -80,17 +82,11 @@ int TSL(Lock *lock) return oldval > 0; */ -#if defined(i686) || defined(x86_64) +#if defined(LINUX) int* lw; int res; lw = (int*)lock; if (*lock == 1) return 1; - /* In assembly we use the so-called AT & T syntax where - the order of operands is inverted compared to the ordinary Intel - syntax. The 'l' after the mnemonics denotes a 32-bit operation. - The line after the code tells which values come out of the asm - code, and the second line tells the input to the asm code. */ - /* This assembly compiles only with -O2 option, and not with -g option. Version1 __asm__ __volatile__( "movl $1, %%eax; xchgl (%%ecx), %%eax" @@ -117,18 +113,15 @@ int TSL(Lock *lock) return(res); -#elif defined (sparc) +#elif defined (SOLARIS) Lock res; - __asm__ __volatile__("ldstub [%2], %0 \n" - "=r"(res), "+m"(*lock) - "r"(lock) - "memory"); - return (int) res; + res = atomic_cas_32(lock, 0, 1); + return (res); #endif } #endif -int Mutex::tryLock(int tryTimes, int waitmsecs) +int Mutex::tryLock(int tryTimes, int waitmsecs,bool share) { if (TSL(&lock) == 0) { @@ -145,34 +138,49 @@ int Mutex::tryLock(int tryTimes, int waitmsecs) timeout.tv_usec = Conf::config.getMutexUSecs(); tryTimes = Conf::config.getMutexRetries(); } + int cnt=0; while (tries < tryTimes) { -#if defined(sparc) || defined(i686) || defined(x86_64) - if (TSL(&lock) == 0) - { - return 0; - } +#if defined(sparc) || defined(i686) || defined (x86_64) + if (Conf::config.getNoOfProcessors() >1) { + cnt=0; + while(true) { + if (TSL(&lock) == 0) + { + return 0; + } + cnt++; + if (cnt == tryTimes * 100) break; + } + }else { + if (TSL(&lock) == 0) return 0; + } #else - ret = pthread_mutex_trylock(&mutex_); - if (EBUSY != ret) return 0; + ret = pthread_mutex_trylock(&mutex_); + if (EBUSY != ret) return 0; #endif os::select(0, 0, 0, 0, &timeout); tries++; } + if(share && noOfRead != -1) { + noOfRead++; + return 2; + } printError(ErrLockTimeOut, "Unable to get the mutex , tried %d times", tries); return 1; } -int Mutex::getLock(int procSlot, bool procAccount) +int Mutex::getLock(int procSlot, bool procAccount,bool share) { int ret=0; -#if defined(sparc) || defined(i686) || defined(x86_64) - ret = tryLock(); +#if defined(sparc) || defined(i686) || defined (x86_64) + ret = tryLock(0,0,share); //add it to the has_ of the ThreadInfo if (ret ==0 && procAccount) ProcessManager::addMutex(this, procSlot); - + if(share & noOfRead == -1 && ret == 0 ) noOfRead ++; + if(ret == 2) return 0; return ret; #else ret = pthread_mutex_lock(&mutex_); @@ -182,10 +190,11 @@ int Mutex::getLock(int procSlot, bool procAccount) return 1; } -int Mutex::releaseLock(int procSlot, bool procAccount) +int Mutex::releaseLock(int procSlot, bool procAccount,bool share) { + if (noOfRead > 0 && share){ noOfRead--; return 0;} int ret=0; -#if defined(sparc) || defined(i686) || defined(x86_64) +#if defined(sparc) || defined(i686) || defined (x86_64) /*int *lw = &lock; if (*lw == 0) return 0; __asm__ __volatile__("movl $0, %%eax; xchgl (%%ecx), %%eax" : @@ -200,6 +209,7 @@ int Mutex::releaseLock(int procSlot, bool procAccount) if (ret == 0 && procAccount) { ProcessManager::removeMutex(this, procSlot); + if( noOfRead == 0 && share) noOfRead--; return ret; } else @@ -208,7 +218,7 @@ int Mutex::releaseLock(int procSlot, bool procAccount) int Mutex::destroy() { -#if defined(sparc) || defined(i686) || defined(x86_64) +#if defined(sparc) || defined(i686) || defined (x86_64) #else return pthread_mutex_destroy(&mutex_); #endif @@ -218,7 +228,7 @@ int Mutex::destroy() int Mutex::recoverMutex() { int ret=0; -#if defined(sparc) || defined(i686) || defined(x86_64) +#if defined(sparc) || defined(i686) || defined (x86_64) /*int *lw = &lock; if (*lw == 0) return 0; __asm__ __volatile__("movl $0, %%eax; xchgl (%%ecx), %%eax" : @@ -232,4 +242,74 @@ int Mutex::recoverMutex() #endif return ret; } - + +int Mutex::CASL(long *ptr, long oldVal, long newVal) +{ +#ifdef SOLARIS +#ifdef x86_64 //or sparc64 + unsigned long res = atomic_cas_64((unsigned long*)ptr, + (unsigned long) oldVal, (unsigned long) newVal); + if (res == oldVal) return 0; else return 1; +#else + return CAS((int*)ptr, (int)oldVal, (int)newVal); +#endif +#endif +#ifdef LINUX +#ifdef x86_64 + long result; + __asm__ __volatile__ ("lock; cmpxchgq %q2, %1" + : "=a" (result), "=m" (*ptr) + : "r" (newVal), "m" (*ptr), "0" (oldVal)); + if (result == oldVal) return 0; + + struct timeval timeout; + timeout.tv_sec=0; + timeout.tv_usec=1000; + os::select(0,0,0,0, &timeout); + __asm__ __volatile__ ("lock; cmpxchgq %q2, %1" + : "=a" (result), "=m" (*ptr) + : "r" (newVal), "m" (*ptr), "0" (oldVal)); + + //if (result) return 0; else {printf("DEBUG::CAS Fails %d-\n", result); return 1; } + if (result == oldVal) return 0; else return 1; +#else + return CAS((int*)ptr, (int)oldVal, (int)newVal); +#endif +#endif + +} +int Mutex::CAS(int *ptr, int oldVal, int newVal) +{ +#ifdef LINUX + unsigned char ret; + __asm__ __volatile__ ( + " lock\n" + " cmpxchgl %2,%1\n" + " sete %0\n" + : "=q" (ret), "=m" (*ptr) + : "r" (newVal), "m" (*ptr), "a" (oldVal) + : "memory"); + + //above assembly returns 0 in case of failure + if (ret) return 0; + + struct timeval timeout; + timeout.tv_sec=0; + timeout.tv_usec=1000; + os::select(0,0,0,0, &timeout); + __asm__ __volatile__ ( + " lock\n" + " cmpxchgl %2,%1\n" + " sete %0\n" + : "=q" (ret), "=m" (*ptr) + : "r" (newVal), "m" (*ptr), "a" (oldVal) + : "memory"); + //if (ret) return 0; else {printf("DEBUG::CAS Fails %d-\n", ret); return 1; } + if (ret) return 0; else return 1; +#else //for solaris + unsigned int ret; + ret = atomic_cas_32((unsigned int*)ptr, (unsigned int) oldVal, + (unsigned int) newVal); + if (ret == oldVal) return 0; else return 1; +#endif +} diff --git a/src/storage/TableImpl.cxx b/src/storage/TableImpl.cxx index e365dc00..71a49405 100644 --- a/src/storage/TableImpl.cxx +++ b/src/storage/TableImpl.cxx @@ -1130,7 +1130,7 @@ DbRetVal TableImpl::close() //table->unlock(); delete pred_; delete this; - logFinest(logger, "Closing Table"); + logFinest(Conf::logger, "Closing Table"); return OK; } diff --git a/src/storage/os.cxx b/src/storage/os.cxx index 67c666bf..15c4a975 100644 --- a/src/storage/os.cxx +++ b/src/storage/os.cxx @@ -16,9 +16,13 @@ #include #include -caddr_t os::mmap(caddr_t addr, size_t len, int prot, int flags, int fildes, off_t off) +void* os::mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off) { - return ((caddr_t)::mmap(addr,len,prot,flags,fildes,off)); +#ifdef SOLARIS + return ((void*)::mmap((char*)addr,len,prot,flags,fildes,off)); +#else + return ((void*)::mmap(addr,len,prot,flags,fildes,off)); +#endif } int os::munmap(caddr_t addr, size_t len) @@ -61,15 +65,21 @@ int os::gettimeofday(struct timeval *tp) struct tm* os::localtime(long *secs) { +#ifdef SOLARIS + return (struct tm*) ::localtime(secs); +#else return ::localtime(secs); +#endif } int os::openFile(const char *name, FileOpenMode flags, size_t size) { int retval = -1; //mode_t mode = S_IRWXU | S_IRGRP | S_IWGRP ; - mode_t mode = (mode_t)0755 ; + mode_t oldMode = umask(0000); + mode_t mode = (mode_t)0777 ; retval=::open(name, flags, mode); + umask(oldMode); if (0 == size) return retval; os::lseek(retval, size-1, SEEK_SET); @@ -77,11 +87,25 @@ int os::openFile(const char *name, FileOpenMode flags, size_t size) os::write(retval, buf, 1); return retval; } +int os::openFileForAppend(const char *name, int flag) +{ + mode_t mode = (mode_t)0644 ; + int flags = flag | O_WRONLY|O_APPEND; + return ::open(name, flags, mode); +} int os::closeFile(int fd) { return ::close(fd); } +int os::lockFile(int fd) +{ + return flock(fd, LOCK_EX); +} +int os::unlockFile(int fd) +{ + return ::flock(fd, LOCK_UN); +} off_t os::lseek(int fildes, off_t offset, int whence) { @@ -143,8 +167,12 @@ int os::usleep(int msecs) os::select(0,0,0,0, &timeout); return 0; } - - +int os::getFileSize(const char *fileName) +{ + struct stat buf; + stat(fileName, &buf); + return buf.st_size; +} char* os::getenv(const char *envVarName) { @@ -155,7 +183,13 @@ char* os::getenv(const char *envVarName) int os::setenv(const char *envVarName, const char *value) { +#ifdef SOLARIS + char str[IDENTIFIER_LENGTH*3]; + sprintf(str, "%s=%s", envVarName, value); + return putenv(str); +#else return ::setenv(envVarName, value,1); +#endif } int os::kill(pid_t pid, int sig) @@ -170,10 +204,10 @@ bool os::atobool(char *value) else if (strlen(value) ==5 && strncasecmp(value,"false",5)==0) return false; return false; } -pid_t os::createProcess(const char* cmdName, const char *arg0, ...) +pid_t os::createProcess(const char* cmdName, const char* execName) { pid_t pid; - pid = ::vfork(); + pid = ::fork(); if (pid == (pid_t) -1 ) { printf("Process creation failed\n"); @@ -184,34 +218,10 @@ pid_t os::createProcess(const char* cmdName, const char *arg0, ...) //return for parent return pid; } - va_list ap; - va_start(ap,arg0); - - const char *argv[5]; - - argv[0]=cmdName; - argv[1]=arg0; - - argv[2]=NULL; - int i = 2; - while(argv[i++]=va_arg(ap,char *)); - switch(i){ - case 2: - pid=::execl(argv[0],argv[1]);break; - case 3: - pid=::execl(argv[0],argv[1],argv[2]);break; - case 4: - pid=::execl(argv[0],argv[1],argv[2],argv[3]);break; - case 5: - pid=::execl(argv[0],argv[1],argv[2],argv[3],argv[4]);break; - default: - printf("only three options allowed\n"); - pid=-1;break; - } + pid=::execl(cmdName,execName, NULL); if (pid < 0) printf("Exec failed\n"); return pid; - } pid_t os::fork() { @@ -219,11 +229,26 @@ pid_t os::fork() } size_t os::send(int fd, const void *buf, size_t len, int flags) { - return ::send(fd, buf, len, flags); + size_t totalLen = len; + size_t nbytes = ::send(fd, buf, len, flags); + while (nbytes != -1 && nbytes != len) { + len = len - nbytes; + nbytes = ::send(fd, ((char *)buf)+nbytes, len, flags); + } + if (nbytes == -1) return -1; + else return totalLen; } size_t os::recv(int fd, void *buf, size_t len, int flags) { - return ::recv(fd, buf, len, flags); + size_t totalLen = len; + size_t nbytes = ::recv(fd, buf, len, flags); + if (!nbytes) return 0; + while (nbytes != -1 && nbytes != len) { + len = len - nbytes; + nbytes = ::recv(fd, ((char *)buf)+nbytes, len, flags); + } + if (nbytes == -1) return -1; + else return totalLen; } int os::gethostname(char *hostname, size_t len) { @@ -233,3 +258,83 @@ int os::strmatch(char *pattern, char *str) { return ::fnmatch(pattern, str, 0); } + +int os::msgget(key_t key, int oflag) +{ + return ::msgget(key, oflag | IPC_CREAT); +} + +int os::msgsnd(int msqid, const void *ptr, size_t len, int flag) +{ + return ::msgsnd(msqid, ptr, len, flag); +} + +ssize_t os::msgrcv(int msqid, void *ptr, size_t len, long type, int flag) +{ + return ::msgrcv(msqid, ptr, len, type, flag); +}; + +int os::msgctl(int msqid, int cmd, struct msqid_ds *buff) +{ + return ::msgctl(msqid, cmd, buff); +} +bool os::fileExists(char *fileName) +{ + int ret = access(fileName, R_OK); + if (0 == ret) return true; else return false; +} +int os::isValidIP(char ipstr[] ) +{ +#if defined(LINUX) + struct ifaddrs * ifAddrStruct=NULL; + void * tmpAddrPtr=NULL; + char addressBuffer[100]; + int i=0; + getifaddrs(&ifAddrStruct); + + while (ifAddrStruct!=NULL) + { + if (ifAddrStruct->ifa_addr->sa_family==AF_INET && strcmp(ifAddrStruct->ifa_name, "lo0")!=0) + { + tmpAddrPtr=&((struct sockaddr_in *)ifAddrStruct->ifa_addr)->sin_addr; + inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, 100); + if(strcmp(ipstr,addressBuffer) == 0) + { + // printf("\nThe ip is matched %s and %s",ipstr,addressBuffer); + return 1; + } + // printf("IP Address %s\n", inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, 100)); + } + ifAddrStruct=ifAddrStruct->ifa_next; + } +#endif + return 0; +} +char* os::strcasestr(char *str1, const char *str2) +{ +#if defined(LINUX) + return ::strcasestr(str1, str2); +#else + return ::strstr(str1, str2); + /* + int size=strlen(str1); + char *tmpStr=new char[size]; + char *tmpStrPtr=NULL; + strcpy(tmpStr, str1); + tmpStrPtr=tmpStr; + while(*tmpStrPtr != '\0') + { + *tmpStrPtr=::toupper(*tmpStrPtr); + tmpStrPtr++; + } + char *subStrPtr = ::strstr(tmpStr, str2); + delete []tmpStr; + return subStrPtr; + */ +#endif +} +int os::getNoOfProcessors() +{ + return ::sysconf(_SC_NPROCESSORS_ONLN); +} + diff --git a/src/tools/csqlcacheserver.cxx b/src/tools/csqlcacheserver.cxx index fef818c2..50752aca 100644 --- a/src/tools/csqlcacheserver.cxx +++ b/src/tools/csqlcacheserver.cxx @@ -123,7 +123,7 @@ int getRecordsFromTargetDb(int mode) int rows =0; DbRetVal rv = OK; char StmtStr[1024]; - caId =Conf::config.getCacheID(); + caId =Conf::config.getSiteID(); AbsSqlStatement *stmt = SqlFactory::createStatement(CSqlAdapter); stmt->setConnection(targetconn); AbsSqlStatement *delstmt = SqlFactory::createStatement(CSqlAdapter); diff --git a/src/tools/csqlreplserver.cxx b/src/tools/csqlreplserver.cxx index 223dbb6a..866addb1 100644 --- a/src/tools/csqlreplserver.cxx +++ b/src/tools/csqlreplserver.cxx @@ -80,20 +80,7 @@ int main(int argc, char **argv) SqlNetworkHandler::conn->disconnect(); return 1; } - bool found =false; - while(!feof(fp)) { - fscanf(fp, "%d:%d:%s\n", &nwid, &port, hostname); - printf( "%d:%d:%s\n", nwid, port, hostname); - if (nwid == Conf::config.getNetworkID()) { found = true; break;} - } fclose(fp); - if (!found) - { - printf("Info not found in REPL_CONFIG_FILE for nwid %d\n", - Conf::config.getNetworkID()); - SqlNetworkHandler::conn->disconnect(); - return 1; - } NetworkServer *nwServer; nwServer = new UDPServer(); diff --git a/src/tools/csqlserver.cxx b/src/tools/csqlserver.cxx index a3f3d614..3484f831 100644 --- a/src/tools/csqlserver.cxx +++ b/src/tools/csqlserver.cxx @@ -50,7 +50,7 @@ DbRetVal releaseAllResources(Database *sysdb, ThreadInfo *info ) if (info->has_[i] != NULL) { printf("Dead Procs: %d %lu holding mutex %x %s \n", info->pid_, info->thrid_, info->has_[i], info->has_[i]->name); - logFine(logger, "Dead Procs: %d %lu holding mutex %x %s \n", info->pid_, info->thrid_, info->has_[i], info->has_[i]->name); + logFine(Conf::logger, "Dead Procs: %d %lu holding mutex %x %s \n", info->pid_, info->thrid_, info->has_[i], info->has_[i]->name); //TODO::recovery of mutexes sysdb->recoverMutex(info->has_[i]); //srvStop = 1; @@ -115,7 +115,7 @@ DbRetVal logActiveProcs(Database *sysdb) for (; i < Conf::config.getMaxProcs(); i++) { if (pInfo->pid_ !=0 ) { - logFine(logger, "Registered Procs: %d %lu\n", pInfo->pid_, pInfo->thrid_); + logFine(Conf::logger, "Registered Procs: %d %lu\n", pInfo->pid_, pInfo->thrid_); printf("Client process with pid %d is still registered\n", pInfo->pid_); count++; } @@ -187,14 +187,14 @@ int main(int argc, char **argv) } os::signal(SIGINT, sigTermHandler); os::signal(SIGTERM, sigTermHandler); - rv = logger.startLogger(Conf::config.getLogFile(), true); + rv = Conf::logger.startLogger(Conf::config.getLogFile(), true); if (rv != OK) { printf("Unable to start the logger\n"); return 2; } bool isInit = true; - logFine(logger, "Server Started"); + logFine(Conf::logger, "Server Started"); int ret = session->initSystemDatabase(); if (0 != ret) { @@ -240,7 +240,7 @@ int main(int argc, char **argv) int ret = system("redo -a"); if (ret != 0) { printf("Recovery failed. Redo log file corrupted\n"); - logger.stopLogger(); + Conf::logger.stopLogger(); session->destroySystemDatabase(); delete session; return 10; @@ -250,7 +250,7 @@ int main(int argc, char **argv) ret = system(cmd); if (ret != 0) { printf("Unable to create checkpoint file\n"); - logger.stopLogger(); + Conf::logger.stopLogger(); session->destroySystemDatabase(); delete session; return 11; @@ -258,7 +258,7 @@ int main(int argc, char **argv) ret = unlink(dbRedoFileName); if (ret != 0) { printf("Unable to delete redo log file. Delete and restart the server\n"); - logger.stopLogger(); + Conf::logger.stopLogger(); session->destroySystemDatabase(); delete session; return 11; @@ -272,7 +272,7 @@ int main(int argc, char **argv) int ret = system("cachetable -U root -P manager -R"); if (ret != 0) { printf("Cached Tables recovery failed %d\n", ret); - logger.stopLogger(); + Conf::logger.stopLogger(); session->destroySystemDatabase(); delete session; return 2; @@ -280,7 +280,7 @@ int main(int argc, char **argv) printf("Cached Tables recovered\n"); } else { printf("Cache mode is not set in csql.conf. Cannot recover\n"); - logger.stopLogger(); + Conf::logger.stopLogger(); session->destroySystemDatabase(); delete session; return 1; @@ -320,11 +320,11 @@ reloop: os::kill(cachepid, SIGTERM); os::kill(sqlserverpid, SIGTERM); //if (recoverFlag) dumpData(); - logFine(logger, "Server Exiting"); + logFine(Conf::logger, "Server Exiting"); printf("Server Exiting\n"); - logFine(logger, "Server Ended"); + logFine(Conf::logger, "Server Ended"); UID.destroy(); - logger.stopLogger(); + Conf::logger.stopLogger(); session->destroySystemDatabase(); delete session; return 0; -- 2.11.4.GIT