* Helping a client in the midst of a 10x growth period.
* Assisting clients in SOX compliance and acquisition readiness.
* Numerous upgrades to 5.1.
* Integrating Percona xtrahotbackup with MySQL-zrm
* Rolling out and tuning Percona 5.1 binaries w/xtraDB plugin
* Using mk-query-digest to help clients get visibility into their systems without turning on invasive logging.
* Security audits and roll-outs (much to the dismay of developer communities across the world! *evil laugh here*)
* Implementation of a new database historical tracker that combines rancid schema and user monitoring, historical versioning and historical volumetrics. (more on this soon!)
* Breakdancing!
* and much much more.
]]>http://dev.mysql.com/tech-resources/articles/testing-partitions-large-db.html
http://datacharmer.blogspot.com/2006/03/mysql-51-improving-archive-performance.html
http://blog.plasticfish.info/categories/tech/mysql/mysql-partitioning/
http://mysqlguy.net/2008/02/20/using-events-manage-table-partitioning-date-wrap
As far as partition management goes, I like the idea of DB events, primarily because you don’t have to worry about crontabs continually slamming a database that’s down, and the events are portable with the database making failovers, migrations and copies that much easier. So, what events do we need to manage partitions? There are three cases that I have been using. Remember, these are for date based partitions (logs, events etc…)
1) Create the next day (or week or month etc…) ’s partition.
2) Purge any partions older than n days.
3) Check that the necessary partition for the current time period exists, and if not, create it on the fly. After all, what happens if the DB is down when the event is supposed to fire? We need to remember the edge cases.
So, in the interest of sharing, here are some events I created. I consider these rudimentary at best. Remember that it isn’t just about functionality. These need to be robust. I’m still planning on adding more error handling and email notifications on failure but I wanted to share. (I’m a giver)
DELIMITER $
CREATE EVENT log_add_partition
ON SCHEDULE
EVERY 1 DAY STARTS ‘2008-02-19 23:59:00′
DO
BEGIN
SET @stmt := CONCAT(
‘ALTER TABLE log ADD PARTITION (’
, ‘PARTITION p’
, DATE_FORMAT( DATE_ADD( CURDATE(), INTERVAL 1 DAY ), ‘%y%m%d’ )
, ‘ VALUES LESS THAN (’
, TO_DAYS( CURDATE() ) + 1
, ‘))’
);
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
$
DELIMITER ;
DELIMITER $
CREATE EVENT log_purge_partition
ON SCHEDULE
EVERY 1 DAY STARTS ‘2008-02-20 00:00:01′
DO
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE part_name VARCHAR(25);
DECLARE cur1 CURSOR FOR
SELECT partition_name
FROM information_schema.partitions
WHERE table_name = ‘log’
AND str_to_date(substr(partition_name from 2), ‘%y%m%d’) < date_sub(now(), INTERVAL 31 day);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
REPEAT
FETCH cur1 INTO part_name;
IF NOT done THEN
SET @stmt := CONCAT(
‘ALTER TABLE log DROP PARTITION ‘
, part_name
);
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
END
$
DELIMITER ;
DELIMITER $
CREATE EVENT log_check_partition
ON SCHEDULE
EVERY 15 MINUTE STARTS ‘2008-02-20 00:00:01′
DO
BEGIN
DECLARE no_rows INT DEFAULT 0;
DECLARE part_name VARCHAR(25);
DECLARE cur1 CURSOR FOR
SELECT partition_name
FROM information_schema.partitions
WHERE table_name = ‘log’
AND str_to_date(substr(partition_name from 2), ‘%y%m%d’) = date_format(now(), ‘%y%m%d’) ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_rows = 1;
OPEN cur1;
FETCH cur1 INTO part_name;
IF no_rows=1 THEN
SET @stmt := CONCAT(
‘ALTER TABLE log ADD PARTITION (’
, ‘PARTITION p’
, DATE_FORMAT ( CURDATE(), ‘%y%m%d’ )
, ‘ VALUES LESS THAN (’
, TO_DAYS( CURDATE() ) + 1
, ‘))’
);
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
CLOSE cur1;
END
$
DELIMITER ;
]]>Mismatch between production and development: Development environments are often neglected, particularly when it comes to OS and DBMS patches. When this happens I consistently find myself in a catch-22 when it is time to do patching in production. With nowhere to test a patch, you have to either go in blind and pray (never the most optimal choice) or neglect the patch, potentially retaining security vulnerabilities or bugs or limiting the access to potential performance or feature improvements. This is especially concerning in complex environments like an Oracle RAC cluster, where patches can be tricky at best. Of course, when working with any features outside of pure DML, you can expect occasional glitches as you introduce change, particularly when working with triggers, procedures, replication, partitioning, or any other complex feature.
Mismatch between MySQL masters and slaves: In MySQL, a lot of pain is taken to allow a slave’s version to be higher than the master’s. This can be a godsend in an upgrade scenario but I wouldn’t rely on this without significant testing. There are numerous features that may function incorrectly in such a scenario, particularly if you are using technologies that are relatively new and thus might be changing significantly between release versions, such as triggers in a 5.0.xx release. My recommendations are simple. If you’re running in day to day operations, you have to maintain consistency in your database versions. If you want to use replication as a way to do a rolling upgrade across a replicated cluster, test it thoroughly in development and make sure you test any procedures, views, triggers and functions against every possible storage engine and partitioned vs. non-partitioned tables. If your application does DDL, then test that as well. I can’t stress this one enough. I’ve had clients who were plagued with replication problems that “magically” went away once we brought their RDBMS and OS versions into sync.
Consistency between functional clusters: When I say functional cluster, I’m talking about a group of databases, usually replicated or physically clustered that support the same application component. In high activity environments, this kind of functional partitioning can be crucial in a scaling strategy. However, lack of discipline can cause these clusters to be built at or migrated to different versions over time. While this may not lead to isaster if your team is disciplined, at it’s best you will find your resources taxed. You’ll need to maintain multiple server builds, you’ll need to do a lot more qa at the data access tier and will require more steps in case you need to trade hardware between functional clusters. If you don’t have rock solid documentation and processes, new servers will be built at different versions, potentially even introduced into production with the wrong version. There will be redo work and troubleshooting that plagues you to varying levels.
To recap, when it comes to the same database in various environments (dev, test, stage etc…) there is no reason to allow for version drift. You must incorporate proper upgrade and deployment processes that, combined with discipline, will maintain that consistency. A proper configuration database can help with this as well. When it comes to a functional cluster, there absolutely must be consistency as well. There is a place for version mismatch in a rolling upgrade strategy, but only here, and only with extensive testing where possible. And finally, if there are valid reasons to have different versions across different functional clusters, be prepared for rigorous discipline and overhead in your administrative processes.
]]>I actually use the archiver in two different client sites. In one situation I have a significant influx of logs representing user activity. As with most data, only a limited window of time is required for analysis in the front-end. So we use archiver to move the older data to a separate datawarehouse. In another environment, we’ve wrapped it into a larger program for redistributing data between shards in a large cluster.
It is an excellent piece of code. I have not run into a bug as of yet, and it is highly configurable in regards to commit frequencies, transaction sizes, retries etc… Additionally, performance is a consideration, scanning the indexes forward only to create efficiency while working with large datasets. As the documentation states:
“The strategy is to find the first row(s), then scan some index forward-only to find more rows efficiently. Each subsequent query should not scan the entire table; it should seek into the index, then scan until it finds more archivable rows. .”
I have been an Oracle DBA for longer than I’d care to think about, and the world of open source is relatively new to me. I am consistently impressed with the open-source community that creates amazingly useful tools such as this. It is a refreshing change from the world of Oracle where everything is in the thousands or more of dollars. If you can support this kind of work through contributions of time or money, I’d strongly suggest you do so.
]]>Here are the three criteria I would recommend focusing on:
Each of these phases must be taken with a viewpoint of the entire business. While all of us OCD architects and administrators would absoutely love to design the perfect solution from scratch, it is not realistic for a company on a shoestring budget or that has no clue about the traffic patterns they’ll be driving. Bottlenecks and pain points need to be looked at as indicators of needs for a) growth or b) improved processes. Taken in this manner, one can create a roadmap for growth based on the individual site’s needs rather than busting the budget immediately or optimizing for scenarios that will never occur.
Of course, there is an exception, and that is pain points that compromise a site’s revenue or reputation. Luckily, in 80 – 90% of the scenarios (potentially more!) these are problems that have already been solved to some degree. In the immortal words of Tyler Durden – You are not a beautiful or unique snowflake. That’s where my job comes in, to help utilize those existing lessons learned before investing in new solutions from scratch. Each phase has them, and that’s where I will be focusing my initial posts.
]]>So, I’ve decided to focus on the strategy of database design and growth as the theme of my blogging. There will also be some tactical posts, particularly in regards to tools, scenarios and solutions that I’ve come across. My goal with this? To create something that my customers and other web-businesses can use to encourage their creative juices and to be more proactive with their own database infrastructures.
]]>