[tracker/graph: 7/7] libtracker-db: Update journal to support named graphs
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/graph: 7/7] libtracker-db: Update journal to support named graphs
- Date: Tue, 16 Feb 2010 18:20:24 +0000 (UTC)
commit 6f083b1cf74e328a81ce57fc66d46d1e7a42caf6
Author: Jürg Billeter <j bitron ch>
Date: Tue Feb 16 11:18:08 2010 +0100
libtracker-db: Update journal to support named graphs
src/libtracker-data/tracker-data-manager.c | 44 ++++++++---
src/libtracker-data/tracker-data-update.c | 20 ++++--
src/libtracker-db/tracker-db-journal.c | 106 +++++++++++++++++++++++-----
src/libtracker-db/tracker-db-journal.h | 18 +++--
tests/libtracker-db/tracker-db-journal.c | 14 ++--
5 files changed, 153 insertions(+), 49 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index dd3b566..39a70c5 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -340,9 +340,9 @@ load_ontology_from_journal (void)
gint subject_id, predicate_id, object_id;
if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT) {
- tracker_db_journal_reader_get_statement (&subject_id, &predicate_id, &object);
+ tracker_db_journal_reader_get_statement (NULL, &subject_id, &predicate_id, &object);
} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID) {
- tracker_db_journal_reader_get_statement_id (&subject_id, &predicate_id, &object_id);
+ tracker_db_journal_reader_get_statement_id (NULL, &subject_id, &predicate_id, &object_id);
object = g_hash_table_lookup (id_uri_map, GINT_TO_POINTER (object_id));
} else {
continue;
@@ -411,8 +411,8 @@ replay_journal (void)
while (tracker_db_journal_reader_next (&journal_error)) {
GError *error = NULL;
TrackerDBJournalEntryType type;
- const gchar *subject, *predicate, *object;
- gint subject_id, predicate_id, object_id;
+ const gchar *graph, *subject, *predicate, *object;
+ gint graph_id, subject_id, predicate_id, object_id;
type = tracker_db_journal_reader_get_type ();
if (type == TRACKER_DB_JOURNAL_RESOURCE) {
@@ -438,35 +438,55 @@ replay_journal (void)
} else if (type == TRACKER_DB_JOURNAL_END_TRANSACTION) {
tracker_data_commit_transaction ();
} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT) {
- tracker_db_journal_reader_get_statement (&subject_id, &predicate_id, &object);
+ tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id, &object);
+ if (graph_id > 0) {
+ graph = query_resource_by_id (graph_id);
+ } else {
+ graph = NULL;
+ }
subject = query_resource_by_id (subject_id);
predicate = query_resource_by_id (predicate_id);
- tracker_data_insert_statement_with_string (NULL, subject, predicate, object, &error);
+ tracker_data_insert_statement_with_string (graph, subject, predicate, object, &error);
} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID) {
- tracker_db_journal_reader_get_statement_id (&subject_id, &predicate_id, &object_id);
+ tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
+ if (graph_id > 0) {
+ graph = query_resource_by_id (graph_id);
+ } else {
+ graph = NULL;
+ }
subject = query_resource_by_id (subject_id);
predicate = query_resource_by_id (predicate_id);
object = query_resource_by_id (object_id);
- tracker_data_insert_statement_with_uri (NULL, subject, predicate, object, &error);
+ tracker_data_insert_statement_with_uri (graph, subject, predicate, object, &error);
} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT) {
- tracker_db_journal_reader_get_statement (&subject_id, &predicate_id, &object);
+ tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id, &object);
+ if (graph_id > 0) {
+ graph = query_resource_by_id (graph_id);
+ } else {
+ graph = NULL;
+ }
subject = query_resource_by_id (subject_id);
predicate = query_resource_by_id (predicate_id);
- tracker_data_delete_statement (NULL, subject, predicate, object, &error);
+ tracker_data_delete_statement (graph, subject, predicate, object, &error);
} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID) {
- tracker_db_journal_reader_get_statement_id (&subject_id, &predicate_id, &object_id);
+ tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
+ if (graph_id > 0) {
+ graph = query_resource_by_id (graph_id);
+ } else {
+ graph = NULL;
+ }
subject = query_resource_by_id (subject_id);
predicate = query_resource_by_id (predicate_id);
object = query_resource_by_id (object_id);
- tracker_data_delete_statement (NULL, subject, predicate, object, &error);
+ tracker_data_delete_statement (graph, subject, predicate, object, &error);
}
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index a37bb90..9f8f0e5 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1321,7 +1321,9 @@ tracker_data_delete_statement (const gchar *graph,
class = tracker_ontology_get_class_by_uri (object);
if (class != NULL) {
if (!in_journal_replay) {
- tracker_db_journal_append_delete_statement_id (resource_buffer->id,
+ tracker_db_journal_append_delete_statement_id (
+ (graph != NULL ? query_resource_id (graph) : 0),
+ resource_buffer->id,
tracker_data_query_resource_id (predicate),
query_resource_id (object));
}
@@ -1337,11 +1339,15 @@ tracker_data_delete_statement (const gchar *graph,
gint id = tracker_property_get_id (field);
if (!in_journal_replay) {
if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- tracker_db_journal_append_delete_statement_id (resource_buffer->id,
+ tracker_db_journal_append_delete_statement_id (
+ (graph != NULL ? query_resource_id (graph) : 0),
+ resource_buffer->id,
(id != 0) ? id : tracker_data_query_resource_id (predicate),
query_resource_id (object));
} else {
- tracker_db_journal_append_delete_statement (resource_buffer->id,
+ tracker_db_journal_append_delete_statement (
+ (graph != NULL ? query_resource_id (graph) : 0),
+ resource_buffer->id,
(id != 0) ? id : tracker_data_query_resource_id (predicate),
object);
}
@@ -1591,7 +1597,9 @@ tracker_data_insert_statement_with_uri (const gchar *graph,
}
if (!in_journal_replay) {
- tracker_db_journal_append_insert_statement_id (resource_buffer->id,
+ tracker_db_journal_append_insert_statement_id (
+ (graph != NULL ? query_resource_id (graph) : 0),
+ resource_buffer->id,
(prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate),
query_resource_id (object));
}
@@ -1657,7 +1665,9 @@ tracker_data_insert_statement_with_string (const gchar *graph,
}
if (!in_journal_replay) {
- tracker_db_journal_append_insert_statement (resource_buffer->id,
+ tracker_db_journal_append_insert_statement (
+ (graph != NULL ? query_resource_id (graph) : 0),
+ resource_buffer->id,
(id != 0) ? id : tracker_data_query_resource_id (predicate),
object);
}
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index 1f84c48..17ec6d6 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -44,15 +44,17 @@
/*
* data_format:
* #... 0000 0000 (total size is 4 bytes)
- * ||`- resource insert (all other bits must be 0 if 1)
- * |`-- object type (1 = id, 0 = cstring)
- * `--- operation type (0 = insert, 1 = delete)
+ * |||`- resource insert (all other bits must be 0 if 1)
+ * ||`-- object type (1 = id, 0 = cstring)
+ * |`--- operation type (0 = insert, 1 = delete)
+ * `---- graph (0 = default graph, 1 = named graph)
*/
typedef enum {
DATA_FORMAT_RESOURCE_INSERT = 1 << 0,
DATA_FORMAT_OBJECT_ID = 1 << 1,
- DATA_FORMAT_OPERATION_DELETE = 1 << 2
+ DATA_FORMAT_OPERATION_DELETE = 1 << 2,
+ DATA_FORMAT_GRAPH = 1 << 3
} DataFormat;
static struct {
@@ -68,6 +70,7 @@ static struct {
gint64 time;
TrackerDBJournalEntryType type;
const gchar *uri;
+ gint g_id;
gint s_id;
gint p_id;
gint o_id;
@@ -345,7 +348,8 @@ tracker_db_journal_start_transaction (time_t time)
}
gboolean
-tracker_db_journal_append_delete_statement (gint s_id,
+tracker_db_journal_append_delete_statement (gint g_id,
+ gint s_id,
gint p_id,
const gchar *object)
{
@@ -354,18 +358,26 @@ tracker_db_journal_append_delete_statement (gint s_id,
gint size;
g_return_val_if_fail (writer.journal > 0, FALSE);
+ g_return_val_if_fail (g_id >= 0, FALSE);
g_return_val_if_fail (s_id > 0, FALSE);
g_return_val_if_fail (p_id > 0, FALSE);
g_return_val_if_fail (object != NULL, FALSE);
o_len = strlen (object);
- df = DATA_FORMAT_OPERATION_DELETE;
-
- size = (sizeof (guint32) * 3) + o_len + 1;
+ if (g_id == 0) {
+ df = DATA_FORMAT_OPERATION_DELETE;
+ size = (sizeof (guint32) * 3) + o_len + 1;
+ } else {
+ df = DATA_FORMAT_OPERATION_DELETE | DATA_FORMAT_GRAPH;
+ size = (sizeof (guint32) * 4) + o_len + 1;
+ }
cur_block_maybe_expand (size);
cur_setnum (writer.cur_block, &writer.cur_pos, df);
+ if (g_id > 0) {
+ cur_setnum (writer.cur_block, &writer.cur_pos, g_id);
+ }
cur_setnum (writer.cur_block, &writer.cur_pos, s_id);
cur_setnum (writer.cur_block, &writer.cur_pos, p_id);
cur_setstr (writer.cur_block, &writer.cur_pos, object, o_len);
@@ -377,7 +389,8 @@ tracker_db_journal_append_delete_statement (gint s_id,
}
gboolean
-tracker_db_journal_append_delete_statement_id (gint s_id,
+tracker_db_journal_append_delete_statement_id (gint g_id,
+ gint s_id,
gint p_id,
gint o_id)
{
@@ -385,16 +398,25 @@ tracker_db_journal_append_delete_statement_id (gint s_id,
gint size;
g_return_val_if_fail (writer.journal > 0, FALSE);
+ g_return_val_if_fail (g_id >= 0, FALSE);
g_return_val_if_fail (s_id > 0, FALSE);
g_return_val_if_fail (p_id > 0, FALSE);
g_return_val_if_fail (o_id > 0, FALSE);
- df = DATA_FORMAT_OPERATION_DELETE | DATA_FORMAT_OBJECT_ID;
- size = sizeof (guint32) * 4;
+ if (g_id == 0) {
+ df = DATA_FORMAT_OPERATION_DELETE | DATA_FORMAT_OBJECT_ID;
+ size = sizeof (guint32) * 4;
+ } else {
+ df = DATA_FORMAT_OPERATION_DELETE | DATA_FORMAT_OBJECT_ID | DATA_FORMAT_GRAPH;
+ size = sizeof (guint32) * 5;
+ }
cur_block_maybe_expand (size);
cur_setnum (writer.cur_block, &writer.cur_pos, df);
+ if (g_id > 0) {
+ cur_setnum (writer.cur_block, &writer.cur_pos, g_id);
+ }
cur_setnum (writer.cur_block, &writer.cur_pos, s_id);
cur_setnum (writer.cur_block, &writer.cur_pos, p_id);
cur_setnum (writer.cur_block, &writer.cur_pos, o_id);
@@ -406,7 +428,8 @@ tracker_db_journal_append_delete_statement_id (gint s_id,
}
gboolean
-tracker_db_journal_append_insert_statement (gint s_id,
+tracker_db_journal_append_insert_statement (gint g_id,
+ gint s_id,
gint p_id,
const gchar *object)
{
@@ -415,17 +438,26 @@ tracker_db_journal_append_insert_statement (gint s_id,
gint size;
g_return_val_if_fail (writer.journal > 0, FALSE);
+ g_return_val_if_fail (g_id >= 0, FALSE);
g_return_val_if_fail (s_id > 0, FALSE);
g_return_val_if_fail (p_id > 0, FALSE);
g_return_val_if_fail (object != NULL, FALSE);
o_len = strlen (object);
- df = 0x00;
- size = (sizeof (guint32) * 3) + o_len + 1;
+ if (g_id == 0) {
+ df = 0x00;
+ size = (sizeof (guint32) * 3) + o_len + 1;
+ } else {
+ df = DATA_FORMAT_GRAPH;
+ size = (sizeof (guint32) * 4) + o_len + 1;
+ }
cur_block_maybe_expand (size);
cur_setnum (writer.cur_block, &writer.cur_pos, df);
+ if (g_id > 0) {
+ cur_setnum (writer.cur_block, &writer.cur_pos, g_id);
+ }
cur_setnum (writer.cur_block, &writer.cur_pos, s_id);
cur_setnum (writer.cur_block, &writer.cur_pos, p_id);
cur_setstr (writer.cur_block, &writer.cur_pos, object, o_len);
@@ -437,7 +469,8 @@ tracker_db_journal_append_insert_statement (gint s_id,
}
gboolean
-tracker_db_journal_append_insert_statement_id (gint s_id,
+tracker_db_journal_append_insert_statement_id (gint g_id,
+ gint s_id,
gint p_id,
gint o_id)
{
@@ -445,16 +478,25 @@ tracker_db_journal_append_insert_statement_id (gint s_id,
gint size;
g_return_val_if_fail (writer.journal > 0, FALSE);
+ g_return_val_if_fail (g_id >= 0, FALSE);
g_return_val_if_fail (s_id > 0, FALSE);
g_return_val_if_fail (p_id > 0, FALSE);
g_return_val_if_fail (o_id > 0, FALSE);
- df = DATA_FORMAT_OBJECT_ID;
- size = sizeof (guint32) * 4;
+ if (g_id == 0) {
+ df = DATA_FORMAT_OBJECT_ID;
+ size = sizeof (guint32) * 4;
+ } else {
+ df = DATA_FORMAT_OBJECT_ID | DATA_FORMAT_GRAPH;
+ size = sizeof (guint32) * 5;
+ }
cur_block_maybe_expand (size);
cur_setnum (writer.cur_block, &writer.cur_pos, df);
+ if (g_id > 0) {
+ cur_setnum (writer.cur_block, &writer.cur_pos, g_id);
+ }
cur_setnum (writer.cur_block, &writer.cur_pos, s_id);
cur_setnum (writer.cur_block, &writer.cur_pos, p_id);
cur_setnum (writer.cur_block, &writer.cur_pos, o_id);
@@ -659,6 +701,7 @@ tracker_db_journal_reader_shutdown (void)
reader.amount_of_triples = 0;
reader.type = TRACKER_DB_JOURNAL_START;
reader.uri = NULL;
+ reader.g_id = 0;
reader.s_id = 0;
reader.p_id = 0;
reader.o_id = 0;
@@ -901,6 +944,23 @@ tracker_db_journal_reader_next (GError **error)
}
}
+ if (df & DATA_FORMAT_GRAPH) {
+ if (reader.end - reader.current < sizeof (guint32)) {
+ /* damaged journal entry */
+ g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
+ "Damaged journal entry, %d < sizeof(guint32)",
+ (gint) (reader.end - reader.current));
+ return FALSE;
+ }
+
+ /* named graph */
+ reader.g_id = read_uint32 (reader.current);
+ reader.current += 4;
+ } else {
+ /* default graph */
+ reader.g_id = 0;
+ }
+
if (reader.end - reader.current < 2 * sizeof (guint32)) {
/* damaged journal entry */
g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0,
@@ -984,7 +1044,8 @@ tracker_db_journal_reader_get_resource (gint *id,
}
gboolean
-tracker_db_journal_reader_get_statement (gint *s_id,
+tracker_db_journal_reader_get_statement (gint *g_id,
+ gint *s_id,
gint *p_id,
const gchar **object)
{
@@ -993,6 +1054,9 @@ tracker_db_journal_reader_get_statement (gint *s_id,
reader.type == TRACKER_DB_JOURNAL_DELETE_STATEMENT,
FALSE);
+ if (g_id) {
+ *g_id = reader.g_id;
+ }
*s_id = reader.s_id;
*p_id = reader.p_id;
*object = reader.object;
@@ -1001,7 +1065,8 @@ tracker_db_journal_reader_get_statement (gint *s_id,
}
gboolean
-tracker_db_journal_reader_get_statement_id (gint *s_id,
+tracker_db_journal_reader_get_statement_id (gint *g_id,
+ gint *s_id,
gint *p_id,
gint *o_id)
{
@@ -1010,6 +1075,9 @@ tracker_db_journal_reader_get_statement_id (gint *s_id,
reader.type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID,
FALSE);
+ if (g_id) {
+ *g_id = reader.g_id;
+ }
*s_id = reader.s_id;
*p_id = reader.p_id;
*o_id = reader.o_id;
diff --git a/src/libtracker-db/tracker-db-journal.h b/src/libtracker-db/tracker-db-journal.h
index 6692288..0710c52 100644
--- a/src/libtracker-db/tracker-db-journal.h
+++ b/src/libtracker-db/tracker-db-journal.h
@@ -53,16 +53,20 @@ const gchar* tracker_db_journal_get_filename (void);
gsize tracker_db_journal_get_size (void);
gboolean tracker_db_journal_start_transaction (time_t time);
-gboolean tracker_db_journal_append_delete_statement (gint s_id,
+gboolean tracker_db_journal_append_delete_statement (gint g_id,
+ gint s_id,
gint p_id,
const gchar *object);
-gboolean tracker_db_journal_append_delete_statement_id (gint s_id,
+gboolean tracker_db_journal_append_delete_statement_id (gint g_id,
+ gint s_id,
gint p_id,
gint o_id);
-gboolean tracker_db_journal_append_insert_statement (gint s_id,
+gboolean tracker_db_journal_append_insert_statement (gint g_id,
+ gint s_id,
gint p_id,
const gchar *object);
-gboolean tracker_db_journal_append_insert_statement_id (gint s_id,
+gboolean tracker_db_journal_append_insert_statement_id (gint g_id,
+ gint s_id,
gint p_id,
gint o_id);
gboolean tracker_db_journal_append_resource (gint s_id,
@@ -86,10 +90,12 @@ gboolean tracker_db_journal_reader_next (GError **erro
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 *s_id,
+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 *s_id,
+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);
diff --git a/tests/libtracker-db/tracker-db-journal.c b/tests/libtracker-db/tracker-db-journal.c
index 03f7a8b..581c8c3 100644
--- a/tests/libtracker-db/tracker-db-journal.c
+++ b/tests/libtracker-db/tracker-db-journal.c
@@ -71,7 +71,7 @@ test_write_functions (void)
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_append_resource (11, "http://predicate");
g_assert_cmpint (result, ==, TRUE);
- result = tracker_db_journal_append_delete_statement (10, 11, "test");
+ result = tracker_db_journal_append_delete_statement (0, 10, 11, "test");
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_rollback_transaction ();
g_assert_cmpint (result, ==, TRUE);
@@ -87,7 +87,7 @@ test_write_functions (void)
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_append_resource (14, "http://resource");
g_assert_cmpint (result, ==, TRUE);
- result = tracker_db_journal_append_delete_statement_id (12, 13, 14);
+ result = tracker_db_journal_append_delete_statement_id (0, 12, 13, 14);
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_commit_transaction ();
g_assert_cmpint (result, ==, TRUE);
@@ -101,7 +101,7 @@ test_write_functions (void)
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_append_resource (16, "http://predicate");
g_assert_cmpint (result, ==, TRUE);
- result = tracker_db_journal_append_insert_statement (15, 16, "test");
+ result = tracker_db_journal_append_insert_statement (0, 15, 16, "test");
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_commit_transaction ();
g_assert_cmpint (result, ==, TRUE);
@@ -115,7 +115,7 @@ test_write_functions (void)
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_append_resource (19, "http://resource");
g_assert_cmpint (result, ==, TRUE);
- result = tracker_db_journal_append_insert_statement_id (17, 18, 19);
+ result = tracker_db_journal_append_insert_statement_id (0, 17, 18, 19);
g_assert_cmpint (result, ==, TRUE);
result = tracker_db_journal_commit_transaction ();
g_assert_cmpint (result, ==, TRUE);
@@ -201,7 +201,7 @@ test_read_functions (void)
type = tracker_db_journal_reader_get_type ();
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID);
- result = tracker_db_journal_reader_get_statement_id (&s_id, &p_id, &o_id);
+ result = tracker_db_journal_reader_get_statement_id (NULL, &s_id, &p_id, &o_id);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (s_id, ==, 12);
g_assert_cmpint (p_id, ==, 13);
@@ -253,7 +253,7 @@ test_read_functions (void)
type = tracker_db_journal_reader_get_type ();
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_INSERT_STATEMENT);
- result = tracker_db_journal_reader_get_statement (&s_id, &p_id, &str);
+ result = tracker_db_journal_reader_get_statement (NULL, &s_id, &p_id, &str);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (s_id, ==, 15);
g_assert_cmpint (p_id, ==, 16);
@@ -317,7 +317,7 @@ test_read_functions (void)
type = tracker_db_journal_reader_get_type ();
g_assert_cmpint (type, ==, TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID);
- result = tracker_db_journal_reader_get_statement_id (&s_id, &p_id, &o_id);
+ result = tracker_db_journal_reader_get_statement_id (NULL, &s_id, &p_id, &o_id);
g_assert_cmpint (result, ==, TRUE);
g_assert_cmpint (s_id, ==, 17);
g_assert_cmpint (p_id, ==, 18);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]