diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-06-12 14:48:00 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-06-12 14:48:00 +0200 |
commit | f6a87ee66310529edf76c0fab76cdc7cd2aac216 (patch) | |
tree | e3697e5f549bd6d0adbeede9935b67313d4907cf /src/datacache/plugin_datacache_postgres.c | |
parent | ae8b5cb2eac770be0d18b7d46c238bf865e34023 (diff) | |
download | gnunet-f6a87ee66310529edf76c0fab76cdc7cd2aac216.tar.gz gnunet-f6a87ee66310529edf76c0fab76cdc7cd2aac216.zip |
ensure datacache does not return expired records, fixig pq behavior with respect to FOREVER absolute time
Diffstat (limited to 'src/datacache/plugin_datacache_postgres.c')
-rw-r--r-- | src/datacache/plugin_datacache_postgres.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index 6eeeb5873..ea87acc1f 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c | |||
@@ -82,12 +82,12 @@ init_connection (struct Plugin *plugin) | |||
82 | struct GNUNET_PQ_PreparedStatement ps[] = { | 82 | struct GNUNET_PQ_PreparedStatement ps[] = { |
83 | GNUNET_PQ_make_prepare ("getkt", | 83 | GNUNET_PQ_make_prepare ("getkt", |
84 | "SELECT discard_time,type,value,path FROM gn011dc " | 84 | "SELECT discard_time,type,value,path FROM gn011dc " |
85 | "WHERE key=$1 AND type=$2", | 85 | "WHERE key=$1 AND type=$2 AND discard_time >= $3", |
86 | 2), | 86 | 3), |
87 | GNUNET_PQ_make_prepare ("getk", | 87 | GNUNET_PQ_make_prepare ("getk", |
88 | "SELECT discard_time,type,value,path FROM gn011dc " | 88 | "SELECT discard_time,type,value,path FROM gn011dc " |
89 | "WHERE key=$1", | 89 | "WHERE key=$1 AND discard_time >= $2", |
90 | 1), | 90 | 2), |
91 | GNUNET_PQ_make_prepare ("getex", | 91 | GNUNET_PQ_make_prepare ("getex", |
92 | "SELECT length(value) AS len,oid,key FROM gn011dc" | 92 | "SELECT length(value) AS len,oid,key FROM gn011dc" |
93 | " WHERE discard_time < $1" | 93 | " WHERE discard_time < $1" |
@@ -97,18 +97,15 @@ init_connection (struct Plugin *plugin) | |||
97 | "SELECT length(value) AS len,oid,key FROM gn011dc" | 97 | "SELECT length(value) AS len,oid,key FROM gn011dc" |
98 | " ORDER BY prox ASC, discard_time ASC LIMIT 1", | 98 | " ORDER BY prox ASC, discard_time ASC LIMIT 1", |
99 | 0), | 99 | 0), |
100 | GNUNET_PQ_make_prepare ("getp", | ||
101 | "SELECT length(value) AS len,oid,key FROM gn011dc " | ||
102 | "ORDER BY discard_time ASC LIMIT 1", | ||
103 | 0), | ||
104 | GNUNET_PQ_make_prepare ("get_random", | 100 | GNUNET_PQ_make_prepare ("get_random", |
105 | "SELECT discard_time,type,value,path,key FROM gn011dc " | 101 | "SELECT discard_time,type,value,path,key FROM gn011dc" |
106 | "ORDER BY key ASC LIMIT 1 OFFSET $1", | 102 | " WHERE discard_time >= $1" |
107 | 1), | 103 | " ORDER BY key ASC LIMIT 1 OFFSET $2", |
104 | 2), | ||
108 | GNUNET_PQ_make_prepare ("get_closest", | 105 | GNUNET_PQ_make_prepare ("get_closest", |
109 | "SELECT discard_time,type,value,path,key FROM gn011dc " | 106 | "SELECT discard_time,type,value,path,key FROM gn011dc " |
110 | "WHERE key>=$1 ORDER BY key ASC LIMIT $2", | 107 | "WHERE key>=$1 AND discard_time >= $2 ORDER BY key ASC LIMIT $3", |
111 | 1), | 108 | 3), |
112 | GNUNET_PQ_make_prepare ("delrow", | 109 | GNUNET_PQ_make_prepare ("delrow", |
113 | "DELETE FROM gn011dc WHERE oid=$1", | 110 | "DELETE FROM gn011dc WHERE oid=$1", |
114 | 1), | 111 | 1), |
@@ -313,18 +310,22 @@ postgres_plugin_get (void *cls, | |||
313 | { | 310 | { |
314 | struct Plugin *plugin = cls; | 311 | struct Plugin *plugin = cls; |
315 | uint32_t type32 = (uint32_t) type; | 312 | uint32_t type32 = (uint32_t) type; |
313 | struct GNUNET_TIME_Absolute now; | ||
316 | struct GNUNET_PQ_QueryParam paramk[] = { | 314 | struct GNUNET_PQ_QueryParam paramk[] = { |
317 | GNUNET_PQ_query_param_auto_from_type (key), | 315 | GNUNET_PQ_query_param_auto_from_type (key), |
316 | GNUNET_PQ_query_param_absolute_time (&now), | ||
318 | GNUNET_PQ_query_param_end | 317 | GNUNET_PQ_query_param_end |
319 | }; | 318 | }; |
320 | struct GNUNET_PQ_QueryParam paramkt[] = { | 319 | struct GNUNET_PQ_QueryParam paramkt[] = { |
321 | GNUNET_PQ_query_param_auto_from_type (key), | 320 | GNUNET_PQ_query_param_auto_from_type (key), |
322 | GNUNET_PQ_query_param_uint32 (&type32), | 321 | GNUNET_PQ_query_param_uint32 (&type32), |
322 | GNUNET_PQ_query_param_absolute_time (&now), | ||
323 | GNUNET_PQ_query_param_end | 323 | GNUNET_PQ_query_param_end |
324 | }; | 324 | }; |
325 | enum GNUNET_DB_QueryStatus res; | 325 | enum GNUNET_DB_QueryStatus res; |
326 | struct HandleResultContext hr_ctx; | 326 | struct HandleResultContext hr_ctx; |
327 | 327 | ||
328 | now = GNUNET_TIME_absolute_get (); | ||
328 | hr_ctx.iter = iter; | 329 | hr_ctx.iter = iter; |
329 | hr_ctx.iter_cls = iter_cls; | 330 | hr_ctx.iter_cls = iter_cls; |
330 | hr_ctx.key = key; | 331 | hr_ctx.key = key; |
@@ -427,6 +428,7 @@ postgres_plugin_get_random (void *cls, | |||
427 | { | 428 | { |
428 | struct Plugin *plugin = cls; | 429 | struct Plugin *plugin = cls; |
429 | uint32_t off; | 430 | uint32_t off; |
431 | struct GNUNET_TIME_Absolute now; | ||
430 | struct GNUNET_TIME_Absolute expiration_time; | 432 | struct GNUNET_TIME_Absolute expiration_time; |
431 | size_t data_size; | 433 | size_t data_size; |
432 | void *data; | 434 | void *data; |
@@ -436,6 +438,7 @@ postgres_plugin_get_random (void *cls, | |||
436 | uint32_t type; | 438 | uint32_t type; |
437 | enum GNUNET_DB_QueryStatus res; | 439 | enum GNUNET_DB_QueryStatus res; |
438 | struct GNUNET_PQ_QueryParam params[] = { | 440 | struct GNUNET_PQ_QueryParam params[] = { |
441 | GNUNET_PQ_query_param_absolute_time (&now), | ||
439 | GNUNET_PQ_query_param_uint32 (&off), | 442 | GNUNET_PQ_query_param_uint32 (&off), |
440 | GNUNET_PQ_query_param_end | 443 | GNUNET_PQ_query_param_end |
441 | }; | 444 | }; |
@@ -459,6 +462,7 @@ postgres_plugin_get_random (void *cls, | |||
459 | return 0; | 462 | return 0; |
460 | if (NULL == iter) | 463 | if (NULL == iter) |
461 | return 1; | 464 | return 1; |
465 | now = GNUNET_TIME_absolute_get (); | ||
462 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 466 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
463 | plugin->num_items); | 467 | plugin->num_items); |
464 | res = GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, | 468 | res = GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, |
@@ -620,8 +624,10 @@ postgres_plugin_get_closest (void *cls, | |||
620 | { | 624 | { |
621 | struct Plugin *plugin = cls; | 625 | struct Plugin *plugin = cls; |
622 | uint32_t num_results32 = (uint32_t) num_results; | 626 | uint32_t num_results32 = (uint32_t) num_results; |
627 | struct GNUNET_TIME_Absolute now; | ||
623 | struct GNUNET_PQ_QueryParam params[] = { | 628 | struct GNUNET_PQ_QueryParam params[] = { |
624 | GNUNET_PQ_query_param_auto_from_type (key), | 629 | GNUNET_PQ_query_param_auto_from_type (key), |
630 | GNUNET_PQ_query_param_absolute_time (&now), | ||
625 | GNUNET_PQ_query_param_uint32 (&num_results32), | 631 | GNUNET_PQ_query_param_uint32 (&num_results32), |
626 | GNUNET_PQ_query_param_end | 632 | GNUNET_PQ_query_param_end |
627 | }; | 633 | }; |
@@ -630,6 +636,7 @@ postgres_plugin_get_closest (void *cls, | |||
630 | 636 | ||
631 | erc.iter = iter; | 637 | erc.iter = iter; |
632 | erc.iter_cls = iter_cls; | 638 | erc.iter_cls = iter_cls; |
639 | now = GNUNET_TIME_absolute_get (); | ||
633 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, | 640 | res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, |
634 | "get_closest", | 641 | "get_closest", |
635 | params, | 642 | params, |