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
);
34 printf("Usage: csqlcheckpointserver \n");
35 printf("Description: Start the csql checkpoint server.\n");
38 DbRetVal
takeCheckpoint()
40 char fileName
[MAX_FILE_LEN
];
41 sprintf(fileName
, "%s/csql.db.cur", Conf::config
.getDbFile());
42 if (::access(fileName
, F_OK
) != 0 ) return OK
;
43 int fileSize
= os::getFileSize(fileName
);
44 logFine(Conf::logger
, "Redo log file size %d", fileSize
);
45 if (fileSize
< Conf::config
.getChkptRedoLimit()) return OK
;
48 DbRetVal rv
= conn
.open(I_USER
, I_PASS
);
49 if (rv
!= OK
) return rv
;
50 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
54 int tries
= 0, totalTries
=10;
55 while(tries
< totalTries
) {
56 rv
= dbMgr
->checkPoint();
57 if (rv
== ErrLoadingOn
) {
62 if (rv
== ErrLockTimeOut
) {
63 os::sleep(1); //sleep for 1 second
64 } else if (rv
!= OK
) {
65 printError(rv
, "checkpoint: failed");
69 }else if (rv
== OK
) break;
73 if (rv
!= ErrLockTimeOut
) {
74 logFine(Conf::logger
, "Checkpoint taken %lld microsecs", timer
.avg()/1000);
75 //printf("Time Taken for checkpoint %lld\n", timer.avg()/1000/1000);
77 logFine(Conf::logger
, "Checkpoint:Could not get TXN consistent point");
82 int main(int argc
, char **argv
)
85 while ((c
= getopt(argc
, argv
, "?")) != EOF
)
89 case '?' : { opt
= 10; break; } //print help
100 DbRetVal rv
= session
.readConfigFile();
103 printError(ErrSysInternal
,"Unable to read the configuration file \n");
106 os::signal(SIGINT
, sigTermHandler
);
107 os::signal(SIGTERM
, sigTermHandler
);
108 os::signal(SIGCHLD
, SIG_IGN
);
110 if (!Conf::config
.useDurability())
112 printError(ErrSysInternal
, "Durablity is set to OFF in csql.conf file\n");
115 logFine(Conf::logger
, "CSQL Checkpoint server started");
117 struct timeval timeout
, tval
;
118 timeout
.tv_sec
= Conf::config
.getChkptSecs();
123 tval
.tv_sec
= timeout
.tv_sec
;
124 ret
= os::select(0, 0, 0, 0, &tval
);
128 printf("Csql Checkpoint Daemon Exiting\n");
129 logFine(Conf::logger
, "CSQL Checkpoint server exiting");