diff options
Diffstat (limited to 'src/datacache/plugin_datacache_sqlite.c')
-rw-r--r-- | src/datacache/plugin_datacache_sqlite.c | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 15438b29b..455dcab0b 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c | |||
@@ -38,7 +38,7 @@ | |||
38 | * How much overhead do we assume per entry in the | 38 | * How much overhead do we assume per entry in the |
39 | * datacache? | 39 | * datacache? |
40 | */ | 40 | */ |
41 | #define OVERHEAD (sizeof(struct GNUNET_HashCode) + 32) | 41 | #define OVERHEAD (sizeof(struct GNUNET_HashCode) + 36) |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Context for all functions in this plugin. | 44 | * Context for all functions in this plugin. |
@@ -150,6 +150,7 @@ sq_prepare (sqlite3 *dbh, | |||
150 | * | 150 | * |
151 | * @param cls closure (our `struct Plugin`) | 151 | * @param cls closure (our `struct Plugin`) |
152 | * @param key key to store @a data under | 152 | * @param key key to store @a data under |
153 | * @param am_closest are we the closest peer? | ||
153 | * @param size number of bytes in @a data | 154 | * @param size number of bytes in @a data |
154 | * @param data data to store | 155 | * @param data data to store |
155 | * @param type type of the value | 156 | * @param type type of the value |
@@ -161,6 +162,7 @@ sq_prepare (sqlite3 *dbh, | |||
161 | static ssize_t | 162 | static ssize_t |
162 | sqlite_plugin_put (void *cls, | 163 | sqlite_plugin_put (void *cls, |
163 | const struct GNUNET_HashCode *key, | 164 | const struct GNUNET_HashCode *key, |
165 | int am_closest, | ||
164 | size_t size, | 166 | size_t size, |
165 | const char *data, | 167 | const char *data, |
166 | enum GNUNET_BLOCK_Type type, | 168 | enum GNUNET_BLOCK_Type type, |
@@ -170,10 +172,12 @@ sqlite_plugin_put (void *cls, | |||
170 | { | 172 | { |
171 | struct Plugin *plugin = cls; | 173 | struct Plugin *plugin = cls; |
172 | uint32_t type32 = type; | 174 | uint32_t type32 = type; |
175 | uint32_t prox = am_closest; | ||
173 | struct GNUNET_SQ_QueryParam params[] = { | 176 | struct GNUNET_SQ_QueryParam params[] = { |
174 | GNUNET_SQ_query_param_uint32 (&type32), | 177 | GNUNET_SQ_query_param_uint32 (&type32), |
175 | GNUNET_SQ_query_param_absolute_time (&discard_time), | 178 | GNUNET_SQ_query_param_absolute_time (&discard_time), |
176 | GNUNET_SQ_query_param_auto_from_type (key), | 179 | GNUNET_SQ_query_param_auto_from_type (key), |
180 | GNUNET_SQ_query_param_uint32 (&prox), | ||
177 | GNUNET_SQ_query_param_fixed_size (data, size), | 181 | GNUNET_SQ_query_param_fixed_size (data, size), |
178 | GNUNET_SQ_query_param_fixed_size (path_info, | 182 | GNUNET_SQ_query_param_fixed_size (path_info, |
179 | path_info_len * sizeof (struct GNUNET_PeerIdentity)), | 183 | path_info_len * sizeof (struct GNUNET_PeerIdentity)), |
@@ -386,6 +390,7 @@ sqlite_plugin_del (void *cls) | |||
386 | uint64_t rowid; | 390 | uint64_t rowid; |
387 | void *data; | 391 | void *data; |
388 | size_t dsize; | 392 | size_t dsize; |
393 | uint32_t prox; | ||
389 | struct GNUNET_HashCode hc; | 394 | struct GNUNET_HashCode hc; |
390 | struct GNUNET_SQ_ResultSpec rs[] = { | 395 | struct GNUNET_SQ_ResultSpec rs[] = { |
391 | GNUNET_SQ_result_spec_uint64 (&rowid), | 396 | GNUNET_SQ_result_spec_uint64 (&rowid), |
@@ -398,9 +403,26 @@ sqlite_plugin_del (void *cls) | |||
398 | GNUNET_SQ_query_param_uint64 (&rowid), | 403 | GNUNET_SQ_query_param_uint64 (&rowid), |
399 | GNUNET_SQ_query_param_end | 404 | GNUNET_SQ_query_param_end |
400 | }; | 405 | }; |
406 | struct GNUNET_SQ_QueryParam prox_params[] = { | ||
407 | GNUNET_SQ_query_param_uint32 (&prox), | ||
408 | GNUNET_SQ_query_param_end | ||
409 | }; | ||
401 | 410 | ||
402 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
403 | "Processing DEL\n"); | 412 | "Processing DEL\n"); |
413 | prox = GNUNET_NO; | ||
414 | again: | ||
415 | if (GNUNET_OK != | ||
416 | GNUNET_SQ_bind (plugin->del_select_stmt, | ||
417 | prox_params)) | ||
418 | { | ||
419 | LOG_SQLITE (plugin->dbh, | ||
420 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
421 | "sqlite3_bind"); | ||
422 | GNUNET_SQ_reset (plugin->dbh, | ||
423 | plugin->del_stmt); | ||
424 | return GNUNET_SYSERR; | ||
425 | } | ||
404 | if (SQLITE_ROW != | 426 | if (SQLITE_ROW != |
405 | sqlite3_step (plugin->del_select_stmt)) | 427 | sqlite3_step (plugin->del_select_stmt)) |
406 | { | 428 | { |
@@ -409,15 +431,25 @@ sqlite_plugin_del (void *cls) | |||
409 | "sqlite3_step"); | 431 | "sqlite3_step"); |
410 | GNUNET_SQ_reset (plugin->dbh, | 432 | GNUNET_SQ_reset (plugin->dbh, |
411 | plugin->del_select_stmt); | 433 | plugin->del_select_stmt); |
434 | if (GNUNET_NO == prox) | ||
435 | { | ||
436 | prox = GNUNET_YES; | ||
437 | goto again; | ||
438 | } | ||
412 | return GNUNET_SYSERR; | 439 | return GNUNET_SYSERR; |
413 | } | 440 | } |
414 | if (GNUNET_OK != | 441 | if (GNUNET_OK != |
415 | GNUNET_SQ_extract_result (plugin->del_select_stmt, | 442 | GNUNET_SQ_extract_result (plugin->del_select_stmt, |
416 | rs)) | 443 | rs)) |
417 | { | 444 | { |
418 | GNUNET_break (0); | ||
419 | GNUNET_SQ_reset (plugin->dbh, | 445 | GNUNET_SQ_reset (plugin->dbh, |
420 | plugin->del_select_stmt); | 446 | plugin->del_select_stmt); |
447 | if (GNUNET_NO == prox) | ||
448 | { | ||
449 | prox = GNUNET_YES; | ||
450 | goto again; | ||
451 | } | ||
452 | GNUNET_break (0); | ||
421 | return GNUNET_SYSERR; | 453 | return GNUNET_SYSERR; |
422 | } | 454 | } |
423 | GNUNET_SQ_cleanup_result (rs); | 455 | GNUNET_SQ_cleanup_result (rs); |
@@ -709,13 +741,14 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) | |||
709 | SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3"); | 741 | SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3"); |
710 | 742 | ||
711 | SQLITE3_EXEC (dbh, | 743 | SQLITE3_EXEC (dbh, |
712 | "CREATE TABLE ds090 (" " type INTEGER NOT NULL DEFAULT 0," | 744 | "CREATE TABLE ds091 (" " type INTEGER NOT NULL DEFAULT 0," |
713 | " expire INTEGER NOT NULL DEFAULT 0," | 745 | " expire INTEGER NOT NULL," |
714 | " key BLOB NOT NULL DEFAULT ''," | 746 | " key BLOB NOT NULL DEFAULT ''," |
715 | " value BLOB NOT NULL DEFAULT ''," | 747 | " prox INTEGER NOT NULL," |
748 | " value BLOB NOT NULL," | ||
716 | " path BLOB DEFAULT '')"); | 749 | " path BLOB DEFAULT '')"); |
717 | SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds090 (key,type,expire)"); | 750 | SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds090 (key,type,expire)"); |
718 | SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire ON ds090 (expire)"); | 751 | SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire ON ds090 (prox,expire)"); |
719 | plugin = GNUNET_new (struct Plugin); | 752 | plugin = GNUNET_new (struct Plugin); |
720 | plugin->env = env; | 753 | plugin->env = env; |
721 | plugin->dbh = dbh; | 754 | plugin->dbh = dbh; |
@@ -723,35 +756,35 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) | |||
723 | 756 | ||
724 | if ( (SQLITE_OK != | 757 | if ( (SQLITE_OK != |
725 | sq_prepare (plugin->dbh, | 758 | sq_prepare (plugin->dbh, |
726 | "INSERT INTO ds090 (type, expire, key, value, path) " | 759 | "INSERT INTO ds091 (type, expire, key, prox, value, path) " |
727 | "VALUES (?, ?, ?, ?, ?)", | 760 | "VALUES (?, ?, ?, ?, ?, ?)", |
728 | &plugin->insert_stmt)) || | 761 | &plugin->insert_stmt)) || |
729 | (SQLITE_OK != | 762 | (SQLITE_OK != |
730 | sq_prepare (plugin->dbh, | 763 | sq_prepare (plugin->dbh, |
731 | "SELECT count(*) FROM ds090 " | 764 | "SELECT count(*) FROM ds091 " |
732 | "WHERE key=? AND type=? AND expire >= ?", | 765 | "WHERE key=? AND type=? AND expire >= ?", |
733 | &plugin->get_count_stmt)) || | 766 | &plugin->get_count_stmt)) || |
734 | (SQLITE_OK != | 767 | (SQLITE_OK != |
735 | sq_prepare (plugin->dbh, | 768 | sq_prepare (plugin->dbh, |
736 | "SELECT value,expire,path FROM ds090 " | 769 | "SELECT value,expire,path FROM ds091 " |
737 | "WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?", | 770 | "WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?", |
738 | &plugin->get_stmt)) || | 771 | &plugin->get_stmt)) || |
739 | (SQLITE_OK != | 772 | (SQLITE_OK != |
740 | sq_prepare (plugin->dbh, | 773 | sq_prepare (plugin->dbh, |
741 | "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", | 774 | "SELECT _ROWID_,key,value FROM ds091 WHERE prox=? ORDER BY expire ASC LIMIT 1", |
742 | &plugin->del_select_stmt)) || | 775 | &plugin->del_select_stmt)) || |
743 | (SQLITE_OK != | 776 | (SQLITE_OK != |
744 | sq_prepare (plugin->dbh, | 777 | sq_prepare (plugin->dbh, |
745 | "DELETE FROM ds090 WHERE _ROWID_=?", | 778 | "DELETE FROM ds091 WHERE _ROWID_=?", |
746 | &plugin->del_stmt)) || | 779 | &plugin->del_stmt)) || |
747 | (SQLITE_OK != | 780 | (SQLITE_OK != |
748 | sq_prepare (plugin->dbh, | 781 | sq_prepare (plugin->dbh, |
749 | "SELECT value,expire,path,key,type FROM ds090 " | 782 | "SELECT value,expire,path,key,type FROM ds091 " |
750 | "ORDER BY key LIMIT 1 OFFSET ?", | 783 | "ORDER BY key LIMIT 1 OFFSET ?", |
751 | &plugin->get_random_stmt)) || | 784 | &plugin->get_random_stmt)) || |
752 | (SQLITE_OK != | 785 | (SQLITE_OK != |
753 | sq_prepare (plugin->dbh, | 786 | sq_prepare (plugin->dbh, |
754 | "SELECT value,expire,path,type,key FROM ds090 " | 787 | "SELECT value,expire,path,type,key FROM ds091 " |
755 | "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?", | 788 | "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?", |
756 | &plugin->get_closest_stmt)) | 789 | &plugin->get_closest_stmt)) |
757 | ) | 790 | ) |