[tracker/remove-journal-on-db-bump] tracker-data: Remove the journal when a db-bump takes place
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/remove-journal-on-db-bump] tracker-data: Remove the journal when a db-bump takes place
- Date: Thu, 12 Aug 2010 16:04:28 +0000 (UTC)
commit d77a5ca62e55d9e3b5eb81b24292a55586bb99b4
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Aug 12 13:48:54 2010 +0200
tracker-data: Remove the journal when a db-bump takes place
Also remove the db-version.txt file when tracker-control -r is called.
This fixes NB#184823,
src/libtracker-data/tracker-data-manager.c | 6 +-
src/libtracker-data/tracker-db-manager.c | 139 ++++++++++++++--------------
src/libtracker-data/tracker-db-manager.h | 1 -
src/tracker-control/tracker-control.c | 2 +-
4 files changed, 75 insertions(+), 73 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c568808..232e55b 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -2684,7 +2684,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
GList *sorted = NULL, *l;
const gchar *env_path;
gint max_id = 0;
- gboolean read_only, needed_reindex = FALSE;
+ gboolean read_only;
tracker_data_update_init ();
@@ -2704,7 +2704,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
read_journal = FALSE;
- if (!tracker_db_manager_init (flags, &is_first_time_index, &needed_reindex, TRUE)) {
+ if (!tracker_db_manager_init (flags, &is_first_time_index, TRUE)) {
return FALSE;
}
@@ -2718,7 +2718,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
iface = tracker_db_manager_get_db_interface ();
- if (journal_check && is_first_time_index && !needed_reindex) {
+ if (journal_check && is_first_time_index) {
if (tracker_db_journal_reader_init (NULL)) {
if (tracker_db_journal_reader_next (NULL)) {
/* journal with at least one valid transaction
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 37ad10f..0f8855e 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -384,92 +384,96 @@ db_interface_create (TrackerDB db)
}
static void
-db_manager_remove_all (gboolean rm_journal)
+db_manager_remove_journal (void)
{
+ gchar *path;
+ gchar *directory, *rotate_to = NULL;
+ gsize chunk_size;
+ gboolean do_rotate = FALSE;
+ const gchar *dirs[3] = { NULL, NULL, NULL };
guint i;
- g_message ("Removing all database/storage files");
-
- /* Remove stamp files */
- tracker_db_manager_set_first_index_done (FALSE);
- tracker_db_manager_set_last_crawl_done (FALSE);
-
- /* NOTE: We don't have to be initialized for this so we
- * calculate the absolute directories here.
+ /* We duplicate the path here because later we shutdown the
+ * journal which frees this data. We want to survive that.
*/
- for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-
- g_message (" Removing database:'%s'",
- dbs[i].abs_filename);
- g_unlink (dbs[i].abs_filename);
+ path = g_strdup (tracker_db_journal_get_filename ());
+ if (!path) {
+ return;
}
- if (rm_journal) {
- const gchar *opath = tracker_db_journal_get_filename ();
+ g_message (" Removing journal:'%s'", path);
- if (opath) {
- GFile *file;
- gchar *cpath;
- gchar *directory, *rotate_to = NULL;
- gsize chunk_size;
- gboolean do_rotate = FALSE;
- const gchar *dirs[3] = { NULL, NULL, NULL };
+ directory = g_path_get_dirname (path);
- cpath = g_strdup (opath);
+ tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
+ tracker_db_journal_shutdown ();
- g_message (" Removing journal:'%s'", cpath);
+ dirs[0] = directory;
+ dirs[1] = do_rotate ? rotate_to : NULL;
- directory = g_path_get_dirname (cpath);
+ for (i = 0; dirs[i] != NULL; i++) {
+ GDir *journal_dir;
+ const gchar *f;
- tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
+ journal_dir = g_dir_open (dirs[i], 0, NULL);
+ if (!journal_dir) {
+ continue;
+ }
- tracker_db_journal_shutdown ();
+ /* Remove rotated chunks */
+ while ((f = g_dir_read_name (journal_dir)) != NULL) {
+ gchar *fullpath;
- dirs[0] = directory;
- dirs[1] = do_rotate ? rotate_to : NULL;
+ if (!g_str_has_prefix (f, TRACKER_DB_JOURNAL_FILENAME ".")) {
+ continue;
+ }
- for (i = 0; dirs[i] != NULL; i++) {
- GDir *journal_dir;
- const gchar *f_name;
+ fullpath = g_build_filename (dirs[i], f, NULL);
+ g_unlink (fullpath);
+ g_free (fullpath);
+ }
- journal_dir = g_dir_open (dirs[i], 0, NULL);
- if (!journal_dir) {
- continue;
- }
- f_name = g_dir_read_name (journal_dir);
+ g_dir_close (journal_dir);
+ }
- /* Remove rotated chunks */
- while (f_name) {
- gchar *fullpath;
+ g_free (rotate_to);
+ g_free (directory);
- if (f_name) {
- if (!g_str_has_prefix (f_name, TRACKER_DB_JOURNAL_FILENAME ".")) {
- f_name = g_dir_read_name (journal_dir);
- continue;
- }
- }
+ /* Remove active journal */
+ g_unlink (path);
+ g_free (path);
+}
- fullpath = g_build_filename (dirs[i], f_name, NULL);
- file = g_file_new_for_path (fullpath);
- g_file_delete (file, NULL, NULL);
- g_object_unref (file);
- g_free (fullpath);
+static void
+db_manager_remove_all (gboolean rm_journal)
+{
+ guint i;
- f_name = g_dir_read_name (journal_dir);
- }
+ g_message ("Removing all database/storage files");
- g_dir_close (journal_dir);
- }
+ /* Remove stamp files */
+ tracker_db_manager_set_first_index_done (FALSE);
+ tracker_db_manager_set_last_crawl_done (FALSE);
- g_free (rotate_to);
- g_free (directory);
+ /* NOTE: We don't have to be initialized for this so we
+ * calculate the absolute directories here.
+ */
+ for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
+ g_message (" Removing database:'%s'", dbs[i].abs_filename);
+ g_unlink (dbs[i].abs_filename);
+ }
- /* Remove active journal */
- file = g_file_new_for_path (cpath);
- g_file_delete (file, NULL, NULL);
- g_object_unref (file);
- g_free (cpath);
- }
+ if (rm_journal) {
+ gchar *filename;
+
+ db_manager_remove_journal ();
+
+ /* If also the journal is gone, we can also remove db-version.txt, it
+ * would have no more relevance whatsoever. */
+ filename = g_build_filename (data_dir, TRACKER_DB_VERSION_FILE, NULL);
+ g_message (" Removing db-version file:'%s'", filename);
+ g_unlink (filename);
+ g_free (filename);
}
}
@@ -654,7 +658,6 @@ free_thread_interface (gpointer data)
gboolean
tracker_db_manager_init (TrackerDBManagerFlags flags,
gboolean *first_time,
- gboolean *needed_reindex,
gboolean shared_cache)
{
GType etype;
@@ -745,9 +748,9 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
}
if (need_reindex) {
- if (needed_reindex) {
- *needed_reindex = TRUE;
- }
+ tracker_db_journal_init (NULL, FALSE);
+ db_manager_remove_journal ();
+ tracker_db_journal_shutdown ();
db_set_version ();
}
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index dd9cc56..635f4f5 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -49,7 +49,6 @@ typedef enum {
GType tracker_db_get_type (void) G_GNUC_CONST;
gboolean tracker_db_manager_init (TrackerDBManagerFlags flags,
gboolean *first_time,
- gboolean *needed_reindex,
gboolean shared_cache);
void tracker_db_manager_shutdown (void);
void tracker_db_manager_remove_all (gboolean rm_journal);
diff --git a/src/tracker-control/tracker-control.c b/src/tracker-control/tracker-control.c
index 04fb4a8..3efe871 100644
--- a/src/tracker-control/tracker-control.c
+++ b/src/tracker-control/tracker-control.c
@@ -431,7 +431,7 @@ main (int argc, char **argv)
g_object_unref (db_config);
/* Clean up */
- if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, NULL, FALSE)) {
+ if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE)) {
return EXIT_FAILURE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]