|
43 | 43 | import java.sql.*; |
44 | 44 | import java.text.MessageFormat; |
45 | 45 | import java.util.*; |
| 46 | +import java.util.concurrent.atomic.AtomicBoolean; |
46 | 47 |
|
47 | 48 | import static com.alipay.oceanbase.rpc.location.model.partition.ObPartitionKey.MAX_PARTITION_ELEMENT; |
48 | 49 | import static com.alipay.oceanbase.rpc.location.model.partition.ObPartitionKey.MIN_PARTITION_ELEMENT; |
@@ -216,6 +217,8 @@ public class LocationUtil { |
216 | 217 | private static final int MAX_TABLET_NUMS_EPOCH = Integer.parseInt(System.getProperty("max.table.num.epoch","300")); |
217 | 218 | private static final int TABLE_ENTRY_LOCATION_REFRESH_THRESHOLD = Integer.parseInt(System.getProperty("table.entry.location.refresh.threshold","0")); |
218 | 219 |
|
| 220 | + private static final AtomicBoolean DRIVER_LOADED = new AtomicBoolean(); |
| 221 | + |
219 | 222 | private abstract static class TableEntryRefreshWithPriorityCallback<T> { |
220 | 223 | abstract T execute(ObServerAddr obServerAddr) throws ObTableEntryRefreshException; |
221 | 224 | } |
@@ -309,20 +312,26 @@ private static Connection getMetaRefreshConnection(String url, ObUserAuth sysUA) |
309 | 312 | } |
310 | 313 |
|
311 | 314 | private static void loadJdbcDriver() { |
312 | | - try { |
313 | | - Class.forName("com.mysql.cj.jdbc.Driver"); |
314 | | - return; |
315 | | - } catch (ClassNotFoundException e) { |
316 | | - RUNTIME.info("Class 'com.mysql.cj.jdbc.Driver' not found, " |
317 | | - + "try to load legacy driver class 'com.mysql.jdbc.Driver'"); |
318 | | - } |
| 315 | + if (DRIVER_LOADED.get()) return; |
319 | 316 |
|
320 | | - try { |
321 | | - Class.forName("com.mysql.jdbc.Driver"); |
322 | | - } catch (ClassNotFoundException e) { |
323 | | - RUNTIME.error(LCD.convert("01-00006"), e.getMessage(), e); |
324 | | - throw new ObTableEntryRefreshException(format("fail to find jdbc driver, errMsg=%s", |
325 | | - e.getMessage()), e); |
| 317 | + synchronized (LocationUtil.class) { |
| 318 | + if (DRIVER_LOADED.get()) return; |
| 319 | + |
| 320 | + try { |
| 321 | + Class.forName("com.mysql.cj.jdbc.Driver"); |
| 322 | + DRIVER_LOADED.set(true); |
| 323 | + return; |
| 324 | + } catch (ClassNotFoundException ignored) { |
| 325 | + RUNTIME.debug("MySQL CJ driver not available"); |
| 326 | + } |
| 327 | + |
| 328 | + try { |
| 329 | + Class.forName("com.mysql.jdbc.Driver"); |
| 330 | + DRIVER_LOADED.set(true); |
| 331 | + } catch (ClassNotFoundException e) { |
| 332 | + RUNTIME.error(LCD.convert("01-00006"), "No JDBC driver found"); |
| 333 | + throw new ObTableEntryRefreshException("No JDBC driver available", e); |
| 334 | + } |
326 | 335 | } |
327 | 336 | } |
328 | 337 |
|
|
0 commit comments