Backlogdata is now made persistent every 10 minutes.
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 2 Feb 2008 17:26:50 +0000 (17:26 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 2 Feb 2008 17:26:50 +0000 (17:26 +0000)
Found a bug while implementing: backlog data isn't replayed right
now. Gonna Fix that right now. Please DO NOT use this revision or
r437. Stay tuned.

src/core/abstractsqlstorage.cpp
src/core/abstractsqlstorage.h
src/core/core.cpp
src/core/core.h
src/core/storage.h
version.inc

index bc18caf..825dda8 100644 (file)
@@ -102,6 +102,16 @@ bool AbstractSqlStorage::init(const QVariantMap &settings) {
   return true;
 }
 
+void AbstractSqlStorage::sync() {
+  QHash<QPair<QString, int>, QSqlQuery *>::iterator iter = _queryCache.begin();
+  while(iter != _queryCache.end()) {
+    delete *iter;
+    iter = _queryCache.erase(iter);
+  }
+
+  logDb().commit();
+}
+
 QString AbstractSqlStorage::queryString(const QString &queryName, int version) {
   if(version == 0)
     version = schemaVersion();
index 7002699..6fefb78 100644 (file)
@@ -40,6 +40,7 @@ public:
   
 protected:
   bool init(const QVariantMap &settings = QVariantMap());
+  virtual void sync();
   
   QSqlDatabase logDb();
   
index 2024387..4826c3e 100644 (file)
@@ -49,6 +49,10 @@ Core::Core()
   : storage(0)
 {
   startTime = QDateTime::currentDateTime();  // for uptime :)
+
+  connect(&_storageSyncTimer, SIGNAL(timeout()),
+         this, SLOT(syncStorage()));
+  _storageSyncTimer.start(10 * 60 * 1000); // in msecs
 }
 
 void Core::init() {
@@ -95,6 +99,11 @@ Core::~Core() {
   qDeleteAll(sessions);
 }
 
+void Core::syncStorage() {
+  QMutexLocker locker(&mutex);
+  return instance()->storage->sync();
+}
+
 void Core::restoreState() {
   if(instance()->sessions.count()) {
     qWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!"));
index 51237ec..091c0f7 100644 (file)
@@ -25,6 +25,7 @@
 #include <QMutex>
 #include <QString>
 #include <QVariant>
+#include <QTimer>
 #include <QTcpServer>
 #include <QTcpSocket>
 
@@ -130,6 +131,12 @@ class Core : public QObject {
      */
     static QList<BufferInfo> requestBuffers(UserId user, QDateTime since = QDateTime());
 
+  public slots:
+    //! Make storage data persistent
+    /** \note This method is threadsafe.
+     */
+    void syncStorage();
+  
   signals:
     //! Sent when a BufferInfo is updated in storage.
     void bufferInfoUpdated(UserId user, const BufferInfo &info);
@@ -158,6 +165,7 @@ class Core : public QObject {
     UserId guiUser;
     QHash<UserId, SessionThread *> sessions;
     Storage *storage;
+    QTimer _storageSyncTimer;
 
     QTcpServer server; // TODO: implement SSL
     QHash<QTcpSocket *, quint32> blocksizes;
index 30c1c0b..6470b40 100644 (file)
@@ -60,7 +60,14 @@ class Storage : public QObject {
      *  \return True if and only if the storage provider was initialized successfully.
      */
     virtual bool init(const QVariantMap &settings = QVariantMap()) = 0;
-    
+
+  //! Makes temp data persistent
+  /** This Method is periodically called by the Quassel Core to make temporary
+   *  data persistant. This reduces the data loss drastically in the
+   *  unlikely case of a Core crash.
+   */
+    virtual void sync() = 0;
+  
     // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
 
     /* User handling */
index 51bdc10..1708688 100644 (file)
@@ -5,7 +5,7 @@
 
   quasselVersion = "0.2.0-pre";
   quasselDate = "2008-02-02";
-  quasselBuild = 437;
+  quasselBuild = 438;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 435;