aboutsummaryrefslogtreecommitdiff
path: root/src/datacache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-18 10:42:00 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-18 10:42:00 +0000
commit7a0a5ba82e4c30f8aa81ab3d29337b03fb5de5c0 (patch)
treec86a3d112483370b481d5a47c199b66a3d13def5 /src/datacache
parentaabfdd760bd17771c90c25eadbc9594dd2d51ee3 (diff)
downloadgnunet-7a0a5ba82e4c30f8aa81ab3d29337b03fb5de5c0.tar.gz
gnunet-7a0a5ba82e4c30f8aa81ab3d29337b03fb5de5c0.zip
more efficient implementation, maybe helping with 1777
Diffstat (limited to 'src/datacache')
-rw-r--r--src/datacache/datacache.c2
-rw-r--r--src/datacache/plugin_datacache_sqlite.c34
2 files changed, 14 insertions, 22 deletions
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index 26402362b..43a9234e5 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -237,7 +237,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
237 GNUNET_NO); 237 GNUNET_NO);
238 GNUNET_CONTAINER_bloomfilter_add (h->filter, key); 238 GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
239 while (h->utilization + used > h->env.quota) 239 while (h->utilization + used > h->env.quota)
240 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls)); 240 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
241 h->utilization += used; 241 h->utilization += used;
242 return GNUNET_OK; 242 return GNUNET_OK;
243} 243}
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 369e8c101..4bb61dcd1 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -115,7 +115,7 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
115 dval = INT64_MAX; 115 dval = INT64_MAX;
116 if (sq_prepare 116 if (sq_prepare
117 (plugin->dbh, 117 (plugin->dbh,
118 "INSERT INTO ds090 " "(type, expire, key, value) " "VALUES (?, ?, ?, ?)", 118 "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)",
119 &stmt) != SQLITE_OK) 119 &stmt) != SQLITE_OK)
120 { 120 {
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -275,11 +275,10 @@ static int
275sqlite_plugin_del (void *cls) 275sqlite_plugin_del (void *cls)
276{ 276{
277 struct Plugin *plugin = cls; 277 struct Plugin *plugin = cls;
278 unsigned long long rowid;
278 unsigned int dsize; 279 unsigned int dsize;
279 unsigned int dtype;
280 sqlite3_stmt *stmt; 280 sqlite3_stmt *stmt;
281 sqlite3_stmt *dstmt; 281 sqlite3_stmt *dstmt;
282 char blob[65536];
283 GNUNET_HashCode hc; 282 GNUNET_HashCode hc;
284 283
285#if DEBUG_DATACACHE_SQLITE 284#if DEBUG_DATACACHE_SQLITE
@@ -289,7 +288,7 @@ sqlite_plugin_del (void *cls)
289 dstmt = NULL; 288 dstmt = NULL;
290 if (sq_prepare 289 if (sq_prepare
291 (plugin->dbh, 290 (plugin->dbh,
292 "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", 291 "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1",
293 &stmt) != SQLITE_OK) 292 &stmt) != SQLITE_OK)
294 { 293 {
295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -307,18 +306,16 @@ sqlite_plugin_del (void *cls)
307 (void) sqlite3_finalize (stmt); 306 (void) sqlite3_finalize (stmt);
308 return GNUNET_SYSERR; 307 return GNUNET_SYSERR;
309 } 308 }
310 dtype = sqlite3_column_int (stmt, 0); 309 rowid = sqlite3_column_int64 (stmt, 0);
311 GNUNET_break (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode)); 310 GNUNET_assert (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode));
312 dsize = sqlite3_column_bytes (stmt, 2);
313 GNUNET_assert (dsize <= sizeof (blob));
314 memcpy (blob, sqlite3_column_blob (stmt, 2), dsize);
315 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); 311 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
312 dsize = sqlite3_column_bytes (stmt, 2);
316 if (SQLITE_OK != sqlite3_finalize (stmt)) 313 if (SQLITE_OK != sqlite3_finalize (stmt))
317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
318 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", 315 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
319 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 316 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
320 if (sq_prepare 317 if (sq_prepare
321 (plugin->dbh, "DELETE FROM ds090 " "WHERE key=? AND value=? AND type=?", 318 (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?",
322 &dstmt) != SQLITE_OK) 319 &dstmt) != SQLITE_OK)
323 { 320 {
324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -328,15 +325,12 @@ sqlite_plugin_del (void *cls)
328 (void) sqlite3_finalize (stmt); 325 (void) sqlite3_finalize (stmt);
329 return GNUNET_SYSERR; 326 return GNUNET_SYSERR;
330 } 327 }
331 if ((SQLITE_OK != 328 if (SQLITE_OK !=
332 sqlite3_bind_blob (dstmt, 1, &hc, sizeof (GNUNET_HashCode), 329 sqlite3_bind_int64 (dstmt, 1, rowid))
333 SQLITE_TRANSIENT)) || 330 {
334 (SQLITE_OK != sqlite3_bind_blob (dstmt, 2, blob, dsize, SQLITE_TRANSIENT)) 331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
335 || (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype))) 332 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind",
336 { 333 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
338 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind",
339 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
340 (void) sqlite3_finalize (dstmt); 334 (void) sqlite3_finalize (dstmt);
341 return GNUNET_SYSERR; 335 return GNUNET_SYSERR;
342 } 336 }
@@ -420,8 +414,6 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
420 return api; 414 return api;
421} 415}
422 416
423// explain SELECT type FROM gn090 WHERE NOT EXISTS (SELECT 1 from gn090 WHERE expire < 42 LIMIT 1) OR expire < 42 ORDER BY repl DESC, Random() LIMIT 1;
424
425 417
426/** 418/**
427 * Exit point from the plugin. 419 * Exit point from the plugin.