Jay Pipes wrote:
Baron Schwartz wrote:
Look at the Percona patches to MySQL for
quick wins -- add things like thread/session ID, for example.
I can get this done today. It's an easy win.
Baron, based on your request, I have added Session ID to the command log.
We also have Server ID and the Global Transaction ID, as shown in the
output below (though the trx id isn't currently working properly for DDL
statements...)
Please do let me know any others important attributes that should be added.
== demonstration ==
So, in one terminal, I start up drizzled with replication enabled:
jpi...@serialcoder:~/repos/drizzle/replication/tests$ ./dtr --start-and-exit
--mysqld=--default-replicator-enable --mysqld=--command-log-enable
Logging: ./dtr --start-and-exit --mysqld=--default-replicator-enable
--mysqld=--command-log-enable
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins.
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
090811 15:35:18 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
090811 15:35:18 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
090811 15:35:18 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
090811 15:35:19 InnoDB Plugin 1.0.3 started; log sequence number 0
090811 15:35:19 InnoDB: Starting shutdown...
090811 15:35:20 InnoDB: Shutdown completed; log sequence number 46409
MySQL Version 2009.08.1087
Using MTR_BUILD_THREAD = -69.4
Using MASTER_MYPORT = 9306
Using MASTER_MYPORT1 = 9307
Using SLAVE_MYPORT = 9308
Using SLAVE_MYPORT1 = 9309
Using SLAVE_MYPORT2 = 9310
Killing Possible Leftover Processes
Removing Stale Files
Creating Directories
=======================================================
DEFAULT STORAGE ENGINE: innodb
TEST RESULT TIME (ms)
-------------------------------------------------------
Servers started, exiting
I then open two terminals and connect to drizzled with a client in each:
jpi...@serialcoder:~/repos/drizzle/replication/tests$ ../client/drizzle
--port=9306
Welcome to the Drizzle client.. Commands end with ; or \g.
Your Drizzle connection id is 2
Server version: 2009.08.1087 Source distribution (replication)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
drizzle> use test
Database changed
I then issue a variety of commands in each of the two clients,
alternating between the two...
Then, I check the log in the first terminal:
jpi...@serialcoder:~/repos/drizzle/replication/tests$ ../drizzled/message/command_reader var/master-data/command.log
/* Timestamp: 1250019425976098 */
/* SERVER ID: 1 TRX ID: 0 SESSION ID: 1 */ create table t1 (id int not null,
padding varchar(20) null);
/* Timestamp: 1250019441860739 */
/* SERVER ID: 1 TRX ID: 0 SESSION ID: 2 */ create table t2 (id int not null,
padding varchar(20) null);
/* Timestamp: 1250019466432980 */
/* SERVER ID: 1 TRX ID: 14 SESSION ID: 2 */ INSERT INTO `test`.`t2` (`id`, `padding`) VALUES
("1", "aaa");
/* Timestamp: 1250019476550373 */
/* SERVER ID: 1 TRX ID: 15 SESSION ID: 2 */ INSERT INTO `test`.`t2` (`id`, `padding`) VALUES
("2", "bbb");
/* Timestamp: 1250019488252589 */
/* SERVER ID: 1 TRX ID: 16 SESSION ID: 1 */ INSERT INTO `test`.`t1` (`id`, `padding`) VALUES
("1", "xxx");
/* Timestamp: 1250019492882562 */
/* SERVER ID: 1 TRX ID: 17 SESSION ID: 1 */ INSERT INTO `test`.`t1` (`id`, `padding`) VALUES
("2", "yyy");
Voila...session IDs are in the log :)
It was about 10 lines of code...here is the total diff:
=== modified file 'drizzled/message/command_reader.cc'
--- drizzled/message/command_reader.cc 2009-08-10 19:18:08 +0000
+++ drizzled/message/command_reader.cc 2009-08-11 19:18:44 +0000
@@ -160,7 +160,12 @@
message::TransactionContext trx= command.transaction_context();
- cout << "/* SID: " << trx.server_id() << " XID: " << trx.transaction_id() << " */ ";
+ cout << "/* SERVER ID: " << trx.server_id() << " TRX ID: " <<
trx.transaction_id();
+
+ if (command.has_session_id())
+ cout << " SESSION ID: " << command.session_id();
+
+ cout << " */ ";
switch (command.type())
{
=== modified file 'drizzled/message/replication.proto'
--- drizzled/message/replication.proto 2009-07-29 23:25:20 +0000
+++ drizzled/message/replication.proto 2009-08-11 19:15:52 +0000
@@ -77,6 +77,8 @@
optional InsertRecord insert_record = 7;
optional DeleteRecord delete_record = 8;
optional UpdateRecord update_record = 9;
+
+ optional uint32 session_id = 30; /* Optionally stores the ID of the session
which executed this command */
}
message Transaction
=== modified file 'drizzled/replication_services.cc'
--- drizzled/replication_services.cc 2009-08-10 19:07:57 +0000
+++ drizzled/replication_services.cc 2009-08-11 19:21:05 +0000
@@ -177,6 +177,8 @@
message::TransactionContext *trx= in_command.mutable_transaction_context();
trx->set_server_id(in_session->getServerId());
trx->set_transaction_id(in_session->getTransactionId());
+
+ in_command.set_session_id((uint32_t) in_session->getSessionId());
}
void ReplicationServices::startTransaction(Session *in_session)
=== modified file 'drizzled/session.cc'
--- drizzled/session.cc 2009-08-05 08:02:52 +0000
+++ drizzled/session.cc 2009-08-11 19:24:26 +0000
@@ -1696,13 +1696,13 @@
}
/**
- Return the thread id of a user thread
- @param session user thread
- @return thread id
+ Return the session id of a user session
+ @param pointer to Session object
+ @return session's id
*/
extern "C" unsigned long session_get_thread_id(const Session *session)
{
- return((unsigned long)session->thread_id);
+ return (unsigned long) session->getSessionId();
}
=== modified file 'drizzled/session.h'
--- drizzled/session.h 2009-08-05 22:00:50 +0000
+++ drizzled/session.h 2009-08-11 19:22:48 +0000
@@ -838,6 +838,12 @@
return strlen(query);
}
+ /** Accessor method returning the session's ID. */
+ inline uint64_t getSessionId() const
+ {
+ return thread_id;
+ }
+
/** Accessor method returning the server's ID. */
inline uint32_t getServerId() const
{
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp