[tracker/urho-sync: 121/121] Atomic rename and journal load



commit 2c25a572dbadf53ed5d9316d1eb61c0655335e98
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Aug 19 15:30:58 2009 +0200

    Atomic rename and journal load

 src/libtracker-db/tracker-db-backup.c |   25 ++++++++++++++++++++-
 src/tracker-store/tracker-store.c     |   38 +++++---------------------------
 2 files changed, 29 insertions(+), 34 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-backup.c b/src/libtracker-db/tracker-db-backup.c
index 4ed9a3c..68fe821 100644
--- a/src/libtracker-db/tracker-db-backup.c
+++ b/src/libtracker-db/tracker-db-backup.c
@@ -36,6 +36,7 @@
 
 #include "tracker-db-backup.h"
 
+#define TRACKER_DB_BACKUP_META_FILENAME_T	"meta-backup.db.tmp"
 
 typedef struct {
 	TrackerBackupFinished callback;
@@ -47,6 +48,7 @@ typedef struct {
 	sqlite3_backup *backup_db;
 	gchar *backup_fname;
 	int result;
+	GFile *parent;
 } BackupInfo;
 
 GQuark
@@ -72,6 +74,10 @@ backup_info_free (gpointer user_data)
 {
 	BackupInfo *info = user_data;
 
+	if (info->parent) {
+		g_object_unref (info->parent);
+	}
+
 	if (info->destroy) {
 		info->destroy (info->user_data);
 	}
@@ -156,6 +162,21 @@ on_backup_temp_finished (gpointer user_data)
 		             "%s", sqlite3_errmsg (info->backup_temp));
 	}
 
+	if (!info->error) {
+		GFile *from_file, *to_file;
+
+		from_file = g_file_get_child (info->parent, TRACKER_DB_BACKUP_META_FILENAME_T);
+		to_file = g_file_get_child (info->parent, TRACKER_DB_BACKUP_META_FILENAME);
+
+		g_file_move (from_file, to_file, 
+			     G_FILE_COPY_OVERWRITE, 
+			     NULL, NULL, NULL,
+			     &info->error);
+
+		g_object_unref (from_file);
+		g_object_unref (to_file);
+	}
+
 	perform_callback (info);
 
 	backup_info_free (info);
@@ -190,8 +211,8 @@ tracker_db_backup_save (TrackerBackupFinished callback,
 	file = g_file_new_for_path (db_file);
 	parent = g_file_get_parent (file);
 	g_object_unref (file);
-	file = g_file_get_child (parent, TRACKER_DB_BACKUP_META_FILENAME);
-	g_object_unref (parent);
+	file = g_file_get_child (parent, TRACKER_DB_BACKUP_META_FILENAME_T);
+	info->parent = parent;
 	info->backup_fname = g_file_get_path (file);
 	g_object_unref (file);
 
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index c04635e..a2617ed 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -30,6 +30,7 @@
 #include <libtracker-db/tracker-db-backup.h>
 #include <libtracker-db/tracker-db-journal.h>
 #include <libtracker-db/tracker-db-interface-sqlite.h>
+#include <libtracker-db/tracker-db-journal.h>
 
 #include <libtracker-data/tracker-data-update.h>
 #include <libtracker-data/tracker-data-query.h>
@@ -288,25 +289,6 @@ sync_idle_destroy (gpointer user_data)
 	private->have_sync_handler = FALSE;
 }
 
-static void
-on_committed (gpointer user_data)
-{
-	TrackerStorePrivate *private;
-
-	tracker_db_journal_truncate ();
-
-	private = g_static_private_get (&private_key);
-	g_return_if_fail (private != NULL);
-
-	private->start_log = TRUE;
-}
-
-static void
-immediate_commit (GError *error, gpointer user_data)
-{
-	tracker_store_queue_commit (on_committed, NULL, NULL);
-}
-
 void
 tracker_store_init (gboolean load_journal)
 {
@@ -328,23 +310,15 @@ tracker_store_init (gboolean load_journal)
 	tracker_db_journal_open ();
 
 	if (lines) {
-
-		/* This way there's a small chance of a sparql_update taking
-		 * place that'll see its journal-log truncated without a 
-		 * backup yet having been made (in on_committed), so perhaps
-		 * we should instead use the synchronous tracker_store_sparql_update
-		 * here. It'll make startup of tracker-store slower, though. */
-
-		tracker_store_queue_sparql_update (lines,
-		                                   immediate_commit, 
-		                                   NULL, NULL);
+		tracker_store_sparql_update (lines, NULL);
+		tracker_db_journal_truncate ();
 		g_free (lines);
-	} else {
-		private->start_log = TRUE;
 	}
 
+	private->start_log = TRUE;
+
 	private->sync_handler = g_timeout_add_seconds_full (G_PRIORITY_LOW,
-	                                                    60,
+	                                                    60 * 30, /* 30 minutes worth of seconds*/
 	                                                    sync_idle_handler,
 	                                                    private,
 	                                                    sync_idle_destroy);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]