diff options
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 4 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_heap.c | 7 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 13 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 17 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 11 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 8 | ||||
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 2 |
7 files changed, 38 insertions, 24 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 6c493768d..37df441c4 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -1241,7 +1241,7 @@ disk_utilization_change_cb (void *cls, | |||
1241 | _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), | 1241 | _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), |
1242 | (long long) payload, | 1242 | (long long) payload, |
1243 | (long long) -delta); | 1243 | (long long) -delta); |
1244 | payload = plugin->api->estimate_size (plugin->api->cls); | 1244 | plugin->api->estimate_size (plugin->api->cls, &payload); |
1245 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1245 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1246 | _("New payload: %lld\n"), | 1246 | _("New payload: %lld\n"), |
1247 | (long long) payload); | 1247 | (long long) payload); |
@@ -1404,7 +1404,7 @@ process_stat_done (void *cls, int success) | |||
1404 | { | 1404 | { |
1405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1406 | "Failed to obtain value from statistics service, recomputing it\n"); | 1406 | "Failed to obtain value from statistics service, recomputing it\n"); |
1407 | payload = plugin->api->estimate_size (plugin->api->cls); | 1407 | plugin->api->estimate_size (plugin->api->cls, &payload); |
1408 | } | 1408 | } |
1409 | if (GNUNET_YES == refresh_bf) | 1409 | if (GNUNET_YES == refresh_bf) |
1410 | { | 1410 | { |
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c index 8f7f3d1de..09b3fd416 100644 --- a/src/datastore/plugin_datastore_heap.c +++ b/src/datastore/plugin_datastore_heap.c | |||
@@ -184,12 +184,13 @@ struct Plugin | |||
184 | * @param cls our "struct Plugin*" | 184 | * @param cls our "struct Plugin*" |
185 | * @return number of bytes used on disk | 185 | * @return number of bytes used on disk |
186 | */ | 186 | */ |
187 | static unsigned long long | 187 | static void |
188 | heap_plugin_estimate_size (void *cls) | 188 | heap_plugin_estimate_size (void *cls, unsigned long long *estimate) |
189 | { | 189 | { |
190 | struct Plugin *plugin = cls; | 190 | struct Plugin *plugin = cls; |
191 | 191 | ||
192 | return plugin->size; | 192 | if (NULL != estimate) |
193 | *estimate = plugin->size; | ||
193 | } | 194 | } |
194 | 195 | ||
195 | 196 | ||
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index fab10b206..3a234e365 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -246,22 +246,25 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid) | |||
246 | * @param cls our "struct Plugin *" | 246 | * @param cls our "struct Plugin *" |
247 | * @return number of bytes used on disk | 247 | * @return number of bytes used on disk |
248 | */ | 248 | */ |
249 | static unsigned long long | 249 | static void |
250 | mysql_plugin_estimate_size (void *cls) | 250 | mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) |
251 | { | 251 | { |
252 | struct Plugin *plugin = cls; | 252 | struct Plugin *plugin = cls; |
253 | MYSQL_BIND cbind[1]; | 253 | MYSQL_BIND cbind[1]; |
254 | long long total; | 254 | long long total; |
255 | 255 | ||
256 | if (NULL == estimate) | ||
257 | return; | ||
256 | memset (cbind, 0, sizeof (cbind)); | 258 | memset (cbind, 0, sizeof (cbind)); |
257 | total = 0; | 259 | total = 0; |
258 | cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; | 260 | cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; |
259 | cbind[0].buffer = &total; | 261 | cbind[0].buffer = &total; |
260 | cbind[0].is_unsigned = GNUNET_NO; | 262 | cbind[0].is_unsigned = GNUNET_NO; |
261 | if (GNUNET_OK != | 263 | if (GNUNET_OK == |
262 | GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) | 264 | GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) |
263 | return 0; | 265 | *estimate = total; |
264 | return total; | 266 | else |
267 | *estimate = 0; | ||
265 | } | 268 | } |
266 | 269 | ||
267 | 270 | ||
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index e9495d35e..e7f7a7dd5 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -228,13 +228,15 @@ init_connection (struct Plugin *plugin) | |||
228 | * @param cls our `struct Plugin *` | 228 | * @param cls our `struct Plugin *` |
229 | * @return number of bytes used on disk | 229 | * @return number of bytes used on disk |
230 | */ | 230 | */ |
231 | static unsigned long long | 231 | static void |
232 | postgres_plugin_estimate_size (void *cls) | 232 | postgres_plugin_estimate_size (void *cls, unsigned long long *estimate) |
233 | { | 233 | { |
234 | struct Plugin *plugin = cls; | 234 | struct Plugin *plugin = cls; |
235 | unsigned long long total; | 235 | unsigned long long total; |
236 | PGresult *ret; | 236 | PGresult *ret; |
237 | 237 | ||
238 | if (NULL == estimate) | ||
239 | return; | ||
238 | ret = | 240 | ret = |
239 | PQexecParams (plugin->dbh, | 241 | PQexecParams (plugin->dbh, |
240 | "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0, | 242 | "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0, |
@@ -242,23 +244,26 @@ postgres_plugin_estimate_size (void *cls) | |||
242 | if (GNUNET_OK != | 244 | if (GNUNET_OK != |
243 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_TUPLES_OK, "PQexecParams", "get_size")) | 245 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_TUPLES_OK, "PQexecParams", "get_size")) |
244 | { | 246 | { |
245 | return 0; | 247 | *estimate = 0; |
248 | return; | ||
246 | } | 249 | } |
247 | if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) ) | 250 | if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) ) |
248 | { | 251 | { |
249 | GNUNET_break (0); | 252 | GNUNET_break (0); |
250 | PQclear (ret); | 253 | PQclear (ret); |
251 | return 0; | 254 | *estimate = 0; |
255 | return; | ||
252 | } | 256 | } |
253 | if (PQgetlength (ret, 0, 0) != sizeof (unsigned long long)) | 257 | if (PQgetlength (ret, 0, 0) != sizeof (unsigned long long)) |
254 | { | 258 | { |
255 | GNUNET_break (0 == PQgetlength (ret, 0, 0)); | 259 | GNUNET_break (0 == PQgetlength (ret, 0, 0)); |
256 | PQclear (ret); | 260 | PQclear (ret); |
257 | return 0; | 261 | *estimate = 0; |
262 | return; | ||
258 | } | 263 | } |
259 | total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0)); | 264 | total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0)); |
260 | PQclear (ret); | 265 | PQclear (ret); |
261 | return total; | 266 | *estimate = total; |
262 | } | 267 | } |
263 | 268 | ||
264 | 269 | ||
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index ae57c6aa0..b962d22d7 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -1135,8 +1135,8 @@ sqlite_plugin_drop (void *cls) | |||
1135 | * @param cls the `struct Plugin` | 1135 | * @param cls the `struct Plugin` |
1136 | * @return the size of the database on disk (estimate) | 1136 | * @return the size of the database on disk (estimate) |
1137 | */ | 1137 | */ |
1138 | static unsigned long long | 1138 | static void |
1139 | sqlite_plugin_estimate_size (void *cls) | 1139 | sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate) |
1140 | { | 1140 | { |
1141 | struct Plugin *plugin = cls; | 1141 | struct Plugin *plugin = cls; |
1142 | sqlite3_stmt *stmt; | 1142 | sqlite3_stmt *stmt; |
@@ -1147,12 +1147,15 @@ sqlite_plugin_estimate_size (void *cls) | |||
1147 | char *e; | 1147 | char *e; |
1148 | #endif | 1148 | #endif |
1149 | 1149 | ||
1150 | if (NULL == estimate) | ||
1151 | return; | ||
1150 | if (SQLITE_VERSION_NUMBER < 3006000) | 1152 | if (SQLITE_VERSION_NUMBER < 3006000) |
1151 | { | 1153 | { |
1152 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "datastore-sqlite", | 1154 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "datastore-sqlite", |
1153 | _ | 1155 | _ |
1154 | ("sqlite version to old to determine size, assuming zero\n")); | 1156 | ("sqlite version to old to determine size, assuming zero\n")); |
1155 | return 0; | 1157 | *estimate = 0; |
1158 | return; | ||
1156 | } | 1159 | } |
1157 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); | 1160 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); |
1158 | CHECK (SQLITE_OK == | 1161 | CHECK (SQLITE_OK == |
@@ -1172,7 +1175,7 @@ sqlite_plugin_estimate_size (void *cls) | |||
1172 | _ | 1175 | _ |
1173 | ("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), | 1176 | ("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), |
1174 | (unsigned long long) pages, (unsigned long long) page_size); | 1177 | (unsigned long long) pages, (unsigned long long) page_size); |
1175 | return pages * page_size; | 1178 | *estimate = pages * page_size; |
1176 | } | 1179 | } |
1177 | 1180 | ||
1178 | 1181 | ||
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index 5e577b1bc..cf4b2ec99 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c | |||
@@ -47,11 +47,13 @@ struct Plugin | |||
47 | * @param cls our "struct Plugin*" | 47 | * @param cls our "struct Plugin*" |
48 | * @return number of bytes used on disk | 48 | * @return number of bytes used on disk |
49 | */ | 49 | */ |
50 | static unsigned long long | 50 | static void |
51 | template_plugin_estimate_size (void *cls) | 51 | template_plugin_estimate_size (void *cls, unsigned long long *estimate) |
52 | { | 52 | { |
53 | if (NULL == estimate) | ||
54 | return; | ||
53 | GNUNET_break (0); | 55 | GNUNET_break (0); |
54 | return 0; | 56 | *estimate = 0; |
55 | } | 57 | } |
56 | 58 | ||
57 | 59 | ||
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index 4eefcaefa..bf3deb2f4 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c | |||
@@ -241,7 +241,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
241 | for (j = 0; j < PUT_10; j++) | 241 | for (j = 0; j < PUT_10; j++) |
242 | { | 242 | { |
243 | put_value (crc->api, j, crc->i); | 243 | put_value (crc->api, j, crc->i); |
244 | cs = crc->api->estimate_size (crc->api->cls); | 244 | crc->api->estimate_size (crc->api->cls, &cs); |
245 | GNUNET_assert (os <= cs); | 245 | GNUNET_assert (os <= cs); |
246 | os = cs; | 246 | os = cs; |
247 | } | 247 | } |