diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-23 15:01:43 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-23 15:01:43 +0200 |
commit | d6e1cea9a8b3a1eee91e52eb46adc82e2005b975 (patch) | |
tree | 8184a8531c8cd916e2de4d7f505dc60ecefcb9e8 /src/namestore | |
parent | 7eb7bd8666aeb2e855cd22b1ea7f44b87bb60400 (diff) | |
download | gnunet-d6e1cea9a8b3a1eee91e52eb46adc82e2005b975.tar.gz gnunet-d6e1cea9a8b3a1eee91e52eb46adc82e2005b975.zip |
more incremental processing of zoneimporter
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-zoneimport.c | 95 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 2 |
2 files changed, 80 insertions, 17 deletions
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 0148f42a7..a01772e67 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -37,7 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * Maximum number of queries pending at the same time. | 38 | * Maximum number of queries pending at the same time. |
39 | */ | 39 | */ |
40 | #define THRESH 20 | 40 | #define THRESH 100 |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * TIME_THRESH is in usecs. How quickly do we submit fresh queries. | 43 | * TIME_THRESH is in usecs. How quickly do we submit fresh queries. |
@@ -250,6 +250,11 @@ static unsigned int failures; | |||
250 | static unsigned int records; | 250 | static unsigned int records; |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * #GNUNET_YES if we have more work to be read from `stdin`. | ||
254 | */ | ||
255 | static int stdin_waiting; | ||
256 | |||
257 | /** | ||
253 | * Heap of all requests to perform, sorted by | 258 | * Heap of all requests to perform, sorted by |
254 | * the time we should next do the request (i.e. by expires). | 259 | * the time we should next do the request (i.e. by expires). |
255 | */ | 260 | */ |
@@ -794,6 +799,7 @@ store_completed_cb (void *cls, | |||
794 | int32_t success, | 799 | int32_t success, |
795 | const char *emsg) | 800 | const char *emsg) |
796 | { | 801 | { |
802 | static unsigned int pdot; | ||
797 | struct Request *req = cls; | 803 | struct Request *req = cls; |
798 | 804 | ||
799 | req->qe = NULL; | 805 | req->qe = NULL; |
@@ -810,6 +816,9 @@ store_completed_cb (void *cls, | |||
810 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
811 | "Stored records under `%s'\n", | 817 | "Stored records under `%s'\n", |
812 | req->label); | 818 | req->label); |
819 | pdot++; | ||
820 | if (0 == pdot % 1000) | ||
821 | fprintf (stderr, "."); | ||
813 | } | 822 | } |
814 | } | 823 | } |
815 | 824 | ||
@@ -1061,28 +1070,32 @@ do_shutdown (void *cls) | |||
1061 | GNUNET_SCHEDULER_cancel (t); | 1070 | GNUNET_SCHEDULER_cancel (t); |
1062 | t = NULL; | 1071 | t = NULL; |
1063 | } | 1072 | } |
1064 | if (NULL != ns) | ||
1065 | { | ||
1066 | GNUNET_NAMESTORE_disconnect (ns); | ||
1067 | ns = NULL; | ||
1068 | } | ||
1069 | if (NULL != ctx) | ||
1070 | { | ||
1071 | GNUNET_DNSSTUB_stop (ctx); | ||
1072 | ctx = NULL; | ||
1073 | } | ||
1074 | while (NULL != (req = req_head)) | 1073 | while (NULL != (req = req_head)) |
1075 | { | 1074 | { |
1076 | GNUNET_CONTAINER_DLL_remove (req_head, | 1075 | GNUNET_CONTAINER_DLL_remove (req_head, |
1077 | req_tail, | 1076 | req_tail, |
1078 | req); | 1077 | req); |
1078 | if (NULL != req->qe) | ||
1079 | GNUNET_NAMESTORE_cancel (req->qe); | ||
1079 | free_request (req); | 1080 | free_request (req); |
1080 | } | 1081 | } |
1081 | while (NULL != (req = GNUNET_CONTAINER_heap_remove_root (req_heap))) | 1082 | while (NULL != (req = GNUNET_CONTAINER_heap_remove_root (req_heap))) |
1082 | { | 1083 | { |
1083 | req->hn = NULL; | 1084 | req->hn = NULL; |
1085 | if (NULL != req->qe) | ||
1086 | GNUNET_NAMESTORE_cancel (req->qe); | ||
1084 | free_request (req); | 1087 | free_request (req); |
1085 | } | 1088 | } |
1089 | if (NULL != ns) | ||
1090 | { | ||
1091 | GNUNET_NAMESTORE_disconnect (ns); | ||
1092 | ns = NULL; | ||
1093 | } | ||
1094 | if (NULL != ctx) | ||
1095 | { | ||
1096 | GNUNET_DNSSTUB_stop (ctx); | ||
1097 | ctx = NULL; | ||
1098 | } | ||
1086 | if (NULL != req_heap) | 1099 | if (NULL != req_heap) |
1087 | { | 1100 | { |
1088 | GNUNET_CONTAINER_heap_destroy (req_heap); | 1101 | GNUNET_CONTAINER_heap_destroy (req_heap); |
@@ -1100,6 +1113,32 @@ do_shutdown (void *cls) | |||
1100 | 1113 | ||
1101 | 1114 | ||
1102 | /** | 1115 | /** |
1116 | * Begin processing hostnames from stdin. | ||
1117 | * | ||
1118 | * @param cls NULL | ||
1119 | */ | ||
1120 | static void | ||
1121 | process_stdin (void *cls); | ||
1122 | |||
1123 | |||
1124 | /** | ||
1125 | * If applicable, continue processing from stdin. | ||
1126 | */ | ||
1127 | static void | ||
1128 | continue_stdin () | ||
1129 | { | ||
1130 | if ( (pending < THRESH) && | ||
1131 | (stdin_waiting) ) | ||
1132 | { | ||
1133 | if (NULL != t) | ||
1134 | GNUNET_SCHEDULER_cancel (t); | ||
1135 | t = GNUNET_SCHEDULER_add_now (&process_stdin, | ||
1136 | NULL); | ||
1137 | } | ||
1138 | } | ||
1139 | |||
1140 | |||
1141 | /** | ||
1103 | * Function called if #GNUNET_NAMESTORE_records_lookup() failed. | 1142 | * Function called if #GNUNET_NAMESTORE_records_lookup() failed. |
1104 | * Continues resolution based on assumption namestore has no data. | 1143 | * Continues resolution based on assumption namestore has no data. |
1105 | * | 1144 | * |
@@ -1115,6 +1154,8 @@ ns_lookup_error_cb (void *cls) | |||
1115 | "Failed to load data from namestore for `%s'\n", | 1154 | "Failed to load data from namestore for `%s'\n", |
1116 | req->label); | 1155 | req->label); |
1117 | insert_sorted (req); | 1156 | insert_sorted (req); |
1157 | pending--; | ||
1158 | continue_stdin (); | ||
1118 | } | 1159 | } |
1119 | 1160 | ||
1120 | 1161 | ||
@@ -1137,6 +1178,7 @@ ns_lookup_result_cb (void *cls, | |||
1137 | struct Request *req = cls; | 1178 | struct Request *req = cls; |
1138 | 1179 | ||
1139 | req->qe = NULL; | 1180 | req->qe = NULL; |
1181 | pending--; | ||
1140 | GNUNET_break (0 == memcmp (zone, | 1182 | GNUNET_break (0 == memcmp (zone, |
1141 | &req->zone->key, | 1183 | &req->zone->key, |
1142 | sizeof (*zone))); | 1184 | sizeof (*zone))); |
@@ -1187,6 +1229,7 @@ ns_lookup_result_cb (void *cls, | |||
1187 | req->hostname, | 1229 | req->hostname, |
1188 | GNUNET_STRINGS_absolute_time_to_string (req->expires)); | 1230 | GNUNET_STRINGS_absolute_time_to_string (req->expires)); |
1189 | insert_sorted (req); | 1231 | insert_sorted (req); |
1232 | continue_stdin (); | ||
1190 | } | 1233 | } |
1191 | 1234 | ||
1192 | 1235 | ||
@@ -1213,6 +1256,7 @@ queue (const char *hostname) | |||
1213 | "Refusing invalid hostname `%s'\n", | 1256 | "Refusing invalid hostname `%s'\n", |
1214 | hostname); | 1257 | hostname); |
1215 | rejects++; | 1258 | rejects++; |
1259 | continue_stdin (); | ||
1216 | return; | 1260 | return; |
1217 | } | 1261 | } |
1218 | dot = strchr (hostname, | 1262 | dot = strchr (hostname, |
@@ -1223,6 +1267,7 @@ queue (const char *hostname) | |||
1223 | "Refusing invalid hostname `%s' (lacks '.')\n", | 1267 | "Refusing invalid hostname `%s' (lacks '.')\n", |
1224 | hostname); | 1268 | hostname); |
1225 | rejects++; | 1269 | rejects++; |
1270 | continue_stdin (); | ||
1226 | return; | 1271 | return; |
1227 | } | 1272 | } |
1228 | for (zone = zone_head; NULL != zone; zone = zone->next) | 1273 | for (zone = zone_head; NULL != zone; zone = zone->next) |
@@ -1235,6 +1280,7 @@ queue (const char *hostname) | |||
1235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1236 | "Domain name `%s' not in ego list!\n", | 1281 | "Domain name `%s' not in ego list!\n", |
1237 | dot + 1); | 1282 | dot + 1); |
1283 | continue_stdin (); | ||
1238 | return; | 1284 | return; |
1239 | } | 1285 | } |
1240 | q.name = (char *) hostname; | 1286 | q.name = (char *) hostname; |
@@ -1259,9 +1305,11 @@ queue (const char *hostname) | |||
1259 | "Failed to pack query for hostname `%s'\n", | 1305 | "Failed to pack query for hostname `%s'\n", |
1260 | hostname); | 1306 | hostname); |
1261 | rejects++; | 1307 | rejects++; |
1308 | continue_stdin (); | ||
1262 | return; | 1309 | return; |
1263 | } | 1310 | } |
1264 | 1311 | ||
1312 | pending++; | ||
1265 | req = GNUNET_new (struct Request); | 1313 | req = GNUNET_new (struct Request); |
1266 | req->zone = zone; | 1314 | req->zone = zone; |
1267 | req->hostname = GNUNET_strdup (hostname); | 1315 | req->hostname = GNUNET_strdup (hostname); |
@@ -1288,21 +1336,33 @@ queue (const char *hostname) | |||
1288 | static void | 1336 | static void |
1289 | process_stdin (void *cls) | 1337 | process_stdin (void *cls) |
1290 | { | 1338 | { |
1339 | static unsigned int pdot; | ||
1291 | char hn[256]; | 1340 | char hn[256]; |
1292 | 1341 | ||
1293 | (void) cls; | 1342 | (void) cls; |
1294 | t = NULL; | 1343 | t = NULL; |
1295 | GNUNET_IDENTITY_disconnect (id); | 1344 | if (NULL != id) |
1296 | id = NULL; | 1345 | { |
1297 | while (NULL != | 1346 | GNUNET_IDENTITY_disconnect (id); |
1298 | fgets (hn, | 1347 | id = NULL; |
1299 | sizeof (hn), | 1348 | } |
1300 | stdin)) | 1349 | if (NULL != |
1350 | fgets (hn, | ||
1351 | sizeof (hn), | ||
1352 | stdin)) | ||
1301 | { | 1353 | { |
1302 | if (strlen(hn) > 0) | 1354 | if (strlen(hn) > 0) |
1303 | hn[strlen(hn)-1] = '\0'; /* eat newline */ | 1355 | hn[strlen(hn)-1] = '\0'; /* eat newline */ |
1356 | pdot++; | ||
1357 | if (0 == pdot % 1000) | ||
1358 | fprintf (stderr, "."); | ||
1304 | queue (hn); | 1359 | queue (hn); |
1360 | return; | ||
1305 | } | 1361 | } |
1362 | stdin_waiting = GNUNET_NO; | ||
1363 | fprintf (stderr, "\n"); | ||
1364 | t = GNUNET_SCHEDULER_add_now (&process_queue, | ||
1365 | NULL); | ||
1306 | } | 1366 | } |
1307 | 1367 | ||
1308 | 1368 | ||
@@ -1352,6 +1412,7 @@ identity_cb (void *cls, | |||
1352 | { | 1412 | { |
1353 | if (NULL != zone_head) | 1413 | if (NULL != zone_head) |
1354 | { | 1414 | { |
1415 | stdin_waiting = GNUNET_YES; | ||
1355 | t = GNUNET_SCHEDULER_add_now (&process_stdin, | 1416 | t = GNUNET_SCHEDULER_add_now (&process_stdin, |
1356 | NULL); | 1417 | NULL); |
1357 | } | 1418 | } |
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index a9c19d517..e38fcafb1 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -296,6 +296,8 @@ parse_result_call_iterator (void *cls, | |||
296 | { | 296 | { |
297 | struct ParserContext *pc = cls; | 297 | struct ParserContext *pc = cls; |
298 | 298 | ||
299 | if (NULL == pc->iter) | ||
300 | return; /* no need to do more work */ | ||
299 | for (unsigned int i=0;i<num_results;i++) | 301 | for (unsigned int i=0;i<num_results;i++) |
300 | { | 302 | { |
301 | void *data; | 303 | void *data; |