[tracker/binary-log-2: 43/43] Pass the transaction's time around instead of using time(NULL) in the journal



commit d04139faaec4654aeecc75d437069a69c68ed335
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Jan 12 11:24:10 2010 +0100

    Pass the transaction's time around instead of using time(NULL) in the journal

 src/libtracker-data/tracker-data-manager.c |    6 +++---
 src/libtracker-data/tracker-data-update.c  |   16 +++++++++++-----
 src/libtracker-data/tracker-data-update.h  |    2 +-
 src/libtracker-db/tracker-db-journal.c     |    4 ++--
 src/libtracker-db/tracker-db-journal.h     |    2 +-
 tests/libtracker-db/tracker-db-journal.c   |    8 ++++----
 6 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 99e865d..7b85045 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -436,7 +436,7 @@ replay_journal (void)
 			tracker_db_statement_bind_int64 (stmt, 2, tracker_db_journal_reader_get_time ());
 			tracker_db_statement_execute (stmt, &error);
 		} else if (type == TRACKER_DB_JOURNAL_START_TRANSACTION) {
-			tracker_data_begin_replay_transaction ();
+			tracker_data_begin_replay_transaction (tracker_db_journal_reader_get_time ());
 		} else if (type == TRACKER_DB_JOURNAL_END_TRANSACTION) {
 			tracker_data_commit_transaction ();
 		} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT) {
@@ -1055,7 +1055,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		/* load ontology from journal into memory */
 		load_ontology_from_journal ();
 
-		tracker_data_begin_replay_transaction ();
+		tracker_data_begin_replay_transaction (tracker_db_journal_reader_get_time ());
 		import_ontology_into_db ();
 		tracker_data_commit_transaction ();
 
@@ -1128,7 +1128,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		}
 
 		tracker_data_begin_transaction ();
-		tracker_db_journal_start_transaction ();
+		tracker_db_journal_start_transaction (time (NULL));
 
 		import_ontology_into_db ();
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 1ac2936..c3a90be 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -121,6 +121,7 @@ static TrackerDataUpdateBuffer update_buffer;
 /* current resource */
 static TrackerDataUpdateBufferResource *resource_buffer;
 static TrackerDataBlankBuffer blank_buffer;
+static time_t resource_time = 0;
 
 static GPtrArray *insert_callbacks = NULL;
 static GPtrArray *delete_callbacks = NULL;
@@ -391,7 +392,8 @@ ensure_resource_id (const gchar *uri)
 		stmt = tracker_db_interface_create_statement (iface, "INSERT INTO \"rdfs:Resource\" (ID, Uri, \"tracker:added\", \"tracker:modified\", Available) VALUES (?, ?, ?, ?, 1)");
 		tracker_db_statement_bind_int (stmt, 0, id);
 		tracker_db_statement_bind_text (stmt, 1, uri);
-		tracker_db_statement_bind_int64 (stmt, 2, (gint64) time (NULL));
+		g_warn_if_fail  (resource_time != 0);
+		tracker_db_statement_bind_int64 (stmt, 2, (gint64) resource_time);
 		tracker_db_statement_bind_int (stmt, 3, tracker_data_update_get_next_modseq ());
 		tracker_db_statement_execute (stmt, NULL);
 		g_object_unref (stmt);
@@ -1860,8 +1862,9 @@ tracker_data_begin_transaction (void)
 }
 
 void
-tracker_data_begin_replay_transaction (void)
+tracker_data_begin_replay_transaction (time_t time)
 {
+	resource_time = time;
 	in_journal_replay = TRUE;
 	tracker_data_begin_transaction ();
 }
@@ -2118,9 +2121,9 @@ tracker_data_update_sparql (const gchar  *update,
 	iface = tracker_db_manager_get_db_interface ();
 
 	sparql_query = tracker_sparql_query_new_update (update);
-
+	resource_time = time (NULL);
 	tracker_db_interface_execute_query (iface, NULL, "SAVEPOINT sparql");
-	tracker_db_journal_start_transaction ();
+	tracker_db_journal_start_transaction (resource_time);
 
 	tracker_sparql_query_execute_update (sparql_query, FALSE, &actual_error);
 
@@ -2145,6 +2148,7 @@ tracker_data_update_sparql (const gchar  *update,
 	}
 
 	tracker_db_journal_commit_transaction ();
+	resource_time = 0;
 	tracker_db_interface_execute_query (iface, NULL, "RELEASE sparql");
 
 	g_object_unref (sparql_query);
@@ -2166,8 +2170,9 @@ tracker_data_update_sparql_blank (const gchar  *update,
 
 	sparql_query = tracker_sparql_query_new_update (update);
 
+	resource_time = time (NULL);
 	tracker_db_interface_execute_query (iface, NULL, "SAVEPOINT sparql");
-	tracker_db_journal_start_transaction ();
+	tracker_db_journal_start_transaction (resource_time);
 
 	blank_nodes = tracker_sparql_query_execute_update (sparql_query, TRUE, &actual_error);
 
@@ -2192,6 +2197,7 @@ tracker_data_update_sparql_blank (const gchar  *update,
 	}
 
 	tracker_db_journal_commit_transaction ();
+	resource_time = 0;
 	tracker_db_interface_execute_query (iface, NULL, "RELEASE sparql");
 
 	g_object_unref (sparql_query);
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 8e847c1..4483441 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -77,7 +77,7 @@ void     tracker_data_insert_statement_with_string  (const gchar               *
                                                      const gchar               *object,
                                                      GError                   **error);
 void     tracker_data_begin_transaction             (void);
-void     tracker_data_begin_replay_transaction      (void);
+void     tracker_data_begin_replay_transaction      (time_t                     time);
 void     tracker_data_commit_transaction            (void);
 void     tracker_data_update_sparql                 (const gchar               *update,
                                                      GError                   **error);
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index 3019801..2c3fa5a 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -300,7 +300,7 @@ tracker_db_journal_get_filename (void)
 }
 
 gboolean
-tracker_db_journal_start_transaction (void)
+tracker_db_journal_start_transaction (time_t time)
 {
 	guint size;
 
@@ -320,7 +320,7 @@ tracker_db_journal_start_transaction (void)
 
 	/* add timestamp */
 	cur_block_maybe_expand (sizeof (gint32));
-	cur_setnum (writer.cur_block, &writer.cur_pos, time (NULL));
+	cur_setnum (writer.cur_block, &writer.cur_pos, time);
 	writer.cur_block_len += sizeof (gint32);
 
 	return TRUE;
diff --git a/src/libtracker-db/tracker-db-journal.h b/src/libtracker-db/tracker-db-journal.h
index 6187568..1097f7a 100644
--- a/src/libtracker-db/tracker-db-journal.h
+++ b/src/libtracker-db/tracker-db-journal.h
@@ -52,7 +52,7 @@ gboolean     tracker_db_journal_shutdown                     (void);
 const gchar* tracker_db_journal_get_filename                 (void);
 gsize        tracker_db_journal_get_size                     (void);
 
-gboolean     tracker_db_journal_start_transaction            (void);
+gboolean     tracker_db_journal_start_transaction            (time_t       time);
 gboolean     tracker_db_journal_append_delete_statement      (guint32      s_id,
                                                               guint32      p_id,
                                                               const gchar *object);
diff --git a/tests/libtracker-db/tracker-db-journal.c b/tests/libtracker-db/tracker-db-journal.c
index 516f0a6..427a271 100644
--- a/tests/libtracker-db/tracker-db-journal.c
+++ b/tests/libtracker-db/tracker-db-journal.c
@@ -65,7 +65,7 @@ test_write_functions (void)
 
 	/* Check with rollback, nothing is added */
 	initial_size = tracker_db_journal_get_size ();
-	result = tracker_db_journal_start_transaction ();
+	result = tracker_db_journal_start_transaction (time (NULL));
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_resource (10, "http://resource";);
 	g_assert_cmpint (result, ==, TRUE);
@@ -79,7 +79,7 @@ test_write_functions (void)
 	g_assert_cmpint (initial_size, ==, actual_size);
 
 	/* Check with commit, somethign is added */
-	result = tracker_db_journal_start_transaction ();
+	result = tracker_db_journal_start_transaction (time (NULL));
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_resource (12, "http://resource";);
 	g_assert_cmpint (result, ==, TRUE);
@@ -95,7 +95,7 @@ test_write_functions (void)
 	g_assert_cmpint (initial_size, !=, actual_size);
 
 	/* Test insert statement */
-	result = tracker_db_journal_start_transaction ();
+	result = tracker_db_journal_start_transaction (time (NULL));
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_resource (15, "http://resource";);
 	g_assert_cmpint (result, ==, TRUE);
@@ -107,7 +107,7 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 
 	/* Test insert id */
-	result = tracker_db_journal_start_transaction ();
+	result = tracker_db_journal_start_transaction (time (NULL));
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_resource (17, "http://resource";);
 	g_assert_cmpint (result, ==, TRUE);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]