1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 ***************************************************************************/
16 #include <AbsSqlConnection.h>
17 #include <AbsSqlStatement.h>
18 #include <SqlConnection.h>
19 #include <SqlStatement.h>
20 #include <SqlFactory.h>
22 #include <SessionImpl.h>
23 #include <NanoTimer.h>
26 static void sigTermHandler(int sig
)
28 printf("Received signal %d\nStopping the server\n", sig
);
31 static void sigChildHandler(int sig
)
33 os::signal(SIGCHLD
, sigChildHandler
);
35 waitpid(-1, &stat
, WNOHANG
);
36 //TODO::move waitpid to os wrapper
42 printf("Usage: csqlcheckpointserver \n");
43 printf("Description: Start the csql checkpoint server.\n");
46 DbRetVal
takeCheckpoint()
48 char fileName
[MAX_FILE_LEN
];
49 sprintf(fileName
, "%s/csql.db.cur", Conf::config
.getDbFile());
50 if (::access(fileName
, F_OK
) != 0 ) return OK
;
51 int fileSize
= os::getFileSize(fileName
);
52 logFine(Conf::logger
, "Redo log file size %d", fileSize
);
53 if (fileSize
< Conf::config
.getChkptRedoLimit()) return OK
;
56 DbRetVal rv
= conn
.open(I_USER
, I_PASS
);
57 if (rv
!= OK
) return rv
;
58 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
62 int tries
= 0, totalTries
=10;
63 while(tries
< totalTries
) {
64 rv
= dbMgr
->checkPoint();
65 if (rv
== ErrLoadingOn
) {
70 if (rv
== ErrLockTimeOut
) {
71 os::sleep(1); //sleep for 1 second
72 } else if (rv
!= OK
) {
73 printError(rv
, "checkpoint: failed");
77 }else if (rv
== OK
) break;
81 if (rv
!= ErrLockTimeOut
) {
82 logFine(Conf::logger
, "Checkpoint taken %lld microsecs", timer
.avg()/1000);
83 //printf("Time Taken for checkpoint %lld\n", timer.avg()/1000/1000);
85 logFine(Conf::logger
, "Checkpoint:Could not get TXN consistent point");
90 int main(int argc
, char **argv
)
93 while ((c
= getopt(argc
, argv
, "?")) != EOF
)
97 case '?' : { opt
= 10; break; } //print help
108 DbRetVal rv
= session
.readConfigFile();
111 printError(ErrSysInternal
,"Unable to read the configuration file \n");
114 os::signal(SIGINT
, sigTermHandler
);
115 os::signal(SIGTERM
, sigTermHandler
);
116 os::signal(SIGCHLD
, sigChildHandler
);
118 if (!Conf::config
.useDurability())
120 printError(ErrSysInternal
, "Durablity is set to OFF in csql.conf file\n");
123 logFine(Conf::logger
, "CSQL Checkpoint server started");
125 struct timeval timeout
, tval
;
126 timeout
.tv_sec
= Conf::config
.getChkptSecs();
131 tval
.tv_sec
= timeout
.tv_sec
;
132 ret
= os::select(0, 0, 0, 0, &tval
);
136 printf("Csql Checkpoint Daemon Exiting\n");
137 logFine(Conf::logger
, "CSQL Checkpoint server exiting");