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