Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit651f187

Browse files
committed
Add transaction hash
1 parent19d012c commit651f187

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

‎dtmd/include/transaction.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct L2List
1919

2020
typedefstructTransaction {
2121
L2Listelem;
22+
structTransaction*collision;
2223
xid_txid;
2324
xid_txmin;
2425

‎dtmd/src/main.c‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ static xid_t get_global_xmin();
2323
L2Listactive_transactions= {&active_transactions,&active_transactions};
2424
L2List*free_transactions;
2525

26+
Transaction*transaction_hash[MAX_TRANSACTIONS];
27+
2628
// We reserve the local xids if they fit between (prev, next) range, and
2729
// reserve something in (next, x) range otherwise, moving 'next' after 'x'.
2830
xid_tprev_gxid,next_gxid;
2931
xid_tglobal_xmin=INVALID_XID;
3032

33+
staticTransaction*find_transaction(xid_txid) {
34+
Transaction*t;
35+
for (t=transaction_hash[xid %MAX_TRANSACTIONS];t!=NULL&&t->xid!=xid;t=t->collision);
36+
returnt;
37+
38+
}
39+
3140
typedefstructclient_userdata_t {
3241
intid;
3342
intsnapshots_sent;
@@ -54,6 +63,9 @@ static void free_client_userdata(client_userdata_t *cd) {
5463
}
5564

5665
inlinestaticvoidfree_transaction(Transaction*t) {
66+
Transaction**tpp;
67+
for (tpp=&transaction_hash[t->xid %MAX_TRANSACTIONS];*tpp!=t;tpp=&(*tpp)->collision);
68+
*tpp=t->collision;
5769
l2_list_unlink(&t->elem);
5870
t->elem.next=free_transactions;
5971
free_transactions=&t->elem;
@@ -116,26 +128,19 @@ static void ondisconnect(client_t client) {
116128
debug("[%d] disconnected\n",CLIENT_ID(client));
117129

118130
if (CLIENT_XID(client)!=INVALID_XID) {
119-
Transaction*t;
120-
121-
// need to abort the transaction this client is participating in
122-
for (t= (Transaction*)active_transactions.next;t!= (Transaction*)&active_transactions;t= (Transaction*)t->elem.next) {
123-
if (t->xid==CLIENT_XID(client)) {
124-
if (clog_write(clg,t->xid,NEGATIVE)) {
125-
notify_listeners(t,NEGATIVE);
126-
free_transaction(t);
127-
}else {
128-
shout(
129-
"[%d] DISCONNECT: transaction %u"
130-
" failed to abort O_o\n",
131-
CLIENT_ID(client),t->xid
131+
Transaction*t=find_transaction(CLIENT_XID(client));
132+
if (t!=NULL) {
133+
if (clog_write(clg,t->xid,NEGATIVE)) {
134+
notify_listeners(t,NEGATIVE);
135+
free_transaction(t);
136+
}else {
137+
shout(
138+
"[%d] DISCONNECT: transaction %u"
139+
" failed to abort O_o\n",
140+
CLIENT_ID(client),t->xid
132141
);
133-
}
134-
break;
135-
}
136-
}
137-
138-
if (t== (Transaction*)&active_transactions) {
142+
}
143+
}else {
139144
shout(
140145
"[%d] DISCONNECT: transaction %u not found O_o\n",
141146
CLIENT_ID(client),CLIENT_XID(client)
@@ -281,6 +286,8 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
281286
}
282287
transaction_clear(t);
283288
l2_list_link(&active_transactions,&t->elem);
289+
t->collision=transaction_hash[t->xid %MAX_TRANSACTIONS];
290+
transaction_hash[t->xid %MAX_TRANSACTIONS]=t;
284291

285292
prev_gxid=t->xid=next_gxid++;
286293
t->snapshots_count=0;
@@ -318,16 +325,6 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
318325
}client_message_finish(client);
319326
}
320327

321-
staticTransaction*find_transaction(xid_txid) {
322-
Transaction*t;
323-
324-
for (t= (Transaction*)active_transactions.next;t!= (Transaction*)&active_transactions;t= (Transaction*)t->elem.next) {
325-
if (t->xid==xid) {
326-
returnt;
327-
}
328-
}
329-
returnNULL;
330-
}
331328

332329
staticboolqueue_for_transaction_finish(client_tclient,xid_txid,charcmd) {
333330
assert((cmd >='a')&& (cmd <='z'));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp