Merge lp:~zeitgeist/zeitgeist/dbfails into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Merge reported by: Siegfried Gevatter
Merged at revision: not available
Proposed branch: lp:~zeitgeist/zeitgeist/dbfails
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 329 lines (+149/-25)
6 files modified
doc/zeitgeist-daemon.1 (+6/-0)
src/errors.vala (+6/-1)
src/sql-schema.vala (+13/-6)
src/sql.vala (+69/-7)
src/utils.vala (+18/-4)
src/zeitgeist-daemon.vala (+37/-7)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/dbfails
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Siegfried Gevatter Needs Fixing
Review via email: mp+87195@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

<mhr3> RainCT, can you propagate the error one more level up, so there's no need for the posix.exit?

review: Needs Fixing
lp:~zeitgeist/zeitgeist/dbfails updated
357. By Michal Hruby

Add a define to explain query plans

358. By Michal Hruby

Merge lp:~zeitgeist/zeitgeist/bluebird-no-distinct

359. By Seif Lotfy

Add Exclusive lock for secure writing

360. By Michal Hruby

Add real-world query samples

361. By Michal Hruby

Don't use fts when using in-memory database

362. By Michal Hruby

Don't display debug messages by default

363. By Michal Hruby

Add a way to disable extensions

364. By Seif Lotfy

Fix bug 909708 where inserting and event with 2 subjects.
Since we already parse the subjects before insertion I added a list with subj_uris to find if there is a duplicate and return 0 if one is found

365. By Michal Hruby

Fix Reindex in FTS indexer

366. By Michal Hruby

Disable the VolumeMonitor in StorageMonitor extension to avoid weird races

Revision history for this message
Michal Hruby (mhr3) wrote :

Yes, please :)

review: Needs Fixing
lp:~zeitgeist/zeitgeist/dbfails updated
367. By Seif Lotfy

optimize allocations of variants

368. By Seif Lotfy

Seperate the allocation optimization into a new method optimize_variant_allocation.
This optimization effects marshalling by slowint it down by around 0.06s for 10k
events yet saves us 10MB in memory consumption.

369. By Siegfried Gevatter

Merge Seif's FTS changes removing database writes.

370. By Siegfried Gevatter

Automatically recover from corrupt database and be more clear
on some other errors.

Revision history for this message
Michal Hruby (mhr3) wrote :

282 + throw err;
289 + throw err;
293 + throw err;

Seems like it could be moved out of the ifs.

Other than that it's fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'doc/zeitgeist-daemon.1'
--- doc/zeitgeist-daemon.1 2012-01-02 19:31:15 +0000
+++ doc/zeitgeist-daemon.1 2012-01-25 11:17:27 +0000
@@ -87,6 +87,12 @@
87.TP87.TP
88.B 1088.B 10
89There is already a running Zeitgeist instance.89There is already a running Zeitgeist instance.
90.TP
91.B 21
92Could not access the database file.
93.TP
94.B 22
95The database file is locked.
9096
91.SH SEE ALSO97.SH SEE ALSO
92\fBzeitgeist-datahub\fR, \fBgnome-activity-journal\fR98\fBzeitgeist-datahub\fR, \fBgnome-activity-journal\fR
9399
=== modified file 'src/errors.vala'
--- src/errors.vala 2011-10-20 13:32:51 +0000
+++ src/errors.vala 2012-01-25 11:17:27 +0000
@@ -23,10 +23,15 @@
23 [DBus (name = "org.gnome.zeitgeist.EngineError")]23 [DBus (name = "org.gnome.zeitgeist.EngineError")]
24 public errordomain EngineError24 public errordomain EngineError
25 {25 {
26 BACKUP_FAILED,
27 DATABASE_BUSY,
28 DATABASE_CANTOPEN,
29 DATABASE_CORRUPT,
26 DATABASE_ERROR,30 DATABASE_ERROR,
31 DATABASE_RETIRE_FAILED,
27 INVALID_ARGUMENT,32 INVALID_ARGUMENT,
28 INVALID_KEY,33 INVALID_KEY,
29 BACKUP_FAILED,34 EXISTING_INSTANCE,
30 }35 }
3136
32 // vala doesn't include proper headers, this fixes it37 // vala doesn't include proper headers, this fixes it
3338
=== modified file 'src/sql-schema.vala'
--- src/sql-schema.vala 2011-12-31 19:15:54 +0000
+++ src/sql-schema.vala 2012-01-25 11:17:27 +0000
@@ -414,8 +414,8 @@
414 }414 }
415415
416 /**416 /**
417 * Execute the given SQL. If the query doesn't succeed, log a417 * Execute the given SQL. If the query doesn't succeed, throw
418 * critical warning (potentially aborting the program).418 * an error.
419 *419 *
420 * @param database the database on which to run the query420 * @param database the database on which to run the query
421 * @param sql the SQL query to run421 * @param sql the SQL query to run
@@ -426,10 +426,17 @@
426 int rc = database.exec (sql);426 int rc = database.exec (sql);
427 if (rc != Sqlite.OK)427 if (rc != Sqlite.OK)
428 {428 {
429 const string fmt_str = "Can't create database: %d, %s\n\n" +429 if (rc == Sqlite.CORRUPT)
430 "Unable to execute SQL:\n%s";430 {
431 var err_msg = fmt_str.printf (rc, database.errmsg (), sql);431 throw new EngineError.DATABASE_CORRUPT (database.errmsg ());
432 throw new EngineError.DATABASE_ERROR (err_msg);432 }
433 else
434 {
435 const string fmt_str = "Can't create database: %d, %s\n\n" +
436 "Unable to execute SQL:\n%s";
437 var err_msg = fmt_str.printf (rc, database.errmsg (), sql);
438 throw new EngineError.DATABASE_ERROR (err_msg);
439 }
433 }440 }
434 }441 }
435442
436443
=== modified file 'src/sql.vala'
--- src/sql.vala 2012-01-02 19:30:51 +0000
+++ src/sql.vala 2012-01-25 11:17:27 +0000
@@ -67,13 +67,7 @@
6767
68 public ZeitgeistDatabase () throws EngineError68 public ZeitgeistDatabase () throws EngineError
69 {69 {
70 message ("Opening DB from %s", Utils.get_database_file_path ());70 open_database (true);
71 int rc = Sqlite.Database.open_v2 (
72 Utils.get_database_file_path (),
73 out database);
74 assert_query_success (rc, "Can't open database");
75
76 DatabaseSchema.ensure_schema (database);
7771
78 prepare_queries ();72 prepare_queries ();
7973
@@ -82,6 +76,74 @@
82 database.update_hook (update_callback);76 database.update_hook (update_callback);
83 }77 }
8478
79 private void open_database (bool retry)
80 throws EngineError
81 {
82 int rc = Sqlite.Database.open_v2 (
83 Utils.get_database_file_path (),
84 out database);
85
86 if (rc == Sqlite.OK)
87 {
88 try
89 {
90 // Error (like a malformed database) may not be exposed
91 // until we try to operate on the database.
92 DatabaseSchema.ensure_schema (database);
93 }
94 catch (EngineError err)
95 {
96 if (err is EngineError.DATABASE_CORRUPT && retry)
97 rc = Sqlite.CORRUPT;
98 else if (err is EngineError.DATABASE_CANTOPEN)
99 rc = Sqlite.CANTOPEN;
100 else if (err is EngineError.DATABASE_BUSY)
101 rc = Sqlite.BUSY;
102 else
103 throw err;
104 }
105 }
106
107 if (rc != Sqlite.OK)
108 {
109 if (rc == Sqlite.CORRUPT && retry)
110 {
111 // The database disk image is malformed
112 warning ("It looks like your database is corrupt. " +
113 "It will be renamed and a new one will be created.");
114 try
115 {
116 Utils.retire_database ();
117 }
118 catch (Error err)
119 {
120 string message =
121 "Could not rename database: %s".printf (
122 err.message);
123 throw new EngineError.DATABASE_RETIRE_FAILED (message);
124 }
125 open_database (false);
126 }
127 else if (rc == Sqlite.PERM || rc == Sqlite.CANTOPEN)
128 {
129 // Access permission denied / Unable to open database file
130 throw new EngineError.DATABASE_CANTOPEN (
131 database.errmsg ());
132 }
133 else if (rc == Sqlite.BUSY)
134 {
135 // The database file is locked
136 throw new EngineError.DATABASE_BUSY (database.errmsg ());
137 }
138 else
139 {
140 string message = "Can't open database: %d, %s".printf(rc,
141 database.errmsg ());
142 throw new EngineError.DATABASE_ERROR (message);
143 }
144 }
145 }
146
85 public uint32 get_last_id () throws EngineError147 public uint32 get_last_id () throws EngineError
86 {148 {
87 int last_id = -1;149 int last_id = -1;
88150
=== modified file 'src/utils.vala'
--- src/utils.vala 2011-10-31 15:28:09 +0000
+++ src/utils.vala 2012-01-25 11:17:27 +0000
@@ -31,7 +31,8 @@
31 private static string DATABASE_FILE_BACKUP_PATH;31 private static string DATABASE_FILE_BACKUP_PATH;
32 private static string LOCAL_EXTENSIONS_PATH;32 private static string LOCAL_EXTENSIONS_PATH;
3333
34 public const string ZEITGEIST_DATA_FOLDER = "zeitgeist";34 public const string DATA_FOLDER = "zeitgeist";
35 public const string DATABASE_BASENAME = "activity.sqlite";
35 public const string USER_EXTENSION_PATH = "";36 public const string USER_EXTENSION_PATH = "";
3637
37 // D-Bus38 // D-Bus
@@ -48,7 +49,7 @@
4849
49 DATA_PATH = Environment.get_variable ("ZEITGEIST_DATA_PATH") ??50 DATA_PATH = Environment.get_variable ("ZEITGEIST_DATA_PATH") ??
50 Path.build_filename (Environment.get_user_data_dir (),51 Path.build_filename (Environment.get_user_data_dir (),
51 ZEITGEIST_DATA_FOLDER);52 DATA_FOLDER);
5253
53 if (!FileUtils.test (DATA_PATH, FileTest.IS_DIR))54 if (!FileUtils.test (DATA_PATH, FileTest.IS_DIR))
54 {55 {
@@ -66,7 +67,7 @@
6667
67 DATABASE_FILE_PATH =68 DATABASE_FILE_PATH =
68 Environment.get_variable ("ZEITGEIST_DATABASE_PATH") ??69 Environment.get_variable ("ZEITGEIST_DATABASE_PATH") ??
69 Path.build_filename (get_data_path (), "activity.sqlite");70 Path.build_filename (get_data_path (), DATABASE_BASENAME);
7071
71 debug ("DATABASE_FILE_PATH = %s", DATABASE_FILE_PATH);72 debug ("DATABASE_FILE_PATH = %s", DATABASE_FILE_PATH);
7273
@@ -80,13 +81,20 @@
8081
81 DATABASE_FILE_BACKUP_PATH =82 DATABASE_FILE_BACKUP_PATH =
82 Environment.get_variable ("ZEITGEIST_DATABASE_BACKUP_PATH") ??83 Environment.get_variable ("ZEITGEIST_DATABASE_BACKUP_PATH") ??
83 Path.build_filename (get_data_path (), "activity.sqlite.bck");84 Path.build_filename (get_data_path (),
85 DATABASE_BASENAME + ".bck");
8486
85 debug ("DATABASE_FILE_BACKUP_PATH = %s", DATABASE_FILE_BACKUP_PATH);87 debug ("DATABASE_FILE_BACKUP_PATH = %s", DATABASE_FILE_BACKUP_PATH);
8688
87 return DATABASE_FILE_BACKUP_PATH;89 return DATABASE_FILE_BACKUP_PATH;
88 }90 }
8991
92 public string get_database_file_retire_name ()
93 {
94 return DATABASE_BASENAME + ".%s.bck".printf (
95 new DateTime.now_local ().format ("%Y%m%d-%H%M%S"));
96 }
97
90 public unowned string get_local_extensions_path ()98 public unowned string get_local_extensions_path ()
91 {99 {
92 if (LOCAL_EXTENSIONS_PATH != null) return LOCAL_EXTENSIONS_PATH;100 if (LOCAL_EXTENSIONS_PATH != null) return LOCAL_EXTENSIONS_PATH;
@@ -113,6 +121,12 @@
113121
114 original.copy (destination, FileCopyFlags.OVERWRITE, null, null);122 original.copy (destination, FileCopyFlags.OVERWRITE, null, null);
115 }123 }
124
125 public void retire_database () throws Error
126 {
127 File dbfile = File.new_for_path (get_database_file_path ());
128 dbfile.set_display_name (get_database_file_retire_name ());
129 }
116 }130 }
117}131}
118132
119133
=== modified file 'src/zeitgeist-daemon.vala'
--- src/zeitgeist-daemon.vala 2012-01-02 19:30:51 +0000
+++ src/zeitgeist-daemon.vala 2012-01-25 11:17:27 +0000
@@ -329,6 +329,7 @@
329 }329 }
330330
331 static void run ()331 static void run ()
332 throws Error
332 {333 {
333 DBusConnection connection;334 DBusConnection connection;
334 bool name_owned;335 bool name_owned;
@@ -342,8 +343,7 @@
342 }343 }
343 catch (IOError err)344 catch (IOError err)
344 {345 {
345 critical ("%s", err.message);346 throw err;
346 return;
347 }347 }
348 if (name_owned)348 if (name_owned)
349 {349 {
@@ -353,9 +353,10 @@
353 }353 }
354 else354 else
355 {355 {
356 critical ("An existing instance was found. Please use " +356 warning ("An existing instance was found. Please use " +
357 "--replace to stop it and start a new instance.");357 "--replace to stop it and start a new instance.");
358 Posix.exit (10);358 throw new EngineError.EXISTING_INSTANCE (
359 "Zeitgeist is running already.");
359 }360 }
360 }361 }
361362
@@ -370,8 +371,24 @@
370 }371 }
371 catch (Error err)372 catch (Error err)
372 {373 {
373 critical ("%s", err.message);374 if (err is EngineError.DATABASE_CANTOPEN)
374 return;375 {
376 warning ("Could not access the database file.\n" +
377 "Please check the permissions of file %s.",
378 Utils.get_database_file_path ());
379 throw err;
380 }
381 else if (err is EngineError.DATABASE_BUSY)
382 {
383 warning ("It looks like another Zeitgeist instance " +
384 "is already running (the database is locked). " +
385 "If you want to start a new instance, use --replace.");
386 throw err;
387 }
388 else
389 {
390 throw err;
391 }
375 }392 }
376393
377 uint owner_id = Bus.own_name_on_connection (connection,394 uint owner_id = Bus.own_name_on_connection (connection,
@@ -437,7 +454,7 @@
437454
438 return 0;455 return 0;
439 }456 }
440 457
441 LogLevelFlags discarded = LogLevelFlags.LEVEL_DEBUG;458 LogLevelFlags discarded = LogLevelFlags.LEVEL_DEBUG;
442 if (log_level != null)459 if (log_level != null)
443 {460 {
@@ -472,9 +489,22 @@
472489
473 run ();490 run ();
474 }491 }
492 catch (EngineError.EXISTING_INSTANCE err)
493 {
494 return 10;
495 }
496 catch (EngineError.DATABASE_CANTOPEN err)
497 {
498 return 21;
499 }
500 catch (EngineError.DATABASE_BUSY err)
501 {
502 return 22;
503 }
475 catch (Error err)504 catch (Error err)
476 {505 {
477 warning ("%s", err.message);506 warning ("%s", err.message);
507 return 1;
478 }508 }
479509
480 return 0;510 return 0;

Subscribers

People subscribed via source and target branches