From 361abcf230197c71e21a6ef37bc5e8ce058fb494 Mon Sep 17 00:00:00 2001 From: zixi0825 Date: Sat, 19 Oct 2024 11:25:19 +0800 Subject: [PATCH] [Fix][Server] Fix datatype convert error --- .../common/enums/DataVinesDataType.java | 9 +++++---- .../datavines/registry/plugin/MysqlMutex.java | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/datavines-common/src/main/java/io/datavines/common/enums/DataVinesDataType.java b/datavines-common/src/main/java/io/datavines/common/enums/DataVinesDataType.java index fd3e7bfce..13426f631 100644 --- a/datavines-common/src/main/java/io/datavines/common/enums/DataVinesDataType.java +++ b/datavines-common/src/main/java/io/datavines/common/enums/DataVinesDataType.java @@ -119,11 +119,12 @@ public static DataVinesDataType getType(String type) { } type = type.toLowerCase(); - if (type.contains("int") || "decimal".equalsIgnoreCase(type) - || type.contains("float") || "double".equalsIgnoreCase(type) - || type.contains("number") || type.contains("numeric") || type.contains("real") || type.contains("serial")) { + if (type.contains("int") || type.contains("decimal") + || type.contains("float") || type.contains("double") + || type.contains("number") || type.contains("numeric") + || type.contains("real") || type.contains("serial")) { return NUMERIC_TYPE; - } else if (type.contains("char") || "blob".equalsIgnoreCase(type) || type.contains("text")) { + } else if (type.contains("char") || type.contains("blob") || type.contains("text")) { return STRING_TYPE; } else if (type.contains("time") || type.contains("date")) { return DATE_TIME_TYPE; diff --git a/datavines-registry/datavines-registry-plugins/datavines-registry-mysql/src/main/java/io/datavines/registry/plugin/MysqlMutex.java b/datavines-registry/datavines-registry-plugins/datavines-registry-mysql/src/main/java/io/datavines/registry/plugin/MysqlMutex.java index 24a3a5e7e..218490709 100644 --- a/datavines-registry/datavines-registry-plugins/datavines-registry-mysql/src/main/java/io/datavines/registry/plugin/MysqlMutex.java +++ b/datavines-registry/datavines-registry-plugins/datavines-registry-mysql/src/main/java/io/datavines/registry/plugin/MysqlMutex.java @@ -27,6 +27,7 @@ import java.sql.*; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -36,7 +37,7 @@ public class MysqlMutex { public static final long LOCK_ACQUIRE_INTERVAL = 1000; - private final long expireTimeWindow = 5000; + private final long expireTimeWindow = 600; private Connection connection; @@ -44,13 +45,13 @@ public class MysqlMutex { private final ServerInfo serverInfo; - private final Map lockHoldMap; + private final ConcurrentHashMap lockHoldMap; public MysqlMutex(Connection connection, Properties properties) throws SQLException { this.connection = connection; this.properties = properties; this.serverInfo = new ServerInfo(NetUtils.getHost(), Integer.valueOf((String) properties.get("server.port"))); - this.lockHoldMap = new HashMap<>(); + this.lockHoldMap = new ConcurrentHashMap<>(); ScheduledExecutorService lockTermUpdateThreadPool = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("RegistryLockRefreshThread").setDaemon(true).build()); @@ -78,6 +79,11 @@ public boolean acquire(String lockKey, long time) { count = 0; } catch (SQLException e) { log.error("Acquire the lock error, {}, try again!", e.getLocalizedMessage()); + try { + clearExpireLock(); + } catch (SQLException ex) { + log.error("clear expire lock error : ", ex); + } ThreadUtils.sleep(LOCK_ACQUIRE_INTERVAL); count--; } @@ -137,9 +143,10 @@ private void executeDelete(String key) throws SQLException { checkConnection(); PreparedStatement preparedStatement = connection.prepareStatement("delete from dv_registry_lock where lock_key = ?"); preparedStatement.setString(1, key); - preparedStatement.executeUpdate(); + if (preparedStatement.executeUpdate() > 0) { + lockHoldMap.remove(key); + } preparedStatement.close(); - lockHoldMap.remove(key); } private boolean isExists(String key, ServerInfo serverInfo) throws SQLException {