@@ -246,13 +246,19 @@ static void onreserve(client_t client, int argc, xid_t *argv) {
246
246
}
247
247
248
248
static xid_t get_global_xmin () {
249
+ int j ;
249
250
xid_t xmin = next_gxid ;
250
251
Transaction * t ;
251
252
for (t = (Transaction * )active_transactions .next ; t != (Transaction * )& active_transactions ; t = (Transaction * )t -> elem .next ) {
252
- if (t -> xmin < xmin ) {
253
- xmin = t -> xmin ;
254
- }
255
- }
253
+ j = t -> snapshots_count > MAX_SNAPSHOTS_PER_TRANS ? MAX_SNAPSHOTS_PER_TRANS : t -> snapshots_count ;
254
+ while (-- j >= 0 ) {
255
+ Snapshot * s = transaction_snapshot (t , j );
256
+ if (s -> xmin < xmin ) {
257
+ xmin = s -> xmin ;
258
+ }
259
+ // minor TODO: Use 'times_sent' to generate a bit greater xmin?
260
+ }
261
+ }
256
262
return xmin ;
257
263
}
258
264
@@ -277,6 +283,7 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
277
283
free_transactions = t -> elem .next ;
278
284
}
279
285
transaction_clear (t );
286
+ l2_list_link (& active_transactions , & t -> elem );
280
287
281
288
prev_gxid = t -> xid = next_gxid ++ ;
282
289
t -> snapshots_count = 0 ;
@@ -292,15 +299,15 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
292
299
CLIENT_ID (client ), t -> xid
293
300
);
294
301
client_message_shortcut (client , RES_FAILED );
295
- free_transaction (t );
296
302
return ;
297
303
}
304
+
298
305
xid_t gxmin = get_global_xmin ();
299
- Snapshot * snap = transaction_next_snapshot (t );
300
- gen_snapshot (snap ); // FIXME: increase 'times_sent' here? see also 4765234987
301
306
302
- t -> xmin = snap -> xmin ;
303
- l2_list_link (& active_transactions , & t -> elem );
307
+ gen_snapshot (transaction_next_snapshot (t ));
308
+ // will wrap around if exceeded max snapshots
309
+ Snapshot * snap = transaction_latest_snapshot (t );
310
+ // FIXME: increase 'times_sent' here? see also 4765234987
304
311
305
312
xid_t ok = RES_OK ;
306
313
client_message_start (client ); {
@@ -455,11 +462,7 @@ static void onsnapshot(client_t client, int argc, xid_t *argv) {
455
462
456
463
if (CLIENT_SNAPSENT (client ) == t -> snapshots_count ) {
457
464
// a fresh snapshot is needed
458
- Snapshot * snap = transaction_next_snapshot (t );
459
- gen_snapshot (snap );
460
- if (snap -> xmin < t -> xmin ) {
461
- t -> xmin = snap -> xmin ;
462
- }
465
+ gen_snapshot (transaction_next_snapshot (t ));
463
466
}
464
467
465
468
xid_t gxmin = get_global_xmin ();
0 commit comments