[tracker/binary-log-2: 1/63] Removed old backup code



commit a1ec73536440f5902e48dd329ea26c5c137f5c6a
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Dec 28 10:34:52 2009 +0100

    Removed old backup code
    
    - Removed periodic backup code
    - Stubbed DBus API backup code

 src/libtracker-data/tracker-data-backup.c |  215 +--------------------------
 src/libtracker-db/tracker-db-backup.c     |  225 -----------------------------
 src/libtracker-db/tracker-db-backup.h     |    5 -
 src/libtracker-db/tracker-db-manager.c    |   74 ----------
 src/tracker-store/tracker-store.c         |   41 ------
 5 files changed, 7 insertions(+), 553 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index 0acd8c8..5d24675 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -28,121 +28,10 @@
 
 #include "tracker-data-backup.h"
 
-typedef struct {
-	GFile *destination, *journal, *file;
-	TrackerDataBackupFinished callback;
-	gpointer user_data;
-	GDestroyNotify destroy;
-	GError *error;
-} BackupSaveInfo;
-
-static void
-free_backup_save_info (BackupSaveInfo *info)
+GQuark
+tracker_data_backup_error_quark (void)
 {
-	if (info->destination) {
-		g_object_unref (info->destination);
-	}
-	if (info->journal) {
-		g_object_unref (info->journal);
-	}
-	if (info->file) {
-		g_object_unref (info->file);
-	}
-
-	if (info->destroy) {
-		info->destroy (info->user_data);
-	}
-
-	g_clear_error (&info->error);
-
-	g_free (info);
-}
-
-
-static void
-on_meta_copied (GObject *source_object,
-                GAsyncResult *res,
-                gpointer user_data)
-{
-	BackupSaveInfo *info = user_data;
-	GError *error = NULL;
-
-	g_file_copy_finish (info->file, res, &error);
-
-	if (info->callback) {
-		info->callback (error, info->user_data);
-	}
-
-	free_backup_save_info (info);
-
-	g_clear_error (&error);
-}
-
-static void
-on_journal_copied (GObject *source_object,
-                   GAsyncResult *res,
-                   gpointer user_data)
-{
-	BackupSaveInfo *info = user_data;
-	GError *error = NULL;
-
-	if (!g_file_copy_finish (info->journal, res, &error)) {
-		if (info->callback) {
-			info->callback (error, info->user_data);
-		}
-		free_backup_save_info (info);
-	} else {
-		g_file_copy_async (info->file, info->destination,
-		                   G_FILE_COPY_OVERWRITE,
-		                   G_PRIORITY_HIGH,
-		                   NULL, NULL, NULL,
-		                   on_meta_copied,
-		                   info);
-	}
-
-	g_clear_error (&error);
-}
-
-static void
-save_copy_procedure (BackupSaveInfo *info)
-{
-	GFile *journal_o;
-
-	journal_o = g_file_new_for_path (tracker_db_journal_filename ());
-
-	if (g_file_query_exists (journal_o, NULL)) {
-		g_file_copy_async (journal_o, info->journal,
-		                   G_FILE_COPY_OVERWRITE,
-		                   G_PRIORITY_HIGH,
-		                   NULL, NULL, NULL,
-		                   on_journal_copied,
-		                   info);
-	} else {
-		g_file_copy_async (info->file, info->destination,
-		                   G_FILE_COPY_OVERWRITE,
-		                   G_PRIORITY_HIGH,
-		                   NULL, NULL, NULL,
-		                   on_meta_copied,
-		                   info);
-	}
-
-	g_object_unref (journal_o);
-}
-
-static void
-on_backup_finished (GError *error, gpointer user_data)
-{
-	BackupSaveInfo *info = user_data;
-
-	if (error) {
-		if (info->callback) {
-			info->callback (error, info->user_data);
-		}
-		free_backup_save_info (info);
-		return;
-	}
-
-	save_copy_procedure (info);
+	return g_quark_from_static_string ("tracker-data-backup-error-quark");
 }
 
 void
@@ -152,76 +41,8 @@ tracker_data_backup_save (GFile *destination,
                           gpointer user_data,
                           GDestroyNotify destroy)
 {
-	BackupSaveInfo *info;
-
-	info = g_new0 (BackupSaveInfo, 1);
-	info->destination = g_object_ref (destination);
-	info->journal = g_object_ref (journal);
-	info->callback = callback;
-	info->user_data = user_data;
-	info->destroy = destroy;
-
-	info->file = tracker_db_backup_file (NULL, TRACKER_DB_BACKUP_META_FILENAME);
-
-	if (g_file_query_exists (info->file, NULL)) {
-		/* Making a backup just means copying meta-backup.db */
-		save_copy_procedure (info);
-	} else {
-		/* If we don't have a meta-backup.db yet, we first make one */
-		tracker_db_backup_save (on_backup_finished,
-		                        info, NULL);
-	}
-}
-
-static gboolean
-on_restore_done (gpointer user_data)
-{
-	BackupSaveInfo *info = user_data;
-
-	if (info->callback) {
-		info->callback (info->error, info->user_data);
-	}
-
-	free_backup_save_info (info);
-
-	return FALSE;
-}
-
-static void
-restore_copy_procedure (BackupSaveInfo *info)
-{
-	GFile *journal_d;
-	GError *error = NULL;
-
-	/* Restore should block the mainloop until finished */
-
-	journal_d = g_file_new_for_path (tracker_db_journal_filename ());
-
-	if (g_file_query_exists (journal_d, NULL)) {
-		g_file_copy (info->journal, journal_d,
-		             G_FILE_COPY_OVERWRITE,
-		             NULL, NULL, NULL,
-		             &error);
-	}
-
-	g_object_unref (journal_d);
-
-	if (error) {
-		goto error_handle;
-	}
-
-	g_file_copy (info->destination, info->file,
-	             G_FILE_COPY_OVERWRITE,
-	             NULL, NULL, NULL,
-	             &error);
-
-	if (error) {
-		goto error_handle;
-	}
-
- error_handle:
-
-	info->error = error;
+	// TODO: Unimplemented
+	g_critical ("tracker_data_backup_save unimplemented");
 }
 
 void
@@ -231,29 +52,7 @@ tracker_data_backup_restore (GFile *backup,
                              gpointer user_data,
                              GDestroyNotify destroy)
 {
-	BackupSaveInfo *info;
-
-	tracker_db_manager_disconnect ();
-	tracker_db_journal_close ();
-
-	info = g_new0 (BackupSaveInfo, 1);
-	info->destination = g_object_ref (backup);
-	info->journal = g_object_ref (journal);
-	info->callback = callback;
-	info->user_data = user_data;
-	info->destroy = destroy;
-
-	info->file = tracker_db_backup_file (NULL, TRACKER_DB_BACKUP_META_FILENAME);
-
-	/* This is all synchronous, blocking the mainloop indeed */
-
-	restore_copy_procedure (info);
-
-	tracker_db_journal_open ();
-	tracker_db_manager_reconnect ();
-
-	tracker_db_backup_sync_fts ();
-
-	g_idle_add (on_restore_done, info);
+	// TODO: Unimplemented
+	g_critical ("tracker_data_backup_restore");
 }
 
diff --git a/src/libtracker-db/tracker-db-backup.c b/src/libtracker-db/tracker-db-backup.c
index d448480..94ffa3f 100644
--- a/src/libtracker-db/tracker-db-backup.c
+++ b/src/libtracker-db/tracker-db-backup.c
@@ -26,28 +26,12 @@
 #include <glib.h>
 #include <glib/gstdio.h>
 
-#include <sqlite3.h>
-
 #include <libtracker-common/tracker-common.h>
 #include <libtracker-db/tracker-db.h>
 #include <libtracker-fts/tracker-fts.h>
 
 #include "tracker-db-backup.h"
 
-#define TRACKER_DB_BACKUP_META_FILENAME_T       "meta-backup.db.tmp"
-
-typedef struct {
-	TrackerDBBackupFinished callback;
-	GDestroyNotify destroy;
-	gpointer user_data;
-	GError *error;
-	sqlite3_stmt *stmt;
-	sqlite3 *db, *backup_temp;
-	sqlite3_backup *backup_db;
-	gchar *backup_fname;
-	int result;
-	GFile *parent;
-} BackupInfo;
 
 GQuark
 tracker_db_backup_error_quark (void)
@@ -55,215 +39,6 @@ tracker_db_backup_error_quark (void)
 	return g_quark_from_static_string ("tracker-db-backup-error-quark");
 }
 
-static gboolean
-perform_callback (gpointer user_data)
-{
-	BackupInfo *info = user_data;
-
-	if (info->callback) {
-		info->callback (info->error, info->user_data);
-	}
-
-	return FALSE;
-}
-
-static void
-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);
-	}
-
-	g_clear_error (&info->error);
-
-	if (info->stmt) {
-		sqlite3_finalize (info->stmt);
-	}
-
-	if (info->backup_db) {
-		sqlite3_backup_finish (info->backup_db);
-		info->backup_db = NULL;
-	}
-
-	if (info->backup_temp) {
-		sqlite3_close (info->backup_temp);
-	}
-
-	if (info->db) {
-		sqlite3_close (info->db);
-	}
-
-	if (info->backup_fname) {
-		g_free (info->backup_fname);
-	}
-
-	g_free (info);
-}
-
-
-static gboolean
-backup_file_step (gpointer user_data)
-{
-	BackupInfo *info = user_data;
-	guint cnt = 0;
-	gboolean cont = TRUE;
-
-	while (cont && info->result == SQLITE_OK) {
-
-		info->result = sqlite3_backup_step(info->backup_db, 5);
-
-		switch (info->result) {
-		case SQLITE_OK:
-			break;
-
-		case SQLITE_ERROR:
-		default:
-			cont = FALSE;
-			break;
-		}
-
-		if (cnt > 100) {
-			break;
-		}
-
-		cnt++;
-	}
-
-	return cont;
-}
-
-static void
-on_backup_temp_finished (gpointer user_data)
-{
-	BackupInfo *info = user_data;
-
-	if (info->backup_db) {
-		sqlite3_backup_finish (info->backup_db);
-		info->backup_db = NULL;
-	}
-
-	if (info->db) {
-		sqlite3_close (info->db);
-		info->db = NULL;
-	}
-
-
-	if (!info->error && info->result != SQLITE_DONE) {
-		g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR,
-		             TRACKER_DB_BACKUP_ERROR_UNKNOWN,
-		             "%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);
-
-	return;
-}
-
-GFile *
-tracker_db_backup_file (GFile **parent_out, const gchar *type)
-{
-	GFile *file, *parent;
-	gchar *parent_path;
-
-	parent_path = g_build_filename (g_get_user_data_dir (),
-	                                "tracker",
-	                                "data",
-	                                NULL);
-
-	parent = g_file_new_for_path (parent_path);
-	file = g_file_get_child (parent, type);
-
-	if (parent_out) {
-		*parent_out = parent;
-	} else {
-		g_object_unref (parent);
-	}
-
-	g_free (parent_path);
-
-	return file;
-}
-
-
-void
-tracker_db_backup_save (TrackerDBBackupFinished callback,
-                        gpointer user_data,
-                        GDestroyNotify destroy)
-{
-	const gchar *db_file = tracker_db_manager_get_file (TRACKER_DB_METADATA);
-	BackupInfo *info = g_new0 (BackupInfo, 1);
-	GFile *file;
-
-	/* This procedure makes a meta-backup.db using sqlite3_backup API */
-
-	info->callback = callback;
-	info->user_data = user_data;
-	info->destroy = destroy;
-
-	file = tracker_db_backup_file (&info->parent, TRACKER_DB_BACKUP_META_FILENAME_T);
-	info->backup_fname = g_file_get_path (file);
-	g_object_unref (file);
-
-	if (sqlite3_open_v2 (db_file, &info->db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
-		g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN,
-		             "Could not open sqlite3 database:'%s'", db_file);
-
-		g_idle_add_full (G_PRIORITY_DEFAULT, perform_callback, info,
-		                 backup_info_free);
-
-		return;
-	}
-
-	if (sqlite3_open (info->backup_fname, &info->backup_temp) != SQLITE_OK) {
-		g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN,
-		             "Could not open sqlite3 database:'%s'", info->backup_fname);
-
-		g_idle_add_full (G_PRIORITY_DEFAULT, perform_callback, info,
-		                 backup_info_free);
-
-		return;
-	}
-
-	info->backup_db = sqlite3_backup_init (info->backup_temp, "main",
-	                                       info->db, "main");
-
-	if (!info->backup_db) {
-		g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN,
-		             "Unknown error creating backup db: '%s'", info->backup_fname);
-
-		g_idle_add_full (G_PRIORITY_DEFAULT, perform_callback, info,
-		                 backup_info_free);
-
-		return;
-	}
-
-	g_idle_add_full (G_PRIORITY_DEFAULT, backup_file_step, info,
-	                 on_backup_temp_finished);
-}
-
 
 void
 tracker_db_backup_sync_fts (void)
diff --git a/src/libtracker-db/tracker-db-backup.h b/src/libtracker-db/tracker-db-backup.h
index d54c295..f1ff241 100644
--- a/src/libtracker-db/tracker-db-backup.h
+++ b/src/libtracker-db/tracker-db-backup.h
@@ -42,11 +42,6 @@ typedef void (*TrackerDBBackupFinished) (GError   *error,
                                          gpointer  user_data);
 
 GQuark tracker_db_backup_error_quark (void);
-void   tracker_db_backup_save        (TrackerDBBackupFinished   callback,
-                                      gpointer                  user_data,
-                                      GDestroyNotify            destroy);
-GFile *tracker_db_backup_file        (GFile                   **parent_out,
-                                      const gchar              *type);
 void   tracker_db_backup_sync_fts    (void);
 
 G_END_DECLS
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 63d1f45..c82cb02 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -864,16 +864,8 @@ db_manager_remove_all (gboolean rm_backup_and_log, gboolean not_meta)
 
 	if (rm_backup_and_log) {
 		GFile *file;
-		gchar *path;
 		const gchar *cpath;
 
-		file = tracker_db_backup_file (NULL, TRACKER_DB_BACKUP_META_FILENAME);
-		path = g_file_get_path (file);
-		g_message ("  Removing database:'%s'",
-		           path);
-		g_free (path);
-		g_file_delete (file, NULL, NULL);
-		g_object_unref (file);
 		cpath = tracker_db_journal_filename ();
 		g_message ("  Removing database:'%s'",
 		           cpath);
@@ -1019,65 +1011,6 @@ tracker_db_manager_ensure_locale (void)
 	g_free (stored_locale);
 }
 
-static gboolean
-check_meta_backup (gboolean *did_copy)
-{
-	const gchar *meta_filename;
-	gboolean retval = FALSE;
-
-	/* This is currently the only test for need_journal. We should add a
-	 * couple tests that test meta.db against consistenty, and if not
-	 * good, copy meta-backup.db over and set need_journal (being less
-	 * conservative about using the backup, and not trusting the meta.db
-	 * as much as we do right now) */
-
-	meta_filename = dbs[TRACKER_DB_METADATA].abs_filename;
-
-	if (meta_filename) {
-		GFile *file;
-
-		file = g_file_new_for_path (meta_filename);
-
-		/* (more) Checks for a healthy meta.db should happen here */
-
-		if (!g_file_query_exists (file, NULL)) {
-			GFile *backup;
-
-			backup = tracker_db_backup_file (NULL, TRACKER_DB_BACKUP_META_FILENAME);
-
-			if (g_file_query_exists (backup, NULL)) {
-				GError *error = NULL;
-
-				/* Note that we leave meta-backup.db as is, it'll
-				 * be overwritten first-next time tracker-store.c's
-				 * sync_idle_handler will instruct this. */
-
-				g_file_copy (backup, file, G_FILE_COPY_OVERWRITE,
-				             NULL, NULL, NULL, &error);
-
-				if (!error && did_copy) {
-					*did_copy = TRUE;
-				}
-
-				g_clear_error (&error);
-			}
-
-			/* We always play the journal in case meta.db wasn't
-			 * healthy. Also if meta-backup.db didn't exist: that
-			 * just means that tracker-store.c's sync_idle_handler
-			 * didn't yet ran (meanwhile a first log-file is yet
-			 * already being made) */
-
-			retval = TRUE;
-
-			g_object_unref (backup);
-		}
-
-		g_object_unref (file);
-	}
-
-	return retval;
-}
 
 gboolean
 tracker_db_manager_init (TrackerDBManagerFlags  flags,
@@ -1195,13 +1128,6 @@ tracker_db_manager_init (TrackerDBManagerFlags  flags,
 		}
 	}
 
-	if (need_journal) {
-		/* That did_copy is used for called db_manager_remove_all, we
-		 * don't want it to also remove our freshly copied meta.db file. */
-
-		*need_journal = check_meta_backup (&did_copy);
-	}
-
 	/* If we are just initializing to remove the databases,
 	 * return here.
 	 */
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 4ea4de8..6d47de0 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -26,7 +26,6 @@
 
 #include <libtracker-common/tracker-dbus.h>
 #include <libtracker-db/tracker-db-dbus.h>
-#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>
@@ -38,7 +37,6 @@
 #include "tracker-store.h"
 
 #define TRACKER_STORE_TRANSACTION_MAX                   4000            /* At commit is journal fsynced too */
-#define TRACKER_STORE_JOURNAL_TIMEOUT_BEFORE_BACKUP     (60 * 60 * 2)   /* Two hours before backup */
 
 typedef struct {
 	gboolean  have_handler, have_sync_handler;
@@ -170,21 +168,9 @@ end_batch (TrackerStorePrivate *private)
 }
 
 static void
-on_backup_done (GError *error, gpointer user_data)
-{
-	if (!error) {
-		tracker_db_journal_truncate ();
-	}
-}
-
-static void
 log_to_journal (TrackerStorePrivate *private, const gchar *query)
 {
 	tracker_db_journal_log (query);
-
-	if (tracker_db_journal_get_size () > TRACKER_DB_JOURNAL_MAX_SIZE) {
-		tracker_db_backup_save (on_backup_done, NULL, NULL);
-	}
 }
 
 static gboolean
@@ -288,14 +274,6 @@ queue_idle_handler (gpointer user_data)
 	return !g_queue_is_empty (private->queue);
 }
 
-static gboolean
-sync_idle_handler (gpointer user_data)
-{
-	tracker_db_backup_save (on_backup_done, NULL, NULL);
-
-	return TRUE;
-}
-
 static void
 queue_idle_destroy (gpointer user_data)
 {
@@ -304,17 +282,6 @@ queue_idle_destroy (gpointer user_data)
 	private->have_handler = FALSE;
 }
 
-
-static void
-sync_idle_destroy (gpointer user_data)
-{
-	TrackerStorePrivate *private = user_data;
-
-	tracker_db_journal_close ();
-
-	private->have_sync_handler = FALSE;
-}
-
 void
 tracker_store_flush_journal (void)
 {
@@ -379,14 +346,6 @@ tracker_store_init (gboolean load_journal)
 	}
 
 	tracker_db_journal_open ();
-
-	private->start_log = TRUE;
-
-	private->sync_handler = g_timeout_add_seconds_full (G_PRIORITY_LOW,
-	                                                    TRACKER_STORE_JOURNAL_TIMEOUT_BEFORE_BACKUP,
-	                                                    sync_idle_handler,
-	                                                    private,
-	                                                    sync_idle_destroy);
 }
 
 void



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