18
18
#define DEFAULT_LISTENHOST "0.0.0.0"
19
19
#define DEFAULT_LISTENPORT 5431
20
20
21
+ static xid_t get_global_xmin ();
22
+
21
23
L2List active_transactions = {& active_transactions , & active_transactions };
22
24
L2List * free_transactions ;
23
25
24
26
// We reserve the local xids if they fit between (prev, next) range, and
25
27
// reserve something in (next, x) range otherwise, moving 'next' after 'x'.
26
28
xid_t prev_gxid , next_gxid ;
29
+ xid_t global_xmin = INVALID_XID ;
27
30
28
31
typedef struct client_userdata_t {
29
32
int id ;
@@ -55,6 +58,9 @@ inline static void free_transaction(Transaction* t)
55
58
l2_list_unlink (& t -> elem );
56
59
t -> elem .next = free_transactions ;
57
60
free_transactions = & t -> elem ;
61
+ if (t -> xmin == global_xmin ) {
62
+ global_xmin = get_global_xmin ();
63
+ }
58
64
}
59
65
60
66
@@ -246,18 +252,12 @@ static void onreserve(client_t client, int argc, xid_t *argv) {
246
252
}
247
253
248
254
static xid_t get_global_xmin () {
249
- int j ;
250
255
xid_t xmin = next_gxid ;
251
256
Transaction * t ;
252
257
for (t = (Transaction * )active_transactions .next ; t != (Transaction * )& active_transactions ; t = (Transaction * )t -> elem .next ) {
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
- }
258
+ if (t -> xmin < xmin ) {
259
+ xmin = t -> xmin ;
260
+ }
261
261
}
262
262
return xmin ;
263
263
}
@@ -285,7 +285,7 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
285
285
transaction_clear (t );
286
286
l2_list_link (& active_transactions , & t -> elem );
287
287
288
- prev_gxid = t -> xid = t -> xmin = next_gxid ++ ;
288
+ prev_gxid = t -> xid = next_gxid ++ ;
289
289
t -> snapshots_count = 0 ;
290
290
t -> size = 1 ;
291
291
@@ -303,16 +303,18 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
303
303
return ;
304
304
}
305
305
306
- xid_t gxmin = get_global_xmin ();
307
306
Snapshot * snap = transaction_next_snapshot (t );
308
307
gen_snapshot (snap ); // FIXME: increase 'times_sent' here? see also 4765234987
309
308
t -> xmin = snap -> xmin ;
309
+ if (global_xmin == INVALID_XID ) {
310
+ global_xmin = snap -> xmin ;
311
+ }
310
312
311
313
xid_t ok = RES_OK ;
312
314
client_message_start (client ); {
313
315
client_message_append (client , sizeof (xid_t ), & ok );
314
316
client_message_append (client , sizeof (xid_t ), & t -> xid );
315
- client_message_append (client , sizeof (xid_t ), & gxmin );
317
+ client_message_append (client , sizeof (xid_t ), & global_xmin );
316
318
client_message_append (client , sizeof (xid_t ), & snap -> xmin );
317
319
client_message_append (client , sizeof (xid_t ), & snap -> xmax );
318
320
client_message_append (client , sizeof (xid_t ) * snap -> nactive , snap -> active );
@@ -464,15 +466,13 @@ static void onsnapshot(client_t client, int argc, xid_t *argv) {
464
466
gen_snapshot (transaction_next_snapshot (t ));
465
467
}
466
468
467
- xid_t gxmin = get_global_xmin ();
468
-
469
469
Snapshot * snap = transaction_snapshot (t , CLIENT_SNAPSENT (client )++ );
470
470
snap -> times_sent += 1 ; // FIXME: does times_sent get used anywhere? see also 4765234987
471
471
472
472
xid_t ok = RES_OK ;
473
473
client_message_start (client ); {
474
474
client_message_append (client , sizeof (xid_t ), & ok );
475
- client_message_append (client , sizeof (xid_t ), & gxmin );
475
+ client_message_append (client , sizeof (xid_t ), & global_xmin );
476
476
client_message_append (client , sizeof (xid_t ), & snap -> xmin );
477
477
client_message_append (client , sizeof (xid_t ), & snap -> xmax );
478
478
client_message_append (client , sizeof (xid_t ) * snap -> nactive , snap -> active );
0 commit comments