Skip to content

Commit 2f81a22

Browse files
author
Peng Gu
committed
Support transaction isolation
1 parent c1b762f commit 2f81a22

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

libspectrum/src/protobuf/spectrum.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ message SystemVariables {
4242

4343
message Thread {
4444
int64 id = 1;
45-
SystemVariables system_variables = 2;
45+
int32 tx_isolation = 2;
46+
int32 sql_command = 3;
47+
SystemVariables system_variables = 4;
4648
}
4749

4850
message Row {

libspectrum/src/spectrum_common.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ this program; if not, write to the Free Software Foundation, Inc.,
4949
#include <sql/table.h>
5050
#include <sql/log.h>
5151

52+
#include <mysql/plugin.h>
53+
5254
#include <grpc/grpc.h>
5355
#include "spectrum.h"
5456

@@ -90,6 +92,8 @@ void spectrum_thread_fill_system_variables(THD *thd, spectrum::Thread *spectrum_
9092

9193
void spectrum_thread_fill(THD *thd, spectrum::Thread *spectrum_thread) {
9294
spectrum_thread->set_id(thd->spectrum_thread_id);
95+
spectrum_thread->set_tx_isolation(thd->tx_isolation);
96+
spectrum_thread->set_sql_command(thd_sql_command(thd));
9397

9498
spectrum_thread_fill_system_variables(thd, spectrum_thread);
9599
}

mysql-test/r/spectrum.result

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
drop database if exists spectrum_test_30;
2-
create database spectrum_test_30;
3-
use spectrum_test_30;
1+
drop database if exists spectrum_test_45;
2+
create database spectrum_test_45;
3+
use spectrum_test_45;
44
create table employees (id INT PRIMARY KEY, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, hire_date DATE, salary DECIMAL(10, 2));
55
insert into employees (id, first_name, last_name, hire_date, salary) VALUES (2, 'Peng', 'Gu', '2024-12-01', 60000.00);
66
insert into employees (id, first_name, last_name, hire_date, salary) VALUES (1, 'John', 'Doe', '2024-12-01', 50000.00);
@@ -12,8 +12,15 @@ update employees set salary=555 where id=1;
1212
select * from employees where id=1;
1313
id first_name last_name hire_date salary
1414
1 John Doe 2024-12-01 555.00
15-
use spectrum_test_30;
15+
use spectrum_test_45;
1616
select * from employees;
1717
id first_name last_name hire_date salary
1818
1 John Doe 2024-12-01 555.00
1919
2 Peng Gu 2024-12-01 60000.00
20+
set autocommit = 0;
21+
update employees set salary=888 where id=1;
22+
set session transaction isolation level READ COMMITTED;
23+
select * from employees where id=1;
24+
id first_name last_name hire_date salary
25+
1 John Doe 2024-12-01 555.00
26+
commit;

mysql-test/t/spectrum.test

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
connect(compute0,localhost,root,,,3306,/tmp/mysql-spectrum-compute-0.sock);
22
connect(compute1,localhost,root,,,3306,/tmp/mysql-spectrum-compute-1.sock);
33

4-
--let $db=spectrum_test_30
4+
--let $db=spectrum_test_45
55

66
connection compute0;
77

@@ -22,3 +22,14 @@ select * from employees where id=1;
2222
connection compute1;
2323
eval use $db;
2424
select * from employees;
25+
26+
connection compute0;
27+
set autocommit = 0;
28+
update employees set salary=888 where id=1;
29+
30+
connection compute1;
31+
set session transaction isolation level READ COMMITTED;
32+
select * from employees where id=1;
33+
34+
connection compute0;
35+
commit;

plugin/spectrum_storage/spectrum_storage.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class StorageNodeImpl final : public spectrum::StorageNode::Service {
9898
spectrum_thread.id(), thd->thread_id());
9999
}
100100
thd->store_globals();
101+
thd->lex->sql_command = (enum_sql_command)spectrum_thread.sql_command();
102+
thd->tx_isolation = (enum_tx_isolation)spectrum_thread.tx_isolation();
101103
thd->variables.option_bits = spectrum_thread.system_variables().option_bits();
102104
return (thd);
103105
}

0 commit comments

Comments
 (0)