集群同步-》最小位移对齐

This commit is contained in:
许晓东
2021-10-26 21:16:46 +08:00
parent a06b6dbb5f
commit b46492930c
2 changed files with 88 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import com.xuxd.kafka.console.beans.ResponseData;
import com.xuxd.kafka.console.beans.dos.MinOffsetAlignmentDO;
import com.xuxd.kafka.console.dao.MinOffsetAlignmentMapper;
import com.xuxd.kafka.console.service.OperationService;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import kafka.console.OperationConsole;
@@ -37,8 +38,26 @@ public class OperationServiceImpl implements OperationService {
}
@Override public ResponseData syncConsumerOffset(String groupId, String topic, Properties thatProps) {
QueryWrapper<MinOffsetAlignmentDO> wrapper = new QueryWrapper<>();
wrapper.eq("group_id", groupId);
wrapper.eq("topic", topic);
MinOffsetAlignmentDO alignmentDO = minOffsetAlignmentMapper.selectOne(wrapper);
if (alignmentDO == null) {
return ResponseData.create().failed("No min offset info.");
}
Tuple2<Object, String> tuple2 = operationConsole.syncConsumerOffset(groupId, topic, thatProps);
Map<String, Object> thisOffset = gson.fromJson(alignmentDO.getThisOffset(), Map.class);
Map<String, Object> thatOffset = gson.fromJson(alignmentDO.getThatOffset(), Map.class);
Map<TopicPartition, Object> thisMinOffset = new HashMap<>(), thatMinOffset = new HashMap<>();
thisOffset.forEach((k, v)-> {
thisMinOffset.put(new TopicPartition(topic, Integer.valueOf(k)), Long.valueOf(v.toString()));
});
thatOffset.forEach((k, v)-> {
thatMinOffset.put(new TopicPartition(topic, Integer.valueOf(k)), Long.valueOf(v.toString()));
});
Tuple2<Object, String> tuple2 = operationConsole.syncConsumerOffset(groupId, topic, thatProps, thisMinOffset, thatMinOffset);
return (boolean) tuple2._1() ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2());
}