[tracker/tracker-0.10] libtracker-data: Fixes after review
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] libtracker-data: Fixes after review
- Date: Thu, 28 Apr 2011 11:11:27 +0000 (UTC)
commit 0a2a0d04524c3e98d53f415cf46efbf121eac788
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Apr 26 16:55:15 2011 +0200
libtracker-data: Fixes after review
src/libtracker-data/tracker-data-manager.c | 14 ++++-
src/libtracker-data/tracker-data-update.c | 14 ++---
src/libtracker-data/tracker-db-journal.c | 87 ++++++++++++++++------------
src/libtracker-data/tracker-db-journal.h | 8 +++
4 files changed, 74 insertions(+), 49 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 36fa618..d68fddb 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3557,13 +3557,17 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (journal_check && is_first_time_index) {
/* Call may fail without notice (it's handled) */
- if (tracker_db_journal_reader_init (NULL, NULL)) {
+ if (tracker_db_journal_reader_init (NULL, &internal_error)) {
if (tracker_db_journal_reader_next (NULL)) {
/* journal with at least one valid transaction
is required to trigger journal replay */
read_journal = TRUE;
}
tracker_db_journal_reader_shutdown ();
+ } else if (internal_error && (internal_error->domain != TRACKER_DB_JOURNAL_ERROR ||
+ internal_error->code != TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
+ g_propagate_error (error, internal_error);
+ return FALSE;
}
}
@@ -4129,11 +4133,17 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (internal_error) {
if (g_error_matches (internal_error, TRACKER_DB_INTERFACE_ERROR, TRACKER_DB_NO_SPACE)) {
+ GError *n_error = NULL;
tracker_db_manager_remove_all (FALSE);
tracker_db_manager_shutdown ();
/* Call may fail without notice, we're in error handling already.
* When fails it means that close() of journal file failed. */
- tracker_db_journal_shutdown (NULL);
+ tracker_db_journal_shutdown (&n_error);
+ if (n_error) {
+ g_warning ("Error closing journal: %s",
+ n_error->message ? n_error->message : "No error given");
+ g_error_free (n_error);
+ }
}
g_hash_table_unref (uri_id_map);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index e65bd16..955b4b7 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2964,7 +2964,7 @@ tracker_data_begin_transaction (GError **error)
tracker_db_journal_start_ontology_transaction (resource_time, &n_error);
if (n_error) {
- /* Q: Should we do a tracker_data_rollback_transaction () here? */
+ /* No need for rollback here */
tracker_db_interface_end_db_transaction (iface, NULL);
g_propagate_error (error, n_error);
return;
@@ -3032,15 +3032,9 @@ tracker_data_commit_transaction (GError **error)
}
if (actual_error) {
-
- /* Can't write in journal anymore; quite a serious problem, not sure
- * if rollback of transaction in the sqlite database is what must be
- * done here (behaviour change while adding error reporting to the
- * journal) */
-
- tracker_data_rollback_transaction ();
+ /* Can't write in journal anymore; quite a serious problem */
g_propagate_error (error, actual_error);
- return;
+ /* Don't return, remainder of the function cleans things up */
}
}
@@ -3486,6 +3480,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
tracker_db_journal_init (NULL, FALSE, &n_error);
if (n_error) {
+ g_clear_error (&journal_error);
/* This is fatal (journal file not writable, etc) */
g_propagate_error (error, n_error);
return;
@@ -3494,6 +3489,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
tracker_db_journal_shutdown (&n_error);
if (n_error) {
+ g_clear_error (&journal_error);
/* This is fatal (close of journal file failed after truncate) */
g_propagate_error (error, n_error);
return;
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index 7626b49..526cd7c 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -164,7 +164,8 @@ journal_read_uint32 (JournalReader *jreader,
} else {
if (jreader->end - jreader->current < sizeof (guint32)) {
/* damaged journal entry */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
"Damaged journal entry, %d < sizeof(guint32)",
(gint) (jreader->end - jreader->current));
return 0;
@@ -230,8 +231,9 @@ journal_read_string (JournalReader *jreader,
if (g_buffered_input_stream_fill (bstream, -1, NULL, error) <= 0) {
/* error or end of stream */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, no terminating zero found");
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, no terminating zero found");
return NULL;
}
}
@@ -244,8 +246,9 @@ journal_read_string (JournalReader *jreader,
str_length = strnlen (jreader->current, jreader->end - jreader->current);
if (str_length == jreader->end - jreader->current) {
/* damaged journal entry (no terminating '\0' character) */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, no terminating zero found");
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, no terminating zero found");
return NULL;
}
@@ -257,8 +260,9 @@ journal_read_string (JournalReader *jreader,
if (!g_utf8_validate (result, -1, NULL)) {
/* damaged journal entry (invalid UTF-8) */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, invalid UTF-8");
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, invalid UTF-8");
g_free (result);
return NULL;
}
@@ -456,7 +460,8 @@ db_journal_init_file (JournalWriter *jwriter,
jwriter->journal = g_open (jwriter->journal_filename, flags, mode);
if (jwriter->journal == -1) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_WRITE,
"Could not open journal for writing, %s",
g_strerror (errno));
g_free (jwriter->journal_filename);
@@ -526,7 +531,8 @@ db_journal_writer_init (JournalWriter *jwriter,
mode = S_IRWXU | S_IRWXG | S_IRWXO;
if (g_mkdir_with_parents (directory, mode)) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_WRITE,
"tracker data directory does not exist and "
"could not be created: %s",
g_strerror (errno));
@@ -621,7 +627,8 @@ db_journal_writer_shutdown (JournalWriter *jwriter,
}
if (close (jwriter->journal) != 0) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_CLOSE,
"Could not close journal, %s",
g_strerror (errno));
return FALSE;
@@ -1169,7 +1176,8 @@ db_journal_writer_commit_db_transaction (JournalWriter *jwriter,
cur_setnum (jwriter->cur_block, &begin_pos, crc);
if (!write_all_data (jwriter->journal, jwriter->cur_block, jwriter->cur_block_len)) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_WRITE,
"Could not write to journal, %s",
g_strerror (errno));
return FALSE;
@@ -1189,13 +1197,13 @@ tracker_db_journal_commit_db_transaction (GError **error)
{
gboolean ret;
GError *n_error = NULL;
- GError *nn_error = NULL;
g_return_val_if_fail (current_transaction_format != TRANSACTION_FORMAT_NONE, FALSE);
if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
ret = db_journal_writer_commit_db_transaction (&ontology_writer, &n_error);
- db_journal_writer_shutdown (&ontology_writer, &nn_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);
@@ -1208,14 +1216,8 @@ tracker_db_journal_commit_db_transaction (GError **error)
#endif /* GLib check */
}
- /* Coalesces the two error reports: */
if (n_error) {
g_propagate_error (error, n_error);
- if (nn_error) {
- g_error_free (nn_error);
- }
- } else if (nn_error) {
- g_propagate_error (error, nn_error);
}
current_transaction_format = TRANSACTION_FORMAT_NONE;
@@ -1338,7 +1340,8 @@ db_journal_reader_init_file (JournalReader *jreader,
#endif /* GLib check */
if (!journal_verify_header (jreader)) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL,
"Damaged journal entry at begin of journal");
tracker_db_journal_reader_shutdown ();
return FALSE;
@@ -1386,7 +1389,8 @@ db_journal_reader_init (JournalReader *jreader,
!g_error_matches (n_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
/* Do not set error if the file does not exist, just return FALSE */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_UNKNOWN,
"Could not create TrackerDBJournalReader for file '%s', %s",
jreader->filename,
n_error->message ? n_error->message : "no error given");
@@ -1653,7 +1657,8 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
/* Check that entry is big enough for header and footer */
if (entry_size < 5 * sizeof (guint32)) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
"Damaged journal entry, size %d < 5 * sizeof(guint32)",
(gint) entry_size);
return FALSE;
@@ -1667,8 +1672,9 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
* of the journal.
*/
if (jreader->end < jreader->entry_end) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, end < entry end");
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, end < entry end");
return FALSE;
}
@@ -1677,10 +1683,11 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
if (entry_size != entry_size_check) {
/* damaged journal entry */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, %d != %d (entry size != entry size check)",
- entry_size,
- entry_size_check);
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, %d != %d (entry size != entry size check)",
+ entry_size,
+ entry_size_check);
return FALSE;
}
}
@@ -1709,10 +1716,11 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
/* Verify checksum */
if (crc != crc_check) {
/* damaged journal entry */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, 0x%.8x != 0x%.8x (crc32 failed)",
- crc,
- crc_check);
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, 0x%.8x != 0x%.8x (crc32 failed)",
+ crc,
+ crc_check);
return FALSE;
}
}
@@ -1749,10 +1757,11 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
if (!jreader->stream) {
if (jreader->current != jreader->entry_end) {
/* damaged journal entry */
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
- "Damaged journal entry, %p != %p (end of transaction with 0 triples)",
- jreader->current,
- jreader->entry_end);
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ "Damaged journal entry, %p != %p (end of transaction with 0 triples)",
+ jreader->current,
+ jreader->entry_end);
return FALSE;
}
}
@@ -1870,7 +1879,8 @@ tracker_db_journal_reader_verify_last (const gchar *filename,
entry_size_check = read_uint32 (jreader.end - 4);
if (jreader.end - entry_size_check < jreader.current) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
"Damaged journal entry at end of journal");
db_journal_reader_shutdown (&jreader);
return FALSE;
@@ -2117,7 +2127,8 @@ tracker_db_journal_rotate (GError **error)
tracker_db_journal_fsync ();
if (close (writer.journal) != 0) {
- g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_CLOSE,
"Could not close journal, %s",
g_strerror (errno));
return FALSE;
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index d8d5096..d93efb8 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -32,6 +32,14 @@ G_BEGIN_DECLS
#define TRACKER_DB_JOURNAL_FILENAME "tracker-store.journal"
#define TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME "tracker-store.ontology.journal"
+enum {
+ TRACKER_DB_JOURNAL_ERROR_UNKNOWN = 0,
+ TRACKER_DB_JOURNAL_ERROR_DAMAGED_JOURNAL_ENTRY,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_WRITE,
+ TRACKER_DB_JOURNAL_ERROR_COULD_NOT_CLOSE,
+ TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL
+};
+
typedef enum {
TRACKER_DB_JOURNAL_START,
TRACKER_DB_JOURNAL_START_TRANSACTION,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]