[tracker/journal: 3/13] libtracker-data: Write transactions in ontology journal



commit 03991da3f187bbe811123252994c85fb4064c03c
Author: Jürg Billeter <j bitron ch>
Date:   Tue Sep 28 15:50:20 2010 +0200

    libtracker-data: Write transactions in ontology journal

 src/libtracker-data/tracker-db-journal.c |   50 +++++++++++++++++++++++++++++-
 src/libtracker-data/tracker-db-journal.h |    7 ++--
 2 files changed, 53 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index 8a26ac4..040d668 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -62,6 +62,7 @@ typedef enum {
 } DataFormat;
 
 typedef enum {
+	TRANSACTION_FORMAT_NONE      = 0,
 	TRANSACTION_FORMAT_DATA      = 1 << 0,
 	TRANSACTION_FORMAT_ONTOLOGY  = 1 << 1,
 } TransactionFormat;
@@ -111,6 +112,9 @@ static struct {
 
 static JournalReader reader = {0};
 static JournalWriter writer = {0};
+static JournalWriter ontology_writer = {0};
+
+static TransactionFormat current_transaction_format;
 
 #if GLIB_CHECK_VERSION (2, 24, 2)
 static gboolean tracker_db_journal_rotate (void);
@@ -550,6 +554,26 @@ tracker_db_journal_init (const gchar *filename,
 }
 
 static gboolean
+db_journal_ontology_init (void)
+{
+	gboolean ret;
+	gchar *filename;
+
+	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);
+
+	ret = db_journal_writer_init (&ontology_writer, FALSE, FALSE, filename);
+	g_free (filename);
+
+	return ret;
+}
+
+static gboolean
 db_journal_writer_shutdown (JournalWriter *jwriter)
 {
 	g_free (jwriter->journal_filename);
@@ -600,6 +624,9 @@ db_journal_writer_start_transaction (JournalWriter    *jwriter,
 	guint size;
 
 	g_return_val_if_fail (jwriter->journal > 0, FALSE);
+	g_return_val_if_fail (current_transaction_format == TRANSACTION_FORMAT_NONE, FALSE);
+
+	current_transaction_format = kind;
 
 	size = sizeof (guint32) * 3;
 	cur_block_maybe_expand (jwriter, size);
@@ -636,7 +663,11 @@ tracker_db_journal_start_transaction (time_t time)
 gboolean
 tracker_db_journal_start_ontology_transaction (time_t time)
 {
-	return db_journal_writer_start_transaction (&writer, time,
+	if (!db_journal_ontology_init ()) {
+		return FALSE;
+	}
+
+	return db_journal_writer_start_transaction (&ontology_writer, time,
 	                                            TRANSACTION_FORMAT_ONTOLOGY);
 }
 
@@ -882,9 +913,17 @@ gboolean
 tracker_db_journal_rollback_transaction (void)
 {
 	g_return_val_if_fail (writer.journal > 0, FALSE);
+	g_return_val_if_fail (current_transaction_format != TRANSACTION_FORMAT_NONE, FALSE);
 
 	cur_block_kill (&writer);
 
+	if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
+		cur_block_kill (&ontology_writer);
+		db_journal_writer_shutdown (&ontology_writer);
+	}
+
+	current_transaction_format = TRANSACTION_FORMAT_NONE;
+
 	return TRUE;
 }
 
@@ -949,8 +988,17 @@ tracker_db_journal_commit_db_transaction (void)
 {
 	gboolean ret;
 
+	g_return_val_if_fail (current_transaction_format != TRANSACTION_FORMAT_NONE, FALSE);
+
 	ret = db_journal_writer_commit_db_transaction (&writer);
 
+	if (current_transaction_format == TRANSACTION_FORMAT_ONTOLOGY) {
+		db_journal_writer_commit_db_transaction (&ontology_writer);
+		db_journal_writer_shutdown (&ontology_writer);
+	}
+
+	current_transaction_format = TRANSACTION_FORMAT_NONE;
+
 #if GLIB_CHECK_VERSION (2, 24, 2)
 	if (ret) {
 		if (rotating_settings.do_rotating && (writer.cur_size > rotating_settings.chunk_size)) {
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index 6783aff..71ec08b 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -27,9 +27,10 @@
 
 G_BEGIN_DECLS
 
-#define TRACKER_DB_JOURNAL_ERROR_DOMAIN "TrackerDBJournal"
-#define TRACKER_DB_JOURNAL_ERROR        tracker_db_journal_error_quark()
-#define TRACKER_DB_JOURNAL_FILENAME     "tracker-store.journal"
+#define TRACKER_DB_JOURNAL_ERROR_DOMAIN       "TrackerDBJournal"
+#define TRACKER_DB_JOURNAL_ERROR              tracker_db_journal_error_quark()
+#define TRACKER_DB_JOURNAL_FILENAME          "tracker-store.journal"
+#define TRACKER_DB_JOURNAL_ONTOLOGY_FILENAME "tracker-store.ontology.journal"
 
 typedef enum {
 	TRACKER_DB_JOURNAL_START,



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