[Optimize]优化Topic元信息更新策略(#806)

This commit is contained in:
zengqiao
2022-12-04 17:53:31 +08:00
committed by EricZeng
parent 2c82baf9fc
commit 4293d05fca
9 changed files with 99 additions and 53 deletions

View File

@@ -14,6 +14,11 @@ import java.io.Serializable;
@NoArgsConstructor
@AllArgsConstructor
public class TopicConfig implements Serializable {
/**
* 表主键ID
*/
private Long id;
/**
* 物理集群ID
*/

View File

@@ -5,6 +5,8 @@ import com.xiaojukeji.know.streaming.km.common.bean.po.BasePO;
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
import lombok.Data;
import java.util.Objects;
@Data
@TableName(Constant.MYSQL_TABLE_NAME_PREFIX + "topic")
public class TopicPO extends BasePO {
@@ -52,4 +54,35 @@ public class TopicPO extends BasePO {
* 备注信息
*/
private String description;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
TopicPO topicPO = (TopicPO) o;
return Objects.equals(clusterPhyId, topicPO.clusterPhyId)
&& Objects.equals(topicName, topicPO.topicName)
&& Objects.equals(replicaNum, topicPO.replicaNum)
&& Objects.equals(partitionNum, topicPO.partitionNum)
&& Objects.equals(brokerIds, topicPO.brokerIds)
&& Objects.equals(partitionMap, topicPO.partitionMap)
&& Objects.equals(retentionMs, topicPO.retentionMs)
&& Objects.equals(type, topicPO.type)
&& Objects.equals(description, topicPO.description);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), clusterPhyId, topicName, replicaNum, partitionNum, brokerIds, partitionMap, retentionMs, type, description);
}
}

View File

@@ -55,10 +55,6 @@ public class TopicConverter {
* 仅合并Topic的元信息部分业务信息和配置信息部分不合并
*/
public static TopicPO mergeAndOnlyMetadata2NewTopicPO(Topic newTopicData, TopicPO oldDBTopicPO) {
if (newTopicData == null) {
return null;
}
TopicPO newTopicPO = new TopicPO();
newTopicPO.setId(oldDBTopicPO != null? oldDBTopicPO.getId(): null);
@@ -68,6 +64,7 @@ public class TopicConverter {
newTopicPO.setReplicaNum(newTopicData.getReplicaNum());
newTopicPO.setBrokerIds(CommonUtils.intList2String(new ArrayList<>(newTopicData.getBrokerIdSet())));
newTopicPO.setType(newTopicData.getType());
newTopicPO.setPartitionMap(ConvertUtil.obj2Json(newTopicData.getPartitionMap()));
if (newTopicData.getCreateTime() != null) {
newTopicPO.setCreateTime(new Date(newTopicData.getCreateTime()));
@@ -77,8 +74,8 @@ public class TopicConverter {
newTopicPO.setUpdateTime(oldDBTopicPO != null? oldDBTopicPO.getUpdateTime(): new Date());
}
newTopicPO.setPartitionMap(ConvertUtil.obj2Json(newTopicData.getPartitionMap()));
newTopicPO.setDescription(oldDBTopicPO != null? oldDBTopicPO.getDescription(): null);
newTopicPO.setRetentionMs(oldDBTopicPO != null? oldDBTopicPO.getRetentionMs(): null);
return newTopicPO;
}