线上ElasticJob堵塞问题排查

[原创]个人理解,请批判接受,有误请指正。转载请注明出处: https://heyfl.gitee.io/Bug-Log-Optimization/elasticJob-bug-fix.html


背景

刚进新公司3天正逢双十一,领导生产补数出问题了,补数速度不稳定时快时慢,百万条数据补了好几个小时,之前都是几分钟搞定的,导致通了个宵;
早上我早到公司,领导截了个数据库的图给我,说交给我来看,然后刚通宵完的他就去开会汇报去了。。。我还没来得及熟悉环境,就被扔到了火坑里了,压力山大。。。
具体的过程没记录,这里只能凭回忆记录下了

问题描述

阅读更多

docker部署zookeeper集群

1
2
3
4
// 查看config命令参数
$ docker-compose -f zookeeper-compose.yml config --help
// 校验配置文件,不打印
$ docker-compose -f zookeeper-compose.yml config -q

启动zookeeper集群

1
2
// -d 后台启动
$ docker-compose -f zookeeper-compose.yml up -d

查看容器启动情况

1
$ docker-compose -f zookeeper-compose.yml ps
阅读更多

docker部署redis集群(Sentinel版)

拉取Redis镜像

1
docker pull redis

通过镜像启动容器(Redis集群实例*3 1主2从,集群部署完再设密码)

1
2
3
4
5
6
7
docker run -it --name redis9000 -d -p 9000:6379 redis redis-server --requirepass 123456 --port 6379
docker run -it --name redis9001 -d -p 9001:6379 redis redis-server --requirepass 123456 --port 6379
docker run -it --name redis9002 -d -p 9002:6379 redis redis-server --requirepass 123456 --port 6379

#docker run -it --name redis9003 -d -p 9003:6379 redis redis-server --requirepass 123456 --port 6379
#docker run -it --name redis9004 -d -p 9004:6379 redis redis-server --requirepass 123456 --port 6379
#docker run -it --name redis9005 -d -p 9005:6379 redis redis-server --requirepass 123456 --port 6379

查询各个实例的容器IP

阅读更多

自用docker-compose

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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
version: '2'  # 定义版本,不指定默认为版本 1,新版本功能更多
services: # 容器
zoo1:
image: zookeeper:3.4.14
restart: always
container_name: zoo1
hostname: zoo1
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
networks:
mynet:
#ipv4_address: 172.20.0.2
zoo2:
image: zookeeper:3.4.14
restart: always
container_name: zoo2
hostname: zoo2
ports:
- "2182:2181"
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
networks:
mynet:
#ipv4_address: 172.20.0.3
zoo3:
image: zookeeper:3.4.14
restart: always
container_name: zoo3
hostname: zoo3
ports:
- "2183:2181"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
networks:
mynet:
#ipv4_address: 172.20.0.4
broker1:
image: wurstmeister/kafka:0.8.2.1
restart: always
container_name: broker1
ports:
- "9091:9092"
depends_on:
- zoo1
- zoo2
- zoo3
hostname: '{{.Node.Hostname}}'
environment:
KAFKA_BROKER_ID: 1
KAFKA_ADVERTISED_HOST_NAME: broker1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_HOST_NAME: broker1
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2182,zoo3:2183
KAFKA_LISTENERS: PLAINTEXT://broker1:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker1:9092
volumes:
- /Users/chris-cai/Documents/docker/runningFile/brocker1/docker.sock:/var/run/docker.sock
networks:
mynet:
#ipv4_address: 172.20.0.5
broker2:
image: wurstmeister/kafka:0.8.2.1
restart: always
container_name: broker2
ports:
- "9092:9092"
depends_on:
- zoo1
- zoo2
- zoo3
hostname: '{{.Node.Hostname}}'
environment:
KAFKA_BROKER_ID: 2
KAFKA_ADVERTISED_HOST_NAME: broker2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_HOST_NAME: broker2
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2182,zoo3:2183
KAFKA_LISTENERS: PLAINTEXT://broker2:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker2:9092
volumes:
- /Users/chris-cai/Documents/docker/runningFile/brocker2/docker.sock:/var/run/docker.sock
networks:
mynet:
#ipv4_address: 172.20.0.6
broker3:
image: wurstmeister/kafka:0.8.2.1
restart: always
container_name: broker3
ports:
- "9093:9092"
depends_on:
- zoo1
- zoo2
- zoo3
hostname: '{{.Node.Hostname}}'
environment:
KAFKA_BROKER_ID: 3
KAFKA_ADVERTISED_HOST_NAME: broker3
KAFKA_ADVERTISED_PORT: 9092
KAFKA_HOST_NAME: broker3
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2182,zoo3:2183
KAFKA_LISTENERS: PLAINTEXT://broker3:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker3:9092
volumes:
- /Users/chris-cai/Documents/docker/runningFile/brocker3/docker.sock:/var/run/docker.sock
networks:
mynet:
#ipv4_address: 172.20.0.7
kafka-manager:
image: sheepkiller/kafka-manager
restart: always
depends_on:
- zoo1
- zoo2
- zoo3
- broker1
- broker2
- broker3
environment:
ZK_HOSTS: zoo1:2181,zoo2:2182,zoo3:2183
ports:
- "9000:9000"
container_name: kafka-manager
networks:
mynet:
kafka-offset-monitor:
image: 564239555/kafkaoffsetmonitor
volumes:
- /Users/chris-cai/Documents/docker/runningFile/kafkaoffsetmonitor/conf:/kafkaoffsetmonitor
ports:
- "8089:8089"
depends_on:
- zoo1
- zoo2
- zoo3
- broker1
- broker2
- broker3
environment:
ZK_HOSTS: zoo1:2181,zoo2:2182,zoo3:2183
KAFKA_BROKERS: broker1:9091,broker2:9092,broker3:9093
REFRESH_SECENDS: 10
RETAIN_DAYS: 2
container_name: kafka-monitor
mysql1:
image: mysql:5.7.29
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_USER: test
MYSQL_PASS: 123456
volumes:
- "/Users/chris-cai/Documents/docker/runningFile/mysql/db:/var/lib/mysql"
- "/Users/chris-cai/Documents/docker/runningFile/mysql/conf/my.cnf:/etc/my.cnf"
- "/Users/chris-cai/Documents/docker/runningFile/mysql/init:/docker-entrypoint-initdb.d/"
ports:
- 3306:3306
networks:
mynet:
#ipv4_address: 172.20.0.10
container_name: mysql1
nginx:
restart: always
image: nginx:stable
ports:
- 8080:80
- 80:80
- 443:443
volumes:
- /Users/chris-cai/Documents/docker/runningFile/nginx/conf.d:/etc/nginx/conf.d
- /Users/chris-cai/Documents/docker/runningFile/nginx/log:/var/log/nginx
- /Users/chris-cai/Documents/docker/runningFile/nginx/www:/var/www
jenkins:
image: 'jenkins/jenkins:2.60.3' # 镜像
container_name: jenkins # 容器名称
restart: always # 同 --restart 参数
ports: # 端口映射,同 -p 参数,本地端口:容器端口
- '8080:8080'
- '50000:50000'
volumes: # 数据卷,本地文件夹:容器文件夹
- '/c/Users/01390559/dockerTmp/jenkins:/var/jenkins_home'
environment:
TZ: Asia/Shanghai
networks:
mynet:
driver: bridge

目录接口篇

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
gds-parent  根目录
gds-wms-parent 仓库运营系统服务
gds-wms 仓库运营系统服务
src
common 公共类
utils 工具类 命名以Util结尾的类
domain 业务对象
enums 枚举类
exception 放自定义异常类
mapper 如果用JPA操作数据库用repository 放命名以Repository结尾的类,
用mybaits操作数据库用mapper 放命名以Mapper结尾的类
remote 远程调用,放fegin调用接口
consumer 存放[调用]外部Feign服务的类 命名以Client结尾
fallback 存放consumer调用降级处理类 命名以FallbackFactory结尾
provider 存放对外提供的HTTP(Feign)类 命名以Remote结尾
service 放业务逻辑处理接口 命名以Service结尾的类
impl 放业务处理实现`类 命名以对应接口名+Impl结尾的类(后面同理)
web 放controller 命名以Controller结尾的类
...
resources
mapper 存放sql的xml文件
static 存放静态资源(js/css/img....)
templates 存放页面模板
error 存放错误相关的页面
wms 存放业务相关的页面
gds-wms-api 仓库运营系统服务Api
gds-wos-parent 仓库作业系统服务
gds-wos 仓库作业系统服务
gds-wos-api 仓库作业系统服务Api

接口篇

以下为以前开发自己设定的一些规范,供以后参考

1. 返回类型

  1. 所有接口返回类型都为ResponseMsg
  2. 除了与外界交互的接口,不允许其它返回类型为ResponseMsg的方法

2. 对外接口请求路径规则

  1. 提供给app用的接口统一以[/app]开头
  2. 提供给外部系统调用的接口统一以[/api]开头
  3. 提供给页面的接口统一以[/page]开头
阅读更多

异常处理与日志篇

异常处理

  1. 异常处理不需要手动输出日志
      - 全局异常处理会帮你做这件事
  2. 遇到的所有异常都包装成[业务异常]or[系统异常]后往上抛
  3. 业务异常(校验异常等) 对应类:BusinessRuntimeException
      常用方法:
      1. throw BusinessRuntimeException.buildBusyException(EnumCommomSysErrorCode.MQ_ERROR, “消费异常”, parm);
      2. throw BusinessRuntimeException.buildBusyException(parm,EnumCommomSysErrorCode.MQ_ERROR,);
  4. 系统异常(404,MQ联不通等) 对应类:SystemRuntimeException
      常用方法:
      1. throw SystemRuntimeException.buildSysException(EnumCommomSysErrorCode.FILE_TYPE_NOT_SUPPORT, e, parm);
      2. throw SystemRuntimeException.buildSysException(EnumCommomSysErrorCode.FILE_TYPE_NOT_SUPPORT, “文件类型不支持”,e, parm);

业务日志打印

  1. 对HTTP请求(Controller)进来参数,不需要打印(对于Dubbo/MQ等入参还是需要打印的)
      - 已经做了拦截器全局进行打印

数据库篇

脚本提交

统一使用Flyway进行统一的管理
svn://172.16.30.16:20044/G2G_DS/trunk/WMS/wms_db_script

Dao操作相关

  1. 对数据库表更新/删除操作不能使用ID作为’第一’条件, 如

    错误用法

    1
    update parcel set a="value" where id=123

    正确用法 应用业务主键作为条件

    1
    update parcel set a="value" where fpxTrackingNo="fpx20190402"
  2. 数据库查询不允许使用select *, 应使用select a,b,c