[tracker/ttl: 6/8] libtracker-data: Do not append to invalid journals
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/ttl: 6/8] libtracker-data: Do not append to invalid journals
- Date: Thu, 18 Mar 2010 08:54:52 +0000 (UTC)
commit 6da28fc014493a05d8c6ab3888b642f931d9bfde
Author: Jürg Billeter <j bitron ch>
Date: Thu Mar 18 09:27:47 2010 +0100
libtracker-data: Do not append to invalid journals
Truncate invalid journals and ignored journals of test cases.
src/libtracker-data/tracker-data-backup.c | 2 +-
src/libtracker-data/tracker-data-manager.c | 8 +++++---
src/libtracker-data/tracker-data-update.c | 2 +-
src/libtracker-db/tracker-db-journal.c | 10 +++++++++-
src/libtracker-db/tracker-db-journal.h | 3 ++-
src/tracker-control/tracker-control.c | 2 +-
tests/libtracker-db/tracker-db-journal.c | 6 +++---
7 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index e00e5ae..54a8054 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -154,7 +154,7 @@ tracker_data_backup_restore (GFile *journal,
&info->error);
tracker_db_manager_init_locations ();
- tracker_db_journal_init (NULL);
+ tracker_db_journal_init (NULL, FALSE);
if (info->error) {
tracker_db_manager_restore_from_temp ();
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 8fab22e..24d922c 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1529,7 +1529,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
in_journal_replay = FALSE;
/* open journal for writing */
- tracker_db_journal_init (NULL);
+ tracker_db_journal_init (NULL, FALSE);
check_ontology = TRUE;
g_hash_table_unref (classes);
@@ -1539,7 +1539,9 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
sorted = get_ontologies (test_schema != NULL, ontologies_dir);
- tracker_db_journal_init (NULL);
+ /* truncate journal as it does not even contain a single valid transaction
+ * or is explicitly ignored (journal_check == FALSE, only for test cases) */
+ tracker_db_journal_init (NULL, TRUE);
/* load ontology from files into memory (max_id starts at zero: first-time) */
@@ -1578,7 +1580,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
sorted = NULL;
check_ontology = FALSE;
} else {
- tracker_db_journal_init (NULL);
+ tracker_db_journal_init (NULL, FALSE);
/* load ontology from database into memory */
db_get_static_data (iface);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index fc17f84..aedd83c 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2675,7 +2675,7 @@ tracker_data_replay_journal (GHashTable *classes,
size = tracker_db_journal_reader_get_size_of_correct ();
tracker_db_journal_reader_shutdown ();
- tracker_db_journal_init (NULL);
+ tracker_db_journal_init (NULL, FALSE);
tracker_db_journal_truncate (size);
tracker_db_journal_shutdown ();
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index 347942e..1da00cf 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -193,7 +193,7 @@ tracker_db_journal_error_quark (void)
}
gboolean
-tracker_db_journal_init (const gchar *filename)
+tracker_db_journal_init (const gchar *filename, gboolean truncate)
{
gchar *directory;
struct stat st;
@@ -238,6 +238,14 @@ tracker_db_journal_init (const gchar *filename)
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
flags = O_WRONLY | O_APPEND | O_CREAT;
+ if (truncate) {
+ /* existing journal contents are invalid: reindex where journal
+ * does not even contain a single valid entry
+ *
+ * or should be ignored: only for test cases
+ */
+ flags |= O_TRUNC;
+ }
writer.journal = g_open (writer.journal_filename, flags, mode);
if (writer.journal == -1) {
diff --git a/src/libtracker-db/tracker-db-journal.h b/src/libtracker-db/tracker-db-journal.h
index 7819bc5..864d6e1 100644
--- a/src/libtracker-db/tracker-db-journal.h
+++ b/src/libtracker-db/tracker-db-journal.h
@@ -46,7 +46,8 @@ GQuark tracker_db_journal_error_quark (void);
/*
* Writer API
*/
-gboolean tracker_db_journal_init (const gchar *filename);
+gboolean tracker_db_journal_init (const gchar *filename,
+ gboolean truncate);
gboolean tracker_db_journal_shutdown (void);
const gchar* tracker_db_journal_get_filename (void);
diff --git a/src/tracker-control/tracker-control.c b/src/tracker-control/tracker-control.c
index fb5c3ea..3a5a072 100644
--- a/src/tracker-control/tracker-control.c
+++ b/src/tracker-control/tracker-control.c
@@ -347,7 +347,7 @@ main (int argc, char **argv)
g_log_set_default_handler (log_handler, NULL);
/* This call is needed to set the journal's filename */
- tracker_db_journal_init (NULL);
+ tracker_db_journal_init (NULL, FALSE);
/* Clean up */
if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE)) {
diff --git a/tests/libtracker-db/tracker-db-journal.c b/tests/libtracker-db/tracker-db-journal.c
index fe45cf8..ed89521 100644
--- a/tests/libtracker-db/tracker-db-journal.c
+++ b/tests/libtracker-db/tracker-db-journal.c
@@ -29,13 +29,13 @@ test_init_and_shutdown (void)
gboolean result;
/* check double init/shutdown */
- result = tracker_db_journal_init (NULL);
+ result = tracker_db_journal_init (NULL, FALSE);
g_assert (result == TRUE);
result = tracker_db_journal_shutdown ();
g_assert (result == TRUE);
- result = tracker_db_journal_init (NULL);
+ result = tracker_db_journal_init (NULL, FALSE);
g_assert (result == TRUE);
result = tracker_db_journal_shutdown ();
@@ -53,7 +53,7 @@ test_write_functions (void)
path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", "tracker-store.journal", NULL);
g_unlink (path);
- tracker_db_journal_init (path);
+ tracker_db_journal_init (path, FALSE);
filename = tracker_db_journal_get_filename ();
g_assert (filename != NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]