zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #05304
[Branch ~zeitgeist/zeitgeist/bluebird] Rev 452: Merge lp:~rainct/zeitgeist/limit-dbus-mb
Merge authors:
Siegfried Gevatter (rainct)
Related merge proposals:
https://code.launchpad.net/~rainct/zeitgeist/limit-dbus-mb/+merge/99349
proposed by: Siegfried Gevatter (rainct)
review: Approve - Michal Hruby (mhr3)
------------------------------------------------------------
revno: 452 [merge]
committer: Siegfried-Angel Gevatter Pujals <siegfried@xxxxxxxxxxxx>
branch nick: bluebird
timestamp: Mon 2012-03-26 18:45:28 +0200
message:
Merge lp:~rainct/zeitgeist/limit-dbus-mb
Set a limit on the result size FindEvents and GetEvents may return.
D-Bus has a hard limit of 1GB of data per call and Gio limits us to
100MB. We need to ensure we don't go over this limit, since otherwise
Zeitgeist will crash. Additionally, ransfers of such size take several
minutes and are clear misuse of the Zeitgeist engine.
Therefore, this commit limit the result of FindEvents and GetEvents calls
to not more than 4MiB of data (2MiB would probably be enough, but let's
leave some margin). Queries requesting more than this limit will get
an exception.
modified:
src/datamodel.vala
src/errors.vala
src/utils.vala
src/zeitgeist-daemon.vala
--
lp:zeitgeist
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird
Your team Zeitgeist Framework Team is subscribed to branch lp:zeitgeist.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala 2012-03-20 12:19:23 +0000
+++ src/datamodel.vala 2012-03-26 15:31:28 +0000
@@ -621,6 +621,46 @@
return vb.end ();
}
+ /* Same as to_variant but raises an exception if the variant size
+ * exceeds `limit' bytes.
+ * */
+ public static Variant to_variant_with_limit (GenericArray<Event?> events,
+ size_t limit=Utils.MAX_DBUS_RESULT_SIZE) throws EngineError
+ {
+ var vb = new VariantBuilder(new VariantType("a("+Utils.SIG_EVENT+")"));
+
+ size_t variant_size = 0;
+
+ for (int i = 0; i < events.length; ++i)
+ {
+ Variant event_variant;
+
+ if (events[i] != null)
+ {
+ event_variant = events[i].to_variant ();
+ }
+ else
+ {
+ event_variant = get_null_event_variant ();
+ }
+
+ variant_size += event_variant.get_size();
+ if (variant_size > limit)
+ {
+ size_t avg_event_size = variant_size / (i+1);
+ string error_message = ("Query exceeded size limit of % " +
+ size_t.FORMAT + "MiB (roughly ~%d events).").printf (
+ limit / 1024 / 1024, limit / avg_event_size);
+ warning (error_message);
+ throw new EngineError.TOO_MANY_RESULTS (error_message);
+ }
+
+ vb.add_value (event_variant);
+ }
+
+ return vb.end ();
+ }
+
private static Variant get_null_event_variant ()
{
var vb = new VariantBuilder (new VariantType ("("+Utils.SIG_EVENT+")"));
=== modified file 'src/errors.vala'
--- src/errors.vala 2012-01-25 17:37:55 +0000
+++ src/errors.vala 2012-03-26 15:03:10 +0000
@@ -29,10 +29,11 @@
DATABASE_CORRUPT,
DATABASE_ERROR,
DATABASE_RETIRE_FAILED,
+ EXISTING_INSTANCE,
INVALID_ARGUMENT,
INVALID_KEY,
- EXISTING_INSTANCE,
INVALID_SIGNATURE, // FIXME: change from EngineError to sth. + public
+ TOO_MANY_RESULTS,
}
// vala doesn't include proper headers, this fixes it
=== modified file 'src/utils.vala'
--- src/utils.vala 2012-03-01 14:47:30 +0000
+++ src/utils.vala 2012-03-26 15:03:10 +0000
@@ -38,6 +38,7 @@
// D-Bus
public const string DBUS_INTERFACE = "";
public const string SIG_EVENT = "asaasay";
+ public const size_t MAX_DBUS_RESULT_SIZE = 4 * 1024 * 1024; // 4MiB
// configure runtime cache for events
// default size is 2000
=== modified file 'src/zeitgeist-daemon.vala'
--- src/zeitgeist-daemon.vala 2012-03-01 14:47:30 +0000
+++ src/zeitgeist-daemon.vala 2012-03-26 15:03:10 +0000
@@ -138,7 +138,7 @@
var timer = new Timer ();
GenericArray<Event> events = engine.get_events (event_ids);
debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
- return Events.to_variant (events);
+ return Events.to_variant_with_limit (events);
}
public string[] find_related_uris (Variant time_range,
@@ -176,7 +176,7 @@
Events.from_variant (event_templates),
storage_state, num_events, result_type, sender);
debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
- return Events.to_variant (events);
+ return Events.to_variant_with_limit (events);
}
public uint32[] insert_events (