summaryrefslogtreecommitdiffstats
path: root/queue.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-15 17:08:08 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-15 17:08:08 +0000
commitf2c27aa1e032c2b9e6339c01904334f33b4ac920 (patch)
tree799fa5f91146da36fb9a26fa3b26152b6b90cf61 /queue.c
parentb0ea982f5802b020b9e35f37cfa3a4acacd048bb (diff)
downloadrsyslog-f2c27aa1e032c2b9e6339c01904334f33b4ac920.tar.gz
rsyslog-f2c27aa1e032c2b9e6339c01904334f33b4ac920.tar.xz
rsyslog-f2c27aa1e032c2b9e6339c01904334f33b4ac920.zip
first shot at queue restore on startup, but could not finish before I need
to leave ;)
Diffstat (limited to 'queue.c')
-rw-r--r--queue.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/queue.c b/queue.c
index c6f761e0..02346075 100644
--- a/queue.c
+++ b/queue.c
@@ -1,5 +1,4 @@
// TODO: do an if(debug) in dbgrintf - performanc ein release build!
-// TODO: remove bIsDA?
// TODO: peekmsg() on first entry, with new/inprogress/deleted entry, destruction in
// call consumer state. Facilitates retaining messages in queue until action could
// be called!
@@ -654,6 +653,45 @@ finalize_it:
}
+/* This method checks if we have a QIF file for the current queue (no matter of
+ * queue mode). Returns RS_RET_OK if we have a QIF file or an error status otherwise.
+ * rgerhards, 2008-01-15
+ */
+static rsRetVal
+queueHaveQIF(queue_t *pThis)
+{
+ DEFiRet;
+ uchar pszQIFNam[MAXFNAME];
+ size_t lenQIFNam;
+ struct stat stat_buf;
+
+ ISOBJ_TYPE_assert(pThis, queue);
+
+ if(pThis->pszFilePrefix == NULL)
+ ABORT_FINALIZE(RS_RET_ERR); // TODO: change code!
+
+ /* Construct file name */
+ lenQIFNam = snprintf((char*)pszQIFNam, sizeof(pszQIFNam) / sizeof(uchar), "%s/%s.qi",
+ (char*) glblGetWorkDir(), (char*)pThis->pszFilePrefix);
+
+ /* check if the file exists */
+dbgprintf("stat HaveQIF '%s'\n", pszQIFNam);
+ if(stat((char*) pszQIFNam, &stat_buf) == -1) {
+ if(errno == ENOENT) {
+ dbgprintf("Queue 0x%lx: no .qi file found\n", queueGetID(pThis));
+ ABORT_FINALIZE(RS_RET_FILE_NOT_FOUND);
+ } else {
+ dbgprintf("Queue 0x%lx: error %d trying to access .qi file\n", queueGetID(pThis), errno);
+ ABORT_FINALIZE(RS_RET_IO_ERROR);
+ }
+ }
+ /* If we reach this point, we have a .qi file */
+
+finalize_it:
+ return iRet;
+}
+
+
/* The method loads the persistent queue information.
* rgerhards, 2008-01-11
*/
@@ -1308,6 +1346,7 @@ rsRetVal queueStart(queue_t *pThis) /* this is the ConstructionFinalizer */
{
DEFiRet;
int i;
+ rsRetVal iRetLocal;
assert(pThis != NULL);
@@ -1330,6 +1369,28 @@ rsRetVal queueStart(queue_t *pThis) /* this is the ConstructionFinalizer */
}
}
+ if(pThis->bIsDA) {
+ /* If we are disk-assisted, we need to check if there is a QIF file
+ * which we need to load. -- rgerhards, 2008-01-15
+ */
+ iRetLocal = queueHaveQIF(pThis);
+dbgprintf("HaveQIF %d\n", iRet);
+ if(iRetLocal == RS_RET_OK) {
+dbgprintf("need to restore disk queue\n");
+ // code below to function!
+ /* if we reach this point, we are NOT currently running in DA mode.
+ * TODO: split this function, I think that would make the code easier
+ * to read. -- rgerhards, 2008-10-15
+ */
+ dbgprintf("Queue 0x%lx: on-disk queue present, needs to be reloaded\n",
+ queueGetID(pThis));
+
+ pThis->qRunsDA = QRUNS_DA_INIT; /* indicate we now run in DA mode - this is reset by the DA worker if it fails */
+
+ /* now we must start our DA worker thread - it does the rest of the initialization */
+ CHKiRet(queueStrtWrkThrd(pThis, 0));
+ }
+ }
finalize_it:
return iRet;
}