forked from MyCATApache/Mycat-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MyCATApache#107 from sohudo/master
sqlite并发写问题
- Loading branch information
Showing
7 changed files
with
271 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.mycat.web.task.common; | ||
|
||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.dao.Dao; | ||
|
||
public class SqliteStore { | ||
private volatile static SqliteStore sqliteStore = null; | ||
private SqliteStore(){}; | ||
|
||
public static SqliteStore getInstance(){ | ||
if(sqliteStore == null){ | ||
synchronized (SqliteStore.class) { | ||
if(sqliteStore == null){ | ||
sqliteStore = new SqliteStore(); | ||
} | ||
} | ||
} | ||
return sqliteStore; | ||
} | ||
|
||
public synchronized void insert(Dao dao, String namespace,String statement, Map<String,Object> paramData){ | ||
dao.insert(namespace, statement, paramData); | ||
} | ||
|
||
public synchronized void delete(Dao dao, String namespace,String statement, Map<String,Object> paramData){ | ||
dao.delete(namespace, statement, paramData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,42 @@ | ||
package org.mycat.web.task.server; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.core.SpringApplicationContext; | ||
import org.mycat.web.service.ShowService; | ||
import org.mycat.web.task.common.ITask; | ||
import org.mycat.web.util.DataSourceUtils; | ||
import org.hx.rainbow.common.util.DateUtil; | ||
/* | ||
* 异步持久化mycat中数据 | ||
*/ | ||
|
||
public class SyncSysSql implements ITask { | ||
|
||
private static final String NAMESPACE = "SYSSQL"; | ||
|
||
private static final String SYSPARAM_NAMESPACE = "SYSSHOW"; | ||
|
||
@Override | ||
public void excute(String dbName, Date nowDate) { | ||
//System.out.println("持久化mycat中数据:"+dbName); | ||
// if (!DataSourceUtils.getInstance().isMycatManger(dbName)){ | ||
// return ; | ||
// } | ||
//System.out.println("持久化mycat中数据开始:"+dbName); | ||
ShowService showService = (ShowService)SpringApplicationContext.getBean("showService"); | ||
List<Map<String,Object>> list = showService.getDao().query(dbName, SYSPARAM_NAMESPACE, "sql"); | ||
for(Map<String,Object> entry : list){ | ||
entry.put("START_TM", DateUtil.toDateTimeString(new Date((long) entry.get("START_TIME")))); | ||
entry.put("DB_NAME", DataSourceUtils.getInstance().getDbName(dbName)); | ||
//Map<String,Object> entity = showService.getDao().get(NAMESPACE, "query",entry); | ||
//if(entity == null){ | ||
showService.getDao().insert(NAMESPACE, "insert", entry); | ||
//} | ||
} | ||
} | ||
|
||
} | ||
package org.mycat.web.task.server; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.core.SpringApplicationContext; | ||
import org.mycat.web.service.ShowService; | ||
import org.mycat.web.task.common.ITask; | ||
import org.mycat.web.task.common.SqliteStore; | ||
import org.mycat.web.util.DataSourceUtils; | ||
import org.hx.rainbow.common.util.DateUtil; | ||
/* | ||
* 异步持久化mycat中数据 | ||
*/ | ||
|
||
public class SyncSysSql implements ITask { | ||
|
||
private static final String NAMESPACE = "SYSSQL"; | ||
|
||
private static final String SYSPARAM_NAMESPACE = "SYSSHOW"; | ||
|
||
@Override | ||
public void excute(String dbName, Date nowDate) { | ||
//System.out.println("持久化mycat中数据:"+dbName); | ||
// if (!DataSourceUtils.getInstance().isMycatManger(dbName)){ | ||
// return ; | ||
// } | ||
//System.out.println("持久化mycat中数据开始:"+dbName); | ||
ShowService showService = (ShowService)SpringApplicationContext.getBean("showService"); | ||
List<Map<String,Object>> list = showService.getDao().query(dbName, SYSPARAM_NAMESPACE, "sql"); | ||
for(Map<String,Object> entry : list){ | ||
entry.put("START_TM", DateUtil.toDateTimeString(new Date((long) entry.get("START_TIME")))); | ||
entry.put("DB_NAME", DataSourceUtils.getInstance().getDbName(dbName)); | ||
//Map<String,Object> entity = showService.getDao().get(NAMESPACE, "query",entry); | ||
//if(entity == null){ | ||
SqliteStore.getInstance().insert(showService.getDao(), NAMESPACE, "insert", entry); | ||
//} | ||
} | ||
} | ||
|
||
} |
85 changes: 43 additions & 42 deletions
85
src/main/java/org/mycat/web/task/server/SyncSysSqlhigh.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
package org.mycat.web.task.server; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.core.SpringApplicationContext; | ||
import org.hx.rainbow.common.util.DateUtil; | ||
import org.mycat.web.service.ShowService; | ||
import org.mycat.web.task.common.ITask; | ||
import org.mycat.web.util.DataSourceUtils; | ||
|
||
/* | ||
* 异步持久化mycat中数据 | ||
*/ | ||
|
||
public class SyncSysSqlhigh implements ITask { | ||
|
||
private static final String NAMESPACE = "SYSSQLHIGH"; | ||
|
||
private static final String SYSPARAM_NAMESPACE = "SYSSHOW"; | ||
|
||
@Override | ||
public void excute(String dbName, Date nowDate) { | ||
// if (!DataSourceUtils.getInstance().isMycatManger(dbName)){ | ||
// return ; | ||
// } | ||
ShowService showService = (ShowService)SpringApplicationContext.getBean("showService"); | ||
List<Map<String,Object>> list = showService.getDao().query(dbName, SYSPARAM_NAMESPACE, "sqlhigh"); | ||
for(Map<String,Object> entry : list){ | ||
entry.put("LAST_TM", DateUtil.toDateTimeString(new Date((long) entry.get("LAST_TIME")))); | ||
entry.put("DB_NAME", DataSourceUtils.getInstance().getDbName(dbName)); | ||
//Map<String,Object> entity = showService.getDao().get(NAMESPACE, "query",entry); | ||
//if(entity == null){ | ||
showService.getDao().insert(NAMESPACE, "insert", entry); | ||
//} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
package org.mycat.web.task.server; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.core.SpringApplicationContext; | ||
import org.hx.rainbow.common.util.DateUtil; | ||
import org.mycat.web.service.ShowService; | ||
import org.mycat.web.task.common.ITask; | ||
import org.mycat.web.task.common.SqliteStore; | ||
import org.mycat.web.util.DataSourceUtils; | ||
|
||
/* | ||
* 异步持久化mycat中数据 | ||
*/ | ||
|
||
public class SyncSysSqlhigh implements ITask { | ||
|
||
private static final String NAMESPACE = "SYSSQLHIGH"; | ||
|
||
private static final String SYSPARAM_NAMESPACE = "SYSSHOW"; | ||
|
||
@Override | ||
public void excute(String dbName, Date nowDate) { | ||
// if (!DataSourceUtils.getInstance().isMycatManger(dbName)){ | ||
// return ; | ||
// } | ||
ShowService showService = (ShowService)SpringApplicationContext.getBean("showService"); | ||
List<Map<String,Object>> list = showService.getDao().query(dbName, SYSPARAM_NAMESPACE, "sqlhigh"); | ||
for(Map<String,Object> entry : list){ | ||
entry.put("LAST_TM", DateUtil.toDateTimeString(new Date((long) entry.get("LAST_TIME")))); | ||
entry.put("DB_NAME", DataSourceUtils.getInstance().getDbName(dbName)); | ||
//Map<String,Object> entity = showService.getDao().get(NAMESPACE, "query",entry); | ||
//if(entity == null){ | ||
SqliteStore.getInstance().insert(showService.getDao(), NAMESPACE, "insert", entry); | ||
//} | ||
} | ||
|
||
|
||
} | ||
|
||
} |
94 changes: 44 additions & 50 deletions
94
src/main/java/org/mycat/web/task/server/SyncSysSqlslow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,44 @@ | ||
package org.mycat.web.task.server; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.core.SpringApplicationContext; | ||
import org.hx.rainbow.common.util.DateUtil; | ||
import org.mycat.web.service.ShowService; | ||
import org.mycat.web.task.common.ITask; | ||
import org.mycat.web.util.DataSourceUtils; | ||
import org.mycat.web.util.MailUtil; | ||
|
||
/* | ||
* 异步持久化mycat中数据 | ||
*/ | ||
|
||
public class SyncSysSqlslow implements ITask { | ||
|
||
private static final String NAMESPACE = "SYSSQLSLOW"; | ||
|
||
private static final String SYSPARAM_NAMESPACE = "SYSSHOW"; | ||
|
||
@Override | ||
public void excute(String dbName, Date nowDate) { | ||
// if (!DataSourceUtils.getInstance().isMycatManger(dbName)){ | ||
// return ; | ||
// } | ||
ShowService showService = (ShowService)SpringApplicationContext.getBean("showService"); | ||
List<Map<String,Object>> list = showService.getDao().query(dbName, SYSPARAM_NAMESPACE, "sqlslow"); | ||
for(Map<String,Object> entry : list){ | ||
//entry.put("START_TM", new Date((long) entry.get("START_TIME"))); | ||
entry.put("START_TM", DateUtil.toDateTimeString(new Date((long) entry.get("START_TIME")))); | ||
entry.put("DB_NAME", DataSourceUtils.getInstance().getDbName(dbName)); | ||
//Map<String,Object> entity = showService.getDao().get(NAMESPACE, "query",entry); | ||
//if(entity == null){ | ||
showService.getDao().insert(NAMESPACE, "insert", entry); | ||
//} | ||
|
||
|
||
try { | ||
MailUtil.send("监控到慢SQL", (String)entry.get("SQL")); | ||
} catch (Exception e) { | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
package org.mycat.web.task.server; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.hx.rainbow.common.core.SpringApplicationContext; | ||
import org.hx.rainbow.common.util.DateUtil; | ||
import org.mycat.web.service.ShowService; | ||
import org.mycat.web.task.common.ITask; | ||
import org.mycat.web.task.common.SqliteStore; | ||
import org.mycat.web.util.DataSourceUtils; | ||
|
||
/* | ||
* 异步持久化mycat中数据 | ||
*/ | ||
|
||
public class SyncSysSqlslow implements ITask { | ||
|
||
private static final String NAMESPACE = "SYSSQLSLOW"; | ||
|
||
private static final String SYSPARAM_NAMESPACE = "SYSSHOW"; | ||
|
||
@Override | ||
public void excute(String dbName, Date nowDate) { | ||
// if (!DataSourceUtils.getInstance().isMycatManger(dbName)){ | ||
// return ; | ||
// } | ||
ShowService showService = (ShowService)SpringApplicationContext.getBean("showService"); | ||
List<Map<String,Object>> list = showService.getDao().query(dbName, SYSPARAM_NAMESPACE, "sqlslow"); | ||
for(Map<String,Object> entry : list){ | ||
//entry.put("START_TM", new Date((long) entry.get("START_TIME"))); | ||
entry.put("START_TM", DateUtil.toDateTimeString(new Date((long) entry.get("START_TIME")))); | ||
entry.put("DB_NAME", DataSourceUtils.getInstance().getDbName(dbName)); | ||
//Map<String,Object> entity = showService.getDao().get(NAMESPACE, "query",entry); | ||
//if(entity == null){ | ||
SqliteStore.getInstance().insert(showService.getDao(), NAMESPACE, "insert", entry); | ||
//} | ||
} | ||
|
||
|
||
} | ||
|
||
} |
Oops, something went wrong.