Skip to content

Commit e5b0b30

Browse files
authored
fix ConfigMigrateService derby bug (#13201)
1 parent 61f4c9b commit e5b0b30

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

config/src/main/java/com/alibaba/nacos/config/server/configuration/ConfigCompatibleConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class ConfigCompatibleConfig extends AbstractDynamicConfig {
3535

3636
protected ConfigCompatibleConfig() {
3737
super(CONFIG_NAME);
38+
resetConfig();
3839
}
3940

4041
public boolean isNamespaceCompatibleMode() {

config/src/main/java/com/alibaba/nacos/config/server/service/ConfigMigrateService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ private void doCheckNamespaceMigrate() throws Exception {
559559
for (ConfigInfo configInfo : batchConfigInfosFromEmpty) {
560560
configMigratePersistService.syncConfig(configInfo.getDataId(), configInfo.getGroup(),
561561
StringUtils.EMPTY, namespacePublic, NAMESPACE_MIGRATE_SRC_USER);
562-
startEmptyId = batchConfigInfosFromEmpty.get(batchConfigInfosFromEmpty.size() - 1)
563-
.getId();
564562
}
563+
startEmptyId = batchConfigInfosFromEmpty.get(batchConfigInfosFromEmpty.size() - 1)
564+
.getId();
565565
}
566566
migrateSuccess = true;
567567
break;
@@ -598,9 +598,9 @@ private void doCheckNamespaceMigrate() throws Exception {
598598
for (ConfigInfo configInfo : batchConfigInfosFromPublic) {
599599
configMigratePersistService.syncConfig(configInfo.getDataId(), configInfo.getGroup(),
600600
namespacePublic, StringUtils.EMPTY, NAMESPACE_MIGRATE_SRC_USER);
601-
startPublicId = batchConfigInfosFromPublic.get(batchConfigInfosFromPublic.size() - 1)
602-
.getId();
603601
}
602+
startPublicId = batchConfigInfosFromPublic.get(batchConfigInfosFromPublic.size() - 1)
603+
.getId();
604604
}
605605
migrateSuccess = true;
606606
break;
@@ -668,9 +668,9 @@ private void doCheckNamespaceMigrate() throws Exception {
668668
configMigratePersistService.syncConfigGray(configInfoGrayWrapper.getDataId(),
669669
configInfoGrayWrapper.getGroup(), StringUtils.EMPTY,
670670
configInfoGrayWrapper.getGrayName(), namespacePublic, NAMESPACE_MIGRATE_SRC_USER);
671-
startGrayEmptyId = batchConfigInfoGraysFromEmpty.get(batchConfigInfoGraysFromEmpty.size() - 1)
672-
.getId();
673671
}
672+
startGrayEmptyId = batchConfigInfoGraysFromEmpty.get(batchConfigInfoGraysFromEmpty.size() - 1)
673+
.getId();
674674
}
675675
migrateSuccess = true;
676676
break;
@@ -709,9 +709,9 @@ private void doCheckNamespaceMigrate() throws Exception {
709709
configMigratePersistService.syncConfigGray(configInfoGrayWrapper.getDataId(),
710710
configInfoGrayWrapper.getGroup(), namespacePublic,
711711
configInfoGrayWrapper.getGrayName(), StringUtils.EMPTY, NAMESPACE_MIGRATE_SRC_USER);
712-
startGrayPublicId = batchConfigInfoGraysFromPublic.get(batchConfigInfoGraysFromPublic.size() - 1)
713-
.getId();
714712
}
713+
startGrayPublicId = batchConfigInfoGraysFromPublic.get(batchConfigInfoGraysFromPublic.size() - 1)
714+
.getId();
715715
}
716716
migrateSuccess = true;
717717
break;

plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigMigrateMapperByDerby.java

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,53 @@ public class ConfigMigrateMapperByDerby extends AbstractMapperByDerby implements
3636
public MapperResult findConfigIdNeedInsertMigrate(MapperContext context) {
3737
String sql = "SELECT ci.id FROM config_info ci WHERE ci.tenant_id = '' AND NOT EXISTS "
3838
+ " ( SELECT 1 FROM config_info ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id AND ci2.tenant_id = 'public' )"
39-
+ " AND id > ?" + " OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
40-
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.LAST_MAX_ID),
41-
context.getWhereParameter(FieldConstant.PAGE_SIZE)));
39+
+ " AND ci.id > ?" + " ORDER BY ci.id OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
40+
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
41+
context.getPageSize()));
42+
}
43+
44+
@Override
45+
public MapperResult findConfigNeedUpdateMigrate(MapperContext context) {
46+
String sql = "SELECT ci.id, ci.data_id, ci.group_id, ci.tenant_id"
47+
+ " FROM config_info ci WHERE ci.tenant_id = ? AND "
48+
+ " (ci.src_user <> ? OR ci.src_user IS NULL) AND EXISTS "
49+
+ " ( SELECT 1 FROM config_info ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id "
50+
+ " AND ci2.tenant_id = ? AND ci2.src_user = ? AND ci2.md5 <> ci.md5 "
51+
+ " AND ci2.gmt_modified < ci.gmt_modified )"
52+
+ " AND ci.id > ?" + " ORDER BY ci.id OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
53+
return new MapperResult(sql,
54+
CollectionUtils.list(context.getWhereParameter(FieldConstant.SRC_TENANT),
55+
context.getWhereParameter(FieldConstant.SRC_USER),
56+
context.getWhereParameter(FieldConstant.TARGET_TENANT),
57+
context.getWhereParameter(FieldConstant.SRC_USER), context.getWhereParameter(FieldConstant.ID),
58+
context.getPageSize()));
4259
}
4360

4461
@Override
4562
public MapperResult findConfigGrayIdNeedInsertMigrate(MapperContext context) {
4663
String sql = "SELECT ci.id FROM config_info_gray ci WHERE ci.tenant_id = '' AND NOT EXISTS "
4764
+ " ( SELECT 1 FROM config_info_gray ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id"
48-
+ " AND ci2.tenant_id = 'public' AND ci2.gray_name = ci1.gray_name)" + " AND id > ?"
49-
+ " OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
50-
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.LAST_MAX_ID),
51-
context.getWhereParameter(FieldConstant.PAGE_SIZE)));
65+
+ " AND ci2.tenant_id = 'public' AND ci2.gray_name = ci.gray_name)" + " AND ci.id > ?"
66+
+ " ORDER BY ci.id OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
67+
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
68+
context.getPageSize()));
69+
}
70+
71+
@Override
72+
public MapperResult findConfigGrayNeedUpdateMigrate(MapperContext context) {
73+
String sql = "SELECT ci.id, ci.data_id, ci.group_id, ci.tenant_id, ci.gray_name "
74+
+ " FROM config_info_gray ci WHERE ci.tenant_id = ? AND "
75+
+ " (ci.src_user <> ? OR ci.src_user IS NULL) AND EXISTS "
76+
+ " ( SELECT 1 FROM config_info_gray ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id "
77+
+ " AND ci2.gray_name = ci.gray_name AND ci2.tenant_id = ? AND ci2.src_user = ? AND ci2.md5 <> ci.md5 "
78+
+ " AND ci2.gmt_modified < ci.gmt_modified )"
79+
+ " AND ci.id > ?" + " ORDER BY ci.id OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
80+
return new MapperResult(sql,
81+
CollectionUtils.list(context.getWhereParameter(FieldConstant.SRC_TENANT),
82+
context.getWhereParameter(FieldConstant.SRC_USER),
83+
context.getWhereParameter(FieldConstant.TARGET_TENANT),
84+
context.getWhereParameter(FieldConstant.SRC_USER), context.getWhereParameter(FieldConstant.ID),
85+
context.getPageSize()));
5286
}
5387

5488
@Override

plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigMigrateMapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface ConfigMigrateMapper extends Mapper {
3838
* @return the namespace conflict count
3939
*/
4040
default MapperResult getConfigConflictCount(MapperContext context) {
41-
String sql = "SELECT COUNT(DISTINCT ci1.data_id, ci1.group_id) AS count FROM config_info ci1"
41+
String sql = "SELECT COUNT(*) AS count FROM config_info ci1"
4242
+ " WHERE ci1.tenant_id = 'public' AND (ci1.src_user <> ? OR ci1.src_user IS NULL) "
4343
+ " AND EXISTS (SELECT 1 FROM config_info ci2"
4444
+ " WHERE ci2.data_id = ci1.data_id AND ci2.group_id = ci1.group_id"
@@ -56,7 +56,7 @@ default MapperResult getConfigConflictCount(MapperContext context) {
5656
default MapperResult findConfigIdNeedInsertMigrate(MapperContext context) {
5757
String sql = "SELECT ci.id FROM config_info ci WHERE ci.tenant_id = '' AND NOT EXISTS "
5858
+ " ( SELECT 1 FROM config_info ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id AND ci2.tenant_id = 'public' )"
59-
+ " AND id > ?" + " ORDER BY id LIMIT ?";
59+
+ " AND ci.id > ?" + " ORDER BY ci.id LIMIT ?";
6060
return new MapperResult(sql,
6161
CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));
6262
}
@@ -96,7 +96,7 @@ default MapperResult findConfigGrayNeedUpdateMigrate(MapperContext context) {
9696
+ " ( SELECT 1 FROM config_info_gray ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id "
9797
+ " AND ci2.gray_name = ci.gray_name AND ci2.tenant_id = ? AND ci2.src_user = ? AND ci2.md5 <> ci.md5 "
9898
+ " AND ci2.gmt_modified < ci.gmt_modified )"
99-
+ " AND id > ?" + " ORDER BY id LIMIT ?";
99+
+ " AND ci.id > ?" + " ORDER BY ci.id LIMIT ?";
100100
return new MapperResult(sql,
101101
CollectionUtils.list(context.getWhereParameter(FieldConstant.SRC_TENANT),
102102
context.getWhereParameter(FieldConstant.SRC_USER),
@@ -140,7 +140,7 @@ default MapperResult migrateConfigInsertByIds(MapperContext context) {
140140
*/
141141
default MapperResult getConfigGrayConflictCount(MapperContext context) {
142142
String sql =
143-
"SELECT COUNT(DISTINCT ci1.data_id, ci1.group_id, ci1.gray_name) AS count FROM config_info_gray ci1"
143+
"SELECT COUNT(*) AS count FROM config_info_gray ci1"
144144
+ " WHERE ci1.tenant_id = 'public' AND (ci1.src_user <> ? OR ci1.src_user IS NULL)"
145145
+ " AND EXISTS (SELECT 1 FROM config_info_gray ci2"
146146
+ " WHERE ci2.data_id = ci1.data_id AND ci2.group_id = ci1.group_id AND ci2.gray_name = ci1.gray_name"
@@ -158,8 +158,8 @@ default MapperResult getConfigGrayConflictCount(MapperContext context) {
158158
default MapperResult findConfigGrayIdNeedInsertMigrate(MapperContext context) {
159159
String sql = "SELECT ci.id FROM config_info_gray ci WHERE ci.tenant_id = '' AND NOT EXISTS "
160160
+ " ( SELECT 1 FROM config_info_gray ci2 WHERE ci2.data_id = ci.data_id AND ci2.group_id = ci.group_id"
161-
+ " AND ci2.tenant_id = 'public' AND ci2.gray_name = ci.gray_name )" + " AND id > ?"
162-
+ " ORDER BY id LIMIT ?";
161+
+ " AND ci2.tenant_id = 'public' AND ci2.gray_name = ci.gray_name )" + " AND ci.id > ?"
162+
+ " ORDER BY ci.id LIMIT ?";
163163
return new MapperResult(sql,
164164
CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));
165165
}

0 commit comments

Comments
 (0)