Commit 79ad6802 authored by Philip Van Hoof's avatar Philip Van Hoof Committed by Jürg Billeter

libtracker-data: Initialization of db during restore must be handled if fails

In case the initialization of the db fails during the restore of a
backup, and only in case of --disable-journal, then should the init
fail with an error instead of trying to recreate a clean meta.db
parent 44ca01c2
...@@ -226,7 +226,7 @@ namespace Tracker { ...@@ -226,7 +226,7 @@ namespace Tracker {
[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")] [CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
namespace Data.Manager { namespace Data.Manager {
public bool init (DBManagerFlags flags, [CCode (array_length = false)] string[]? test_schema, out bool first_time, bool journal_check, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status) throws DBInterfaceError, DBJournalError; public bool init (DBManagerFlags flags, [CCode (array_length = false)] string[]? test_schema, out bool first_time, bool journal_check, bool restoring_backup, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status) throws DBInterfaceError, DBJournalError;
public void shutdown (); public void shutdown ();
} }
......
...@@ -608,6 +608,16 @@ tracker_data_backup_restore (GFile *journal, ...@@ -608,6 +608,16 @@ tracker_data_backup_restore (GFile *journal,
tracker_db_manager_init_locations (); tracker_db_manager_init_locations ();
/* Re-set the DB version file, so that its mtime changes. The mtime of this
* file will change only when the whole DB is recreated (after a hard reset
* or after a backup restoration). */
tracker_db_manager_create_version_file ();
/* Given we're radically changing the database, we
* force a full mtime check against all known files in
* the database for complete synchronisation. */
tracker_db_manager_set_need_mtime_check (TRUE);
#ifndef DISABLE_JOURNAL #ifndef DISABLE_JOURNAL
tracker_db_journal_init (NULL, FALSE, &n_error); tracker_db_journal_init (NULL, FALSE, &n_error);
...@@ -621,7 +631,6 @@ tracker_data_backup_restore (GFile *journal, ...@@ -621,7 +631,6 @@ tracker_data_backup_restore (GFile *journal,
} }
n_error = NULL; n_error = NULL;
} }
#endif /* DISABLE_JOURNAL */
if (info->error) { if (info->error) {
restore_from_temp (); restore_from_temp ();
...@@ -629,7 +638,6 @@ tracker_data_backup_restore (GFile *journal, ...@@ -629,7 +638,6 @@ tracker_data_backup_restore (GFile *journal,
remove_temp (); remove_temp ();
} }
#ifndef DISABLE_JOURNAL
tracker_db_journal_shutdown (&n_error); tracker_db_journal_shutdown (&n_error);
if (n_error) { if (n_error) {
...@@ -639,23 +647,26 @@ tracker_data_backup_restore (GFile *journal, ...@@ -639,23 +647,26 @@ tracker_data_backup_restore (GFile *journal,
} }
#endif /* DISABLE_JOURNAL */ #endif /* DISABLE_JOURNAL */
tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, TRUE,
select_cache_size, update_cache_size, select_cache_size, update_cache_size,
busy_callback, busy_user_data, busy_callback, busy_user_data,
"Restoring backup", &internal_error); "Restoring backup", &internal_error);
#ifdef DISABLE_JOURNAL
if (internal_error) { if (internal_error) {
g_propagate_error (error, internal_error); restore_from_temp ();
tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, TRUE,
select_cache_size, update_cache_size,
busy_callback, busy_user_data,
"Restoring backup", &internal_error);
} else { } else {
/* Re-set the DB version file, so that its mtime changes. The mtime of this remove_temp ();
* file will change only when the whole DB is recreated (after a hard reset }
* or after a backup restoration). */ #endif /* DISABLE_JOURNAL */
tracker_db_manager_create_version_file ();
if (internal_error) {
/* Given we're radically changing the database, we g_propagate_error (error, internal_error);
* force a full mtime check against all known files in
* the database for complete synchronisation. */
tracker_db_manager_set_need_mtime_check (TRUE);
} }
} else { } else {
g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR, g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR,
......
...@@ -3405,6 +3405,7 @@ tracker_data_manager_reload (TrackerBusyCallback busy_callback, ...@@ -3405,6 +3405,7 @@ tracker_data_manager_reload (TrackerBusyCallback busy_callback,
NULL, NULL,
&is_first, &is_first,
TRUE, TRUE,
FALSE,
select_cache_size, select_cache_size,
update_cache_size, update_cache_size,
busy_callback, busy_callback,
...@@ -3461,6 +3462,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags, ...@@ -3461,6 +3462,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
const gchar **test_schemas, const gchar **test_schemas,
gboolean *first_time, gboolean *first_time,
gboolean journal_check, gboolean journal_check,
gboolean restoring_backup,
guint select_cache_size, guint select_cache_size,
guint update_cache_size, guint update_cache_size,
TrackerBusyCallback busy_callback, TrackerBusyCallback busy_callback,
...@@ -3505,6 +3507,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags, ...@@ -3505,6 +3507,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (!tracker_db_manager_init (flags, if (!tracker_db_manager_init (flags,
&is_first_time_index, &is_first_time_index,
restoring_backup,
FALSE, FALSE,
select_cache_size, select_cache_size,
update_cache_size, update_cache_size,
...@@ -4023,6 +4026,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags, ...@@ -4023,6 +4026,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
test_schemas, test_schemas,
first_time, first_time,
journal_check, journal_check,
restoring_backup,
select_cache_size, select_cache_size,
update_cache_size, update_cache_size,
busy_callback, busy_callback,
...@@ -4121,6 +4125,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags, ...@@ -4121,6 +4125,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
test_schemas, test_schemas,
first_time, first_time,
journal_check, journal_check,
restoring_backup,
select_cache_size, select_cache_size,
update_cache_size, update_cache_size,
busy_callback, busy_callback,
...@@ -4227,6 +4232,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags, ...@@ -4227,6 +4232,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
test_schemas, test_schemas,
first_time, first_time,
journal_check, journal_check,
restoring_backup,
select_cache_size, select_cache_size,
update_cache_size, update_cache_size,
busy_callback, busy_callback,
......
...@@ -49,6 +49,7 @@ gboolean tracker_data_manager_init (TrackerDBManagerFlags fl ...@@ -49,6 +49,7 @@ gboolean tracker_data_manager_init (TrackerDBManagerFlags fl
const gchar **test_schema, const gchar **test_schema,
gboolean *first_time, gboolean *first_time,
gboolean journal_check, gboolean journal_check,
gboolean restoring_backup,
guint select_cache_size, guint select_cache_size,
guint update_cache_size, guint update_cache_size,
TrackerBusyCallback busy_callback, TrackerBusyCallback busy_callback,
......
...@@ -835,6 +835,7 @@ perform_recreate (gboolean *first_time, GError **error) ...@@ -835,6 +835,7 @@ perform_recreate (gboolean *first_time, GError **error)
gboolean gboolean
tracker_db_manager_init (TrackerDBManagerFlags flags, tracker_db_manager_init (TrackerDBManagerFlags flags,
gboolean *first_time, gboolean *first_time,
gboolean restoring_backup,
gboolean shared_cache, gboolean shared_cache,
guint select_cache_size, guint select_cache_size,
guint update_cache_size, guint update_cache_size,
...@@ -1062,7 +1063,14 @@ tracker_db_manager_init (TrackerDBManagerFlags flags, ...@@ -1062,7 +1063,14 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
* are only one byte in size even initually. */ * are only one byte in size even initually. */
if (size <= 1) { if (size <= 1) {
must_recreate = TRUE; if (!restoring_backup) {
must_recreate = TRUE;
} else {
g_set_error (&internal_error,
TRACKER_DB_INTERFACE_ERROR,
TRACKER_DB_OPEN_ERROR,
"Corrupt db file");
}
continue; continue;
} }
...@@ -1071,8 +1079,10 @@ tracker_db_manager_init (TrackerDBManagerFlags flags, ...@@ -1071,8 +1079,10 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
if (internal_error) { if (internal_error) {
/* If this already doesn't succeed, then surely the file is /* If this already doesn't succeed, then surely the file is
* corrupt. No need to check for integrity anymore. */ * corrupt. No need to check for integrity anymore. */
g_clear_error (&internal_error); if (!restoring_backup) {
must_recreate = TRUE; g_clear_error (&internal_error);
must_recreate = TRUE;
}
continue; continue;
} }
...@@ -1129,9 +1139,13 @@ tracker_db_manager_init (TrackerDBManagerFlags flags, ...@@ -1129,9 +1139,13 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
&internal_error, &internal_error,
"SELECT 1 FROM Resource"); "SELECT 1 FROM Resource");
if (internal_error != NULL) { if (internal_error != NULL) {
must_recreate = TRUE; if (!restoring_backup) {
g_error_free (internal_error); must_recreate = TRUE;
internal_error = NULL; g_error_free (internal_error);
internal_error = NULL;
} else {
continue;
}
} else { } else {
g_object_unref (stmt); g_object_unref (stmt);
} }
...@@ -1150,8 +1164,12 @@ tracker_db_manager_init (TrackerDBManagerFlags flags, ...@@ -1150,8 +1164,12 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
return FALSE; return FALSE;
} }
loaded = FALSE; loaded = FALSE;
} else {
if (internal_error) {
g_propagate_error (error, internal_error);
return FALSE;
}
} }
} }
if (!loaded) { if (!loaded) {
...@@ -1185,14 +1203,17 @@ tracker_db_manager_init (TrackerDBManagerFlags flags, ...@@ -1185,14 +1203,17 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
} }
if (internal_error) { if (internal_error) {
if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) { if ((!restoring_backup) && (flags & TRACKER_DB_MANAGER_READONLY) == 0) {
perform_recreate (first_time, &internal_error); GError *new_error = NULL;
if (!internal_error) {
perform_recreate (first_time, &new_error);
if (!new_error) {
resources_iface = tracker_db_manager_get_db_interfaces (&internal_error, 1, resources_iface = tracker_db_manager_get_db_interfaces (&internal_error, 1,
TRACKER_DB_METADATA); TRACKER_DB_METADATA);
} } else {
if (internal_error) { /* Most serious error is the recreate one here */
g_propagate_error (error, internal_error); g_clear_error (&internal_error);
g_propagate_error (error, new_error);
initialized = FALSE; initialized = FALSE;
return FALSE; return FALSE;
} }
......
...@@ -52,6 +52,7 @@ typedef enum { ...@@ -52,6 +52,7 @@ typedef enum {
GType tracker_db_get_type (void) G_GNUC_CONST; GType tracker_db_get_type (void) G_GNUC_CONST;
gboolean tracker_db_manager_init (TrackerDBManagerFlags flags, gboolean tracker_db_manager_init (TrackerDBManagerFlags flags,
gboolean *first_time, gboolean *first_time,
gboolean restoring_backup,
gboolean shared_cache, gboolean shared_cache,
guint select_cache_size, guint select_cache_size,
guint update_cache_size, guint update_cache_size,
......
...@@ -33,7 +33,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection { ...@@ -33,7 +33,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
select_cache_size = int.parse (env_cache_size); select_cache_size = int.parse (env_cache_size);
} }
Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null); Data.Manager.init (DBManagerFlags.READONLY, null, null, false, false, select_cache_size, 0, null, null);
} }
use_count++; use_count++;
......
...@@ -472,6 +472,7 @@ tracker_control_general_run (void) ...@@ -472,6 +472,7 @@ tracker_control_general_run (void)
if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
NULL, NULL,
FALSE, FALSE,
FALSE,
100, 100,
100, 100,
NULL, NULL,
......
...@@ -272,6 +272,7 @@ License which can be viewed at: ...@@ -272,6 +272,7 @@ License which can be viewed at:
null, null,
out is_first_time_index, out is_first_time_index,
true, true,
false,
select_cache_size, select_cache_size,
update_cache_size, update_cache_size,
busy_callback, busy_callback,
......
...@@ -112,7 +112,8 @@ test_backup_and_restore_helper (gboolean journal) ...@@ -112,7 +112,8 @@ test_backup_and_restore_helper (gboolean journal)
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX, tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
(const gchar **) test_schemas, (const gchar **) test_schemas,
NULL, FALSE, 100, 100, NULL, NULL, NULL, &error); NULL, FALSE, FALSE,
100, 100, NULL, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
...@@ -171,7 +172,8 @@ test_backup_and_restore_helper (gboolean journal) ...@@ -171,7 +172,8 @@ test_backup_and_restore_helper (gboolean journal)
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX, tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
(const gchar **) test_schemas, (const gchar **) test_schemas,
NULL, FALSE, 100, 100, NULL, NULL, NULL, &error); NULL, FALSE, FALSE,
100, 100, NULL, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
......
...@@ -229,7 +229,8 @@ test_ontology_change (void) ...@@ -229,7 +229,8 @@ test_ontology_change (void)
g_chmod (ontology_file, 0666); g_chmod (ontology_file, 0666);
tracker_data_manager_init (0, (const gchar **) test_schemas, tracker_data_manager_init (0, (const gchar **) test_schemas,
NULL, FALSE, 100, 100, NULL, NULL, NULL, &error); NULL, FALSE, FALSE,
100, 100, NULL, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
...@@ -272,7 +273,8 @@ test_ontology_change (void) ...@@ -272,7 +273,8 @@ test_ontology_change (void)
delete_db (FALSE); delete_db (FALSE);
tracker_data_manager_init (0, (const gchar **) test_schemas, tracker_data_manager_init (0, (const gchar **) test_schemas,
NULL, TRUE, 100, 100, NULL, NULL, NULL, &error); NULL, TRUE, FALSE,
100, 100, NULL, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
......
...@@ -181,6 +181,7 @@ test_ontology_init (void) ...@@ -181,6 +181,7 @@ test_ontology_init (void)
NULL, NULL,
NULL, NULL,
FALSE, FALSE,
FALSE,
100, 100,
100, 100,
NULL, NULL,
...@@ -199,6 +200,7 @@ test_ontology_init (void) ...@@ -199,6 +200,7 @@ test_ontology_init (void)
NULL, NULL,
NULL, NULL,
FALSE, FALSE,
FALSE,
100, 100,
100, 100,
NULL, NULL,
...@@ -237,6 +239,7 @@ test_query (gconstpointer test_data) ...@@ -237,6 +239,7 @@ test_query (gconstpointer test_data)
NULL, NULL,
NULL, NULL,
FALSE, FALSE,
FALSE,
100, 100,
100, 100,
NULL, NULL,
......
...@@ -49,6 +49,7 @@ test_blank (void) ...@@ -49,6 +49,7 @@ test_blank (void)
NULL, NULL,
NULL, NULL,
FALSE, FALSE,
FALSE,
100, 100,
100, 100,
NULL, NULL,
......
...@@ -242,7 +242,8 @@ test_sparql_query (gconstpointer test_data) ...@@ -242,7 +242,8 @@ test_sparql_query (gconstpointer test_data)
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX, tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
test_schemas, test_schemas,
NULL, FALSE, 100, 100, NULL, NULL, NULL, &error); NULL, FALSE, FALSE,
100, 100, NULL, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
......
...@@ -75,7 +75,8 @@ test_sparql_query (gconstpointer test_data) ...@@ -75,7 +75,8 @@ test_sparql_query (gconstpointer test_data)
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL); tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX, tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
test_schemas, test_schemas,
NULL, FALSE, 100, 100, NULL, NULL, NULL, &error); NULL, FALSE, FALSE,
100, 100, NULL, NULL, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
......
...@@ -134,6 +134,7 @@ main (int argc, char **argv) ...@@ -134,6 +134,7 @@ main (int argc, char **argv)
NULL, NULL,
&first_time, &first_time,
FALSE, FALSE,
FALSE,
100, 100,
100, 100,
NULL, NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment