提交 b7a0163d authored 作者: Thomas Mueller's avatar Thomas Mueller

INFORMATION_SCHEMA.SESSIONS: the start time of a SQL statement is no longer set…

INFORMATION_SCHEMA.SESSIONS: the start time of a SQL statement is no longer set in each case. It is only set for long running statements.
上级 0baa19ed
......@@ -121,14 +121,14 @@ public abstract class Command implements CommandInterface {
* @return the result set
*/
public ResultInterface executeQuery(int maxrows, boolean scrollable) {
startTime = System.currentTimeMillis();
startTime = 0;
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
session.waitIfExclusiveModeEnabled();
synchronized (sync) {
try {
database.checkPowerOff();
session.setCurrentCommand(this, startTime);
session.setCurrentCommand(this);
return query(maxrows);
} catch (DbException e) {
e.addSQL(sql);
......@@ -144,7 +144,9 @@ public abstract class Command implements CommandInterface {
* Start the stopwatch.
*/
void start() {
startTime = System.currentTimeMillis();
if (trace.isInfoEnabled()) {
startTime = System.currentTimeMillis();
}
}
/**
......@@ -161,7 +163,7 @@ public abstract class Command implements CommandInterface {
private void stop() {
session.closeTemporaryResults();
session.setCurrentCommand(null, 0);
session.setCurrentCommand(null);
if (!isTransactional()) {
session.commit(true);
} else if (session.getAutoCommit()) {
......@@ -183,7 +185,7 @@ public abstract class Command implements CommandInterface {
}
public int executeUpdate() {
long start = startTime = System.currentTimeMillis();
long start = 0;
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
session.waitIfExclusiveModeEnabled();
......@@ -191,7 +193,7 @@ public abstract class Command implements CommandInterface {
database.beforeWriting();
synchronized (sync) {
int rollback = session.getLogId();
session.setCurrentCommand(this, startTime);
session.setCurrentCommand(this);
try {
while (true) {
database.checkPowerOff();
......@@ -200,6 +202,10 @@ public abstract class Command implements CommandInterface {
} catch (DbException e) {
if (e.getErrorCode() == ErrorCode.CONCURRENT_UPDATE_1) {
long now = System.currentTimeMillis();
if (start == 0) {
start = now;
continue;
}
if (now - start > session.getLockTimeout()) {
throw DbException.get(ErrorCode.LOCK_TIMEOUT_1, e.getCause(), "");
}
......
......@@ -64,7 +64,6 @@ public class CommandContainer extends Command {
public int update() {
recompileIfRequired();
// TODO query time: should keep lock time separate from running time
start();
prepared.checkParameters();
int updateCount = prepared.update();
......@@ -74,7 +73,6 @@ public class CommandContainer extends Command {
public ResultInterface query(int maxrows) {
recompileIfRequired();
// TODO query time: should keep lock time separate from running time
start();
prepared.checkParameters();
ResultInterface result = prepared.query(maxrows);
......
......@@ -81,7 +81,7 @@ public class Session extends SessionWithState {
private boolean allowLiterals;
private String currentSchemaName;
private String[] schemaSearchPath;
private String traceModuleName;
private Trace trace;
private HashMap<String, Value> unlinkLobMap;
private int systemIdentifier;
private HashMap<String, Procedure> procedures;
......@@ -699,13 +699,15 @@ public class Session extends SessionWithState {
}
public Trace getTrace() {
if (traceModuleName == null) {
traceModuleName = Trace.JDBC + "[" + id + "]";
if (trace != null && !closed) {
return trace;
}
String traceModuleName = Trace.JDBC + "[" + id + "]";
if (closed) {
return new TraceSystem(null).getTrace(traceModuleName);
}
return database.getTrace(traceModuleName);
trace = database.getTrace(traceModuleName);
return trace;
}
public void setLastIdentity(Value last) {
......@@ -836,6 +838,9 @@ public class Session extends SessionWithState {
* Wait for some time if this session is throttled (slowed down).
*/
public void throttle() {
if (currentCommandStart == 0) {
currentCommandStart = System.currentTimeMillis();
}
if (throttle == 0) {
return;
}
......@@ -858,11 +863,12 @@ public class Session extends SessionWithState {
* @param command the command
* @param startTime the time execution has been started
*/
public void setCurrentCommand(Command command, long startTime) {
public void setCurrentCommand(Command command) {
this.currentCommand = command;
this.currentCommandStart = startTime;
if (queryTimeout > 0 && startTime != 0) {
cancelAt = startTime + queryTimeout;
if (queryTimeout > 0 && command != null) {
long now = System.currentTimeMillis();
currentCommandStart = now;
cancelAt = now + queryTimeout;
}
}
......
......@@ -1495,9 +1495,14 @@ public class MetaTable extends Table {
}
case SESSIONS: {
boolean admin = session.getUser().isAdmin();
long now = System.currentTimeMillis();
for (Session s : database.getSessions(false)) {
if (admin || s == session) {
Command command = s.getCurrentCommand();
long start = s.getCurrentCommandStart();
if (start == 0) {
start = now;
}
add(rows,
// ID
"" + s.getId(),
......@@ -1508,7 +1513,7 @@ public class MetaTable extends Table {
// STATEMENT
command == null ? null : command.toString(),
// STATEMENT_START
new Timestamp(s.getCurrentCommandStart()).toString()
new Timestamp(start).toString()
);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论