先看AckWindows.java
public void flush() {
if (System.currentTimeMillis() - baseTime >= time) {
for (String key : ackBooks.keySet()) {
Map map = ackBooks.get(key);
Ack preValue = null;
boolean isFail = false;
List okOffsetList = new ArrayList<>();
for (Map.Entry entry : map.entrySet()) {
Ack value = entry.getValue();
if (Ack.INIT == value.getStatus()) {
logger.info("topic:{}, partaiton:{}, offset:{}, status: init",
value.getTopic(), value.getPartition(), value.getOffset());
if (preValue != null) this.callBack.ack(preValue);
break;
} else if (Ack.OK == value.getStatus()) {
logger.info("topic:{}, partaiton:{}, offset:{}, status: ok",
value.getTopic(), value.getPartition(), value.getOffset());
okOffsetList.add(value.getOffset());
preValue = value;
continue;
} else if (Ack.FAIL == value.getStatus()) {
logger.info("topic:{}, partaiton:{}, offset:{}, status: fail",
value.getTopic(), value.getPartition(), value.getOffset());
this.callBack.fail(value);
isFail = true;
break;
}
}
if (isFail) {
ackBooks.get(key).clear();
} else {
for (Long offset : okOffsetList) {
ackBooks.get(key).remove(offset);
}
}
}
baseTime = System.currentTimeMillis();
}
}
flush只有在ackBooks存在init类型ack才会触发callback 执行kafka consumer commit offset ;但是从代码上看,很难保证这部分代码能被执行,在我这边环境日志看,基本上就没有执行过这个部分;导致offset根本不会commit。
2019-09-24 10:44:43.960 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5574, trigger ack.
2019-09-24 10:44:43.960 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5574, status: ok
2019-09-24 10:47:59.187 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5575, trigger ack.
2019-09-24 10:47:59.187 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5575, status: ok
2019-09-24 10:48:18.986 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5576, trigger ack.
2019-09-24 10:48:18.986 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5576, status: ok
2019-09-24 10:50:01.592 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5577, trigger ack.
2019-09-24 10:50:01.592 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5577, status: ok
2019-09-24 10:56:23.716 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5578, trigger ack.
2019-09-24 10:56:23.717 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5578, status: ok
2019-09-24 10:56:39.722 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5579, trigger ack.
2019-09-24 10:56:39.722 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5579, status: ok
2019-09-24 10:57:25.731 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5580, trigger ack.
2019-09-24 10:57:25.732 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5580, status: ok
2019-09-24 11:00:32.136 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5581, trigger ack.
2019-09-24 11:00:32.136 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5581, status: ok
2019-09-24 11:00:42.198 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5582, trigger ack.
2019-09-24 11:00:42.198 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5582, status: ok
2019-09-24 11:01:04.342 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5583, trigger ack.
2019-09-24 11:01:04.342 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5583, status: ok
2019-09-24 11:01:38.118 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:31, trigger ack.
2019-09-24 11:04:21.340 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:31, status: ok
2019-09-24 11:04:21.445 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:32, trigger ack.
2019-09-24 11:04:49.213 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:32, status: ok
2019-09-24 11:04:49.322 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:33, trigger ack.
2019-09-24 11:06:06.776 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:33, status: ok
2019-09-24 11:06:07.508 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:34, trigger ack.
2019-09-24 11:07:29.620 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:34, status: ok
2019-09-24 11:07:29.652 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:35, trigger ack.
2019-09-24 11:11:34.924 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:35, status: ok
2019-09-24 11:11:35.042 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:36, trigger ack.
2019-09-24 11:12:22.407 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5588, trigger ack.
2019-09-24 11:12:22.407 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5588, status: ok
2019-09-24 11:12:22.407 c.c.d.r.s.a.AckWindows [INFO] topic:bi_flink_test_tr1_ctrl, partaiton:0, offset:36, status: ok
2019-09-24 11:12:30.231 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5589, trigger ack.
2019-09-24 11:12:30.231 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5589, status: ok
2019-09-24 11:12:39.805 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5590, trigger ack.
2019-09-24 11:12:39.805 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5590, status: ok
2019-09-24 11:31:06.331 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5591, trigger ack.
2019-09-24 11:31:06.331 c.c.d.r.s.a.AckWindows [INFO] topic:db_172_20_13_238_3306.qq_data.result, partaiton:0, offset:5591, status: ok
不太清楚为啥一定要在存在init才触发callback回调,望答复