- PUBLIC ATTRIBUTES
- PUBLIC METHODS
- SEE ALSO
- COPYRIGHT AND LICENSE
ShardedKV::Storage::MySQL - MySQL storage backend for ShardedKV
use ShardedKV; use ShardedKV::Storage::MySQL; ... create ShardedKV... my $storage = ShardedKV::Storage::MySQL->new( ); ... put storage into ShardedKV... # values are array references $skv->set("foo", ["bar"]); my $value_ref = $skv->get("foo");
ShardedKV storage backend that
DBD::mysql to store data in a MySQL table.
Each shard (==
ShardedKV::Storage::MySQL object) is represented by a single table in some schema on some database server.
A callback that must be supplied at object creation time. The storage object will invoke the callback whenever it needs to get a NEW mysql database handle. This means when:
- first connecting - "MySQL server has gone away" => reconnect
The callback allows users to hook into the connection logic to implement things such as connection caching. If you do use connection caching, then do assert that the dbh is alive (eg. using
$dbh->ping() before returning a cached connection.
A callback that should return a unique string that represents the endpoint. In most cases this should be a hostname to allow for debugging connection issues.
The callback allows users to hook into the connection logic and update the string that represents the particular endpoint that this storage instance represents.
This is the public attribute holding a MySQL database handle (which was created using the
mysql_connector). Do not supply this at object creation.
The name of the table that represents this shard. Must be supplied at object creation.
The name of the column to be used for the key. If
ShardedKV::Storage::MySQL creates the shard table for you, then this column is also used as the primary key unless
auto_increment_col_name is set (see below).
There can only be one key column.
Defaults to 'keystr'.
The MySQL type of the key column.
Defaults to 'VARBINARY(16) NOT NULL'.
The name of the column to be used for the auto-increment pimrary key. This is a virtually unused (by ShardedKV) column that, IF DEFINED, will be used as an auto-increment primary key. It is not the column used to fetch rows by, but rather facilitates faster insertion of new records by allowing append instead of insertion at random order within the PK tree.
ShardedKV::Storage::MySQL creates the shard table for you, then this column is also used as the primary key.
There can only be one auto-increment key column.
Defaults to 'id'.
The MySQL type of the auto increment column.
Defaults to 'BIGINT UNSIGNED NOT NULL AUTO_INCREMENT'.
An array reference containing the names of all value columns in the shard table. Needs to contain at least one value column.
An array reference containing the MySQL types of each value column given in
['MEDIUMBLOB NOT NULL', 'TIMESTAMP NOT NULL'].
A string that is included verbatim after the PRIMARY KEY line of the CREATE TABLE IF NOT EXISTS statement that this class generates. This can be used to add additional indexes to the shard tables, such as indexes on the last modification (for expiration from the database, not handled by ShardedKV).
The maximum number of reconnect attempts that the storage object should perform if the MySQL server has gone away. Reconnects are done with exponential back-off (see below).
Defaults to 5.
The base interval for reconnection attempts. Do note that exponential reconnect back-off is used, so if the base reconnect_interval is 1 second, then the first reconnect attempt is done immediately, the second after one second, the third after two seconds, the fourth after four seconds, and so on.
Default: 1 second
Can also be fractional seconds.
This method will generate a
CREATE TABLE statement from the various properties of the storage object and execute it on the MySQL server to prepare the shard table.
Explicitly drops the MySQL connection object and calls back into the provided connect handler to get a new connection.
Steffen Mueller <firstname.lastname@example.org>
Nick Perez <email@example.com>
This software is copyright (c) 2013 by Steffen Mueller.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.