diff options
author | Jerry Kuch <jerryk@vmware.com> | 2011-03-01 13:11:23 -0800 |
---|---|---|
committer | Jerry Kuch <jerryk@vmware.com> | 2011-03-01 13:11:23 -0800 |
commit | 5506a0fad18cf5485662231abe77d1cd4ed24d97 (patch) | |
tree | a2f635695660bb14cb0de47b47e6aef8f59807b3 | |
parent | 6cab27e4a57f6ab9aef2cd37373749cc2b7f5a5c (diff) | |
download | rabbitmq-server-5506a0fad18cf5485662231abe77d1cd4ed24d97.tar.gz |
Delete MySQL data for a given queue_name.
-rw-r--r-- | sql_scripts/setup_all.sql | 5 | ||||
-rw-r--r-- | src/mysql_helper.erl | 18 |
2 files changed, 17 insertions, 6 deletions
diff --git a/sql_scripts/setup_all.sql b/sql_scripts/setup_all.sql index e50569db..ad02b6a7 100644 --- a/sql_scripts/setup_all.sql +++ b/sql_scripts/setup_all.sql @@ -29,7 +29,7 @@ CREATE INDEX q_name_index ON q(queue_name); -- state, so that they can be recovered after a crash. They are updated -- on all MySQL transactions that update them in the in-RAM state. CREATE TABLE IF NOT EXISTS - n (queue_name VARCHAR(256) NOT NULL, -- Maybe FK this later? + n (queue_name VARCHAR(256) NOT NULL, next_seq_id BIGINT UNSIGNED NOT NULL, -- next seq_id to gen PRIMARY KEY(queue_name)) ENGINE=InnoDB; @@ -40,7 +40,10 @@ CREATE TABLE IF NOT EXISTS -- the former if an ack is pending. CREATE TABLE IF NOT EXISTS p (seq_id BIGINT UNSIGNED NOT NULL, + queue_name VARCHAR(256) NOT NULL, -- (BUGBUG: max size?) m MEDIUMBLOB, PRIMARY KEY(seq_id)) ENGINE=InnoDB; CREATE INDEX p_seq_id_index ON p(seq_id); +CREATE INDEX p_queue_name_index ON p(queue_name); + diff --git a/src/mysql_helper.erl b/src/mysql_helper.erl index 5c52bf1c..733f122b 100644 --- a/src/mysql_helper.erl +++ b/src/mysql_helper.erl @@ -42,7 +42,6 @@ ensure_connection_pool() -> rabbit_log:info("Ensuring connection pool ~p exists~n", [?RABBIT_DB_POOL_NAME]), - %% TODO: Args 2 through 7 (or 8?) should be config options w/ defaults try emysql:add_pool(?RABBIT_DB_POOL_NAME, ?RABBIT_DB_POOL_SIZE, ?RABBIT_DB_USERNAME, @@ -62,15 +61,24 @@ prepare_mysql_statements() -> %% are parametrizable, and thus prone to injection attacks and the %% like do seem to be there. Statements = [{insert_q_stmt,<<"INSERT INTO q(queue_name, m) VALUES(?,?)">>}, - {insert_p_stmt,<<"INSERT INTO p() VALUES()">>}, - {insert_n_stmt,<<"INSERT INTO n() VALUES()">>}], + {insert_p_stmt, + <<"INSERT INTO p(seq_id, queue_name, m) VALUES(?,?,?)">>}, + {insert_n_stmt, + <<"INSERT INTO n(queue_name, next_seq_id) VALUES(?,?)">>}, + {delete_q_stmt,<<"DELETE FROM q WHERE queue_name = ?">>}, + {delete_p_stmt,<<"DELETE FROM p WHERE queue_name = ?">>}, + {delete_n_stmt,<<"DELETE FROM n WHERE queue_name = ?">>}], [ emysql:prepare(StmtAtom, StmtBody) || {StmtAtom, StmtBody} <- Statements ]. delete_queue_data(QueueName) -> + %% TODO: Error checking... emysql:execute(?RABBIT_DB_POOL_NAME, <<"START TRANSACTION">>), - %% TODO [jerryk]: Implement table flush transaction ops to clear queue. - rabbit_log:info("NOT YET IMPLEMENTED!"), + [ emysql:execute(?RABBIT_DB_POOL_NAME, + Stmt, + [QueueName]) || Stmt <- [delete_q_stmt, + delete_p_stmt, + delete_n_stmt] ], emysql:execute(?RABBIT_DB_POOL_NAME, <<"COMMIT">>), ok. |