Writing by corra on Thursday, 21 of June , 2007 at 11:58 am
E oggi sono 36.
Il fatto che il mio compleanno, da 11 anni, cada 9 giorni prima della scadenza del contratto annuale … e tutti gli anni siamo alle solite con i soliti discorsi e le solite lungaggini… rende questo giorno meno sereno di quello che dovrebbe essere. Oltre a questo la sorte per oggi ha voluto il piccolo Luca con una laringotonsillite e 39 di febbre e, come se non bastasse, la mia autovettura che non ne vuole pių sapere di partire.
Buon compleanno!
Writing by corra on Saturday, 16 of June , 2007 at 12:27 am
Using MEMORY tables in MySQL is very useful; they are stored in memory and they are usually not so big in order to avoid a huge utilization of RAM. They are very fast.
MEMORY tables are often used to store session user data, chat messages and to store small frames of data from a bigger table in order to achieve great performance.
But, if you use them in a replication environment, you can have some problem due to their “volatility”; MEMORY table rows are lost when the server shuts down.
If you restart a slave host for some reason, you will have empty MEMORY tables on it, while the master host will have the correct ones.
How to populate automatically MEMORY tables at slave start up copying data from master host?
We could use something like LOAD TABLE table_name FROM MASTER, but it’s deprecated, so we will use something else.
I have developed a stored procedure you have to create on the slave host in a database called checkmysql.
Using a cursor and the information_schema database, the routine, at every loop, creates a federated table (fed) that points to a MEMORY table on the master host. The CREATE statements are given by the cursor itself. Such queries are executed as dynamic queries using prepared statements. Then, a simple INSERT INTO db.slave_mem_table SELECT * FROM fed (given by the cursor too and executed with a prepared statemtn) will populate the entire table on the slave.
Here’s the code:
DELIMITER //
CREATE PROCEDURE `sync_mem_tables`()
BEGIN
DECLARE creationcmd TEXT;
DECLARE insertquery TEXT;
DECLARE c_memtables CURSOR FOR
SELECT
CONCAT('CREATE TABLE checkmysql.fed(',
GROUP_CONCAT(column_name,' ',column_type)),
') engine=federated connection='mysql://my_user:my_pwd@master_host/',
t.table_schema,
'/',
t.table_name,
''') AS creation_cmd,
CONCAT('INSERT INTO ',t.table_schema,'.',t.table_name,' SELECT * FROM fed') AS insert_query
FROM information_schema.columns c JOIN information_schema.tables t
ON c.table_name=t.table_name AND c.table_schema=t.table_schema
WHERE engine='memory' AND t.table_schema NOT IN ('information_schema')
GROUP BY t.table_schema, t.table_name;
DROP TABLE IF EXISTS checkmysql.fed;
OPEN c_memtables;
BEGIN
DECLARE EXIT HANDLER FOR SQLSTATE '02000' BEGIN END;
LOOP
FETCH c_memtables INTO creationcmd, insertquery;
SET @v_creationcmd = creationcmd;
SET @v_insertquery = insertquery;
PREPARE ps_cc FROM @v_creationcmd;
EXECUTE ps_cc;
DEALLOCATE PREPARE ps_cc;
PREPARE ps_insq FROM @v_insertquery;
EXECUTE ps_insq;
DEALLOCATE PREPARE ps_insq;
DROP TABLE checkmysql.fed;
END LOOP;
END;
CLOSE c_memtables;
END//
DELIMITER ;
Now, the stored procedure sync_mem_table() has to be executed during start up phase of the slave.
To do such a thing you have to create a simple text file initfile.sql (this name is not mandatory) with the CALL statement.
shell# cat /etc/mysql/initfile.sql
call checkmysql.sync_mem_tables();
then you have to add the variable init-file in my.cnf (MySQL configuration file) in the section [mysqld]:
init-file = /etc/mysql/initfile.sql
So, you don’t have to worry about MEMORY tables shutting down a slave host!
Pay attention to:
1 – you have to create the procedure on the slaves, not on the master
2 – the procedure is a Beta release; no warranty for you if you decide to use it on your servers
3 – to populate every MEMORY table on every database, you have to create the procedure as the administrator user
Thanks
Writing by corra on Saturday, 16 of June , 2007 at 12:16 am
Sono a Napoli, pago dalla vacanza fin qui trascorsa con la prole. Giorni indimenticabili con i figli ma stancanti fisicamente; mi riposo di pių quando lavoro. Lavoro! Proprio oggi ho saputo dei primi contatti di Jamo, luci e ombre all’orizzonte come al solito, ma stavolta di prospetta forse qualcosa di pių epocale; nel bene o nel male! Ai posteri l’arida demenza!
Writing by corra on Saturday, 9 of June , 2007 at 10:07 am
Finalmente il tempo č migliorato. Da 3 giorni riusciamo ad andare in spiaggia e a farci il bagno, anche se l’acqua č ancora un po’ freddina.
Luca scopre un sacco di cose nuove ed č praticamente la mascotte dell’intero hotel.
Ieri siamo stati a Procida in barca nel pomeriggio e indovinate dove siamo andati a bere qualcosa? Nel locale dove il compianto Troisi girō delle mitiche scene de “il Postino”. C’era ancora lė la bicicletta utilizzata durante le riprese. Emozionante!
Comments Off Category: Cazzeggio
Writing by corra on Sunday, 3 of June , 2007 at 3:03 pm
Sono al mare, ma finora dopo due giorni niente mare!
Vento, freddo e pioggia ce li siamo portati dal nord. Piove da stamattina e fa veramente freddo! Ne approfitto per un giro in internet, tanto per non perdere l’abitudine.
Si mangia bene!
Ciao a tutti.