Skip to content

Commit 5418f84

Browse files
committed
{180255805} Add correct effects for chunk transactions after verify error
Signed-off-by: Salil Chandra <[email protected]>
1 parent 01aa21b commit 5418f84

File tree

6 files changed

+311
-35
lines changed

6 files changed

+311
-35
lines changed

db/osql_srs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static int srs_tran_replay_int(struct sqlclntstate *clnt, int(dispatch_fn)(struc
275275
}
276276

277277
do {
278-
reset_query_effects(clnt); /* Reset it for each retry*/
278+
reset_query_effects(clnt, 0); /* Reset it for each retry*/
279279
if (!osql->history) {
280280
logmsg(LOGMSG_ERROR, "Trying to replay, but no history?\n");
281281
abort();

db/sql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ void reset_clnt(struct sqlclntstate *, int initial);
13891389
void cleanup_clnt(struct sqlclntstate *);
13901390
void free_client_info(struct sqlclntstate *);
13911391
void free_client_adj_col_names(struct sqlclntstate *);
1392-
void reset_query_effects(struct sqlclntstate *);
1392+
void reset_query_effects(struct sqlclntstate *, int);
13931393

13941394
int sqlite_to_ondisk(struct schema *s, const void *inp, int len, void *outp,
13951395
const char *tzname, blob_buffer_t *outblob, int maxblobs,

db/sqlinterfaces.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,11 +1813,12 @@ static int handle_sql_wrongstate(struct sqlthdstate *thd,
18131813
return SQLITE_INTERNAL;
18141814
}
18151815

1816-
void reset_query_effects(struct sqlclntstate *clnt)
1816+
void reset_query_effects(struct sqlclntstate *clnt, int keep_chunk_effects)
18171817
{
18181818
bzero(&clnt->effects, sizeof(clnt->effects));
18191819
bzero(&clnt->log_effects, sizeof(clnt->effects));
1820-
bzero(&clnt->chunk_effects, sizeof(clnt->chunk_effects));
1820+
if (!keep_chunk_effects)
1821+
bzero(&clnt->chunk_effects, sizeof(clnt->chunk_effects));
18211822
}
18221823

18231824
char *sqlenginestate_tostr(int state)
@@ -1972,7 +1973,7 @@ void abort_dbtran(struct sqlclntstate *clnt)
19721973
clnt->intrans = 0;
19731974
sql_set_sqlengine_state(clnt, __FILE__, __LINE__,
19741975
SQLENG_FNSH_ABORTED_STATE);
1975-
reset_query_effects(clnt);
1976+
reset_query_effects(clnt, 0);
19761977
}
19771978

19781979
void handle_sql_intrans_unrecoverable_error(struct sqlclntstate *clnt)
@@ -2040,7 +2041,7 @@ static int do_commitrollback(struct sqlthdstate *thd, struct sqlclntstate *clnt,
20402041
clnt->dbtran.shadow_tran = NULL;
20412042
}
20422043
} else {
2043-
reset_query_effects(clnt);
2044+
reset_query_effects(clnt, 1);
20442045
rc = recom_abort(clnt);
20452046
if (rc)
20462047
logmsg(LOGMSG_ERROR, "%s: recom abort failed %d??\n",
@@ -2125,7 +2126,7 @@ static int do_commitrollback(struct sqlthdstate *thd, struct sqlclntstate *clnt,
21252126
}
21262127
}
21272128
} else {
2128-
reset_query_effects(clnt);
2129+
reset_query_effects(clnt, 1);
21292130
if (clnt->dbtran.mode == TRANLEVEL_SERIAL) {
21302131
rc = serial_abort(clnt);
21312132
} else {
@@ -2247,7 +2248,7 @@ static int do_commitrollback(struct sqlthdstate *thd, struct sqlclntstate *clnt,
22472248
clnt->saved_errstr = strdup(clnt->osql.xerr.errstr);
22482249
}
22492250
} else {
2250-
reset_query_effects(clnt);
2251+
reset_query_effects(clnt, 1);
22512252
rc = osql_sock_abort(clnt, OSQL_SOCK_REQ);
22522253
sql_debug_logf(clnt, __func__, __LINE__,
22532254
"'%s' socksql abort rc=%d replay=%d\n",
@@ -3899,7 +3900,7 @@ static int run_stmt(struct sqlthdstate *thd, struct sqlclntstate *clnt,
38993900
}
39003901

39013902
if (clnt->intrans == 0) {
3902-
reset_query_effects(clnt);
3903+
reset_query_effects(clnt, 0);
39033904
}
39043905

39053906
/* no rows actually ? */
@@ -4141,7 +4142,7 @@ int handle_sqlite_requests(struct sqlthdstate *thd, struct sqlclntstate *clnt)
41414142
}
41424143

41434144
if (clnt->statement_query_effects)
4144-
reset_query_effects(clnt);
4145+
reset_query_effects(clnt, 0);
41454146

41464147
int fast_error = 0;
41474148

@@ -5345,7 +5346,7 @@ void reset_clnt(struct sqlclntstate *clnt, int initial)
53455346
clnt->limits.tablescans_warn = gbl_querylimits_tablescans_warn;
53465347
clnt->limits.temptables_warn = gbl_querylimits_temptables_warn;
53475348

5348-
reset_query_effects(clnt);
5349+
reset_query_effects(clnt, 0);
53495350

53505351
reset_user(clnt);
53515352

tests/chunk_txn_effects.test/output.expected

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,36 @@ Number of rows selected 4
128128
Number of rows deleted 0
129129
Number of rows updated 0
130130
Number of rows inserted 0
131+
---------------- ROLLBACK -----------------
132+
Number of rows affected 0
133+
Number of rows selected 1
134+
Number of rows deleted 0
135+
Number of rows updated 0
136+
Number of rows inserted 0
137+
Effects not sent by comdb2 server.
138+
Number of rows affected 0
139+
Number of rows selected 0
140+
Number of rows deleted 0
141+
Number of rows updated 0
142+
Number of rows inserted 0
143+
Number of rows affected 10
144+
Number of rows selected 0
145+
Number of rows deleted 0
146+
Number of rows updated 0
147+
Number of rows inserted 10
148+
Number of rows affected 6
149+
Number of rows selected 0
150+
Number of rows deleted 0
151+
Number of rows updated 0
152+
Number of rows inserted 6
153+
101
154+
102
155+
103
156+
104
157+
105
158+
106
159+
Number of rows affected 0
160+
Number of rows selected 6
161+
Number of rows deleted 0
162+
Number of rows updated 0
163+
Number of rows inserted 0

tests/chunk_txn_effects.test/runit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ INSERT INTO t1 VALUES(13) ON CONFLICT(i) DO NOTHING
3636
INSERT INTO t1 VALUES(14) ON CONFLICT(i) DO NOTHING
3737
COMMIT
3838
SELECT i FROM t1
39+
SELECT "---------------- ROLLBACK -----------------"
40+
SET TRANSACTION CHUNK 6
41+
BEGIN
42+
INSERT INTO t1 SELECT value FROM generate_series(101, 110)
43+
ROLLBACK
44+
SELECT i FROM t1 WHERE i BETWEEN 101 AND 110
3945
EOF
4046

4147
diff output.actual output.expected

0 commit comments

Comments
 (0)