[tracker/wip/carlosg/domain-ontologies: 25/39] libtracker-data: Build all journal file locations from the given GFiles
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/domain-ontologies: 25/39] libtracker-data: Build all journal file locations from the given GFiles
- Date: Tue, 6 Jun 2017 18:32:17 +0000 (UTC)
commit fdcf891a567afb745749e5f85508c09faf0a76e3
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jun 4 14:12:07 2017 +0200
libtracker-data: Build all journal file locations from the given GFiles
This is necessary to make the journals ubiquitous, as otherwise we mangle
the canonical database when opening other ones.
src/libtracker-data/tracker-data-manager.c | 43 +++++----
src/libtracker-data/tracker-data-update.c | 6 +-
src/libtracker-data/tracker-db-journal.c | 135 ++++++++++++++--------------
src/libtracker-data/tracker-db-journal.h | 5 +-
src/libtracker-data/tracker-db-manager.c | 9 ++
src/ontologies/Makefile.am | 6 +-
src/tracker/tracker-reset.c | 2 +-
tests/libtracker-data/tracker-db-journal.c | 49 ++++++++--
8 files changed, 155 insertions(+), 100 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index a8c4f52..e8f1b16 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3841,7 +3841,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
#ifndef DISABLE_JOURNAL
if (journal_check && is_first_time_index) {
/* Call may fail without notice (it's handled) */
- if (tracker_db_journal_reader_init (NULL, &internal_error)) {
+ if (tracker_db_journal_reader_init (NULL, data_location, &internal_error)) {
if (tracker_db_journal_reader_next (NULL)) {
/* journal with at least one valid transaction
is required to trigger journal replay */
@@ -3902,7 +3902,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (read_journal) {
in_journal_replay = TRUE;
- if (tracker_db_journal_reader_ontology_init (NULL, &internal_error)) {
+ if (tracker_db_journal_reader_ontology_init (NULL, data_location, &internal_error)) {
/* Load ontology IDs from journal into memory */
load_ontology_ids_from_journal (&uri_id_map, &max_id);
@@ -3945,24 +3945,24 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
#ifndef DISABLE_JOURNAL
- if (!read_journal) {
- /* 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, cache_location, data_location,
- TRUE, &internal_error);
-
- if (internal_error) {
- g_propagate_error (error, internal_error);
+ /* If we are not replaying, 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, cache_location, data_location,
+ !in_journal_replay, &internal_error);
- tracker_db_manager_shutdown ();
- tracker_ontologies_shutdown ();
- if (!reloading) {
- tracker_locale_shutdown ();
- }
- tracker_data_update_shutdown ();
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
- return FALSE;
+ tracker_db_manager_shutdown ();
+ tracker_ontologies_shutdown ();
+ if (!reloading) {
+ tracker_locale_shutdown ();
}
+ tracker_data_update_shutdown ();
+
+ return FALSE;
}
#endif /* DISABLE_JOURNAL */
@@ -4065,7 +4065,6 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
tracker_data_commit_transaction (&internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
#ifndef DISABLE_JOURNAL
tracker_db_journal_shutdown (NULL);
#endif /* DISABLE_JOURNAL */
@@ -4086,6 +4085,14 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
/* First time, no need to check ontology */
check_ontology = FALSE;
+
+#ifndef DISABLE_JOURNAL
+ /* If we are replaying, close it here again after the ontology
+ * has been written.
+ */
+ if (!read_only && in_journal_replay)
+ tracker_db_journal_shutdown (NULL);
+#endif /* DISABLE_JOURNAL */
} else {
if (!read_only) {
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 62758cd..1fa201e 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -3565,11 +3565,13 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
gint last_operation_type = 0;
const gchar *uri;
GError *n_error = NULL;
-
+ GFile *data_location;
rdf_type = tracker_ontologies_get_rdf_type ();
- tracker_db_journal_reader_init (NULL, &n_error);
+ data_location = tracker_data_manager_get_data_location ();
+ tracker_db_journal_reader_init (NULL, data_location, &n_error);
+ g_object_unref (data_location);
if (n_error) {
/* This is fatal (doesn't happen when file doesn't exist, does happen
* when for some other reason the reader can't be created) */
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index 433eb29..b064e7d 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -70,6 +70,7 @@ typedef enum {
typedef struct {
gchar *filename;
+ GFile *journal_location;
GDataInputStream *stream;
GInputStream *underlying_stream;
GFileInfo *underlying_stream_info;
@@ -95,6 +96,7 @@ typedef struct {
typedef struct {
gchar *journal_filename;
+ GFile *journal_location;
int journal;
gsize cur_size;
guint cur_block_len;
@@ -119,6 +121,9 @@ static TransactionFormat current_transaction_format;
static gboolean tracker_db_journal_rotate (GError **error);
+static gboolean db_journal_ontology_init (GFile *journal_location,
+ GError **error);
+
#ifndef HAVE_STRNLEN
size_t
@@ -525,6 +530,7 @@ db_journal_writer_init (JournalWriter *jwriter,
gboolean truncate,
gboolean global_writer,
const gchar *filename,
+ GFile *journal_location,
GError **error)
{
gchar *directory;
@@ -550,6 +556,7 @@ db_journal_writer_init (JournalWriter *jwriter,
g_free (directory);
jwriter->journal_filename = g_strdup (filename);
+ g_set_object (&jwriter->journal_location, journal_location);
ret = db_journal_init_file (jwriter, truncate, &n_error);
@@ -577,60 +584,58 @@ tracker_db_journal_init (const gchar *filename,
g_return_val_if_fail (writer.journal == 0, FALSE);
if (filename == NULL) {
- if (data_location == NULL) {
- filename_use = g_build_filename (g_get_user_data_dir (),
- "tracker",
- "data",
- TRACKER_DB_JOURNAL_FILENAME,
- NULL);
- } else {
- GFile *child;
+ GFile *child;
- child = g_file_get_child (data_location, TRACKER_DB_JOURNAL_FILENAME);
- filename_use = g_file_get_path (child);
- g_object_unref (child);
+ child = g_file_get_child (data_location, TRACKER_DB_JOURNAL_FILENAME);
+ filename_use = g_file_get_path (child);
+ g_object_unref (child);
- g_assert (filename_use != NULL);
- }
+ g_assert (filename_use != NULL);
filename_free = (gchar *) filename_use;
} else {
filename_use = filename;
}
- ret = db_journal_writer_init (&writer, truncate, TRUE, filename_use, &n_error);
+ ret = db_journal_writer_init (&writer, truncate, TRUE, filename_use, data_location, &n_error);
+ g_free (filename_free);
- if (n_error) {
+ if (!ret) {
g_propagate_error (error, n_error);
+ return ret;
}
- g_free (filename_free);
+ ret = db_journal_ontology_init (data_location, &n_error);
+
+ if (!ret) {
+ g_propagate_error (error, n_error);
+ return ret;
+ }
return ret;
}
static gboolean
-db_journal_ontology_init (GError **error)
+db_journal_ontology_init (GFile *journal_location,
+ GError **error)
{
gboolean ret;
gchar *filename;
GError *n_error = NULL;
+ GFile *child;
g_return_val_if_fail (ontology_writer.journal == 0, FALSE);
- filename = g_build_filename (g_get_user_data_dir (),
- "tracker",
- "data",
- TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME,
- NULL);
+ child = g_file_get_child (journal_location, TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME);
+ filename = g_file_get_path (child);
+ g_object_unref (child);
- ret = db_journal_writer_init (&ontology_writer, FALSE, FALSE, filename, &n_error);
+ ret = db_journal_writer_init (&ontology_writer, FALSE, FALSE, filename, journal_location, &n_error);
+ g_free (filename);
if (n_error) {
g_propagate_error (error, n_error);
}
- g_free (filename);
-
return ret;
}
@@ -638,8 +643,8 @@ static gboolean
db_journal_writer_shutdown (JournalWriter *jwriter,
GError **error)
{
- g_free (jwriter->journal_filename);
- jwriter->journal_filename = NULL;
+ g_clear_pointer (&jwriter->journal_filename, g_free);
+ g_clear_object (&jwriter->journal_location);
if (jwriter->journal == 0) {
return TRUE;
@@ -665,9 +670,15 @@ tracker_db_journal_shutdown (GError **error)
gboolean ret;
ret = db_journal_writer_shutdown (&writer, &n_error);
+ if (!ret) {
+ g_propagate_error (error, n_error);
+ return ret;
+ }
- if (n_error) {
+ ret = db_journal_writer_shutdown (&ontology_writer, &n_error);
+ if (!ret) {
g_propagate_error (error, n_error);
+ return ret;
}
return ret;
@@ -737,17 +748,6 @@ gboolean
tracker_db_journal_start_ontology_transaction (time_t time,
GError **error)
{
- GError *n_error = NULL;
-
- if (!db_journal_ontology_init (&n_error)) {
-
- if (n_error) {
- g_propagate_error (error, n_error);
- }
-
- return FALSE;
- }
-
return db_journal_writer_start_transaction (&ontology_writer, time,
TRANSACTION_FORMAT_ONTOLOGY);
}
@@ -1138,7 +1138,6 @@ tracker_db_journal_rollback_transaction (GError **error)
if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
cur_block_kill (&ontology_writer);
- db_journal_writer_shutdown (&ontology_writer, &n_error);
}
if (n_error) {
@@ -1216,8 +1215,6 @@ tracker_db_journal_commit_db_transaction (GError **error)
if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
ret = db_journal_writer_commit_db_transaction (&ontology_writer, &n_error);
- /* Coalesces the two error reports: */
- db_journal_writer_shutdown (&ontology_writer, n_error ? NULL : &n_error);
} else {
ret = db_journal_writer_commit_db_transaction (&writer, &n_error);
@@ -1361,32 +1358,22 @@ static gboolean
db_journal_reader_init (JournalReader *jreader,
gboolean global_reader,
const gchar *filename,
+ GFile *data_location,
GError **error)
{
- gchar *filename_used;
gchar *filename_open;
GError *n_error = NULL;
g_return_val_if_fail (jreader->file == NULL, FALSE);
- /* Used mostly for testing */
- if (G_UNLIKELY (filename)) {
- filename_used = g_strdup (filename);
- } else {
- filename_used = g_build_filename (g_get_user_data_dir (),
- "tracker",
- "data",
- TRACKER_DB_JOURNAL_FILENAME,
- NULL);
- }
-
- jreader->filename = filename_used;
+ jreader->filename = g_strdup (filename);
+ g_set_object (&jreader->journal_location, data_location);
reader.current_file = 0;
if (global_reader) {
filename_open = reader_get_next_filepath (jreader);
} else {
- filename_open = g_strdup (filename_used);
+ filename_open = g_strdup (filename);
}
jreader->type = TRACKER_DB_JOURNAL_START;
@@ -1417,12 +1404,26 @@ db_journal_reader_init (JournalReader *jreader,
gboolean
tracker_db_journal_reader_init (const gchar *filename,
+ GFile *data_location,
GError **error)
{
gboolean ret;
GError *n_error = NULL;
+ gchar *filename_used;
- ret = db_journal_reader_init (&reader, TRUE, filename, &n_error);
+ /* Used mostly for testing */
+ if (G_UNLIKELY (filename)) {
+ filename_used = g_strdup (filename);
+ } else {
+ GFile *child;
+
+ child = g_file_get_child (data_location, TRACKER_DB_JOURNAL_FILENAME);
+ filename_used = g_file_get_path (child);
+ g_object_unref (child);
+ }
+
+ ret = db_journal_reader_init (&reader, TRUE, filename_used, data_location, &n_error);
+ g_free (filename_used);
if (n_error) {
g_propagate_error (error, n_error);
@@ -1433,6 +1434,7 @@ tracker_db_journal_reader_init (const gchar *filename,
gboolean
tracker_db_journal_reader_ontology_init (const gchar *filename,
+ GFile *data_location,
GError **error)
{
gchar *filename_used;
@@ -1443,19 +1445,19 @@ tracker_db_journal_reader_ontology_init (const gchar *filename,
if (G_UNLIKELY (filename)) {
filename_used = g_strdup (filename);
} else {
- filename_used = g_build_filename (g_get_user_data_dir (),
- "tracker",
- "data",
- TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME,
- NULL);
- }
+ GFile *child;
- result = tracker_db_journal_reader_init (filename_used, &n_error);
+ child = g_file_get_child (data_location, TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME);
+ filename_used = g_file_get_path (child);
+ g_object_unref (child);
+ }
+ result = db_journal_reader_init (&reader, TRUE, filename_used, data_location, &n_error);
g_free (filename_used);
- if (n_error) {
+ if (!result) {
g_propagate_error (error, n_error);
+ return result;
}
return result;
@@ -1878,6 +1880,7 @@ tracker_db_journal_reader_next (GError **error)
gboolean
tracker_db_journal_reader_verify_last (const gchar *filename,
+ GFile *data_location,
GError **error)
{
guint32 entry_size_check;
@@ -1885,7 +1888,7 @@ tracker_db_journal_reader_verify_last (const gchar *filename,
JournalReader jreader = { 0 };
GError *n_error = NULL;
- if (db_journal_reader_init (&jreader, FALSE, filename, &n_error)) {
+ if (db_journal_reader_init (&jreader, FALSE, filename, data_location, &n_error)) {
if (jreader.end != jreader.current) {
entry_size_check = read_uint32 (jreader.end - 4);
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index 789e14e..6bec56f 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -118,8 +118,10 @@ gboolean tracker_db_journal_truncate (gsize new_size);
* Reader API
*/
gboolean tracker_db_journal_reader_init (const gchar *filename,
+ GFile *data_location,
GError **error);
-gboolean tracker_db_journal_reader_ontology_init (const gchar *filename,
+gboolean tracker_db_journal_reader_ontology_init (const gchar *filename,
+ GFile *data_location,
GError **error);
gboolean tracker_db_journal_reader_shutdown (void);
TrackerDBJournalEntryType
@@ -141,6 +143,7 @@ gsize tracker_db_journal_reader_get_size_of_correct (void);
gdouble tracker_db_journal_reader_get_progress (void);
gboolean tracker_db_journal_reader_verify_last (const gchar *filename,
+ GFile *data_location,
GError **error);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 0c24951..9e2d796 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -1039,6 +1039,7 @@ db_manager_init_unlocked (TrackerDBManagerFlags flags,
TRACKER_DB_JOURNAL_FILENAME,
NULL);
must_recreate = !tracker_db_journal_reader_verify_last (journal_filename,
+ data_location,
NULL);
g_free (journal_filename);
@@ -1258,6 +1259,14 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
{
gboolean retval;
+ if (!cache_location || !data_location) {
+ g_set_error (error,
+ TRACKER_DATA_ONTOLOGY_ERROR,
+ TRACKER_DATA_UNSUPPORTED_LOCATION,
+ "All data storage and ontology locations must be provided");
+ return FALSE;
+ }
+
g_mutex_lock (&init_mutex);
retval = db_manager_init_unlocked (flags, cache_location, data_location,
diff --git a/src/ontologies/Makefile.am b/src/ontologies/Makefile.am
index 545e548..b1be3b8 100644
--- a/src/ontologies/Makefile.am
+++ b/src/ontologies/Makefile.am
@@ -1,7 +1,7 @@
maemo_ontology = \
nepomuk/91-maemo.ontology nepomuk/91-maemo.description
-configdir = $(datadir)/tracker/ontologies
+nepomukdir = $(datadir)/tracker/ontologies/nepomuk
internal_config = \
10-xsd.ontology 10-xsd.description \
@@ -10,7 +10,7 @@ internal_config = \
20-dc.ontology 20-dc.description \
31-nao.ontology 31-nao.description
-config_DATA = \
+nepomuk_DATA = \
nepomuk/30-nie.ontology nepomuk/30-nie.description \
nepomuk/32-nco.ontology nepomuk/32-nco.description \
nepomuk/33-nfo.ontology nepomuk/33-nfo.description \
@@ -28,7 +28,7 @@ config_DATA = \
nepomuk/93-libosinfo.ontology nepomuk/93-libosinfo.description
if HAVE_MAEMO
-config_DATA += $(maemo_ontology)
+nepomuk_DATA += $(maemo_ontology)
endif
# GResource
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index 2431046..89aa641 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -319,7 +319,7 @@ reset_run (void)
return EXIT_FAILURE;
}
#ifndef DISABLE_JOURNAL
- tracker_db_journal_init (NULL, NULL, NULL, FALSE, NULL);
+ tracker_db_journal_init (NULL, NULL, data_location, FALSE, NULL);
#endif /* DISABLE_JOURNAL */
tracker_db_manager_remove_all (hard_reset);
diff --git a/tests/libtracker-data/tracker-db-journal.c b/tests/libtracker-data/tracker-db-journal.c
index a0e56f0..1a78431 100644
--- a/tests/libtracker-data/tracker-db-journal.c
+++ b/tests/libtracker-data/tracker-db-journal.c
@@ -30,10 +30,21 @@ test_init_and_shutdown (void)
{
GError *error = NULL;
gboolean result;
+ gchar *path;
+ GFile *data_location, *child;
+
+ path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", NULL);
+ data_location = g_file_new_for_path (path);
+ g_free (path);
+
+ child = g_file_get_child (data_location, "tracker-store.journal");
+ path = g_file_get_path (child);
+ g_unlink (path);
+ g_object_unref (child);
/* check double init/shutdown */
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
- result = tracker_db_journal_init (NULL, NULL, NULL, FALSE, &error);
+ result = tracker_db_journal_init (path, NULL, data_location, FALSE, &error);
g_assert_no_error (error);
g_assert (result == TRUE);
@@ -42,13 +53,16 @@ test_init_and_shutdown (void)
g_assert (result == TRUE);
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
- result = tracker_db_journal_init (NULL, NULL, NULL, FALSE, &error);
+ result = tracker_db_journal_init (path, NULL, data_location, FALSE, &error);
g_assert_no_error (error);
g_assert (result == TRUE);
result = tracker_db_journal_shutdown (&error);
g_assert_no_error (error);
g_assert (result == TRUE);
+
+ g_object_unref (data_location);
+ g_free (path);
}
static void
@@ -59,12 +73,20 @@ test_write_functions (void)
gsize initial_size, actual_size;
gboolean result;
GError *error = NULL;
+ GFile *data_location, *child;
- path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", "tracker-store.journal", NULL);
+ path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", NULL);
+ data_location = g_file_new_for_path (path);
+ g_free (path);
+
+ child = g_file_get_child (data_location, "tracker-store.journal");
+ path = g_file_get_path (child);
g_unlink (path);
+ g_object_unref (child);
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
- tracker_db_journal_init (path, NULL, NULL, FALSE, &error);
+ tracker_db_journal_init (path, NULL, data_location, FALSE, &error);
+ g_object_unref (data_location);
g_assert_no_error (error);
filename = tracker_db_journal_get_filename ();
@@ -150,18 +172,27 @@ static void
test_read_functions (void)
{
GError *error = NULL;
- gchar *path;
+ gchar *path, *filename;
gboolean result;
TrackerDBJournalEntryType type;
gint id, s_id, p_id, o_id;
const gchar *uri, *str;
+ GFile *data_location, *child;
- path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", "tracker-store.journal", NULL);
+ path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", NULL);
+ data_location = g_file_new_for_path (path);
+ g_free (path);
+
+ child = g_file_get_child (data_location, "tracker-store.journal");
+ filename = g_file_get_path (child);
+ g_object_unref (child);
/* NOTE: we don't unlink here so we can use the data from the write tests */
/* Create an iterator */
- result = tracker_db_journal_reader_init (path, &error);
+ result = tracker_db_journal_reader_init (filename, data_location, &error);
+ g_free (filename);
+ g_object_unref (data_location);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
@@ -367,12 +398,12 @@ main (int argc, char **argv)
#ifndef DISABLE_JOURNAL
/* None of these tests make sense in case of disabled journal */
- g_test_add_func ("/libtracker-db/tracker-db-journal/init-and-shutdown",
- test_init_and_shutdown);
g_test_add_func ("/libtracker-db/tracker-db-journal/write-functions",
test_write_functions);
g_test_add_func ("/libtracker-db/tracker-db-journal/read-functions",
test_read_functions);
+ g_test_add_func ("/libtracker-db/tracker-db-journal/init-and-shutdown",
+ test_init_and_shutdown);
#endif /* DISABLE_JOURNAL */
result = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]