[tracker/wip/carlosg/domain-ontologies: 35/39] libtracker-data: Make journal reader a non singleton
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/domain-ontologies: 35/39] libtracker-data: Make journal reader a non singleton
- Date: Tue, 6 Jun 2017 18:33:08 +0000 (UTC)
commit 781035fe961e79128e034280ccd6586b55fa6e6d
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 31 15:58:21 2017 +0200
libtracker-data: Make journal reader a non singleton
We initialize and shutdown it quite selectively, it can be safely
made a temporary object which is later freed.
src/libtracker-data/tracker-data-manager.c | 32 ++--
src/libtracker-data/tracker-data-update.c | 30 ++--
src/libtracker-data/tracker-db-journal.c | 262 ++++++++++++++-------------
src/libtracker-data/tracker-db-journal.h | 54 ++++---
tests/libtracker-data/tracker-db-journal.c | 107 ++++++------
5 files changed, 255 insertions(+), 230 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index bd8ac43..4e5f7af 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1846,23 +1846,24 @@ get_ontology_from_file (GFile *file)
#ifndef DISABLE_JOURNAL
static void
-load_ontology_ids_from_journal (GHashTable **uri_id_map_out,
- gint *max_id)
+load_ontology_ids_from_journal (TrackerDBJournalReader *reader,
+ GHashTable **uri_id_map_out,
+ gint *max_id)
{
GHashTable *uri_id_map;
uri_id_map = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
- while (tracker_db_journal_reader_next (NULL)) {
+ while (tracker_db_journal_reader_next (reader, NULL)) {
TrackerDBJournalEntryType type;
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
if (type == TRACKER_DB_JOURNAL_RESOURCE) {
gint id;
const gchar *uri;
- tracker_db_journal_reader_get_resource (&id, &uri);
+ tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_hash_table_insert (uri_id_map, g_strdup (uri), GINT_TO_POINTER (id));
if (id > *max_id) {
*max_id = id;
@@ -3839,14 +3840,19 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
#ifndef DISABLE_JOURNAL
if (journal_check && is_first_time_index) {
+ TrackerDBJournalReader *journal_reader;
+
/* Call may fail without notice (it's handled) */
- if (tracker_db_journal_reader_init (data_location, &internal_error)) {
- if (tracker_db_journal_reader_next (NULL)) {
+ journal_reader = tracker_db_journal_reader_new (data_location, &internal_error);
+
+ if (journal_reader) {
+ if (tracker_db_journal_reader_next (journal_reader, NULL)) {
/* journal with at least one valid transaction
is required to trigger journal replay */
read_journal = TRUE;
}
- tracker_db_journal_reader_shutdown ();
+
+ tracker_db_journal_reader_free (journal_reader);
} else if (internal_error) {
if (!g_error_matches (internal_error,
TRACKER_DB_JOURNAL_ERROR,
@@ -3893,13 +3899,15 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
#ifndef DISABLE_JOURNAL
if (read_journal) {
+ TrackerDBJournalReader *journal_reader;
+
in_journal_replay = TRUE;
+ journal_reader = tracker_db_journal_reader_ontology_new (data_location, &internal_error);
- if (tracker_db_journal_reader_ontology_init (data_location, &internal_error)) {
+ if (journal_reader) {
/* Load ontology IDs from journal into memory */
- load_ontology_ids_from_journal (&uri_id_map, &max_id);
-
- tracker_db_journal_reader_shutdown ();
+ load_ontology_ids_from_journal (journal_reader, &uri_id_map, &max_id);
+ tracker_db_journal_reader_free (journal_reader);
} else {
if (internal_error) {
if (!g_error_matches (internal_error,
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 876610c..beb3018 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -3566,32 +3566,34 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
const gchar *uri;
GError *n_error = NULL;
GFile *data_location;
+ TrackerDBJournalReader *reader;
rdf_type = tracker_ontologies_get_rdf_type ();
data_location = tracker_data_manager_get_data_location ();
- tracker_db_journal_reader_init (data_location, &n_error);
+ reader = tracker_db_journal_reader_new (data_location, &n_error);
g_object_unref (data_location);
- if (n_error) {
+
+ if (!reader) {
/* This is fatal (doesn't happen when file doesn't exist, does happen
* when for some other reason the reader can't be created) */
g_propagate_error (error, n_error);
return;
}
- while (tracker_db_journal_reader_next (&journal_error)) {
+ while (tracker_db_journal_reader_next (reader, &journal_error)) {
TrackerDBJournalEntryType type;
const gchar *object;
gint graph_id, subject_id, predicate_id, object_id;
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
if (type == TRACKER_DB_JOURNAL_RESOURCE) {
GError *new_error = NULL;
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
gint id;
- tracker_db_journal_reader_get_resource (&id, &uri);
+ tracker_db_journal_reader_get_resource (reader, &id, &uri);
iface = tracker_db_manager_get_db_interface ();
@@ -3611,7 +3613,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
}
} else if (type == TRACKER_DB_JOURNAL_START_TRANSACTION) {
- tracker_data_begin_transaction_for_replay (tracker_db_journal_reader_get_time (),
NULL);
+ tracker_data_begin_transaction_for_replay (tracker_db_journal_reader_get_time
(reader), NULL);
} else if (type == TRACKER_DB_JOURNAL_END_TRANSACTION) {
GError *new_error = NULL;
tracker_data_update_buffer_might_flush (&new_error);
@@ -3632,7 +3634,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
GError *new_error = NULL;
TrackerProperty *property = NULL;
- tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id,
&object);
+ tracker_db_journal_reader_get_statement (reader, &graph_id, &subject_id,
&predicate_id, &object);
if (last_operation_type == -1) {
tracker_data_update_buffer_flush (&new_error);
@@ -3671,7 +3673,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
TrackerClass *class = NULL;
TrackerProperty *property = NULL;
- tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id,
&object_id);
+ tracker_db_journal_reader_get_statement_id (reader, &graph_id, &subject_id,
&predicate_id, &object_id);
if (last_operation_type == -1) {
tracker_data_update_buffer_flush (&new_error);
@@ -3727,7 +3729,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
GError *new_error = NULL;
TrackerProperty *property = NULL;
- tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id,
&object);
+ tracker_db_journal_reader_get_statement (reader, &graph_id, &subject_id,
&predicate_id, &object);
if (last_operation_type == 1) {
tracker_data_update_buffer_flush (&new_error);
@@ -3775,7 +3777,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
TrackerClass *class = NULL;
TrackerProperty *property = NULL;
- tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id,
&object_id);
+ tracker_db_journal_reader_get_statement_id (reader, &graph_id, &subject_id,
&predicate_id, &object_id);
if (last_operation_type == 1) {
tracker_data_update_buffer_flush (&new_error);
@@ -3822,7 +3824,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
if (busy_callback) {
busy_callback (busy_status,
- tracker_db_journal_reader_get_progress (),
+ tracker_db_journal_reader_get_progress (reader),
busy_user_data);
}
}
@@ -3833,8 +3835,8 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
gsize size;
GFile *cache_location, *data_location;
- size = tracker_db_journal_reader_get_size_of_correct ();
- tracker_db_journal_reader_shutdown ();
+ size = tracker_db_journal_reader_get_size_of_correct (reader);
+ tracker_db_journal_reader_free (reader);
cache_location = tracker_data_manager_get_cache_location();
data_location = tracker_data_manager_get_data_location();
@@ -3861,7 +3863,7 @@ tracker_data_replay_journal (TrackerBusyCallback busy_callback,
g_clear_error (&journal_error);
} else {
- tracker_db_journal_reader_shutdown ();
+ tracker_db_journal_reader_free (reader);
}
}
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index db4c054..166f963 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -68,7 +68,7 @@ typedef enum {
TRANSACTION_FORMAT_ONTOLOGY = 1 << 1,
} TransactionFormat;
-typedef struct {
+struct _TrackerDBJournalReader {
gchar *filename;
GFile *journal_location;
GDataInputStream *stream;
@@ -91,8 +91,8 @@ typedef struct {
gint o_id;
gchar *object;
guint current_file;
- gchar *rotate_to;
-} JournalReader;
+ guint total_chunks;
+};
typedef struct {
gchar *journal_filename;
@@ -113,7 +113,6 @@ static struct {
gboolean rotate_progress_flag;
} rotating_settings = {0};
-static JournalReader reader = {0};
static JournalWriter writer = {0};
static JournalWriter ontology_writer = {0};
@@ -136,7 +135,7 @@ strnlen (const char *str, size_t max)
#endif /* HAVE_STRNLEN */
static gboolean
-journal_eof (JournalReader *jreader)
+journal_eof (TrackerDBJournalReader *jreader)
{
if (jreader->stream) {
GBufferedInputStream *bstream;
@@ -167,8 +166,8 @@ read_uint32 (const guint8 *data)
}
static guint32
-journal_read_uint32 (JournalReader *jreader,
- GError **error)
+journal_read_uint32 (TrackerDBJournalReader *jreader,
+ GError **error)
{
guint32 result;
@@ -221,8 +220,8 @@ scan_for_nul (GBufferedInputStream *stream,
}
static gchar *
-journal_read_string (JournalReader *jreader,
- GError **error)
+journal_read_string (TrackerDBJournalReader *jreader,
+ GError **error)
{
gchar *result;
@@ -286,7 +285,7 @@ journal_read_string (JournalReader *jreader,
}
static gboolean
-journal_verify_header (JournalReader *jreader)
+journal_verify_header (TrackerDBJournalReader *jreader)
{
gchar header[8];
gint i;
@@ -1237,9 +1236,10 @@ tracker_db_journal_fsync (void)
* Reader API
*/
+static gboolean db_journal_reader_clear (TrackerDBJournalReader *jreader);
static gchar*
-reader_get_next_filepath (JournalReader *jreader)
+reader_get_next_filepath (TrackerDBJournalReader *jreader)
{
gchar *filename_open = NULL;
gchar *test;
@@ -1291,9 +1291,9 @@ reader_get_next_filepath (JournalReader *jreader)
}
static gboolean
-db_journal_reader_init_file (JournalReader *jreader,
- const gchar *filename,
- GError **error)
+db_journal_reader_init_file (TrackerDBJournalReader *jreader,
+ const gchar *filename,
+ GError **error)
{
if (g_str_has_suffix (filename, ".gz")) {
GFile *file;
@@ -1346,11 +1346,11 @@ db_journal_reader_init_file (JournalReader *jreader,
}
static gboolean
-db_journal_reader_init (JournalReader *jreader,
- gboolean global_reader,
- const gchar *filename,
- GFile *data_location,
- GError **error)
+db_journal_reader_init (TrackerDBJournalReader *jreader,
+ gboolean global_reader,
+ const gchar *filename,
+ GFile *data_location,
+ GError **error)
{
gchar *filename_open;
GError *n_error = NULL;
@@ -1360,7 +1360,7 @@ db_journal_reader_init (JournalReader *jreader,
jreader->filename = g_strdup (filename);
g_set_object (&jreader->journal_location, data_location);
- reader.current_file = 0;
+ jreader->current_file = 0;
if (global_reader) {
filename_open = reader_get_next_filepath (jreader);
} else {
@@ -1384,7 +1384,7 @@ db_journal_reader_init (JournalReader *jreader,
g_free (filename_open);
- tracker_db_journal_reader_shutdown ();
+ db_journal_reader_clear (jreader);
return FALSE;
}
@@ -1393,11 +1393,11 @@ db_journal_reader_init (JournalReader *jreader,
return TRUE;
}
-gboolean
-tracker_db_journal_reader_init (GFile *data_location,
- GError **error)
+TrackerDBJournalReader *
+tracker_db_journal_reader_new (GFile *data_location,
+ GError **error)
{
- gboolean ret;
+ TrackerDBJournalReader *reader;
GError *n_error = NULL;
gchar *filename;
GFile *child;
@@ -1406,22 +1406,24 @@ tracker_db_journal_reader_init (GFile *data_location,
filename = g_file_get_path (child);
g_object_unref (child);
- ret = db_journal_reader_init (&reader, TRUE, filename, data_location, &n_error);
- g_free (filename);
+ reader = g_new0 (TrackerDBJournalReader, 1);
- if (n_error) {
+ if (!db_journal_reader_init (reader, TRUE, filename, data_location, &n_error)) {
g_propagate_error (error, n_error);
+ g_clear_pointer (&reader, g_free);
}
- return ret;
+ g_free (filename);
+
+ return reader;
}
-gboolean
-tracker_db_journal_reader_ontology_init (GFile *data_location,
- GError **error)
+TrackerDBJournalReader *
+tracker_db_journal_reader_ontology_new (GFile *data_location,
+ GError **error)
{
+ TrackerDBJournalReader *reader;
gchar *filename;
- gboolean result;
GError *n_error = NULL;
GFile *child;
@@ -1429,67 +1431,68 @@ tracker_db_journal_reader_ontology_init (GFile *data_location,
filename = g_file_get_path (child);
g_object_unref (child);
- result = db_journal_reader_init (&reader, TRUE, filename, data_location, &n_error);
- g_free (filename);
+ reader = g_new0 (TrackerDBJournalReader, 1);
- if (!result) {
+ if (!db_journal_reader_init (reader, TRUE, filename, data_location, &n_error)) {
g_propagate_error (error, n_error);
- return result;
+ g_clear_pointer (&reader, g_free);
}
- return result;
+ g_free (filename);
+
+ return reader;
}
gsize
-tracker_db_journal_reader_get_size_of_correct (void)
+tracker_db_journal_reader_get_size_of_correct (TrackerDBJournalReader *reader)
{
- g_return_val_if_fail (reader.file != NULL, FALSE);
+ g_return_val_if_fail (reader->file != NULL, FALSE);
- return (gsize) (reader.last_success - reader.start);
+ return (gsize) (reader->last_success - reader->start);
}
static gboolean
-reader_next_file (GError **error)
+reader_next_file (TrackerDBJournalReader *reader,
+ GError **error)
{
gchar *filename_open;
- filename_open = reader_get_next_filepath (&reader);
+ filename_open = reader_get_next_filepath (reader);
- if (reader.stream) {
- g_object_unref (reader.stream);
- reader.stream = NULL;
+ if (reader->stream) {
+ g_object_unref (reader->stream);
+ reader->stream = NULL;
- g_object_unref (reader.underlying_stream);
- reader.underlying_stream = NULL;
- if (reader.underlying_stream_info) {
- g_object_unref (reader.underlying_stream_info);
- reader.underlying_stream_info = NULL;
+ g_object_unref (reader->underlying_stream);
+ reader->underlying_stream = NULL;
+ if (reader->underlying_stream_info) {
+ g_object_unref (reader->underlying_stream_info);
+ reader->underlying_stream_info = NULL;
}
} else {
- g_mapped_file_unref (reader.file);
- reader.file = NULL;
+ g_mapped_file_unref (reader->file);
+ reader->file = NULL;
}
- if (!db_journal_reader_init_file (&reader, filename_open, error)) {
+ if (!db_journal_reader_init_file (reader, filename_open, error)) {
g_free (filename_open);
- tracker_db_journal_reader_shutdown ();
return FALSE;
}
g_free (filename_open);
- reader.type = TRACKER_DB_JOURNAL_END_TRANSACTION;
+ reader->type = TRACKER_DB_JOURNAL_END_TRANSACTION;
- reader.entry_begin = NULL;
- reader.entry_end = NULL;
- reader.amount_of_triples = 0;
+ reader->entry_begin = NULL;
+ reader->entry_end = NULL;
+ reader->amount_of_triples = 0;
return TRUE;
}
static gboolean
-db_journal_reader_shutdown (JournalReader *jreader)
+db_journal_reader_clear (TrackerDBJournalReader *jreader)
{
if (jreader->stream) {
g_object_unref (jreader->stream);
@@ -1526,22 +1529,25 @@ db_journal_reader_shutdown (JournalReader *jreader)
return TRUE;
}
-gboolean
-tracker_db_journal_reader_shutdown (void)
+void
+tracker_db_journal_reader_free (TrackerDBJournalReader *reader)
{
- return db_journal_reader_shutdown (&reader);
+ db_journal_reader_clear (reader);
+ g_free (reader);
}
TrackerDBJournalEntryType
-tracker_db_journal_reader_get_type (void)
+tracker_db_journal_reader_get_entry_type (TrackerDBJournalReader *reader)
{
- g_return_val_if_fail (reader.file != NULL || reader.stream != NULL, FALSE);
+ g_return_val_if_fail (reader->file != NULL || reader->stream != NULL, FALSE);
- return reader.type;
+ return reader->type;
}
static gboolean
-db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError **error)
+db_journal_reader_next (TrackerDBJournalReader *jreader,
+ gboolean global_reader,
+ GError **error)
{
GError *inner_error = NULL;
static gboolean debug_unchecked = TRUE;
@@ -1614,7 +1620,7 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
/* Return FALSE as there is no further entry but
* do not set error as it's not an error case. */
if (global_reader && jreader->current_file != 0) {
- if (reader_next_file (error)) {
+ if (reader_next_file (jreader, error)) {
/* read first entry in next file */
return db_journal_reader_next (jreader, global_reader, error);
} else {
@@ -1850,9 +1856,10 @@ db_journal_reader_next (JournalReader *jreader, gboolean global_reader, GError *
}
gboolean
-tracker_db_journal_reader_next (GError **error)
+tracker_db_journal_reader_next (TrackerDBJournalReader *reader,
+ GError **error)
{
- return db_journal_reader_next (&reader, TRUE, error);
+ return db_journal_reader_next (reader, TRUE, error);
}
gboolean
@@ -1862,7 +1869,7 @@ tracker_db_journal_reader_verify_last (const gchar *filename,
{
guint32 entry_size_check;
gboolean success = FALSE;
- JournalReader jreader = { 0 };
+ TrackerDBJournalReader jreader = { 0 };
GError *n_error = NULL;
if (db_journal_reader_init (&jreader, FALSE, filename, data_location, &n_error)) {
@@ -1874,13 +1881,13 @@ tracker_db_journal_reader_verify_last (const gchar *filename,
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);
+ db_journal_reader_clear (&jreader);
return FALSE;
}
jreader.current = jreader.end - entry_size_check;
success = db_journal_reader_next (&jreader, FALSE, NULL);
- db_journal_reader_shutdown (&jreader);
+ db_journal_reader_clear (&jreader);
} else {
success = TRUE;
}
@@ -1894,85 +1901,88 @@ tracker_db_journal_reader_verify_last (const gchar *filename,
}
gint64
-tracker_db_journal_reader_get_time (void)
+tracker_db_journal_reader_get_time (TrackerDBJournalReader *reader)
{
- return reader.time;
+ return reader->time;
}
gboolean
-tracker_db_journal_reader_get_resource (gint *id,
- const gchar **uri)
+tracker_db_journal_reader_get_resource (TrackerDBJournalReader *reader,
+ gint *id,
+ const gchar **uri)
{
- g_return_val_if_fail (reader.file != NULL || reader.stream != NULL, FALSE);
- g_return_val_if_fail (reader.type == TRACKER_DB_JOURNAL_RESOURCE, FALSE);
+ g_return_val_if_fail (reader->file != NULL || reader->stream != NULL, FALSE);
+ g_return_val_if_fail (reader->type == TRACKER_DB_JOURNAL_RESOURCE, FALSE);
- *id = reader.s_id;
- *uri = reader.uri;
+ *id = reader->s_id;
+ *uri = reader->uri;
return TRUE;
}
gboolean
-tracker_db_journal_reader_get_statement (gint *g_id,
- gint *s_id,
- gint *p_id,
- const gchar **object)
-{
- g_return_val_if_fail (reader.file != NULL || reader.stream != NULL, FALSE);
- g_return_val_if_fail (reader.type == TRACKER_DB_JOURNAL_INSERT_STATEMENT ||
- reader.type == TRACKER_DB_JOURNAL_DELETE_STATEMENT ||
- reader.type == TRACKER_DB_JOURNAL_UPDATE_STATEMENT,
+tracker_db_journal_reader_get_statement (TrackerDBJournalReader *reader,
+ gint *g_id,
+ gint *s_id,
+ gint *p_id,
+ const gchar **object)
+{
+ g_return_val_if_fail (reader->file != NULL || reader->stream != NULL, FALSE);
+ g_return_val_if_fail (reader->type == TRACKER_DB_JOURNAL_INSERT_STATEMENT ||
+ reader->type == TRACKER_DB_JOURNAL_DELETE_STATEMENT ||
+ reader->type == TRACKER_DB_JOURNAL_UPDATE_STATEMENT,
FALSE);
if (g_id) {
- *g_id = reader.g_id;
+ *g_id = reader->g_id;
}
- *s_id = reader.s_id;
- *p_id = reader.p_id;
- *object = reader.object;
+ *s_id = reader->s_id;
+ *p_id = reader->p_id;
+ *object = reader->object;
return TRUE;
}
gboolean
-tracker_db_journal_reader_get_statement_id (gint *g_id,
- gint *s_id,
- gint *p_id,
- gint *o_id)
-{
- g_return_val_if_fail (reader.file != NULL || reader.stream != NULL, FALSE);
- g_return_val_if_fail (reader.type == TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID ||
- reader.type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID ||
- reader.type == TRACKER_DB_JOURNAL_UPDATE_STATEMENT_ID,
+tracker_db_journal_reader_get_statement_id (TrackerDBJournalReader *reader,
+ gint *g_id,
+ gint *s_id,
+ gint *p_id,
+ gint *o_id)
+{
+ g_return_val_if_fail (reader->file != NULL || reader->stream != NULL, FALSE);
+ g_return_val_if_fail (reader->type == TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID ||
+ reader->type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID ||
+ reader->type == TRACKER_DB_JOURNAL_UPDATE_STATEMENT_ID,
FALSE);
if (g_id) {
- *g_id = reader.g_id;
+ *g_id = reader->g_id;
}
- *s_id = reader.s_id;
- *p_id = reader.p_id;
- *o_id = reader.o_id;
+ *s_id = reader->s_id;
+ *p_id = reader->p_id;
+ *o_id = reader->o_id;
return TRUE;
}
gdouble
-tracker_db_journal_reader_get_progress (void)
+tracker_db_journal_reader_get_progress (TrackerDBJournalReader *reader)
{
gdouble chunk = 0, total = 0, ret = 0;
guint current_file;
- static guint total_chunks = 0;
+ guint total_chunks = reader->total_chunks;
- current_file = reader.current_file == 0 ? total_chunks -1 : reader.current_file -1;
+ current_file = reader->current_file == 0 ? reader->total_chunks -1 : reader->current_file -1;
- if (!rotating_settings.rotate_progress_flag) {
+ if (reader->total_chunks == 0) {
gchar *test;
GFile *dest_dir;
gboolean cont = TRUE;
total_chunks = 0;
- test = g_path_get_basename (reader.filename);
+ test = g_path_get_basename (reader->filename);
if (rotating_settings.rotate_to) {
dest_dir = g_file_new_for_path (rotating_settings.rotate_to);
@@ -1991,7 +2001,7 @@ tracker_db_journal_reader_get_progress (void)
gchar *filename;
GFile *possible;
- test = g_strdup_printf ("%s.%d", reader.filename, total_chunks + 1);
+ test = g_strdup_printf ("%s.%d", reader->filename, total_chunks + 1);
filename = g_path_get_basename (test);
g_free (test);
test = filename;
@@ -2008,32 +2018,32 @@ tracker_db_journal_reader_get_progress (void)
}
g_object_unref (dest_dir);
- rotating_settings.rotate_progress_flag = TRUE;
+ reader->total_chunks = total_chunks;
}
if (total_chunks > 0) {
total = ((gdouble) ((gdouble) current_file) / ((gdouble) total_chunks));
}
- if (reader.start != 0) {
+ if (reader->start != 0) {
/* When the last uncompressed part is being processed: */
- gdouble percent = ((gdouble)(reader.end - reader.start));
- ret = chunk = (((gdouble)(reader.current - reader.start)) / percent);
- } else if (reader.underlying_stream) {
+ gdouble percent = ((gdouble)(reader->end - reader->start));
+ ret = chunk = (((gdouble)(reader->current - reader->start)) / percent);
+ } else if (reader->underlying_stream) {
goffset size;
/* When a compressed part is being processed: */
- if (!reader.underlying_stream_info) {
- reader.underlying_stream_info =
- g_file_input_stream_query_info (G_FILE_INPUT_STREAM
(reader.underlying_stream),
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- NULL, NULL);
+ if (!reader->underlying_stream_info) {
+ reader->underlying_stream_info =
+ g_file_input_stream_query_info (G_FILE_INPUT_STREAM
(reader->underlying_stream),
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ NULL, NULL);
}
- if (reader.underlying_stream_info) {
- size = g_file_info_get_size (reader.underlying_stream_info);
- ret = chunk = (gdouble) ((gdouble)g_seekable_tell (G_SEEKABLE
(reader.underlying_stream))) / ((gdouble)size);
+ if (reader->underlying_stream_info) {
+ size = g_file_info_get_size (reader->underlying_stream_info);
+ ret = chunk = (gdouble) ((gdouble)g_seekable_tell (G_SEEKABLE
(reader->underlying_stream))) / ((gdouble)size);
}
}
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index c427bfc..ed4b64d 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -54,6 +54,8 @@ typedef enum {
TRACKER_DB_JOURNAL_UPDATE_STATEMENT_ID,
} TrackerDBJournalEntryType;
+typedef struct _TrackerDBJournalReader TrackerDBJournalReader;
+
GQuark tracker_db_journal_error_quark (void);
/*
@@ -115,32 +117,38 @@ gboolean tracker_db_journal_truncate (gsize new_size);
/*
* Reader API
*/
-gboolean tracker_db_journal_reader_init (GFile *data_location,
+TrackerDBJournalReader *
+ tracker_db_journal_reader_new (GFile *data_location,
GError **error);
-gboolean tracker_db_journal_reader_ontology_init (GFile *data_location,
+TrackerDBJournalReader *
+ tracker_db_journal_reader_ontology_new (GFile *data_location,
GError **error);
-gboolean tracker_db_journal_reader_shutdown (void);
+void tracker_db_journal_reader_free (TrackerDBJournalReader *reader);
TrackerDBJournalEntryType
- tracker_db_journal_reader_get_type (void);
-
-gboolean tracker_db_journal_reader_next (GError **error);
-gint64 tracker_db_journal_reader_get_time (void);
-gboolean tracker_db_journal_reader_get_resource (gint *id,
- const gchar **uri);
-gboolean tracker_db_journal_reader_get_statement (gint *g_id,
- gint *s_id,
- gint *p_id,
- const gchar **object);
-gboolean tracker_db_journal_reader_get_statement_id (gint *g_id,
- gint *s_id,
- gint *p_id,
- gint *o_id);
-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);
+ tracker_db_journal_reader_get_entry_type (TrackerDBJournalReader *reader);
+
+gboolean tracker_db_journal_reader_next (TrackerDBJournalReader *reader,
+ GError **error);
+gint64 tracker_db_journal_reader_get_time (TrackerDBJournalReader *reader);
+gboolean tracker_db_journal_reader_get_resource (TrackerDBJournalReader *reader,
+ gint *id,
+ const gchar **uri);
+gboolean tracker_db_journal_reader_get_statement (TrackerDBJournalReader *reader,
+ gint *g_id,
+ gint *s_id,
+ gint *p_id,
+ const gchar **object);
+gboolean tracker_db_journal_reader_get_statement_id (TrackerDBJournalReader *reader,
+ gint *g_id,
+ gint *s_id,
+ gint *p_id,
+ gint *o_id);
+gsize tracker_db_journal_reader_get_size_of_correct (TrackerDBJournalReader *reader);
+gdouble tracker_db_journal_reader_get_progress (TrackerDBJournalReader *reader);
+
+gboolean tracker_db_journal_reader_verify_last (const gchar *filename,
+ GFile *data_location,
+ GError **error);
G_END_DECLS
diff --git a/tests/libtracker-data/tracker-db-journal.c b/tests/libtracker-data/tracker-db-journal.c
index 42f87da..1d89064 100644
--- a/tests/libtracker-data/tracker-db-journal.c
+++ b/tests/libtracker-data/tracker-db-journal.c
@@ -172,12 +172,13 @@ static void
test_read_functions (void)
{
GError *error = NULL;
- gchar *path, *filename;
+ gchar *path;
gboolean result;
TrackerDBJournalEntryType type;
gint id, s_id, p_id, o_id;
const gchar *uri, *str;
- GFile *data_location, *child;
+ GFile *data_location;
+ TrackerDBJournalReader *reader;
path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", NULL);
data_location = g_file_new_for_path (path);
@@ -186,199 +187,195 @@ test_read_functions (void)
/* 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 (data_location, &error);
- g_free (filename);
+ reader = tracker_db_journal_reader_new (data_location, &error);
g_object_unref (data_location);
g_assert_no_error (error);
- g_assert_cmpint (result, ==, TRUE);
+ g_assert_nonnull (reader);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_START);
/* First transaction */
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_START_TRANSACTION);
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 12);
g_assert_cmpstr (uri, ==, "http://resource");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 13);
g_assert_cmpstr (uri, ==, "http://predicate");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 14);
g_assert_cmpstr (uri, ==, "http://resource");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID);
- result = tracker_db_journal_reader_get_statement_id (NULL, &s_id, &p_id, &o_id);
+ result = tracker_db_journal_reader_get_statement_id (reader, NULL, &s_id, &p_id, &o_id);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (s_id, ==, 12);
g_assert_cmpint (p_id, ==, 13);
g_assert_cmpint (o_id, ==, 14);
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_END_TRANSACTION);
/* Second transaction */
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_START_TRANSACTION);
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 15);
g_assert_cmpstr (uri, ==, "http://resource");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 16);
g_assert_cmpstr (uri, ==, "http://predicate");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_INSERT_STATEMENT);
- result = tracker_db_journal_reader_get_statement (NULL, &s_id, &p_id, &str);
+ result = tracker_db_journal_reader_get_statement (reader, NULL, &s_id, &p_id, &str);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (s_id, ==, 15);
g_assert_cmpint (p_id, ==, 16);
g_assert_cmpstr (str, ==, "test");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_END_TRANSACTION);
/* Third transaction */
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_START_TRANSACTION);
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 17);
g_assert_cmpstr (uri, ==, "http://resource");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 18);
g_assert_cmpstr (uri, ==, "http://predicate");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_RESOURCE);
- result = tracker_db_journal_reader_get_resource (&id, &uri);
+ result = tracker_db_journal_reader_get_resource (reader, &id, &uri);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (id, ==, 19);
g_assert_cmpstr (uri, ==, "http://resource");
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID);
- result = tracker_db_journal_reader_get_statement_id (NULL, &s_id, &p_id, &o_id);
+ result = tracker_db_journal_reader_get_statement_id (reader, NULL, &s_id, &p_id, &o_id);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (s_id, ==, 17);
g_assert_cmpint (p_id, ==, 18);
g_assert_cmpint (o_id, ==, 19);
- result = tracker_db_journal_reader_next (&error);
+ result = tracker_db_journal_reader_next (reader, &error);
g_assert_no_error (error);
g_assert_cmpint (result, ==, TRUE);
- type = tracker_db_journal_reader_get_type ();
+ type = tracker_db_journal_reader_get_entry_type (reader);
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_END_TRANSACTION);
- /* Shutdown */
- result = tracker_db_journal_reader_shutdown ();
- g_assert_cmpint (result, ==, TRUE);
-
+ tracker_db_journal_reader_free (reader);
g_free (path);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]