Skip to content

Commit 55edcc1

Browse files
committed
change fastjson to jackson
1 parent 462531e commit 55edcc1

10 files changed

Lines changed: 58 additions & 51 deletions

File tree

pom.xml

Lines changed: 3 additions & 3 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>

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: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
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.ObjectMapper;
2422
import com.alipay.oceanbase.rpc.ObGlobal;
2523
import com.alipay.oceanbase.rpc.constant.Constants;
2624
import com.alipay.oceanbase.rpc.exception.*;
@@ -59,7 +57,6 @@ public class LocationUtil {
5957
private static final Logger logger = TableClientLoggerFactory
6058
.getLogger(LocationUtil.class);
6159
static {
62-
ParserConfig.getGlobalInstance().setSafeMode(true);
6360
loadJdbcDriver();
6461
}
6562

@@ -236,6 +233,7 @@ public class LocationUtil {
236233
.getProperty(
237234
"table.entry.location.refresh.threshold",
238235
"0"));
236+
private static ObjectMapper objectMapper = new ObjectMapper();
239237

240238
private abstract static class TableEntryRefreshWithPriorityCallback<T> {
241239
abstract T execute(ObServerAddr obServerAddr) throws ObTableEntryRefreshException;
@@ -794,7 +792,7 @@ private static TableEntry getTableEntryFromRemote(final Connection connection,
794792
}
795793
if (logger.isInfoEnabled()) {
796794
logger.info("get part info from remote info:{}",
797-
JSON.toJSON(tableEntry.getPartitionInfo()));
795+
objectMapper.writeValueAsString(tableEntry.getPartitionInfo()));
798796
}
799797
// set partition locations
800798
if (oldTableEntry == null) {
@@ -823,7 +821,7 @@ private static TableEntry getTableEntryFromRemote(final Connection connection,
823821
if (!initialized) {
824822
if (BOOT.isInfoEnabled()) {
825823
BOOT.info("finish get table entry from remote, entry={}",
826-
JSON.toJSON(tableEntry));
824+
objectMapper.writeValueAsString(tableEntry));
827825
}
828826
} else {
829827
if (logger.isInfoEnabled()) {
@@ -1316,15 +1314,15 @@ private static void fetchFirstPart(final Connection connection, TableEntry table
13161314

13171315
if (logger.isInfoEnabled()) {
13181316
logger.info(format("uuid:%s, get first ranges from remote for %s, bounds=%s",
1319-
uuid, tableName, JSON.toJSON(bounds)));
1317+
uuid, tableName, objectMapper.writeValueAsString(bounds)));
13201318
}
13211319

13221320
} else if (obPartFuncType.isListPart()) {
13231321
Map<ObPartitionKey, Long> sets = parseFirstPartSets(rs, tableEntry);
13241322
((ObListPartDesc) tableEntry.getPartitionInfo().getFirstPartDesc()).setSets(sets);
13251323
if (logger.isInfoEnabled()) {
13261324
logger.info(format("uuid:%s, get first list sets from remote for %s, sets=%s",
1327-
uuid, tableName, JSON.toJSON(sets)));
1325+
uuid, tableName, objectMapper.writeValueAsString(sets)));
13281326
}
13291327
} else if (obPartFuncType.isKeyPart() || obPartFuncType.isHashPart()) {
13301328
tableEntry.getPartitionInfo().setPartTabletIdMap(
@@ -1390,14 +1388,14 @@ private static void fetchSubPart(final Connection connection, TableEntry tableEn
13901388
.setHighBoundValues(highBoundVals);
13911389
if (logger.isInfoEnabled()) {
13921390
logger.info(format("uuid:%s, get sub ranges from remote for %s, bounds=%s",
1393-
uuid, tableName, JSON.toJSON(bounds)));
1391+
uuid, tableName, objectMapper.writeValueAsString(bounds)));
13941392
}
13951393
} else if (subPartFuncType.isListPart()) {
13961394
Map<ObPartitionKey, Long> sets = parseSubPartSets(rs, tableEntry);
13971395
((ObListPartDesc) tableEntry.getPartitionInfo().getSubPartDesc()).setSets(sets);
13981396
if (logger.isInfoEnabled()) {
13991397
logger.info(format("uuid:%s, get sub list sets from remote, sets=%s", uuid,
1400-
JSON.toJSON(sets)));
1398+
objectMapper.writeValueAsString(sets)));
14011399
}
14021400
} else if (subPartFuncType.isKeyPart() || subPartFuncType.isHashPart()) {
14031401
tableEntry.getPartitionInfo().setPartTabletIdMap(
@@ -2321,7 +2319,7 @@ private static OcpResponse getRemoteOcpResponseOrNull(String paramURL, String da
23212319
for (; tries < tryTimes; tries++) {
23222320
try {
23232321
content = loadStringFromUrl(paramURL, connectTimeout, readTimeout);
2324-
ocpResponse = JSONObject.parseObject(content, OcpResponse.class);
2322+
ocpResponse = objectMapper.readValue(content, OcpResponse.class);
23252323
if (ocpResponse != null && ocpResponse.validate()) {
23262324
if (dataSourceName != null && !dataSourceName.isEmpty()) {
23272325
saveLocalContent(dataSourceName, content);
@@ -2368,7 +2366,7 @@ private static OcpResponse getRemoteOcpIdcRegionOrNull(String paramURL, int conn
23682366
for (; tries < tryTimes; tries++) {
23692367
try {
23702368
content = loadStringFromUrl(paramURL, connectTimeout, readTimeout);
2371-
ocpResponse = JSONObject.parseObject(content, OcpResponse.class);
2369+
ocpResponse = objectMapper.readValue(content, OcpResponse.class);
23722370
if (ocpResponse != null) {
23732371
return ocpResponse;
23742372
}
@@ -2386,8 +2384,8 @@ private static OcpResponse getRemoteOcpIdcRegionOrNull(String paramURL, int conn
23862384
return null;
23872385
}
23882386

2389-
private static OcpResponse parseOcpResponse(String content) throws JSONException {
2390-
return JSONObject.parseObject(content, OcpResponse.class);
2387+
private static OcpResponse parseOcpResponse(String content) throws JsonProcessingException {
2388+
return objectMapper.readValue(content, OcpResponse.class);
23912389
}
23922390

23932391
private static OcpResponse getLocalOcpResponseOrNull(String fileName) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class OcpResponse {
2222
private String Message;
2323
private boolean Success;
2424
private OcpResponseData Data;
25+
public OcpResponse() {}
2526

2627
/*
2728
* Get code.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class OcpResponseData {
2424
private long ObRegionId = -1;
2525
private List<OcpResponseDataRs> RsList;
2626
private List<OcpResponseDataIDC> IDCList;
27+
public OcpResponseData() {}
2728

2829
/*
2930
* Get ob region.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class OcpResponseDataIDC {
2626
private String idc;
2727
private String region;
28+
public OcpResponseDataIDC() {}
2829

2930
/*
3031
* Get idc.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class OcpResponseDataRs {
2121
private String address;
2222
private String role;
2323
private int sql_port;
24+
public OcpResponseDataRs() {}
2425

2526
/*
2627
* Get address.

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
}

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

Lines changed: 11 additions & 10 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.LocationUtil;
@@ -49,6 +49,7 @@
4949

5050
public class TableRoute {
5151
private static final Logger logger = getLogger(TableRoute.class);
52+
private static final ObjectMapper objectMapper = new ObjectMapper();
5253
private final ObTableClient tableClient;
5354
private final ObUserAuth sysUA; // user and password to access route table
5455
private final ServerRoster serverRoster = new ServerRoster(); // all servers which contain current tenant
@@ -196,8 +197,8 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
196197
ConcurrentHashMap<ObServerAddr, ObTable> addr2Table = new ConcurrentHashMap<ObServerAddr, ObTable>();
197198
List<ObServerAddr> rsList = configServerInfo.getRsList();
198199
BOOT.info("{} success to get rsList, paramURL: {}, rsList: {},idc2Region: {}",
199-
tableClient.getDatabase(), configServerInfo.getParamURL(), JSON.toJSON(rsList),
200-
JSON.toJSON(configServerInfo.getIdc2Region()));
200+
tableClient.getDatabase(), configServerInfo.getParamURL(), objectMapper.writeValueAsString(rsList),
201+
objectMapper.writeValueAsString(configServerInfo.getIdc2Region()));
201202

202203
TableEntry tableEntry = null;
203204
int retryMaxTimes = rsList.size();
@@ -211,7 +212,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
211212
tableClient.getTableEntryAcquireConnectTimeout(),//
212213
tableClient.getTableEntryAcquireSocketTimeout(), sysUA, initialized);
213214
BOOT.info("{} success to get tableEntry with rootServerKey all_dummy_tables {}",
214-
tableClient.getDatabase(), JSON.toJSON(tableEntry));
215+
tableClient.getDatabase(), objectMapper.writeValueAsString(tableEntry));
215216
success = true;
216217
} catch (ObTableEntryRefreshException e) {
217218
if (e.isConnectInactive()) {
@@ -233,7 +234,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
233234
List<ReplicaLocation> replicaLocations = tableEntry.getTableLocation()
234235
.getReplicaLocations();
235236
BOOT.info("{} success to get replicaLocation {}", tableClient.getDatabase(),
236-
JSON.toJSON(replicaLocations));
237+
objectMapper.writeValueAsString(replicaLocations));
237238

238239
List<Exception> obTableExceptions = new ArrayList<>();
239240
for (ReplicaLocation replicaLocation : replicaLocations) {
@@ -273,7 +274,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
273274
}
274275
if (servers.isEmpty()) {
275276
BOOT.error("{} failed to connect any replicaLocation server: {}",
276-
tableClient.getDatabase(), JSON.toJSON(replicaLocations));
277+
tableClient.getDatabase(), objectMapper.writeValueAsString(replicaLocations));
277278
boolean isSameTypeException = true;
278279
int errCode = -1;
279280
// if collected exceptions are the same type, throw the original exception
@@ -297,7 +298,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
297298
}
298299

299300
BOOT.info("{} success to build server connection {}", tableClient.getDatabase(),
300-
JSON.toJSON(servers));
301+
objectMapper.writeValueAsString(servers));
301302
this.tableRoster = TableRoster.getInstanceOf(tableClient.getTenantName(),
302303
tableClient.getUserName(), tableClient.getPassword(), tableClient.getDatabase(),
303304
tableClient.getClientType(runningMode), tableClient.getProperties(),
@@ -343,7 +344,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
343344
tableClient.getCurrentIDC(), regionFromOcp));
344345
if (BOOT.isInfoEnabled()) {
345346
BOOT.info("{} finish refresh serverRoster: {}", tableClient.getDatabase(),
346-
JSON.toJSON(serverRoster));
347+
objectMapper.writeValueAsString(serverRoster));
347348
BOOT.info("finish initMetadata for all tables for database {}",
348349
tableClient.getDatabase());
349350
}
@@ -437,7 +438,7 @@ public void refreshRosterByRsList(List<ObServerAddr> newRsList) throws Exception
437438
} // end while
438439
if (!success) {
439440
logger.error("all tenant servers are not available, tenant: {}, serverRoster: {}",
440-
allDummyKey.getTenantName(), JSON.toJSON(serverRoster));
441+
allDummyKey.getTenantName(), objectMapper.writeValueAsString(serverRoster));
441442
throw new ObTableUnexpectedException("all tenant servers are not available");
442443
}
443444

@@ -448,7 +449,7 @@ public void refreshRosterByRsList(List<ObServerAddr> newRsList) throws Exception
448449

449450
if (logger.isInfoEnabled()) {
450451
logger.info("finish refresh serverRoster: {}, servers num: {}",
451-
JSON.toJSON(serverRoster), servers.size());
452+
objectMapper.writeValueAsString(serverRoster), servers.size());
452453
}
453454
lastRefreshMetadataTimestamp = System.currentTimeMillis();
454455
}

0 commit comments

Comments
 (0)