Skip to content

Commit 92c70e6

Browse files
authored
Replace Fastjson with Jackson (#347)
* change fastjson to jackson * use jackson 2.14.2, compile pass * succeed to print log * update jackson and maven-shade-plugin to the lateset version * revert OcpResponseData constructors * diable reduce pom dependencies
1 parent 31128c0 commit 92c70e6

File tree

10 files changed

+90
-54
lines changed

10 files changed

+90
-54
lines changed

pom.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112
</dependency>
113113

114114
<dependency>
115-
<groupId>com.alibaba</groupId>
116-
<artifactId>fastjson</artifactId>
117-
<version>1.2.83</version>
115+
<groupId>com.fasterxml.jackson.core</groupId>
116+
<artifactId>jackson-databind</artifactId>
117+
<version>2.19.0</version>
118118
</dependency>
119119

120120
<dependency>
@@ -164,6 +164,10 @@
164164
<artifactId>visible-assertions</artifactId>
165165
<groupId>org.rnorth.visible-assertions</groupId>
166166
</exclusion>
167+
<exclusion>
168+
<artifactId>jackson-annotations</artifactId>
169+
<groupId>com.fasterxml.jackson.core</groupId>
170+
</exclusion>
167171
</exclusions>
168172
</dependency>
169173
<dependency>
@@ -388,14 +392,15 @@
388392
</plugin>
389393
<plugin>
390394
<artifactId>maven-shade-plugin</artifactId>
391-
<version>3.2.4</version>
395+
<version>3.6.0</version>
392396
<executions>
393397
<execution>
394398
<phase>package</phase>
395399
<goals>
396400
<goal>shade</goal>
397401
</goals>
398402
<configuration>
403+
<createDependencyReducedPom>false</createDependencyReducedPom>
399404
<shadedArtifactAttached>true</shadedArtifactAttached>
400405
<shadedClassifierName>shade</shadedClassifierName>
401406
<artifactSet>

src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableConnection.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package com.alipay.oceanbase.rpc.bolt.transport;
1919

20-
import com.alibaba.fastjson.JSONObject;
2120
import com.alipay.oceanbase.rpc.ObGlobal;
2221
import com.alipay.oceanbase.rpc.exception.*;
2322
import com.alipay.oceanbase.rpc.location.LocationUtil;
@@ -26,6 +25,7 @@
2625
import com.alipay.oceanbase.rpc.table.ObTable;
2726
import com.alipay.oceanbase.rpc.util.*;
2827
import com.alipay.remoting.Connection;
28+
import com.fasterxml.jackson.databind.ObjectMapper;
2929
import org.slf4j.Logger;
3030

3131
import java.net.ConnectException;
@@ -40,6 +40,7 @@ public class ObTableConnection {
4040

4141
private static final Logger LOGGER = TableClientLoggerFactory
4242
.getLogger(ObTableConnection.class);
43+
private static ObjectMapper objectMapper = new ObjectMapper();
4344
private ObBytesString credential;
4445
private long tenantId = 1; //默认值切勿不要随意改动
4546
private Connection connection;
@@ -154,8 +155,8 @@ private void login() throws Exception {
154155
// When the caller doesn't provide any parameters, configsMap is empty.
155156
// In this case, we don't generate any JSON to avoid creating an empty object.
156157
if (loginWithConfigs && !obTable.getConfigs().isEmpty()) {
157-
JSONObject json = new JSONObject(obTable.getConfigs());
158-
request.setConfigsStr(json.toJSONString());
158+
String configStr = objectMapper.writeValueAsString(obTable.getConfigs());
159+
request.setConfigsStr(configStr);
159160
loginWithConfigs = false;
160161
}
161162
generatePassSecret(request);

src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717

1818
package com.alipay.oceanbase.rpc.location;
1919

20-
import com.alibaba.fastjson.JSON;
21-
import com.alibaba.fastjson.JSONException;
22-
import com.alibaba.fastjson.JSONObject;
23-
import com.alibaba.fastjson.parser.ParserConfig;
20+
import com.fasterxml.jackson.core.JsonProcessingException;
21+
import com.fasterxml.jackson.databind.DeserializationFeature;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
2423
import com.alipay.oceanbase.rpc.ObGlobal;
2524
import com.alipay.oceanbase.rpc.constant.Constants;
2625
import com.alipay.oceanbase.rpc.exception.*;
@@ -35,6 +34,7 @@
3534
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObIndexType;
3635
import com.alipay.oceanbase.rpc.protocol.payload.impl.parser.ObGeneratedColumnExpressParser;
3736
import com.alipay.oceanbase.rpc.util.TableClientLoggerFactory;
37+
import com.fasterxml.jackson.databind.SerializationFeature;
3838
import org.slf4j.Logger;
3939

4040
import java.io.*;
@@ -58,8 +58,12 @@ public class LocationUtil {
5858

5959
private static final Logger logger = TableClientLoggerFactory
6060
.getLogger(LocationUtil.class);
61+
62+
private static final ObjectMapper objectMapper = new ObjectMapper();
63+
6164
static {
62-
ParserConfig.getGlobalInstance().setSafeMode(true);
65+
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
66+
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
6367
loadJdbcDriver();
6468
}
6569

@@ -794,7 +798,7 @@ private static TableEntry getTableEntryFromRemote(final Connection connection,
794798
}
795799
if (logger.isInfoEnabled()) {
796800
logger.info("get part info from remote info:{}",
797-
JSON.toJSON(tableEntry.getPartitionInfo()));
801+
objectMapper.writeValueAsString(tableEntry.getPartitionInfo()));
798802
}
799803
// set partition locations
800804
if (oldTableEntry == null) {
@@ -823,7 +827,7 @@ private static TableEntry getTableEntryFromRemote(final Connection connection,
823827
if (!initialized) {
824828
if (BOOT.isInfoEnabled()) {
825829
BOOT.info("finish get table entry from remote, entry={}",
826-
JSON.toJSON(tableEntry));
830+
objectMapper.writeValueAsString(tableEntry));
827831
}
828832
} else {
829833
if (logger.isInfoEnabled()) {
@@ -1316,15 +1320,15 @@ private static void fetchFirstPart(final Connection connection, TableEntry table
13161320

13171321
if (logger.isInfoEnabled()) {
13181322
logger.info(format("uuid:%s, get first ranges from remote for %s, bounds=%s",
1319-
uuid, tableName, JSON.toJSON(bounds)));
1323+
uuid, tableName, objectMapper.writeValueAsString(bounds)));
13201324
}
13211325

13221326
} else if (obPartFuncType.isListPart()) {
13231327
Map<ObPartitionKey, Long> sets = parseFirstPartSets(rs, tableEntry);
13241328
((ObListPartDesc) tableEntry.getPartitionInfo().getFirstPartDesc()).setSets(sets);
13251329
if (logger.isInfoEnabled()) {
13261330
logger.info(format("uuid:%s, get first list sets from remote for %s, sets=%s",
1327-
uuid, tableName, JSON.toJSON(sets)));
1331+
uuid, tableName, objectMapper.writeValueAsString(sets)));
13281332
}
13291333
} else if (obPartFuncType.isKeyPart() || obPartFuncType.isHashPart()) {
13301334
tableEntry.getPartitionInfo().setPartTabletIdMap(
@@ -1390,14 +1394,14 @@ private static void fetchSubPart(final Connection connection, TableEntry tableEn
13901394
.setHighBoundValues(highBoundVals);
13911395
if (logger.isInfoEnabled()) {
13921396
logger.info(format("uuid:%s, get sub ranges from remote for %s, bounds=%s",
1393-
uuid, tableName, JSON.toJSON(bounds)));
1397+
uuid, tableName, objectMapper.writeValueAsString(bounds)));
13941398
}
13951399
} else if (subPartFuncType.isListPart()) {
13961400
Map<ObPartitionKey, Long> sets = parseSubPartSets(rs, tableEntry);
13971401
((ObListPartDesc) tableEntry.getPartitionInfo().getSubPartDesc()).setSets(sets);
13981402
if (logger.isInfoEnabled()) {
13991403
logger.info(format("uuid:%s, get sub list sets from remote, sets=%s", uuid,
1400-
JSON.toJSON(sets)));
1404+
objectMapper.writeValueAsString(sets)));
14011405
}
14021406
} else if (subPartFuncType.isKeyPart() || subPartFuncType.isHashPart()) {
14031407
tableEntry.getPartitionInfo().setPartTabletIdMap(
@@ -2321,7 +2325,7 @@ private static OcpResponse getRemoteOcpResponseOrNull(String paramURL, String da
23212325
for (; tries < tryTimes; tries++) {
23222326
try {
23232327
content = loadStringFromUrl(paramURL, connectTimeout, readTimeout);
2324-
ocpResponse = JSONObject.parseObject(content, OcpResponse.class);
2328+
ocpResponse = objectMapper.readValue(content, OcpResponse.class);
23252329
if (ocpResponse != null && ocpResponse.validate()) {
23262330
if (dataSourceName != null && !dataSourceName.isEmpty()) {
23272331
saveLocalContent(dataSourceName, content);
@@ -2368,7 +2372,7 @@ private static OcpResponse getRemoteOcpIdcRegionOrNull(String paramURL, int conn
23682372
for (; tries < tryTimes; tries++) {
23692373
try {
23702374
content = loadStringFromUrl(paramURL, connectTimeout, readTimeout);
2371-
ocpResponse = JSONObject.parseObject(content, OcpResponse.class);
2375+
ocpResponse = objectMapper.readValue(content, OcpResponse.class);
23722376
if (ocpResponse != null) {
23732377
return ocpResponse;
23742378
}
@@ -2386,8 +2390,8 @@ private static OcpResponse getRemoteOcpIdcRegionOrNull(String paramURL, int conn
23862390
return null;
23872391
}
23882392

2389-
private static OcpResponse parseOcpResponse(String content) throws JSONException {
2390-
return JSONObject.parseObject(content, OcpResponse.class);
2393+
private static OcpResponse parseOcpResponse(String content) throws JsonProcessingException {
2394+
return objectMapper.readValue(content, OcpResponse.class);
23912395
}
23922396

23932397
private static OcpResponse getLocalOcpResponseOrNull(String fileName) {

src/main/java/com/alipay/oceanbase/rpc/location/model/OcpResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.alipay.oceanbase.rpc.location.model;
1919

20+
import com.fasterxml.jackson.annotation.JsonProperty;
21+
2022
public class OcpResponse {
2123
private int Code;
2224
private String Message;
@@ -26,6 +28,7 @@ public class OcpResponse {
2628
/*
2729
* Get code.
2830
*/
31+
@JsonProperty("Code")
2932
public int getCode() {
3033
return Code;
3134
}
@@ -40,6 +43,7 @@ public void setCode(int code) {
4043
/*
4144
* Get message.
4245
*/
46+
@JsonProperty("Message")
4347
public String getMessage() {
4448
return Message;
4549
}
@@ -58,6 +62,11 @@ public boolean isSuccess() {
5862
return Success;
5963
}
6064

65+
@JsonProperty("Success")
66+
public boolean getSuccess() {
67+
return Success;
68+
}
69+
6170
/*
6271
* Set success.
6372
*/
@@ -68,6 +77,7 @@ public void setSuccess(boolean success) {
6877
/*
6978
* Get data.
7079
*/
80+
@JsonProperty("Data")
7181
public OcpResponseData getData() {
7282
return Data;
7383
}

src/main/java/com/alipay/oceanbase/rpc/location/model/OcpResponseData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.alipay.oceanbase.rpc.location.model;
1919

20+
import com.fasterxml.jackson.annotation.JsonProperty;
21+
2022
import java.util.List;
2123

2224
public class OcpResponseData {
@@ -28,6 +30,7 @@ public class OcpResponseData {
2830
/*
2931
* Get ob region.
3032
*/
33+
@JsonProperty("ObRegion")
3134
public String getObRegion() {
3235
return ObRegion;
3336
}
@@ -42,6 +45,7 @@ public void setObRegion(String obRegion) {
4245
/*
4346
* Get ob region id.
4447
*/
48+
@JsonProperty("ObRegionId")
4549
public long getObRegionId() {
4650
return ObRegionId;
4751
}
@@ -56,6 +60,7 @@ public void setObRegionId(long obRegionId) {
5660
/*
5761
* Get rs list.
5862
*/
63+
@JsonProperty("RsList")
5964
public List<OcpResponseDataRs> getRsList() {
6065
return RsList;
6166
}

src/main/java/com/alipay/oceanbase/rpc/location/model/OcpResponseDataRs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.alipay.oceanbase.rpc.location.model;
1919

20+
import com.fasterxml.jackson.annotation.JsonProperty;
21+
2022
public class OcpResponseDataRs {
2123
private String address;
2224
private String role;
@@ -25,6 +27,7 @@ public class OcpResponseDataRs {
2527
/*
2628
* Get address.
2729
*/
30+
@JsonProperty("address")
2831
public String getAddress() {
2932
return address;
3033
}
@@ -39,6 +42,7 @@ public void setAddress(String address) {
3942
/*
4043
* Get role.
4144
*/
45+
@JsonProperty("role")
4246
public String getRole() {
4347
return role;
4448
}
@@ -53,6 +57,7 @@ public void setRole(String role) {
5357
/*
5458
* Get sql_port.
5559
*/
60+
@JsonProperty("sql_port")
5661
public int getSql_port() {
5762
return sql_port;
5863
}

src/main/java/com/alipay/oceanbase/rpc/location/model/TableLocations.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.alipay.oceanbase.rpc.location.model;
1919

20-
import com.alibaba.fastjson.JSON;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
2121
import com.alipay.oceanbase.rpc.ObTableClient;
2222
import com.alipay.oceanbase.rpc.exception.*;
2323
import com.alipay.oceanbase.rpc.location.model.partition.ObPartitionLocationInfo;
@@ -41,10 +41,11 @@
4141
import static com.alipay.oceanbase.rpc.util.TableClientLoggerFactory.*;
4242

4343
public class TableLocations {
44-
private static final Logger logger = getLogger(TableLocations.class);
45-
private final ObTableClient tableClient;
46-
private Map<String, Lock> metaRefreshingLocks = new ConcurrentHashMap<String, Lock>();
47-
private Map<String, Lock> locationBatchRefreshingLocks = new ConcurrentHashMap<String, Lock>();
44+
private static final Logger logger = getLogger(TableLocations.class);
45+
private static final ObjectMapper objectMapper = new ObjectMapper();
46+
private final ObTableClient tableClient;
47+
private Map<String, Lock> metaRefreshingLocks = new ConcurrentHashMap<String, Lock>();
48+
private Map<String, Lock> locationBatchRefreshingLocks = new ConcurrentHashMap<String, Lock>();
4849
/*
4950
* TableName -> TableEntry, containing table meta and location information
5051
*/
@@ -264,7 +265,7 @@ private TableEntry refreshTableEntry(TableEntry tableEntry, String tableName,
264265
tableEntryRefreshContinuousFailureCount.set(0);
265266
if (logger.isDebugEnabled()) {
266267
logger.debug("refresh table entry, tableName: {}, key:{} entry:{} ", tableName,
267-
tableEntryKey, JSON.toJSON(tableEntry));
268+
tableEntryKey, objectMapper.writeValueAsString(tableEntry));
268269
}
269270
return tableEntry;
270271
}

0 commit comments

Comments
 (0)