通过 jmeter 线程组发起并发对接口(插入数据)进行压力测试
- 考虑处理方案:
- 通过 synchronized 同步互斥锁来控制
- 通过 数据库业务唯一键约束,由数据库来控制并发产生的问题
- 其他方式,暂时没有思路
- 决策
- 通过 synchronized 来控制并发,这将大大降低处理性能,使得多线程处理变成队列式依次进行
- 经由数据库唯一键约束来控制并发,会出现
org.hibernate.exception.ConstraintViolationException
程序异常,然而,这种性能损耗相对于 synchronized 来讲,还是比较小的,
在保证处理性能的前提下,选择这种方式无疑要比 synchronized 好很多,而且本身就应该添加的业务唯一键约束,在没有比这更好的处理方案的情况下,选择这种方案更适合。
- 行动
- 升级数据库(清理脏数据,添加唯一键约束)
- 升级程序(容错处理,日志记录)
1 | import org.springframework.jdbc.core.JdbcTemplate |
- 升级日志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
1512017-01-12 18:36:11,854 [DEBUG] com.hd123.rumba.rdbver.upgrader.UpgraderManager - Call upgrader: com.huanyu.crm.rdb.upgrade.v1.v4.SchemaUpgrader
2017-01-12 18:36:11,855 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - tran:select hst_num,count(uuid) as count_res from tran GROUP BY hst_num,tran_status HAVING count(uuid) > 1
2017-01-12 18:36:11,855 [INFO] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - ====== 开始修复 tran 数据 ======
2017-01-12 18:36:11,855 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [select hst_num,count(uuid) as count_res from tran GROUP BY hst_num,tran_status HAVING count(uuid) > 1]
2017-01-12 18:36:11,855 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,871 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,876 [INFO] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 待修复处理数据:{"type":"list","value":[{"type":"array","value":[{"type":"string","value":"20170316y001"},{"type":"integer","value":5}]},{"type":"array","value":[{"type":"string","value":"20170316ylj003"},{"type":"integer","value":3}]},{"type":"array","value":[{"type":"string","value":"20170317lq001"},{"type":"integer","value":2}]},{"type":"array","value":[{"type":"string","value":"ylj20170316000"},{"type":"integer","value":2}]}]}
2017-01-12 18:36:11,903 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:11,905 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from tran where hst_num = ? ORDER BY created asc]
2017-01-12 18:36:11,905 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,925 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,925 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 tran 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ad60f91015ad683dc060057"},{"type":"string","value":"402880905ad60f91015ad683dc120058"},{"type":"string","value":"402880905ad60f91015ad683dc160059"},{"type":"string","value":"402880905ad60f91015ad683dc19005a"},{"type":"string","value":"402880905ad60f91015ad683dc1c005b"}]}
2017-01-12 18:36:11,925 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad683dc120058 的数据
2017-01-12 18:36:11,925 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,925 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,925 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,933 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,934 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,934 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad683dc160059 的数据
2017-01-12 18:36:11,934 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,934 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,934 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,940 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,942 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,942 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad683dc19005a 的数据
2017-01-12 18:36:11,942 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,942 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,942 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,945 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,946 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,946 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad683dc1c005b 的数据
2017-01-12 18:36:11,946 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,946 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,946 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,949 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,950 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,950 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:11,950 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from tran where hst_num = ? ORDER BY created asc]
2017-01-12 18:36:11,950 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,952 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,952 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 tran 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ad60f91015ad664429d003e"},{"type":"string","value":"402880905ad60f91015ad66442a1003f"},{"type":"string","value":"402880905ad60f91015ad66442a40040"}]}
2017-01-12 18:36:11,952 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad66442a1003f 的数据
2017-01-12 18:36:11,952 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,952 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,952 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,955 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,957 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,957 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad66442a40040 的数据
2017-01-12 18:36:11,957 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,957 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,957 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,959 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,961 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,961 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:11,961 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from tran where hst_num = ? ORDER BY created asc]
2017-01-12 18:36:11,961 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,962 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,962 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 tran 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ada4434015ada59c42b0019"},{"type":"string","value":"402880905ada4434015ada59c42c001a"}]}
2017-01-12 18:36:11,962 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ada4434015ada59c42c001a 的数据
2017-01-12 18:36:11,962 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,962 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,962 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,964 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,964 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,964 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:11,964 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from tran where hst_num = ? ORDER BY created asc]
2017-01-12 18:36:11,964 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,966 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,966 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 tran 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ad60f91015ad650a5cd0025"},{"type":"string","value":"402880905ad60f91015ad650a5ef0026"}]}
2017-01-12 18:36:11,966 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 tran 记录为 uuid:402880905ad60f91015ad650a5ef0026 的数据
2017-01-12 18:36:11,966 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,966 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from tran where uuid = ? ]
2017-01-12 18:36:11,966 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,969 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,970 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,970 [INFO] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - ====== 已完成修复 tran 数据 ======
2017-01-12 18:36:11,970 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - hst:select hst_num,count(uuid) as count_res from hst GROUP BY hst_num,status HAVING count(uuid) > 1
2017-01-12 18:36:11,970 [INFO] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - ====== 开始修复 hst 数据 ======
2017-01-12 18:36:11,970 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [select hst_num,count(uuid) as count_res from hst GROUP BY hst_num,status HAVING count(uuid) > 1]
2017-01-12 18:36:11,970 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,977 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,978 [INFO] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 待修复处理数据:{"type":"list","value":[{"type":"array","value":[{"type":"string","value":"20170316y001"},{"type":"integer","value":5}]},{"type":"array","value":[{"type":"string","value":"20170316ylj003"},{"type":"integer","value":3}]},{"type":"array","value":[{"type":"string","value":"20170317lq001"},{"type":"integer","value":2}]},{"type":"array","value":[{"type":"string","value":"ylj20170316000"},{"type":"integer","value":2}]}]}
2017-01-12 18:36:11,978 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:11,978 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from hst where hst_num = ? ORDER BY createTime asc]
2017-01-12 18:36:11,978 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,981 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,982 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 hst 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ad60f91015ad683dc24005c"},{"type":"string","value":"402880905ad60f91015ad683dc27005e"},{"type":"string","value":"402880905ad60f91015ad683dc2b0060"},{"type":"string","value":"402880905ad60f91015ad683dc330062"},{"type":"string","value":"402880905ad60f91015ad683dc340064"}]}
2017-01-12 18:36:11,982 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad683dc27005e 的数据
2017-01-12 18:36:11,982 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,982 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:11,982 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,985 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,987 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,987 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad683dc2b0060 的数据
2017-01-12 18:36:11,987 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,987 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:11,987 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:11,995 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:11,996 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:11,997 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad683dc330062 的数据
2017-01-12 18:36:11,997 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:11,997 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:11,997 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,001 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:12,002 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,002 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad683dc340064 的数据
2017-01-12 18:36:12,002 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:12,002 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:12,002 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,005 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:12,008 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,009 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:12,009 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from hst where hst_num = ? ORDER BY createTime asc]
2017-01-12 18:36:12,009 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,012 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,012 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 hst 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ad60f91015ad66442a80041"},{"type":"string","value":"402880905ad60f91015ad66442b10043"},{"type":"string","value":"402880905ad60f91015ad66442b20045"}]}
2017-01-12 18:36:12,012 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad66442b10043 的数据
2017-01-12 18:36:12,012 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:12,012 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:12,012 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,016 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:12,017 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,017 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad66442b20045 的数据
2017-01-12 18:36:12,017 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:12,017 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:12,017 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,021 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:12,023 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,023 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:12,023 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from hst where hst_num = ? ORDER BY createTime asc]
2017-01-12 18:36:12,023 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,026 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,026 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 hst 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ada4434015ada59c434001b"},{"type":"string","value":"402880905ada4434015ada59c437001d"}]}
2017-01-12 18:36:12,026 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ada4434015ada59c437001d 的数据
2017-01-12 18:36:12,026 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:12,026 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:12,026 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,029 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:12,030 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,030 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL query
2017-01-12 18:36:12,030 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [select uuid from hst where hst_num = ? ORDER BY createTime asc]
2017-01-12 18:36:12,030 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,032 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,033 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 流水记录表 hst 中重复流水号的 uuid:{"type":"list","value":[{"type":"string","value":"402880905ad60f91015ad650a60e0027"},{"type":"string","value":"402880905ad60f91015ad650a60f0029"}]}
2017-01-12 18:36:12,033 [DEBUG] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - 清理流水记录表 hst 记录为 uuid:402880905ad60f91015ad650a60f0029 的数据
2017-01-12 18:36:12,033 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
2017-01-12 18:36:12,033 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE from hst where uuid = ? ]
2017-01-12 18:36:12,033 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2017-01-12 18:36:12,038 [DEBUG] org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
2017-01-12 18:36:12,040 [DEBUG] org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
2017-01-12 18:36:12,040 [INFO] com.huanyu.crm.rdb.upgrade.v1.v4.UpgradePayNotify - ====== 已完成修复 hst 数据 ======
多线程并发处理事件
1 |
|
- 分析日志
由上述日志分析可见,数据库事件:402880985ad4ba3c015ad50011720002 经由多租户事件分发器:MultiTenantEventDispatcher 分发给多个事件监听处理器时,
并发产生了两个线程(线程:pool-9-thread-3 和 线程:pool-9-thread-2)同时处理一个事件,业务关键在于推送给crm:test, json_data
这一处,这里将
导致将本系统同一份会员数据(同一个会员数据并发同步推送给crm系统)并发同步给crm系统,导致crm系统产生了两个会员(test_number_1 和 test_number_2)。 - 为了解决这种并发场景下的问题产生,需要给同步crm系统这块添加同步互斥锁,因为这是事件处理,性能可以适当降低要求,因此,使用 synchronized 来控制并发。