diff options
Diffstat (limited to 'src/auditor/taler-auditor-sync.c')
-rw-r--r-- | src/auditor/taler-auditor-sync.c | 51 |
1 files changed, 13 insertions, 38 deletions
diff --git a/src/auditor/taler-auditor-sync.c b/src/auditor/taler-auditor-sync.c index 79135230f..0dfaa19a1 100644 --- a/src/auditor/taler-auditor-sync.c +++ b/src/auditor/taler-auditor-sync.c | |||
@@ -120,11 +120,6 @@ static struct Table tables[] = { | |||
120 | struct InsertContext | 120 | struct InsertContext |
121 | { | 121 | { |
122 | /** | 122 | /** |
123 | * Database session to use. | ||
124 | */ | ||
125 | struct TALER_EXCHANGEDB_Session *ds; | ||
126 | |||
127 | /** | ||
128 | * Table we are replicating. | 123 | * Table we are replicating. |
129 | */ | 124 | */ |
130 | struct Table *table; | 125 | struct Table *table; |
@@ -154,7 +149,6 @@ do_insert (void *cls, | |||
154 | if (0 >= ctx->qs) | 149 | if (0 >= ctx->qs) |
155 | return GNUNET_SYSERR; | 150 | return GNUNET_SYSERR; |
156 | qs = dst->insert_records_by_table (dst->cls, | 151 | qs = dst->insert_records_by_table (dst->cls, |
157 | ctx->ds, | ||
158 | td); | 152 | td); |
159 | if (0 >= qs) | 153 | if (0 >= qs) |
160 | { | 154 | { |
@@ -193,42 +187,34 @@ do_insert (void *cls, | |||
193 | * | 187 | * |
194 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to rollback | 188 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to rollback |
195 | */ | 189 | */ |
196 | static int | 190 | static enum GNUNET_GenericReturnValue |
197 | transact (struct TALER_EXCHANGEDB_Session *ss, | 191 | transact (void) |
198 | struct TALER_EXCHANGEDB_Session *ds) | ||
199 | { | 192 | { |
200 | struct InsertContext ctx = { | 193 | struct InsertContext ctx = { |
201 | .ds = ds, | ||
202 | .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT | 194 | .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT |
203 | }; | 195 | }; |
204 | 196 | ||
205 | if (0 > | 197 | if (0 > |
206 | src->start (src->cls, | 198 | src->start (src->cls, |
207 | ss, | ||
208 | "lookup src serials")) | 199 | "lookup src serials")) |
209 | return GNUNET_SYSERR; | 200 | return GNUNET_SYSERR; |
210 | for (unsigned int i = 0; ! tables[i].end; i++) | 201 | for (unsigned int i = 0; ! tables[i].end; i++) |
211 | src->lookup_serial_by_table (src->cls, | 202 | src->lookup_serial_by_table (src->cls, |
212 | ss, | ||
213 | tables[i].rt, | 203 | tables[i].rt, |
214 | &tables[i].end_serial); | 204 | &tables[i].end_serial); |
215 | if (0 > | 205 | if (0 > |
216 | src->commit (src->cls, | 206 | src->commit (src->cls)) |
217 | ss)) | ||
218 | return GNUNET_SYSERR; | 207 | return GNUNET_SYSERR; |
219 | if (GNUNET_OK != | 208 | if (GNUNET_OK != |
220 | dst->start (src->cls, | 209 | dst->start (src->cls, |
221 | ds, | ||
222 | "lookup dst serials")) | 210 | "lookup dst serials")) |
223 | return GNUNET_SYSERR; | 211 | return GNUNET_SYSERR; |
224 | for (unsigned int i = 0; ! tables[i].end; i++) | 212 | for (unsigned int i = 0; ! tables[i].end; i++) |
225 | dst->lookup_serial_by_table (dst->cls, | 213 | dst->lookup_serial_by_table (dst->cls, |
226 | ds, | ||
227 | tables[i].rt, | 214 | tables[i].rt, |
228 | &tables[i].start_serial); | 215 | &tables[i].start_serial); |
229 | if (0 > | 216 | if (0 > |
230 | dst->commit (dst->cls, | 217 | dst->commit (dst->cls)) |
231 | ds)) | ||
232 | return GNUNET_SYSERR; | 218 | return GNUNET_SYSERR; |
233 | for (unsigned int i = 0; ! tables[i].end; i++) | 219 | for (unsigned int i = 0; ! tables[i].end; i++) |
234 | { | 220 | { |
@@ -248,16 +234,13 @@ transact (struct TALER_EXCHANGEDB_Session *ss, | |||
248 | 234 | ||
249 | if (GNUNET_OK != | 235 | if (GNUNET_OK != |
250 | src->start (src->cls, | 236 | src->start (src->cls, |
251 | ss, | ||
252 | "copy table (src)")) | 237 | "copy table (src)")) |
253 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
254 | if (GNUNET_OK != | 239 | if (GNUNET_OK != |
255 | dst->start (dst->cls, | 240 | dst->start (dst->cls, |
256 | ds, | ||
257 | "copy table (dst)")) | 241 | "copy table (dst)")) |
258 | return GNUNET_SYSERR; | 242 | return GNUNET_SYSERR; |
259 | qs = src->lookup_records_by_table (src->cls, | 243 | qs = src->lookup_records_by_table (src->cls, |
260 | ss, | ||
261 | table->rt, | 244 | table->rt, |
262 | table->start_serial, | 245 | table->start_serial, |
263 | &do_insert, | 246 | &do_insert, |
@@ -290,10 +273,8 @@ transact (struct TALER_EXCHANGEDB_Session *ss, | |||
290 | } | 273 | } |
291 | if (0 == ctx.qs) | 274 | if (0 == ctx.qs) |
292 | return GNUNET_SYSERR; /* insertion failed, maybe record existed? try again */ | 275 | return GNUNET_SYSERR; /* insertion failed, maybe record existed? try again */ |
293 | src->rollback (src->cls, | 276 | src->rollback (src->cls); |
294 | ss); | 277 | qs = dst->commit (dst->cls); |
295 | qs = dst->commit (dst->cls, | ||
296 | ds); | ||
297 | if (GNUNET_DB_STATUS_SOFT_ERROR == qs) | 278 | if (GNUNET_DB_STATUS_SOFT_ERROR == qs) |
298 | { | 279 | { |
299 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -328,35 +309,29 @@ static void | |||
328 | do_sync (void *cls) | 309 | do_sync (void *cls) |
329 | { | 310 | { |
330 | static struct GNUNET_TIME_Relative delay; | 311 | static struct GNUNET_TIME_Relative delay; |
331 | struct TALER_EXCHANGEDB_Session *ss; | ||
332 | struct TALER_EXCHANGEDB_Session *ds; | ||
333 | 312 | ||
334 | sync_task = NULL; | 313 | sync_task = NULL; |
335 | actual_size = 0; | 314 | actual_size = 0; |
336 | ss = src->get_session (src->cls); | 315 | if (GNUNET_SYSERR == |
337 | if (NULL == ss) | 316 | src->preflight (src->cls)) |
338 | { | 317 | { |
339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 318 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
340 | "Failed to begin transaction with data source. Exiting\n"); | 319 | "Failed to begin transaction with data source. Exiting\n"); |
341 | return; | 320 | return; |
342 | } | 321 | } |
343 | ds = dst->get_session (dst->cls); | 322 | if (GNUNET_SYSERR == |
344 | if (NULL == ds) | 323 | dst->preflight (dst->cls)) |
345 | { | 324 | { |
346 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 325 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
347 | "Failed to begin transaction with data destination. Exiting\n"); | 326 | "Failed to begin transaction with data destination. Exiting\n"); |
348 | return; | 327 | return; |
349 | } | 328 | } |
350 | if (GNUNET_OK != | 329 | if (GNUNET_OK != transact ()) |
351 | transact (ss, | ||
352 | ds)) | ||
353 | { | 330 | { |
354 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 331 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
355 | "Transaction failed, rolling back\n"); | 332 | "Transaction failed, rolling back\n"); |
356 | src->rollback (src->cls, | 333 | src->rollback (src->cls); |
357 | ss); | 334 | dst->rollback (dst->cls); |
358 | dst->rollback (dst->cls, | ||
359 | ds); | ||
360 | } | 335 | } |
361 | if (0 != global_ret) | 336 | if (0 != global_ret) |
362 | { | 337 | { |