Skip to content

Commit 692c726

Browse files
committed
change fastjson to jackson
1 parent d192cd4 commit 692c726

12 files changed

+280
-87
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@
198198
<version>1.2.12</version>
199199
<scope>test</scope>
200200
</dependency>
201+
<dependency>
202+
<groupId>com.fasterxml.jackson.core</groupId>
203+
<artifactId>jackson-databind</artifactId>
204+
<version>2.19.0</version>
205+
</dependency>
201206
</dependencies>
202207
<repositories>
203208
<repository>

src/main/java/com/alipay/oceanbase/hbase/execute/AbstractObTableMetaExecutor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.execute;
219

320
import com.alipay.oceanbase.rpc.ObTableClient;

src/main/java/com/alipay/oceanbase/hbase/execute/ObTableMetaExecutor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.execute;
219

320
import com.alipay.oceanbase.rpc.ObTableClient;

src/main/java/com/alipay/oceanbase/hbase/util/OHCreateTableExecutor.java

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

1818
package com.alipay.oceanbase.hbase.util;
1919

20-
import com.alibaba.fastjson.JSON;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
2121
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
2222
import com.alipay.oceanbase.rpc.ObTableClient;
2323
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
@@ -53,7 +53,7 @@ public void createTable(TableDescriptor tableDescriptor, byte[][] splitKeys) thr
5353
final ObTableMetaRequest request = new ObTableMetaRequest();
5454
request.setMetaType(getMetaType());
5555
Map<String, Object> requestData = new HashMap<>();
56-
requestData.put("htable_name", tableDescriptor.getTableName().getName());
56+
requestData.put("htable_name", tableDescriptor.getTableName().getNameAsString());
5757
Map<String, Map<String, Integer>> columnFamilies = new HashMap<>();
5858
for (ColumnFamilyDescriptor columnDescriptor : tableDescriptor.getColumnFamilies()) {
5959
Map<String, Integer> columnFamily = new HashMap<>();
@@ -62,7 +62,8 @@ public void createTable(TableDescriptor tableDescriptor, byte[][] splitKeys) thr
6262
columnFamilies.put(columnDescriptor.getNameAsString(), columnFamily);
6363
}
6464
requestData.put("column_families", columnFamilies);
65-
String jsonData = JSON.toJSONString(requestData);
65+
ObjectMapper objectMapper = new ObjectMapper();
66+
String jsonData = objectMapper.writeValueAsString(requestData);
6667
request.setData(jsonData);
6768
execute(client, request);
6869
}

src/main/java/com/alipay/oceanbase/hbase/util/OHDeleteTableExecutor.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.util;
219

3-
import com.alibaba.fastjson.JSON;
4-
import com.alibaba.fastjson.annotation.JSONField;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
521
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
622
import com.alipay.oceanbase.rpc.ObTableClient;
723
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
@@ -24,7 +40,6 @@ public ObTableRpcMetaType getMetaType() {
2440
return ObTableRpcMetaType.HTABLE_DELETE_TABLE;
2541
}
2642

27-
2843
@Override
2944
public Void parse(ObTableMetaResponse response) throws IOException {
3045
// do nothing, error will be thrown from table
@@ -36,7 +51,8 @@ public Void deleteTable(String tableName) throws IOException {
3651
request.setMetaType(getMetaType());
3752
Map<String, Object> requestDataMap = new HashMap<>();
3853
requestDataMap.put("table_name", tableName);
39-
String jsonData = JSON.toJSONString(requestDataMap);
54+
ObjectMapper objectMapper = new ObjectMapper();
55+
String jsonData = objectMapper.writeValueAsString(requestDataMap);
4056
request.setData(jsonData);
4157
return execute(tableClient, request);
4258
}

src/main/java/com/alipay/oceanbase/hbase/util/OHRegionLocator.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.util;
219

320
import com.alipay.oceanbase.rpc.ObTableClient;
@@ -13,16 +30,16 @@
1330
import java.util.List;
1431

1532
public class OHRegionLocator implements RegionLocator {
16-
private byte[][] startKeys;
17-
private byte[][] endKeys;
18-
private ObTableClient tableClient;
19-
private TableName tableName;
33+
private byte[][] startKeys;
34+
private byte[][] endKeys;
35+
private ObTableClient tableClient;
36+
private TableName tableName;
2037

2138
private List<HRegionLocation> regionLocations;
2239

2340
public OHRegionLocator(byte[][] startKeys, byte[][] endKeys,
24-
List<HRegionLocation> regionLocations,
25-
TableName tableName, ObTableClient tableClient) {
41+
List<HRegionLocation> regionLocations, TableName tableName,
42+
ObTableClient tableClient) {
2643
this.startKeys = startKeys;
2744
this.endKeys = endKeys;
2845
this.regionLocations = regionLocations;
@@ -44,15 +61,16 @@ public HRegionLocation getRegionLocation(byte[] bytes) throws IOException {
4461
@Override
4562
public HRegionLocation getRegionLocation(byte[] bytes, boolean b) throws IOException {
4663
if (b || regionLocations.isEmpty()) {
47-
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(), tableClient);
64+
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(),
65+
tableClient);
4866
try {
4967
RegionLocator location = executor.getRegionLocator(tableName.toString());
5068
this.startKeys = location.getStartKeys();
5169
this.endKeys = location.getEndKeys();
5270
this.regionLocations = location.getAllRegionLocations();
5371
} catch (IOException e) {
5472
if (e.getCause() instanceof ObTableTransportException
55-
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
73+
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
5674
throw new TimeoutIOException(e.getCause());
5775
} else {
5876
throw e;

src/main/java/com/alipay/oceanbase/hbase/util/OHRegionLocatorExecutor.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.util;
219

3-
import com.alibaba.fastjson.JSON;
4-
import com.alibaba.fastjson.JSONObject;
20+
import com.fasterxml.jackson.core.type.TypeReference;
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
523
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
624
import com.alipay.oceanbase.rpc.ObTableClient;
725
import com.alipay.oceanbase.rpc.constant.Constants;
8-
import com.alipay.oceanbase.rpc.exception.ObTableException;
926
import com.alipay.oceanbase.rpc.exception.ObTableUnexpectedException;
10-
import com.alipay.oceanbase.rpc.location.model.TableEntry;
1127
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
1228
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
1329
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
@@ -19,7 +35,7 @@
1935
import java.util.stream.IntStream;
2036

2137
public class OHRegionLocatorExecutor extends AbstractObTableMetaExecutor<OHRegionLocator> {
22-
private final String tableName;
38+
private final String tableName;
2339
private final ObTableClient client;
2440

2541
OHRegionLocatorExecutor(String tableName, ObTableClient client) {
@@ -42,7 +58,8 @@ public ObTableRpcMetaType getMetaType() {
4258
public OHRegionLocator parse(ObTableMetaResponse response) throws IOException {
4359
try {
4460
final String jsonData = response.getData();
45-
final JSONObject jsonMap = Optional.<JSONObject>ofNullable(JSON.parseObject(jsonData))
61+
final ObjectMapper objectMapper = new ObjectMapper();
62+
final JsonNode jsonMap = Optional.ofNullable(objectMapper.readTree(jsonData))
4663
.orElseThrow(() -> new IOException("jsonMap is null"));
4764
/*
4865
{
@@ -77,14 +94,17 @@ public OHRegionLocator parse(ObTableMetaResponse response) throws IOException {
7794
]
7895
}
7996
*/
80-
81-
final List<Object> partitions = Optional.<List<Object>>ofNullable(jsonMap.getJSONArray("partitions"))
97+
JsonNode partitionsNode = Optional.<JsonNode>ofNullable(jsonMap.get("partitions"))
8298
.orElseThrow(() -> new IOException("partitions is null"));
99+
List<Object> partitions = objectMapper.convertValue(partitionsNode, new TypeReference<List<Object>>(){});
83100

84-
final List<Object> tableIdDict = Optional.<List<Object>>ofNullable(jsonMap.getJSONArray("table_id_dict"))
101+
JsonNode tableIdDictNode = Optional.<JsonNode>ofNullable(jsonMap.get("table_id_dict"))
85102
.orElseThrow(() -> new IOException("tableIdDict is null"));
86-
final List<Object> replicaDict = Optional.<List<Object>>ofNullable(jsonMap.getJSONArray("replica_dict"))
103+
List<Object> tableIdDict = objectMapper.convertValue(tableIdDictNode, new TypeReference<List<Object>>(){});
104+
105+
JsonNode replicaDictNode = Optional.<JsonNode>ofNullable(jsonMap.get("replica_dict"))
87106
.orElseThrow(() -> new IOException("replicaDict is null"));
107+
List<Object> replicaDict = objectMapper.convertValue(replicaDictNode, new TypeReference<List<Object>>(){});
88108

89109
final boolean isHashLikePartition = partitions.stream()
90110
.map(obj -> (List<Object>) obj)
@@ -213,8 +233,8 @@ public OHRegionLocator getRegionLocator(final String tableName) throws IOExcepti
213233
request.setMetaType(getMetaType());
214234
final Map<String, String> requestData = new HashMap<>();
215235
requestData.put("table_name", tableName);
216-
217-
final String jsonData = JSON.toJSONString(requestData);
236+
ObjectMapper objectMapper = new ObjectMapper();
237+
final String jsonData = objectMapper.writeValueAsString(requestData);
218238
request.setData(jsonData);
219239

220240
return execute(client, request);

src/main/java/com/alipay/oceanbase/hbase/util/OHRegionMetrics.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.util;
219

320
import com.alipay.oceanbase.hbase.exception.FeatureNotSupportedException;
421
import org.apache.hadoop.hbase.RegionMetrics;
522
import org.apache.hadoop.hbase.Size;
623

7-
import java.util.Collections;
824
import java.util.Map;
925

1026
public class OHRegionMetrics implements RegionMetrics {
1127
private final String tablegroup;
12-
private final byte[] name; // tablet_name, id in String
13-
private final Size storeFileSize; // tablet storage used in ssTable
14-
private final Size memStoreSize; // tablet storage used in memTable
28+
private final byte[] name; // tablet_name, id in String
29+
private final Size storeFileSize; // tablet storage used in ssTable
30+
private final Size memStoreSize; // tablet storage used in memTable
1531

1632
OHRegionMetrics(String tablegroup, byte[] name, Size storeFileSize, Size memStoreSize) {
1733
this.tablegroup = tablegroup;

src/main/java/com/alipay/oceanbase/hbase/util/OHRegionMetricsExecutor.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
118
package com.alipay.oceanbase.hbase.util;
219

3-
import com.alibaba.fastjson.JSON;
4-
import com.alibaba.fastjson.JSONObject;
20+
import com.fasterxml.jackson.core.type.TypeReference;
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
523
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
624
import com.alipay.oceanbase.rpc.ObTableClient;
725
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
@@ -11,16 +29,15 @@
1129
import org.apache.hadoop.hbase.Size;
1230

1331
import java.io.IOException;
14-
import java.util.ArrayList;
15-
import java.util.HashMap;
16-
import java.util.List;
17-
import java.util.Map;
32+
import java.util.*;
1833

1934
public class OHRegionMetricsExecutor extends AbstractObTableMetaExecutor<List<RegionMetrics>> {
2035
private final ObTableClient tableClient;
36+
2137
OHRegionMetricsExecutor(ObTableClient tableClient) {
2238
this.tableClient = tableClient;
2339
}
40+
2441
@Override
2542
public ObTableRpcMetaType getMetaType() throws IOException {
2643
return ObTableRpcMetaType.HTABLE_REGION_METRICS;
@@ -38,13 +55,21 @@ public ObTableRpcMetaType getMetaType() throws IOException {
3855
* */
3956
@Override
4057
public List<RegionMetrics> parse(ObTableMetaResponse response) throws IOException {
58+
final ObjectMapper objectMapper = new ObjectMapper();
59+
final JsonNode jsonMap = Optional.<JsonNode>ofNullable(objectMapper.readTree(response.getData()))
60+
.orElseThrow(() -> new IOException("jsonMap is null"));
61+
JsonNode tableGroupNameNode = Optional.<JsonNode>ofNullable(jsonMap.get("tableName"))
62+
.orElseThrow(() -> new IOException("tableName is null"));
63+
String tableGroupName = tableGroupNameNode.asText();
64+
JsonNode regionListNode = Optional.<JsonNode>ofNullable(jsonMap.get("regionList"))
65+
.orElseThrow(() -> new IOException("regionList is null"));
66+
List<Integer> regions = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("regions"), new TypeReference<List<Integer>>() {}))
67+
.orElseThrow(() -> new IOException("regions is null"));
68+
List<Integer> memTableSizeList = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("memTableSize"), new TypeReference<List<Integer>>() {}))
69+
.orElseThrow(() -> new IOException("memTableSize is null"));
70+
List<Integer> ssTableSizeList = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("ssTableSize"), new TypeReference<List<Integer>>() {}))
71+
.orElseThrow(() -> new IOException("ssTableSize is null"));
4172
List<RegionMetrics> metricsList = new ArrayList<>();
42-
JSONObject metrcisJSONObject = JSON.parseObject(response.getData());
43-
String tableGroupName = metrcisJSONObject.getString("tableName");
44-
JSONObject regionList = metrcisJSONObject.getJSONObject("regionList");
45-
List<Integer> regions = regionList.getJSONArray("regions").toJavaList(Integer.class);
46-
List<Integer> memTableSizeList = regionList.getJSONArray("memTableSize").toJavaList(Integer.class);
47-
List<Integer> ssTableSizeList = regionList.getJSONArray("ssTableSize").toJavaList(Integer.class);
4873
if (regions.isEmpty() || regions.size() != memTableSizeList.size() || memTableSizeList.size() != ssTableSizeList.size()) {
4974
throw new IOException("size length has to be the same");
5075
}
@@ -64,7 +89,8 @@ public List<RegionMetrics> getRegionMetrics(String tableName) throws IOException
6489
request.setMetaType(getMetaType());
6590
Map<String, Object> requestData = new HashMap<>();
6691
requestData.put("table_name", tableName);
67-
String jsonData = JSON.toJSONString(requestData);
92+
ObjectMapper objectMapper = new ObjectMapper();
93+
String jsonData = objectMapper.writeValueAsString(requestData);
6894
request.setData(jsonData);
6995
return execute(tableClient, request);
7096
}

0 commit comments

Comments
 (0)