Skip to content

Commit

Permalink
Merge pull request #2949 from alibaba/hotfix_config_clone
Browse files Browse the repository at this point in the history
Hotfix config clone
  • Loading branch information
yanlinly authored Jun 3, 2020
2 parents 7ac0ff8 + 6271022 commit f71c5d8
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.alibaba.nacos.config.server.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.Serializable;
import java.sql.Timestamp;

Expand All @@ -30,7 +33,7 @@ public class ConfigHistoryInfo implements Serializable {
* id, nid, data_id, group_id, content, md5, gmt_create, gmt_modified, (配置创建时间,配置变更时间) src_user, src_ip, (变更操作者)
* op_type(变更操作类型)
*/

@JsonSerialize(using = ToStringSerializer.class)
private long id;
/**
* 上次改动历史的id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.alibaba.nacos.config.server.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.Serializable;

/**
Expand All @@ -25,7 +28,7 @@
public class ConfigInfoAggr implements Serializable {

private static final long serialVersionUID = -3845825581059306364L;

@JsonSerialize(using = ToStringSerializer.class)
private long id;

private String dataId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.PrintWriter;
import java.io.Serializable;
Expand All @@ -32,6 +34,7 @@ public class ConfigInfoBase implements Serializable, Comparable<ConfigInfoBase>
/**
* 不能增加字段
*/
@JsonSerialize(using = ToStringSerializer.class)
private long id;
private String dataId;
private String group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.alibaba.nacos.config.server.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.Serializable;

/**
Expand All @@ -24,6 +27,8 @@
*/
public class GroupInfo implements Serializable {
static final long serialVersionUID = -1L;

@JsonSerialize(using = ToStringSerializer.class)
private long id;
private String address;
private String group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.alibaba.nacos.config.server.model.capacity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.Serializable;
import java.sql.Timestamp;

Expand All @@ -27,6 +30,8 @@
public class Capacity implements Serializable {

private static final long serialVersionUID = 77343194329627468L;

@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private Integer quota;
private Integer usage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,4 @@ private static int getDelayTime(NotifySingleTask task) {
private static int INCREASE_STEPS = 1000;
private static int MAX_COUNT = 6;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public <R> R queryOne(String sql, Class<R> cls) {
LogUtil.fatalLog
.error("An exception occurred during the query operation : {}",
e.toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down Expand Up @@ -247,7 +247,7 @@ public <R> R queryOne(String sql, Object[] args, Class<R> cls) {
LogUtil.fatalLog
.error("An exception occurred during the query operation : {}",
e.toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ public <R> R queryOne(String sql, Object[] args, RowMapper<R> mapper) {
LogUtil.fatalLog
.error("An exception occurred during the query operation : {}",
e.toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down Expand Up @@ -305,7 +305,7 @@ public <R> List<R> queryMany(String sql, Object[] args, RowMapper<R> mapper) {
LogUtil.fatalLog
.error("An exception occurred during the query operation : {}",
e.toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down Expand Up @@ -334,7 +334,7 @@ public <R> List<R> queryMany(String sql, Object[] args, Class<R> rClass) {
LogUtil.fatalLog
.error("An exception occurred during the query operation : {}",
e.toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down Expand Up @@ -363,7 +363,7 @@ public List<Map<String, Object>> queryMany(String sql, Object[] args) {
LogUtil.fatalLog
.error("An exception occurred during the query operation : {}",
e.toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down Expand Up @@ -433,12 +433,12 @@ public Boolean update(List<ModifyRequest> sqlContext,
catch (TimeoutException e) {
LogUtil.fatalLog
.error("An timeout exception occurred during the update operation");
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
catch (Throwable e) {
LogUtil.fatalLog
.error("An exception occurred during the update operation : {}", e);
throw new NacosRuntimeException(NacosException.SERVER_ERROR, ExceptionUtil.getCause(e).toString());
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,10 @@ public Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoLis
notify);
succCount++;
}
catch (DataIntegrityViolationException ive) {
catch (Throwable e) {
if (!StringUtils.contains("DuplicateKeyException", e.toString())) {
throw e;
}
// uniqueness constraint conflict
if (SameConfigPolicy.ABORT.equals(policy)) {
failData = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.model;

import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.consistency.IdGenerator;
import com.alibaba.nacos.core.distributed.id.SnowFlowerIdGenerator;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.env.StandardEnvironment;

public class ConfigInfoTest {

@Test
public void test_precision_issue() throws Exception {
ApplicationUtils.injectEnvironment(new StandardEnvironment());
IdGenerator generator = new SnowFlowerIdGenerator();
long id = generator.nextId();
ConfigInfo configInfo = new ConfigInfo();
configInfo.setId(id);
String json = JacksonUtils.toJson(configInfo);
ConfigInfo _c = JacksonUtils.toObj(json, ConfigInfo.class);
Assert.assertEquals(id, _c.getId());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public IdGeneratorManager() {
if (iterator.hasNext()) {
generator = iterator.next();
} else {
generator = new SnakeFlowerIdGenerator();
generator = new SnowFlowerIdGenerator();
}
generator.init();
return generator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -43,10 +42,10 @@
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
*/
@SuppressWarnings("all")
public class SnakeFlowerIdGenerator implements IdGenerator {
public class SnowFlowerIdGenerator implements IdGenerator {

private static final Logger logger = LoggerFactory
.getLogger(SnakeFlowerIdGenerator.class);
.getLogger(SnowFlowerIdGenerator.class);

/**
* Start time intercept (2018-08-05 08:34)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.alibaba.nacos.test.core;

import com.alibaba.nacos.core.distributed.id.SnakeFlowerIdGenerator;
import com.alibaba.nacos.core.distributed.id.SnowFlowerIdGenerator;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -25,14 +25,14 @@
/**
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class SnakeFlowerIdGenerator_ITCase {
public class SnowFlowerIdGenerator_ITCase {

@Test
public void test_idGenerator() {
ApplicationUtils.injectEnvironment(new StandardEnvironment());
SnakeFlowerIdGenerator generator1 = new SnakeFlowerIdGenerator();
SnakeFlowerIdGenerator generator2 = new SnakeFlowerIdGenerator();
SnakeFlowerIdGenerator generator3 = new SnakeFlowerIdGenerator();
SnowFlowerIdGenerator generator1 = new SnowFlowerIdGenerator();
SnowFlowerIdGenerator generator2 = new SnowFlowerIdGenerator();
SnowFlowerIdGenerator generator3 = new SnowFlowerIdGenerator();

generator1.initialize(1);
generator2.initialize(2);
Expand Down

0 comments on commit f71c5d8

Please sign in to comment.