Skip to content

Commit e78e5f4

Browse files
committed
Reduce the number of ObjectMapper creations to improve performance
1 parent 700fad0 commit e78e5f4

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/main/java/org/tikv/common/PDClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public class PDClient extends AbstractGRPCClient<PDBlockingStub, PDFutureStub>
113113
private static final int PAUSE_CHECKER_TIMEOUT = 300; // in seconds
114114
private static final int KEEP_CHECKER_PAUSE_PERIOD = PAUSE_CHECKER_TIMEOUT / 5; // in seconds
115115
private static final Logger logger = LoggerFactory.getLogger(PDClient.class);
116+
private static final ObjectMapper mapper = new ObjectMapper();
116117

117118
private final RequestKeyCodec codec;
118119
private RequestHeader header;
@@ -226,7 +227,6 @@ public Boolean isCheckerPaused(PDChecker checker) {
226227
URI url = pdAddrs.get(0);
227228
String api = url.toString() + "/pd/api/v1/checker/" + checker.apiName();
228229
try {
229-
ObjectMapper mapper = new ObjectMapper();
230230
HashMap<String, Boolean> status =
231231
mapper.readValue(new URL(api), new TypeReference<HashMap<String, Boolean>>() {});
232232
return status.get("paused");

src/main/java/org/tikv/common/TiDBJDBCClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class TiDBJDBCClient implements AutoCloseable {
4141
private static final int DELAY_CLEAN_TABLE_LOCK_DEFAULT = 0;
4242
private static final String TIDB_ROW_FORMAT_VERSION_SQL = "select @@tidb_row_format_version";
4343
private static final int TIDB_ROW_FORMAT_VERSION_DEFAULT = 1;
44+
private static final ObjectMapper objectMapper = new ObjectMapper();
4445
private final Logger logger = LoggerFactory.getLogger(getClass().getName());
4546
private final Connection connection;
4647

@@ -120,7 +121,6 @@ public boolean dropTable(String databaseName, String tableName) throws SQLExcept
120121

121122
private Map<String, Object> readConfMapFromTiDB() throws SQLException, IOException {
122123
String configJSON = (String) queryTiDBViaJDBC(SELECT_TIDB_CONFIG_SQL).get(0).get(0);
123-
ObjectMapper objectMapper = new ObjectMapper();
124124
TypeReference<HashMap<String, Object>> typeRef =
125125
new TypeReference<HashMap<String, Object>>() {};
126126
return objectMapper.readValue(configJSON, typeRef);

src/main/java/org/tikv/common/catalog/CatalogTransaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
public class CatalogTransaction {
4242
protected static final Logger logger = LoggerFactory.getLogger(CatalogTransaction.class);
43+
private static final ObjectMapper mapper = new ObjectMapper();
4344
private final Snapshot snapshot;
4445

4546
CatalogTransaction(Snapshot snapshot) {
@@ -51,7 +52,6 @@ public static <T> T parseFromJson(ByteString json, Class<T> cls) {
5152
Objects.requireNonNull(cls, "cls is null");
5253

5354
logger.debug(String.format("Parse Json %s : %s", cls.getSimpleName(), json.toStringUtf8()));
54-
ObjectMapper mapper = new ObjectMapper();
5555
try {
5656
return mapper.readValue(json.toStringUtf8(), cls);
5757
} catch (JsonParseException | JsonMappingException e) {

0 commit comments

Comments
 (0)