Top Utility for Cassandra Clusters – cass_top

DataStax’s OpsCenter is pretty, but sometimes you don’t want to chop holes in your firewall for the server and agents.

So here’s cass_top. It works like top, but colorizes the output of nodetool status. It also lets you build nodetool commands using menus, run and log the output.

What’s especially nice is that it uses bash (no python required), and uses minimal screen real estate, so you can view all your clusters on one monitor using eterms.

$ cass_top 10.0.1.140


cass_top Screenshot
cass_top Help Screenshot

Please leave a comment with your suggestions.

github: Cassandra Top cass_top

Posted in Cassandra, Linux, Storage, Tech, Toys | Leave a comment

Perl Clients for Cassandra

The Perl module Net::Async::CassandraCQL supports CQL3 and comes with a few sample programs and several tests.

To get the perldoc sample code to work:

  1. Perl 5.10 or higher is required. If you’re using Redhat 5 or CentOS 5, then use perlbrew or source to install a user-local version of perl (you should leave the vendor perl alone)
  2. install the Perl Cassandra client modules and dependencies with path-to-new-perl/bin/cpan Net::Async::CassandraCQL
  3. run the CREATE commands:
$ cqlsh
create keyspace if not exists "my_keyspace" with replication = { 
   'class' : 'SimpleStrategy', 'replication_factor' : 3
};
create table my_keyspace.numbers (v int primary key);
quit
# Program: cass_sample.pl
# Note: includes bug fixes for Net::Async::CassandraCQL 0.11 version

use strict;
use warnings;
use 5.10.0;

use IO::Async::Loop;
use Net::Async::CassandraCQL;
use Protocol::CassandraCQL qw( CONSISTENCY_QUORUM );

 my $loop = IO::Async::Loop->new;

 my $cass = Net::Async::CassandraCQL->new(
    host => "localhost",
    keyspace => "my_keyspace", # changed dash to underscore in keyspace
    default_consistency => CONSISTENCY_QUORUM,
 );
 $loop->add( $cass );

 $cass->connect->get;

 my @f;
 for my $number (1 .. 100) {  # added brackets around VALUES
    push @f, $cass->query( "INSERT INTO numbers (v) VALUES ($number)" );
 }

 Future->needs_all( @f )->get;

 my $get_stmt = $cass->prepare( "SELECT v FROM numbers" )->get;

 my ( undef, $result ) = $get_stmt->execute( [] )->get;

 for my $row ( $result->rows_hash ) {
    say "We have a number " . $row->{v};
 }

To cleanup the test keyspace:

$ cqlsh
drop keyspace my_keyspace;
quit

RT#97260: lost a sequence Future

Perl Support For Older Versions of Cassandra (Thrift-based)

SO: Using perl to connect to apache cassandra 2.0.1
Perlcassa – an Apache Cassandra Perl Client

Posted in API Programming, Cassandra, Open Source, Perl, Storage, Tech | Leave a comment

Notes on “Getting Started with Time Series Data Modeling” in Cassandra

Patrick McFadin’s tutorial on Getting Started with Time Series Data Modeling aka “The Weather Model” is a very good introduction to a few important concepts in Cassandra:

  1. it’s the canonical time series use case in Cassandra. (Try to DESCRIBE the OpsCenter keyspace for how DataStax does time series rollups.)
  2. basic intro to CQL syntax.

Here’s some notes on getting more out of Patrick’s tutorial:

  • INSERT and UPDATE are the same in CQL and are known as UPSERT. That implies that if event_time was not part of the key, then the time and temp would just keep updating the same row each hour. It also implies that if we do a double-insert with the same timestamp, we will only see the last one to make it even if event_time is part of the key.
  • “PRIMARY KEY ((weatherstation_id,date),event_time)” and “PRIMARY KEY (weatherstation_id,event_time),) WITH CLUSTERING ORDER BY (event_time DESC)” both use event_time as a clustering (sorted) key, but only the latter syntax allows the descending ordering
  • try to do some SELECT statements without specifying the weather station id. What happens? Why?
  • the reason that Patrick is so excited with TTL is that with RDBMS, either you have to do DELETE FROM table where event_time < now() or setup partitions and DROP old ones and CREATE new ones. The first one causes massive IO and the second one increases administration overhead. Also, Cassandra's row TTL is much more granular than table-level
    partitions

  • there is no GROUP BY syntax, but denormalizing into PRIMARY KEY ((station_id), temperature) does something similar
  • although Patrick only inserted 4 test records, that’s still more than most database developers bother to test new features with, so do your own acceptance tests :)

Some more general CSQL tips are:

  • Datastax is promoting CSQL to users more so than Thrift
  • queries on the same node in the same partition are relatively fast, everything else being slower.
  • column names are stored as strings in each column, so keep them short if you want to save space. Remember that wasting space inflates memtables, SStables, snapshots, backups, AWS data transfer, etc.
  • SECONDARY INDEX is generally not recommended as it will usually do a scatter-gather across multiple nodes, thus either taking a long time or even timing out
  • prior to CQL3, you could use the cassandra-cli program to list the column families in more low-level detail to see how they were stored
  • to change the row key or clustering you need to drop the table (column family) and create it again

For those new to csqlsh, here’s the full list of commands to get the sample code working:

$ cqlsh

CREATE KEYSPACE "weather_model" WITH REPLICATION = {
   'class' : 'SimpleStrategy', 'replication_factor' : 3 };

SELECT * FROM system.schema_keyspaces;

USE weather_model;

CREATE TABLE temperature (
   weatherstation_id text,
   event_time timestamp,
   temperature text,
   PRIMARY KEY (weatherstation_id,event_time)
);

INSERT INTO temperature (weatherstation_id,event_time,temperature)
VALUES ('1234ABCD','2013-04-03 07:01:00','72F');

INSERT INTO temperature (weatherstation_id,event_time,temperature)
VALUES ('1234ABCD','2013-04-03 07:02:00','73F');

INSERT INTO temperature (weatherstation_id,event_time,temperature)
VALUES ('1234ABCD','2013-04-03 07:03:00','73F');

INSERT INTO temperature (weatherstation_id,event_time,temperature)
VALUES ('1234ABCD','2013-04-03 07:04:00','74F');
 
SELECT event_time,temperature FROM temperature
WHERE weatherstation_id='1234ABCD';

Display the read and write stats. (Use -h host if you get zero reads or writes.)

$ nodetool cfstats weather_model

Keyspace: weather_model
	Read Count: 2
	Read Latency: 0.1925 ms.
	Write Count: 4
	Write Latency: 0.141 ms.
[...]

Then clean up:

DROP TABLE temperature;

DROP KEYSPACE weather_model;

Links

Cassandra Query Language (CQL) v3
ebaytechblog.com: Cassandra Data Modeling Best Practices

Posted in API Programming, Cassandra, Open Source, Tech | Leave a comment

MariaDB Patch: CREATE [[NO] FORCE] VIEW Options

MariaDB LogoBelow is my patch that implements the CREATE [[NO] FORCE] VIEW options against MySQL/MariaDB 10.1.0.

It adds two new options that look like this:

  1. CREATE NO FORCE VIEW v1 AS SELECT * FROM TABLE1; — base TABLE1 must exist, as before
  2. CREATE FORCE VIEW v1 AS SELECT * FROM TABLE1; — base TABLE1 doesn’t need to exist

Notes:

  • these options follow the Oracle Enterprise options fairly closely. NO FORCE works like the old default – a user needs database, table, column access and CREATE VIEW grant to create a view (more or less). FORCE allows a user to create a view with only database access and CREATE VIEW grant and no underlying base table. At SELECT time, full access control and grant checking is performed, and an error will occur if those constraints are not met.
  • views are more complicated than one would expect, and can be composed of base tables, derived tables, INFORMATION_SCHEMA (IS), and other views. The only table object not allowed is a temporary table
  • CREATE FORCE VIEW is an important option when managing large sets of views when you don’t want to track the creation sequence, or when creating views via program. An example is mysqldump, which can be simplified by replacing the current temporary tables ordering workarounds with FORCE VIEW.
  • It’s a fairly solid patch. I think the best thing is to commit it to alpha and let it bake for a while.
  • One permutation that will need special handling is this: CREATE FORCE VIEW view1 AS SELECT * FROM table1; Since * is not resolved to column names by FORCE, currently ” AS SELECT * AS ” is generated, causing an error. So just use explicit column names like CREATE FORCE VIEW view1 SELECT id, col1, col2 FROM table1; See this bug.
  • it passes t/view.test:
    # ./mysql-test-run.pl view
    Logging: ./mysql-test-run.pl  view
    vardir: /usr/local/mariadb-10.1.0/mysql-test/var
    MariaDB Version 10.1.0-MariaDB-debug
    
    TEST                                  RESULT   TIME (ms) or COMMENT
    -------------------------------------------------------------------
    main.view                            [ pass ]   1896
    -------------------------------------------------------------------
    The servers were restarted 0 times
    Spent 1.896 of 7 seconds executing testcases
    Completed: All 1 tests were successful.
    
  • I wrote tests/view.pl which does 8,000+ test permutations. It passes. :)

$ cat create_force_view.patch

--- ../mariadb-10.1.0/sql/sql_view.h 2014-06-27 04:50:36.000000000 -0700
+++ sql/sql_view.h 2014-09-02 02:35:42.000000000 -0700
@@ -29,10 +29,10 @@
/* Function declarations */

bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
- enum_view_create_mode mode);
+ enum_view_create_mode mode, enum_view_create_force force);

bool mysql_create_view(THD *thd, TABLE_LIST *view,
- enum_view_create_mode mode);
+ enum_view_create_mode mode, enum_view_create_force force);

bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
uint flags);
--- ../mariadb-10.1.0/sql/sql_lex.h 2014-06-27 04:50:33.000000000 -0700
+++ sql/sql_lex.h 2014-09-02 01:21:10.000000000 -0700
@@ -170,6 +170,12 @@
VIEW_CREATE_OR_REPLACE // check only that there are not such table
};

+enum enum_view_create_force
+{
+ VIEW_CREATE_NO_FORCE, // default - check that there are not such VIEW/table
+ VIEW_CREATE_FORCE, // check that there are not such VIEW/table, then ignore table object dependencies
+};
+
enum enum_drop_mode
{
DROP_DEFAULT, // mode is not specified
@@ -2442,6 +2448,7 @@
};
enum enum_var_type option_type;
enum enum_view_create_mode create_view_mode;
+ enum enum_view_create_force create_view_force;
enum enum_drop_mode drop_mode;

uint profile_query_id;
--- ../mariadb-10.1.0/sql/sql_parse.cc 2014-06-27 04:50:34.000000000 -0700
+++ sql/sql_parse.cc 2014-09-02 02:34:31.000000000 -0700
@@ -4943,7 +4943,7 @@
Note: SQLCOM_CREATE_VIEW also handles 'ALTER VIEW' commands
as specified through the thd->lex->create_view_mode flag.
*/
- res= mysql_create_view(thd, first_table, thd->lex->create_view_mode);
+ res= mysql_create_view(thd, first_table, thd->lex->create_view_mode, thd->lex->create_view_force);
break;
}
case SQLCOM_DROP_VIEW:
--- ../mariadb-10.1.0/sql/sql_yacc.yy 2014-06-27 04:50:37.000000000 -0700
+++ sql/sql_yacc.yy 2014-09-05 17:19:29.000000000 -0700
@@ -1851,7 +1851,7 @@
statement sp_suid
sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic xa
opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
- view_algorithm view_or_trigger_or_sp_or_event
+ view_algorithm view_or_trigger_or_sp_or_event view_force_option
definer_tail no_definer_tail
view_suid view_tail view_list_opt view_list view_select
view_check_option trigger_tail sp_tail sf_tail udf_tail event_tail
@@ -2446,6 +2446,7 @@
VIEW_CREATE_OR_REPLACE);
Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
Lex->create_view_suid= TRUE;
+ Lex->create_view_force= VIEW_CREATE_NO_FORCE; /* initialize just in case */
}
view_or_trigger_or_sp_or_event
{
@@ -15887,6 +15888,15 @@
| event_tail
;

+view_force_option:
+ /* empty */ /* 411 - is there a cleaner way of initializing here? */
+ { Lex->create_view_force = VIEW_CREATE_NO_FORCE; }
+ | NO_SYM FORCE_SYM
+ { Lex->create_view_force = VIEW_CREATE_NO_FORCE; }
+ | FORCE_SYM
+ { Lex->create_view_force = VIEW_CREATE_FORCE; }
+ ;
+
/**************************************************************************

DEFINER clause support.
@@ -15944,7 +15954,7 @@
;

view_tail:
- view_suid VIEW_SYM table_ident
+ view_suid view_force_option VIEW_SYM table_ident
{
LEX *lex= thd->lex;
lex->sql_command= SQLCOM_CREATE_VIEW;
--- ../mariadb-10.1.0/sql/sql_view.cc 2014-06-27 04:50:36.000000000 -0700
+++ sql/sql_view.cc 2014-09-05 19:33:58.000000000 -0700
@@ -248,7 +248,7 @@
*/

bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
- enum_view_create_mode mode)
+ enum_view_create_mode mode, enum_view_create_force force)
{
LEX *lex= thd->lex;
/* first table in list is target VIEW name => cut off it */
@@ -259,7 +259,7 @@
DBUG_ENTER("create_view_precheck");

/*
- Privilege check for view creation:
+ Privilege check for view creation with default (NO FORCE):
- user has CREATE VIEW privilege on view table
- user has DROP privilege in case of ALTER VIEW or CREATE OR REPLACE
VIEW
@@ -272,6 +272,7 @@
checked that we have not more privileges on correspondent column of view
table (i.e. user will not get some privileges by view creation)
*/
+
if ((check_access(thd, CREATE_VIEW_ACL, view->db,
&view->grant.privilege,
&view->grant.m_internal,
@@ -285,6 +286,11 @@
check_grant(thd, DROP_ACL, view, FALSE, 1, FALSE))))
goto err;

+ if (force) {
+ res = false;
+ DBUG_RETURN(res || thd->is_error());
+ }
+
for (sl= select_lex; sl; sl= sl->next_select())
{
for (tbl= sl->get_table_list(); tbl; tbl= tbl->next_local)
@@ -369,7 +375,7 @@
#else

bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
- enum_view_create_mode mode)
+ enum_view_create_mode mode, enum_view_create_force force)
{
return FALSE;
}
@@ -391,7 +397,7 @@
*/

bool mysql_create_view(THD *thd, TABLE_LIST *views,
- enum_view_create_mode mode)
+ enum_view_create_mode mode, enum_view_create_force force)
{
LEX *lex= thd->lex;
bool link_to_local;
@@ -425,14 +431,13 @@
goto err;
}

- if ((res= create_view_precheck(thd, tables, view, mode)))
+ if (res= create_view_precheck(thd, tables, view, mode, force))
goto err;

lex->link_first_table_back(view, link_to_local);
view->open_type= OT_BASE_ONLY;

- if (open_temporary_tables(thd, lex->query_tables) ||
- open_and_lock_tables(thd, lex->query_tables, TRUE, 0))
+ if (open_temporary_tables(thd, lex->query_tables) || (!force && open_and_lock_tables(thd, lex->query_tables, TRUE, 0)))
{
view= lex->unlink_first_table(&link_to_local);
res= TRUE;
@@ -513,6 +518,7 @@
}
}

+if (!force) {
/* prepare select to resolve all fields */
lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
if (unit->prepare(thd, 0, 0))
@@ -612,6 +618,7 @@
}
}
#endif
+}

res= mysql_register_view(thd, view, mode);

@@ -621,7 +628,7 @@
meta-data changes after ALTER VIEW.
*/

- if (!res)
+ // if (!res)
+ if (!res && !force) /* 411 - solves segfault problems with CREATE FORCE VIEW option sometimes */
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db, view->table_name, false);

if (mysql_bin_log.is_open())
@@ -908,6 +915,8 @@
fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME);
path.length= strlen(path_buff);

if (ha_table_exists(thd, view->db, view->table_name, NULL))
{
if (mode == VIEW_CREATE_NEW)
--- ../mariadb-10.1.0/mysql-test/t/view.test 2014-06-27 04:50:30.000000000 -0700
+++ mysql-test/t/view.test 2014-09-06 00:23:32.000000000 -0700
@@ -5263,4 +5263,17 @@
--echo # -----------------------------------------------------------------
--echo # -- End of 10.0 tests.
--echo # -----------------------------------------------------------------
+
+create no force view v1 as select 1;
+drop view if exists v1;
+
+create force view v1 as select 1;
+drop view if exists v1;
+
+create force view v1 as select * from missing_base_table;
+drop view if exists v1;
+
+--echo # -----------------------------------------------------------------
+--echo # -- End of 10.1 tests.
+--echo # -----------------------------------------------------------------
SET optimizer_switch=@save_optimizer_switch;

Posted in API Programming, Linux, MySQL, Open Source, Oracle, Storage, Tech | Leave a comment

Installing Datastax Cassandra and Python Driver on CentOS 5


Cassandra Logo

Cassandra can run on CentOS 5.x, but there is no yum repo support.

If you can’t upgrade linux distros, here’s how to install Datastax Cassandra Community Edition and the python cassandra driver on CentOS 5.x.

It’s not difficult, but there’s several steps, including updating java.

(The following steps would make a complete chef or puppet recipe for a non-SSL install with vnodes.)


# setup environment
groupadd -g 602 cassandra
useradd -u 602 -g cassandra -m -s /sbin/nologin cassandra
mkdir /var/lib/cassandra /var/log/cassandra /var/run/cassandra
touch /var/log/cassandra/system.log
chown -R cassandra:cassandra /var/lib/cassandra /var/log/cassandra /var/run/cassandra
mkdir -p /opt && cd /opt


cat >> /etc/security/limits.conf <<EOD
cassandra soft memlock unlimited
cassandra hard memlock unlimited
cassandra soft nofile 8192
cassandra hard nofile 10240
EOD


# upgrade java
yum remove java
# download, then install JDK 7.x from oracle.com
rpm -Uvh jdk-7u67-linux-x64.rpm
# download, then install recent jna.jar from https://github.com/twall/jna
mv jna.jar /usr/share/java
ln -s /usr/share/java/jna.jar /opt/cassandra/lib/
# update envariables
cat >> /etc/profile <<"EOD"
export JAVA_HOME=/usr/java/default
export JRE_HOME=/usr/java/default/jre
export CASSANDRA_HOME=/opt/cassandra
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$CASSANDRA_HOME/bin
EOD


# get Datastax DCE
curl -L http://downloads.datastax.com/community/dsc.tar.gz >dsc-cassandra-2.0.9.tar.gz
tar zxvf - < dsc-cassandra-2.0.9.tar.gz
ln -s /opt/dsc-cassandra-2.0.9 /opt/cassandra
chown -R root:root /opt/cassandra/
bash cassandra/switch_snappy 1.0.4

# open cassandra firewall ports if necessary (not needed if using internal interface on most servers)
vi /etc/sysconfig/iptables
-A INPUT -i eth0 -m state --state NEW -m multiport -p tcp --dport 7000,7199,9042,9160 -j ACCEPT
service iptables restart
# configure /opt/cassandra/conf/cassandra.yaml (at least listen_address, rpc_address, seeds and tokens before starting server. If you need a do-over, clean the cassandra data with # rm -fr /var/lib/cassandra/*)

# download startup script:
wget http://jebriggs.com/php/start_cassandra.txt -O /etc/init.d/cassandra
chown root:root /etc/init.d/cassandra
chmod 755 /etc/init.d/cassandra
chkconfig --add cassandra

# start cassandra server (if it is standalone, or a seed server. otherwise start after the seed servers):
service cassandra start

# cat /etc/redhat-release 
CentOS release 5.10 (Final)

[root@www1 conf]# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address   Load       Tokens  Owns   Host ID                               Rack
UN  10.0.1.2  71.87 KB   256     66.8%  8302c6d5-4c88-4695-bbf4-762bc7f24544  rack1
UN  10.0.1.3  136.63 KB  256     69.9%  eddb03b2-98d3-46ff-be63-95435414a883  rack1
UN  10.0.1.4  100.08 KB  256     63.3%  2a8dde5e-29b0-4a67-8204-40769376c44a  rack1

If you only see the node on localhost, then you have a problem:

  • read and fix any errors in /var/log/cassandra/system.log until there are zero errors. snappy-related errors are from /tmp being noexec or not running the switch_snappy 1.0.4 command above.
  • disable iptables firewall, test and reenable later
  • in log4j-server.properties, increase log4j.rootLogger to DEBUG
  • if you have multiple NICs, JMX (ie. nodetool) can bind to the wrong interface. You likely need to configure the-Djava.rmi.server.hostname=[address] option in cassandra-env.sh - to the address you want to listen on
  • public/private IP address problems in AWS EC2. You may need to set broadcast_address: [public_ec2_address]
  • normally rmiregistry is not needed unless you have some atypical firewalling or routing (NAT.)

Datastax Opscenter 5.0

You can install the binary from yum or tarball, but the important things to know are:

  • the monitoring agent will be installed on each cassandra node and uses port 61621. The init script is called datastax-agent.
  • the UI only needs to be installed once, but needs ports 61620, and 8888 for HTTP.
  • to allow Opscenter to remotely manage nodes with ssh, remove old ssh entries from .ssh/known_hosts first, connect manually to each node, then Opscenter should be happy
  • by default, Opscenter listens for agents on 0.0.0.0, phones home to Datastax.com each day, and does not require web authentication, so you likely want to change those.

Python also needs to be upgraded if you want to use cqlsh or the python client cassandra driver.


# install python 2.6 and dependencies
yum install gcc python26 python26-devel libev libev-devel


# install python's pip module
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python26


# install cassandra driver for python
pip install cassandra-driver


# install blist.py
tar zxvf - < blist-1.3.6.tar.gz
cd blist-1.3.6
python26 setup.py install
cd ..

# cluster.py - test installation

from cassandra.cluster import Cluster

cluster = Cluster(['127.0.0.1'])

def dump(obj):
   for attr in dir(obj):
       if hasattr( obj, attr ):
           print( "obj.%s = %s" % (attr, getattr(obj, attr)))

dump(cluster);
# python26 cluster.py

obj.__class__ = <class 'cassandra.cluster.Cluster'>
[...]

Troubleshooting connection problems in JConsole
datastax.com: Storing OpsCenter Data in a Separate Cluster

Posted in Cassandra, Cloud, Linux, Open Source, Tech | Leave a comment

MySQL 5.6 Views and Stored Procedures Tips

MySQL LogoI recently tuned an existing application that used dozens of views and hundreds of stored procedures using MySQL 5.6.

There seems to be three attitudes towards using views and stored procedures (SPs) with MySQL:

  1. don’t use them at all to increase portability
  2. just use SPs to reduce network traffic in large reporting queries (my choice)
  3. go crazy and use them everywhere like old-school Oracle Enterprise apps.

Here are some notes on using views:

  • before creating views, review your schema to ensure keys have matching types and charsets for good performance. It’s much easier to spot schema problems in a text listing than to guess why a view is slower than expected at execution time. (This is doubly true for MySQL Cluster.)
  • MySQL currently doesn’t have CREATE VIEW FORCE, although MariaDB 10.1.0 alpha has my patch. The FORCE option will greatly simply view administration and also mysqldump output, which creates temporary tables to ensure views can be created regardless of table/view ordering issues
  • When looking at the MariaDB source code, it’s apparent that some view options were never actually implemented, like RESTRICT/CASCADE

And some notes on stored procedures (SPs):

  • if a SP makes a stateful session change, like set sql_log_bin=0, ensure that isn’t going to be a problem later if an exception condition doesn’t reset it
  • after running a SP, SHOW PROFILES will list all the queries executed with performance statistics
  • SPs that do non-essential SELECTs or INFORMATION SCHEMA queries probably need to be reviewed by a DBA for fundamental problems like non-atomic “reading before writing”
  • MySQL compiles SPs again for each thread.

Both views and SPs are relatively new MySQL features, so budget some extra development and testing time when using them, especially with replication.

[MDEV-6365] CREATE VIEW Ignores RESTRICT/CASCADE Options
mysqlperformanceblog.com: Using MySQL triggers and views in Amazon RDS

Posted in MySQL, MySQL Cluster, Open Source, Oracle, Tech | Leave a comment

SVLUG: Devops and Release Canaries with Linux, CloudStack and MySQL Cluster

I did a talk at the Silicon Valley Linux Users Group (SVLUG) tonite on “Devops and Release Canaries with Linux, CloudStack and MySQL Cluster.”

Thanks again to Symantec for hosting.

Posted in API Programming, Cloud, Linux, MySQL, MySQL Cluster, Open Source, Oracle, Tech | Leave a comment

Velocity Conference Santa Clara 2014 Tips Game Cards

The O’Reilly Velocity Web Operations & Performance Conference is June 24-26 in Santa Clara.

Next to the messages/jobs board was a Web Ops & Performance Tips board:

– use source maps to debug compressed JS and CSS
– use ::before to optimize font rendering
– use local storage to persist markup and templates to reduce requests and payload
– avoid CSS block rendering in chrome by not using screen media type until after. Then put screen back to element
– use gatling stress tool for load generation/perf testing (Apache Licence 2.0)
– learn curl
– learn POSIX before recreating another tool that already exists. Bill Joy (?)
– “if you do it more than twice a week, automate”
– it takes no skills to do NoOps! :)

Posted in Cloud, Conferences, Open Source, Tech | Leave a comment

AWS Pop-up Loft, San Francisco



Amazon Web Services pop-up loft (Ask an Architect area, lecture hall, kitchen/lounge)
Photo credit: Amazon.com.

I happened to be in SF today, so I went to the Amazon Web Services pop-up loft on Market St.

Amazon rented an empty storefront for 4 weeks for lecture sessions upstairs, and a computer lab and an ‘Ask an Architect’ bar downstairs.

One of the hosts said the loft was a shell in May, and they had to build out everything: the kitchen area, 2 bathrooms and various partitions.

I asked the experts about new EBS and RDS features, and they had answers as well as a $100 AWS credit.

The weather was sunny and warm in SF.

Lots of street performers and hustlers, including a very smooth male R&B singer. A young rapper named Rap2K15 was selling hand-made CDs.

Update 2014 06 23: Apparently a drawing was held, and I was one of 3 winners of a free general pass to the AWS:Reinvent Conference :)

Update 2014 06 24:

AWS Bootcamp

Full-day AWS overview, including EC2, S3, RDS, VPC and IAM, with 2 labs.

“Provisioning and Managing AWS Infrastructure with Chef” with special guest George Miranda, Chef Technical Consultant, Chef

George talked about using Chef tools like chef metal, knife and chef zero and a minimal amount of ruby to make an AMI and provision a MySQL server and 5 Nginx web servers.

Slides

@gmiranda23, chef-ami-factory

Update 2014 06 26:

Dealing With Obstacles at Scale, Bob Hagemann, Twilio

To reduce pain:

– UTC timezone
– UTF8
– use thin AMI and chef/puppet instead of thick AMI
– wrote boxconfig a few years ago (like netflix asgard)
– remote admin mainly
– small teams 3-8
– services should run in 3 AZs
– monitoring with nagios, cron, pingdom
– haproxy on each host as proxy
– MySQL, MHA, LVM. Manual failover.
– SQS DLQ
– global low latency with route53
– http://github.com/twilio
– @bobzilla42
– Uses freeswitch plus own telcom sw
– billing system 100s QPS
– Ops team is about 8 people
– VPNs to HQ and carrier-approved colo
– three founders, one came from Amazon.

925 Market Street, SF
June 4 – 27, 2014 (likely closed on the 27th for dismantling)
Free registration, tshirts and lunch. Closes 5:30 pm, 6:00 pm or 8:00 pm daily.
Muni 30 and 45 return from Market St. and 5th to Caltrain.

@AWSstartups #AWSloft

AWS Loft Returning in Fall 2014

Posted in API Programming, Business, Cloud, Conferences, Linux, MySQL, Open Source, Oracle, San Jose Bay Area, Tech | Leave a comment

Advanced Liquibase Techniques

Liquibase LogoI recently did some work with liquibase. Here’s some techniques for advanced users to workaround limitations to calculate query cost.

Liquibase Introduction

Liquibase is an Open Source (Apache 2.0 License) Java utility and API for specifying and versioning schema changes (DDL) for several popular databases. It is commonly introduced to projects by programmers, rather than DBAs.

What liquibase can do:

  • allow “refactoring” of SQL schema changes to target multiple databases using XML by using a database-independent syntax, or raw SQL, depending on your preference
  • allow conditional execution and rollback of SQL based on database type or environment.

What liquibase can’t do:

  • has no built-in provisions for operational concerns, like conditionally executing SQL based on time/cost. There’s an assumption that schema changes are online, often true on Oracle and SQL Server, less so on MySQL, especially prior to 5.6 (unless you do micro-sharding)
  • does not do intelligent merges to the same object across changesets, like adding multiple columns to the same table in one statement.

How liquibase works:

  • the programmer specifies schema changes in Java, XML or JSON and runs the liquibase command
  • liquibase creates 2 tables in your database to store version, user and patch name information and to lock out other simultaneous liquibase runs.

How to Make Liquibase Consider Cost for MySQL

After some experimentation, there’s a couple liquibase features you can use to do more advanced things:

  1. create a savepoint using the tag and rollback options:
    • liquibase tag rel0; liquibase update …; liquibase rollback rel0
  2. prepend and append logic to each changeset to use information_schema on the SQL DDL statement. on failure, exit with 1 (See XML example below)

changeset.xml:

<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
       http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

    <changeSet id="1" author="james">
     <sql>
       create table if not exists `profiling` ( `connection_id` int(11) not null default 0, `query_id` int(11) not null default '0', `state` varchar(40) default '', KEY (query_id));
       truncate table profiling;
       set profiling=1;

       alter table department add column test2 int default null;
       insert into profiling (connection_id, query_id, state) select connection_id(), query_id, state from information_schema.profiling where query_id=2;
     </sql>
     <rollback>
        <sql>alter table department drop column test2</sql>
    </rollback>
    </changeSet>

    <changeSet id="1-post" author="james">
      <preConditions onFail="HALT">
        <sqlCheck expectedResult="0">SELECT count(*) from profiling where state='copy to tmp table'</sqlCheck>
      </preConditions>
    </changeSet>
</databaseChangeLog>

Notes:

  1. the changeset DDL statement will still have run, even if the precondition HALTs – they’re separate changesets, after all
  2. the rollback in “1” will not be executed, even if “1-post” HALTs.

The workaround for those 2 issues is to combine the two techniques in a shell script:

#!/bin/bash

liquibase tag rel0

liquibase update changeset.xml || {
    # fail the build pipeline to not propagate changeset to next stage
    # (ie. don't run in production)
    liquibase rollback rel0
    mysql -e 'alter table test.department drop column test2' 
    exit 1
}

The above looks a little kludgy, but provides a stepping stone for the reader to customize in their particular environment. (The preConditions and bash script can be easily autogenerated with a Perl or Python script.)

An alternative to XML is using the Java API to set everything up.

Please leave a comment if you have any suggestions or a Java API program.

Posted in API Programming, MySQL, MySQL Cluster, Open Source, Oracle, Tech | Leave a comment

Percona Live MySQL Conference Santa Clara 2014

The Percona Live MySQL Conference was held once again in Santa Clara from April 1-4, 2014.

Executive Summary:

  1. Percona hosted another excellent conference, with 1,150 attendees from 43 countries plus a vibrant exhibit hall.
  2. The overall themes that emerged this year were “What’s new in MySQL 5.6?” and “The rise of Galera Cluster.” Unfortunately, Oracle delivered the 5.6 features they promised, but didn’t bother to ask production DBAs what they really needed (ie. GTIDs require downtime to configure, and ALTER ONLINE doesn’t support throttling or background operation on slaves (SR 3-8856341908).)
  3. MySQL 5.7 is promising about double the performance of 5.6, but note that the 5.7 feature micro-benchmark effort hasn’t translated into a complete understanding of whole database performance yet.
  4. the current active branches are now: Oracle 5.6/5.7, MariaDB 10.0/10.1, Webscale SQL (Facebook, Google, LinkedIn, and Twitter), Facebook 5.6 with Deployable GTIDs, and Percona Server 5.6. (The version you want to migrate to is one based on MySQL 5.6.17 or later.)


Severalnines Booth
Severalnines.com booth. They create and support cluster and cloud database solutions. Photo credit: Steve Barker, SphinxSearch.com

Wednesday

Wed. Keynotes

Percona Live 2014 opening keynote with Percona CEO Peter Zaitsev
Robert Hodges – Getting Serious about MySQL and Hadoop at Continuent
(Continuent needs to pivot into another market as MySQL’s new built-in features displace their replication products.)
‘Raising the MySQL Bar’ with Oracle’s Tomas Ulin, VP of Engineering for MySQL, Oracle
Adventures in MySQL at Dropbox, Renjish Abraham

Wed. Talks

Online schema changes for maximizing uptime, David Turner, Dropbox, Ben Black, Tango

– MySQL 5.6 has online schema change capability, however there’s no way to throttle IO consumed during the operation and the single-threaded slave will lag
– David has tested the ALTER ONLINE in MySQL 5.6.17 and will use it when ported to Percona Server
– for now uses Percona Online Schema Change utility for its throttling feature.

Be the hero of the day with the InnoDB Data recovery tool, Marco “The Grinch” Tusa and Aleksandr Kuzminsky, Percona Services

– tools have been created by Percona to recover Innodb data if you don’t have backups and you’re out of business otherwise. Call them! :)

Galera Cluster New Features, Seppo Jaakola, Codership

– reviewed features in Galera Cluster versions 3 and 4
– looking good.

MySQL Cluster Performance Tuning, Johan Andersson, severalnines.com

- Disable NUMA
- echo 0 > /proc/sys/vm/swappiness
- bind data node threads to CPUs
- cat /proc/interrupts

ThreadConfig

LDM = cores/2

TC = LDM/4

RealTimeScheduler=1

Numoffraglogparts=LDM

Tune redo log

Fragmentlogsize=256M

Nooffragmentlogfiles=redobuffer=64M

Practical sysbench, Peter Boros, Percona

– prefers “latency” graph style with transparent dots vs. line charts
– uses R and ggplot2 for graphing
– attendees tried to guess SSD performance on Peter’s notebook for different block sizes, most were proven totally wrong by sysbench

Birds of a Feather (BoF) Sessions

“Meet MySQL Team (at Oracle)” BoF

– discussion again this year about parallel query execution (same as at MariaDB BoF last year), with Peter Zaitsev also bringing it up again
– discussion about raw partitions (belief is that they will be 20% more space-efficient and 30% faster, and avoid Linux endless limitations and bugs)
– internal “development roadmap” only extends about 12 months at a time, subject to customer demands
– I griped about FK panic/data loss issues in MySQL Cluster 7.3.3. Tomas Ulin, Vice President, MySQL Engineering, said that was news to him. (See SR 3-8717994851 and SR 3-87646727311)
– Mark Callaghan, Facebook, said he was working on MongoDB now, but requested named keys in flexible schema in MySQL.
– Peter Zaitsev, Percona, said several clients are using GTIDs and they seem to work.
– Oracle pleaded with users to drop MyISAM. I mentioned the main reason was that legacy systems used older compression methods, but InnoDB could be used since it has compression too
– The Oracle MySQL Fabric project is an attempt to counter MongoDB’s automatic slave promotion.

Thursday

Thursday Keynotes

‘9 Things You Need to Know…’, Peter Zaitsev, Percona
The Evolution of MySQL in the All-Flash Datacenter, Nisha Talagala, Fusion-IO
MySQL, Private Cloud Infrastructure and OpenStack, Sean Chighizola, Big Fish Games
Keynote Panel: The Future of Operating MySQL at Scale

Thu. Talks

Benchmarking Databases for Scale, Peter Boros and Kenny Gryp, Percona

Question: “What is Percona’s secret to professional benchmarks?”
Answer: “Benchmark absolutely everything multiple times, time permitting.”

MySQL 5.7: Performance & Scalability Benchmarks, Dimitri KRAVTCHUK

– comprehensive micro-benchmarking graphs of 5.7 to gain a deeper understanding of parts
– the challenge remains: how to tune the whole database to perform well?

Use Your MySQL Knowledge to Become an Instant Cassandra Guru, Robert Hodges, Continuent and Tim Callaghan, Tokutek

– good comparison of relational data modelling and C* data modelling, lots of similarities
– note that MariaDB has a Cassandra plugin

RDS for MYSQL, Tips, Patterns and Common Pitfalls, Laine Campbell, Blackbird (formerly PalominoDB)

Write Conflicts in Multi-Master Replication Topologies, Seppo Jaakola, Codership

– it’s good to see that Codership is paying attention to the details of replication

MySQL Community Awards

Shlomi has a comprehensive post on this years winners.

MySQL Lightning Talks (5 minutes each)

Truncating Sub Optimal DBA Verbal Responses Vectors, David Stokes (Oracle)

MySQL 5.6 Global Transaction IDs: Benefits and Limitations, Stephane Combaudon (Percona)

mysqlfailover
mysqlrpladmin

Zero database downtime using the Federated storage engine and Replication, prasad mani (BBC)

Scaling via adding a Table, Rick James (self)

Rick knows some clever ways to optimize solutions with MySQL. He’s doing consulting now, so contact him.

IPs
Lat/Long
Mysql.rjweb.org
Extra Table Saves the Day: Slides

No es ‘ano’, es ‘año’! A take on encoding in your DB, Ignacio Nin (Vivid Cortex)

What Not to Say to the MySQL DBA, Gillian Gunson (Blackbird (formerly PalominoDB))
“I’ll code around it. ”
“Stop micro-optimizing. ”
“Use passive master for QA”
“MySQL is a toy database. ”
This conference is a support group. ”

Hall of Shame, Shlomi Noach
Triple active-replication in gaming anecdote: don’t do that.

The bash slave-prefetch oneliner, Art van Scheppingen (Spil Games)

Unsung Relay Log, Vishnu Rao, FlipKart
Com_relaylog_dump for tungsten and mysql 5.5

Unique User Count — Rollup, Rick James (self)

Formula for user visit estimation by counting bits.

Logical Backups in the Cloud, Bill Karwin, Percona
Backups for PHP designers
PHP class Mysql/Dump

How to Squat, Kyle Redinger (VividCortex, Inc)

Iron DBA Replication Challenge, Attunity
Humor

Friday

Friday Keynotes

Percona CMO Terry Erisman opens the 3rd and final day of Percona Live 201

Keynote: OpenStack Co­Opetition, A View from Within, Boris Renski, Mirantis and OpenStack Boardmember

– one of the best conference keynotes ever, and a great primer on Open Source marketing … up there with the O’Reilly Open Source Conference keynote on the importance of Android – before it shipped.

Friday Talks

Global Transaction ID at Facebook, Evan Elias, Santosh Banda and Yoshinori Matsunobu, Facebook

– just write your own MySQL branch if a feature is too hard to deploy :)

R for MySQL DBAs, Ryan Lowe and Randy Wigginton, Percona

– R has about 1,000 interesting sample databases (demos included diamonds and cars)
– good interface for quick graphing, not so great for complex programs
– Percona usess R and ggplot graph module for most of the graphs you see now.

MariaDB for Developers, Colin Charles, Chief Evangelist, MariaDB

Closing Prize Drawing

About 30 high-end gifts were handed out.

Some nice prizes contributed by exhibitors, including Nexus 7 tablets, $250 AWS gift certificates, SQLyog and Monyog licenses, and a quad drone!

Exhibits

The exhibits are one of my favorite things at the conference each year because of how strong the MySQL third-party community is.

Some notable absences were Clustrix and Violin memory, but those were offset by new exhibitors. Webyog was a sponsor but I didn’t see a booth. PalominoDB changed their name to Blackbird, and appear to be offering DevOps as well as DBA services.

And of course, as the organizers, Percona had a large, central spread. :)

Thanks to the sponsors and exhibitors for making a conference like this financially possible.

Facebook Debuts Web-Scale Variant Of MySQL

Facebook’s Yoshinori Matsunobu on MySQL, WebScaleSQL & Percona Live
Twitter’s Calvin Sun on WebScaleSQL, Percona Live
Slides
Tweets about PerconaLive
Percona Live MySQL Conference Highlights

Posted in Cassandra, Cloud, Conferences, Linux, MySQL, MySQL Cluster, Open Source, Oracle, Perl, San Jose Bay Area, Storage, Tech | Leave a comment

Cassandra Operations Checklist

Most of the Cassandra rollouts I’ve heard about at conferences have been “Devopsed” – written by Dev and productionized by Dev, with hand-off to Operations long afterwards.

That’s the opposite to how RDBMS projects are usually deployed in large companies.

As Cassandra becomes more mature, this hand-off will occur earlier after development ends.

Here is a checklist for handing off a Cassandra database to Operations (I only consider non-trivial rings of 3 or more nodes in production with a full data set):

  Node Impact
  Item Comments Performance/ Space/ Time/IOPs/BW
Cassandra Server Version Should be exactly the same minor version across cluster except briefly during server updates
Token or vnodes? needs to be configured before first start of server
Cassandra Client/Connector Version Thrift or CQL?
Snitch name? Why? several choices
Replication Factor (RF)? Why? usually RF=3 for SoT* data, defined at keyspace level
Compaction method? Why? Size or Level, defined at CF level
Read Consistency Level? Why? Netflix recommends CL=ONE. ALL seldom makes sense.
Write Consistency Level? Why? ALL seldom makes sense.
TTL? Why? Defined at row level.
Expected Average Query Latency 10 ms is reasonable, 1 ms is tough.
nodetool repair/scrub needed weekly yes more space more
Bootstrapping a new node yes yes
Java gcpause stop the world yes yes
Are there any wide columns? do they get wider over time? pathological case for Cassandra yes more space more
Backup in case of application bug or a disaster. Opscenter, Priam, custom. yes slightly more for incremental backups, double for local cold copy more
Restore requires Cassandra node shutdown yes
If a storage volume fills, howto fix it? Especially a problem with multiple JBOD volumes, which fill unevenly. yes less space less
If a storage volume fails, howto fix it? yes less space less
What is the total data size now? Projected in 12 months? affects most operations yes yes yes
What is the acceptable query latency? affects network and hardware choices
What is the best maintenance window time each week?
What are the business and practical SLAs?
What training is needed for your Operations team? Datastax Admin and Data Modelling Classes (recommend most recent Cassandra version)
What partitioner is used? Opscenter only supports random partitioner or murmur 3 partitioner for rebalancing
What procedures need to be written for your Operations team?
What monitoring tools?
  1. DSE or DCE/OpsCenter
  2. nodetool
  3. Jconsole/jmxterm
  4. Boundary
  5. nagios/zabbix
What bugs have been encountered? Which ones still apply?
What lessons can Devops share with the Operations team?

SoT = Source of Truth

About Data Consistency in Cassandra
ConstantContact techblog: Cassandra and Backups
stackoverflow.com: Do I absolutely need a minimum of 3 nodes/servers for a Cassandra cluster or will 2 suffice?

Posted in Business, Cassandra, Cloud, Tech | Leave a comment

Howto Add a New Command to the MySQL Server

MySQL LogoAdding a new statement or command to the MySQL server is not difficult.

First, decide if you want to modify the server source code, or if a User-Defined Function (UDF) will meet your needs.

Since I just added the SHUTDOWN server command, I thought I would be helpful to outline the steps needed to add a new command.

Prerequisites:

  1. some familiarity with C/C++ syntax and programming (like “The C Programming Language”, by Kernighan and Ritchie.)
  2. some familiarity with lex and yacc. (I read the Dragon Book a long time ago.)
  3. access to a linux account with cmake, gcc, make and bison packages.
# CentOS
yum install cmake gcc make bison

# Ubuntu
apt-get update
apt-get install cmake gcc make bison

# unpack the MySQL source code:

tar zxvf - < mariadb-5.5.30.tar.gz

# most of the files you need to modify are in this directory:

cd mariadb-5.5.30/sql
  • sql_parse.cc
  • sql_yacc.yy
  • sql_prepare.cc
  • mysqld.cc
  • sql_lex.h

# add the token(s) (commands and arguments you think you will need) and verify the syntax:

bison -v sql_yacc.yy

# if you get warnings, fix %expect in sql_yacc.cc

# cut-and-paste a code block from a command with similar syntax in sql_yacc.cc to implement your new command, and build a test version of MySQL

# build your new server in a sandbox:

make.sh:

#!/bin/bash

cd mariadb-5.5.30
cmake . -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mariadb-5.5.30
make --with-debug
sudo make install

# test your new server with 3 terminal windows:

start.sh:

#!/bin/bash

killall mysqld
/usr/local/mariadb-5.5.30/bin/mysqld_safe --user=mysql --debug &
tail -f  /tmp/mysqld.trace | grep Got &
tail -f /var/log/mysqld.log &
mysql -u root -p
# login, then test your new command while watching the log and trace

# read /var/log/mysqld.log and /tmp/mysqld.trace for errors and panics like this:

Version: '5.5.30-MariaDB-debug'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
mysqld: /home/james/mariadb-5.5.30/sql/sql_parse.cc:4477: int mysql_execute_command(THD*): Assertion `0' failed.
130515 11:25:19 [ERROR] mysqld got signal 6 ;

This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.

The above panic was caused by the SQLCOM_ switch falling through, because the new command was not defined yet.

# When you’re done, make a test

vi mysql-test/t/my_new_command.test

# Create a patch file:

mv mariadb-5.5.30 mariadb-5.5.30-new
tar zxvf - < mariadb-5.5.30.tar.gz

cd mariadb-5.5.30/src
>patch.txt
for i in sql_parse.cc sql_yacc.yy sql_prepare.cc mysqld.cc sql_lex.h; do
   echo $i
   diff -u $i ../../mariadb-5.5.30-new/sql/ >>patch.txt
done
# don't forget mysql-test/t/my_new_command.test

# apply your patch file:

patch -b < patch.txt

# do a build and test your patch before distributing it.

Easy peasy, right! :)

Sergei Golubchik wrote on the MariaDB developers list: "Reserved words are keywords (listed in the sql/lex.h) that are
not listed in the 'keyword' rule of sql_yacc.yy (and 'keyword_sp' rule, that 'keyword' rule includes)."

How can I get the output of the DBUG_PRINT
How to find shift/reduce conflict in this yacc file?
MariaDB Contributor Agreement (MCA) Frequently Asked Questions
wikipedia: diff

MySQL Internals Manual
mysqlperformanceblog.com: XtraDB / InnoDB internals in drawing
Overloading Procedures
innodb_diagrams project
Understanding MySQL Internals By Sasha Pachev (O'Reilly)
DTrace can tell you what MySQL is doing
MySQL C Client API programming tutorial
MySQL 5.1 Class Index

  • https://launchpad.net/~maria-developers
  • IRC, #maria channel on Freenode
  • https://kb.askmonty.org/en/community-contributing-to-the-mariadb-project/
  • https://kb.askmonty.org/en/contributing-code/
  • https://kb.askmonty.org/en/google-summer-of-code-2013/ (ideas)
  • http://mariadb.org/jira/ (search for unassigned tasks)

Keywords: MariaDB, MySQL server programming, tutorial, patch.

Posted in API Programming, Linux, MySQL, Open Source, Oracle, Tech, Toys | 3 Comments

Patch to Add Shutdown Statement to MySQL MariaDB

MySQL LogoAt the OSCON 2011 MariaDB Birds-of-a-Feather (BoF) session, I suggested adding a MySQL SHUTDOWN statement to Monty, which was written up as WL#232. Other databases have this feature, and it’s very handy when automating management of a cluster of MySQL servers.

And at the Percona Live MySQL Conference 2013, Monty suggested to MariaDB BOF attendees that a good way to get a new feature added is to to write a patch to pave the way for a committer to start with.

Phase 1

So … I sat down last nite and wrote the patch against MariaDB 5.5.30.

Basically it meant telling mysql’s lex/yacc files to parse “shutdown”, then calling the existing MySQL API shutdown kill_mysql() function.

This code is released under the Open Source BSD-new License, according to the MariaDB Contributor Agreement.

shutdown_0.1.patch.txt – MariaDB 5.5.30:

--- sql_parse.cc	2013-03-11 03:29:13.000000000 -0700
+++ /home/james/mariadb-5.5.30-new/sql/sql_parse.cc	2013-05-15 13:17:05.000000000 -0700
@@ -1305,7 +1305,6 @@
     my_ok(thd);
     break;
   }
-#ifndef EMBEDDED_LIBRARY
   case COM_SHUTDOWN:
   {
     status_var_increment(thd->status_var.com_other);
@@ -1333,7 +1332,6 @@
     error=TRUE;
     break;
   }
-#endif
   case COM_STATISTICS:
   {
     STATUS_VAR *current_global_status_var;      // Big; Don't allocate on stack
@@ -3736,6 +3734,31 @@
                     lex->kill_signal);
     break;
   }
+  case SQLCOM_SHUTDOWN:
+  {
+    // jeb - This code block is copied from COM_SHUTDOWN above. Since kill_mysql(void) {} doesn't take a level argument, the level code is pointless.
+    // jeb - In fact, the level code should be removed and Oracle Database statements implemented: SHUTDOWN, SHUTDOWN IMMEDIATE and SHUTDOWN ABORT. See WL#232.
+
+    status_var_increment(thd->status_var.com_other);
+    if (check_global_access(thd,SHUTDOWN_ACL))
+      break; /* purecov: inspected */
+
+    enum mysql_enum_shutdown_level level;
+    level= SHUTDOWN_DEFAULT;
+    if (level == SHUTDOWN_DEFAULT)
+      level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable
+    else if (level != SHUTDOWN_WAIT_ALL_BUFFERS)
+    {
+      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
+      break;
+    }
+    DBUG_PRINT("SQLCOM_SHUTDOWN",("Got shutdown command for level %u", level));
+    my_eof(thd);
+    kill_mysql();
+    res=TRUE;
+    break;
+  }
+
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   case SQLCOM_SHOW_GRANTS:
   {
--- sql_yacc.yy	2013-03-11 03:29:19.000000000 -0700
+++ /home/james/mariadb-5.5.30-new/sql/sql_yacc.yy	2013-05-15 11:12:03.000000000 -0700
@@ -791,7 +791,7 @@
   Currently there are 174 shift/reduce conflicts.
   We should not introduce new conflicts any more.
 */
-%expect 174
+%expect 196
 
 /*
    Comments for TOKENS.
@@ -1645,6 +1645,7 @@
         definer_opt no_definer definer
         parse_vcol_expr vcol_opt_specifier vcol_opt_attribute
         vcol_opt_attribute_list vcol_attribute
+        shutdown
 END_OF_INPUT
 
 %type  call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt
@@ -1796,6 +1797,7 @@
         | savepoint
         | select
         | set
+        | shutdown
         | signal_stmt
         | show
         | slave
@@ -13715,6 +13717,17 @@
         ;
 
 
+shutdown:
+          SHUTDOWN
+          {
+            LEX *lex=Lex;
+            lex->value_list.empty();
+            lex->users_list.empty();
+            lex->sql_command= SQLCOM_SHUTDOWN;
+          }
+        ;
+
+
 set_expr_or_default:
           expr { $$=$1; }
         | DEFAULT { $$=0; }
--- sql_prepare.cc	2013-03-11 03:29:11.000000000 -0700
+++ /home/james/mariadb-5.5.30-new/sql/sql_prepare.cc	2013-05-15 03:07:00.000000000 -0700
@@ -2173,6 +2173,7 @@
   case SQLCOM_GRANT:
   case SQLCOM_REVOKE:
   case SQLCOM_KILL:
+  case SQLCOM_SHUTDOWN:
     break;
 
   case SQLCOM_PREPARE:
--- mysqld.cc	2013-03-11 03:29:14.000000000 -0700
+++ /home/james/mariadb-5.5.30-new/sql/mysqld.cc	2013-05-15 01:20:11.000000000 -0700
@@ -3333,6 +3333,7 @@
   {"savepoint",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
   {"select",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SELECT]), SHOW_LONG_STATUS},
   {"set_option",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
+  {"shutdown",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHUTDOWN]), SHOW_LONG_STATUS},
   {"signal",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SIGNAL]), SHOW_LONG_STATUS},
   {"show_authors",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_AUTHORS]), SHOW_LONG_STATUS},
   {"show_binlog_events",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOG_EVENTS]), SHOW_LONG_STATUS},
--- sql_lex.h	2013-03-11 03:29:13.000000000 -0700
+++ /home/james/mariadb-5.5.30-new/sql/sql_lex.h	2013-05-15 01:19:17.000000000 -0700
@@ -193,6 +193,7 @@
   SQLCOM_SHOW_RELAYLOG_EVENTS, 
   SQLCOM_SHOW_USER_STATS, SQLCOM_SHOW_TABLE_STATS, SQLCOM_SHOW_INDEX_STATS,
   SQLCOM_SHOW_CLIENT_STATS,
+  SQLCOM_SHUTDOWN,
 
   /*
     When a command is added here, be sure it's also added in mysqld.cc

To apply:

tar zxvf - < mariadb-5.5.30.tar.gz
cd mariadb-5.5.30/sql
wget http://jebriggs.com/php/shutdown_0.1.patch.txt
patch -b < shutdown_0.1.patch.txt

make.sh:

#!/bin/bash

cd mariadb-5.5.30
cmake . -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mariadb-5.5.30
make --with-debug
sudo make install

start.sh:

#!/bin/bash

killall mysqld
/usr/local/mariadb-5.5.30/bin/mysqld_safe --user=mysql --debug &
tail -f  /tmp/mysqld.trace | grep Got &
mysql -u root -p

mysql client (with mysqld.log and mysql.trace entries overlaid):

mysql> shutdown;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 130515 13:20:38 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

/tmp/mysql.trace:


T@4    : | | | >parse_sql
T@4    : | | | <parse_sql
T@4    : | | | >LEX::set_trg_event_type_for_tables
T@4    : | | | <LEX::set_trg_event_type_for_tables
T@4    : | | | >mysql_execute_command
T@4    : | | | | >deny_updates_if_read_only_option
T@4    : | | | | <deny_updates_if_read_only_option
T@4    : | | | | >stmt_causes_implicit_commit
T@4    : | | | | <stmt_causes_implicit_commit
T@4    : | | | | SQLCOM_SHUTDOWN: Got shutdown command for level 16
T@4    : | | | | >set_eof_status
T@4    : | | | | <set_eof_status
T@4    : | | | | >kill_mysql
T@4    : | | | | | quit: After pthread_kill
T@4    : | | | | <kill_mysql
T@4    : | | | | proc_info: /home/james/mariadb-5.5.30/sql/sql_parse.cc:4507  query end

/var/log/mysqld.log:

130515 13:20:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130515 13:20:08 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
130515 13:20:08 InnoDB: The InnoDB memory heap is disabled
130515 13:20:08 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130515 13:20:08 InnoDB: Compressed tables use zlib 1.2.3
130515 13:20:08 InnoDB: Initializing buffer pool, size = 128.0M
130515 13:20:08 InnoDB: Completed initialization of buffer pool
130515 13:20:08 InnoDB: highest supported file format is Barracuda.
130515 13:20:09  InnoDB: Waiting for the background threads to start
130515 13:20:10 Percona XtraDB (http://www.percona.com) 5.5.30-MariaDB-30.1 started; log sequence number 1597945
130515 13:20:10 [Note] Plugin 'FEEDBACK' is disabled.
130515 13:20:10 [Note] Event Scheduler: Loaded 0 events
130515 13:20:10 [Note] /usr/local/mariadb-5.5.30/bin/mysqld: ready for connections.
Version: '5.5.30-MariaDB-debug'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
130515 13:20:37 [Note] Got signal 15 to shutdown mysqld
130515 13:20:37 [Note] /usr/local/mariadb-5.5.30/bin/mysqld: Normal shutdown

130515 13:20:37 [Note] Event Scheduler: Purging the queue. 0 events
130515 13:20:37  InnoDB: Starting shutdown...
130515 13:20:38  InnoDB: Shutdown completed; log sequence number 1597945
130515 13:20:38 [Note] /usr/local/mariadb-5.5.30/bin/mysqld: Shutdown complete

130515 13:20:38 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

A possible test would be like this, but it would interfere with operation of the test mysqld instance:

mysql-test/t/shutdown.test:

shutdown;

Phase 2

My above patch applies cleanly within the existing MySQL shutdown framework, which implements a feature like Oracle Database's SHUTDOWN IMMEDIATE command.

However, my patch is a Pyrrhic victory, since there's so much wrong with MySQL's existing shutdown framework that it will take an internals committer to sort it out.

The shutdown framework is badly designed, if it was designed at all, since it fails the "does this feel programmed on purpose?" test, and in fact doesn't work reliably:

  1. Conceptually, there should be 3 Oracle Database-style SHUTDOWN options: WAIT, IMMEDIATE and ABORT. Implementing SHUTDOWN WAIT would mean intrusive changes to the MySQL source code, while SHUTDOWN ABORT would be easier to program, but at the risk of data integrity.
  2. the following bug reports describe a race condition between mysqld threads and the shutdown thread:

I guess I'll have to pay myself the worklog bounty of $100. :)

This is actually my second MySQL patch contribution. In 1997 or 1998 I submitted a patch for the installer, which was one of the most troublesome components at that time. Monty rewrote it, but I liked my version better.

Update: Sergei Golubchik committed this patch to MariaDB 10.0.4 on 2013-06-25. Thanks, Sergei!

shutdown_0.1.patch.txt
MySQL's Missing Shutdown Statement
WL#232
Bug #63276: skip sleep in srv_master_thread when shutdown is in progress

Posted in Linux, MySQL, Open Source, Oracle, OSCON, Tech | 1 Comment

Jenkins User Conference US West 2014

Jenkins LogoI went to the Jenkins Users Conference, hosted at the very nice Hyatt Regency SFO in Burlingame, Calif. There were about 600 attendees.

There were 3 talk tracks, plus a misc. track. The talks were not technically difficult, but then using Jenkins is mostly about organizational process and installing plugins.

Keynote
Kohsuke Kawaguchi, Jenkins Creator

– X1K project to handle 1,000 build slaves (should be enough for any single corporation)
– NIO for a few threads to manage humdreds of slaves
– Puppet Enterprise consulting donated a week to setup puppet, vagrant and docker infra to replace ad hocness
– 3D print your own Jenkins mascot.

Automation, Innovation and Continuous Delivery
Mario Cruz, Choose Digital @MarioCruz

– private branded digital entertainment downloads for hotels and megacorps (Marriot, petro-canada, airlines)
– moved from on-prem to aws
– outsource everything that doesn’t make money
– feature flags are great for syncing app with apple app store approvals
– builds are automatically deployed to either prod or stage env using one Jenkins hosted by cloudbees
– motivation for CD is to have 2-week vacations
– manager guesses can only be trumped by data
– programmers are on-call. Write better tests if you don’t want to get called
– devs get 45 minutes to either fix or rollback a release, ends up being 30% rollback, 70% fix with frequent releases. Easy if a feature flag can be disabled.
– QA has 45 min to look at stage before live in prod for consumer brands. API just goes out.
– Slack is better than JIRA, but $6 more per developer
– Hipchat, New Relic, Asana, Cloudbees, JIRA
– Archaius from Netflix OSS
– DBA is the real gate for Continuous Deployment. Buy him some lunches and explain what’s in it for him.

Advanced Workflows for Multi-Platform Mobile Development
Emanuele Zattin, Realm Inc. (Italy) @emanuelez

– Nokia before, deployed Jenkins globally to replace custom build scripts
– even if you’re a mobile library, you still have to provide sample apps, so resolution, UI, stores
– make, Xcode, etc., valgrind!
– Tip #1: don’t waste developer time and focus with a context switch. Don’t waste qa time.
– build, test, coverage, todo length, artifact size growth
– Extreme Feedback http://gitgear.com/xfd lamp, gamifies multiple teams!
– Tip #2: fingerprint and store artifacts. You will need them later!
– Tip #4: version control your build scripts, be careful with release scripts
– mobile devices are connected to slaves
– gradle is helpful for Android builds
– custom interface for Apple iOS devices
– Mac Pro with VMware, RAM disks crash
– Ansible to provision slaves
– Docker for Android builds
– gcc and clang have valgrind-type address sanitizer option now that’s very fast, just run valgrind nightly

http://en.wikipedia.org/wiki/AddressSanitizer

Lunch

– sandwiches, but nice mini subs with pasta

Exhibits Area

About a dozen booths.

Keynote Systems

Artifactory

– awesome frog toy
– database tracks artifacts, proxy reduces bw, licence manager tracks usage

Serena

– push button deploy after Jenkins builds
– graphical UI for those who need that

Zend

– Zend server

Cloudbees

– hosted Jenkins

Yahoo!

– recruiting

Ravello

Unmasking the Jenkins DSL
Matt Moore, Google

– ex-compiler optimization guy
– works with Jenkins at Google now
– jobs plugin is crap. Needs knowledge of other 1,000 plugins to work, so far has 7, so 20 years behind already
– hence structured form submission
– YAML project type
– !by-name shell
– create a job, view yaml template
– !kind matrix
– http://Jenkins-ci.com/yaml-project-plugin
– “git flow” by Victor Driessen
– config in code with latest git plugin
– features.yaml, releases.yaml, master.yaml multi-branch
– intended for git and mercurial, others unknown
– Jenkins does most validation in form, so yaml-project doesn’t do much yet
– https://wiki.Jenkins-ci.org/display/JENKINS/YAML+Project+Plugin
– there is also the autojobs plugin

Operating Jenkins at Scale
Ryan Campbell & Robert Sandell, Cloudbees, Inc.

– congratulations, if you’re here, you own a large Jenkins installation! :)
– monitoring
– health, perf, business value
– collectd, graphite, nagios
– Jenkins Metrics Plugin DropWizard
– Jenkins Operations Center (JOC) plugin. Uses ElasticSearch and Kibana
– custom kibana tiles
– who’s responsible?
– how are backups, disk space, sameness, upgrades done?
– choose plugins carefully
– more masters: depts, plugin testing, etc.
– bulk operations plugin for JOC

Using Jenkins to Build Apache vhosts for Github Pull Requests on PHP Apps
Sam Moffatt, Account Bouncer

– previously at ebay, Sears
– pull requests build an environment for developer or qa engineer
– bind9 with mod_vhost_alias, comment out default vhost to avoid conflict
– http://pr1.test, http://pr2.test, …
– ensure if using Github Enterprise and custom SSL they are added to GE
– ensure API setup correct
– beware multiple pulls at same time, can cause confusing errors.

Perfecto Mobile

– USAA mobile app check scan, share feature awesome
– emulators suck – false sense of confidence
– 7 requirements
– managing a device lab is hard – try 65 devices, different versions, can’t roll back
– MobileCloud – Open and Integrated, real devices connected via USB (no jailbreaks)
– will work on shake testing if there’s market demand

Lightning Talk #1: FIFA Gameplay Automated Testing with Jenkins
Stuart Rowe, Electronic Arts

– old system was scripts with manual emails notifying developers, about 8 hours of busywork per week by an engineer
– new system uses Jenkins
– performance testing done on real devices.

Lightning Talk #2: Supercharged Configuration as Code – Using Jenkins to Control Mass Updates of JOB DSL
Alan Beale, Chicago Trading Company

– bulk updating of 100 jobs?

Conversations

– Jenkins backup master. Master is just a directory, so copy files?

Conference Suggestions

– Advanced Track with more programming, like Google’s YAML-project talk
– community bulletin board in hallway.

Interesting phone charger tree with Post Office box-style, with combo locks:

Knuckles Historical Sports Bar

#jenkinsconf

Posted in API Programming, Business, Cloud, Conferences, Open Source, Oracle, Tech, Toys | Leave a comment

Lessons from “Air Crash Investigations” for Passengers

Youtube channel “Canadian Flight Centre” has the National Geographic series “Air Crash Investigations.”

It’s very educational for both pilots and passengers.

Airline travel is very safe in the United States and Europe, with Western airlines having about 1 major accident annually. That doesn’t apply to Asian and Eastern European airlines, and non-airline flights.

Following is a meta-study that summarizes passenger survivability over several accidents.

Lessons for Passengers

Before Flight – Planning Your Flight

  • don’t fly in typhoons, thunderstorms, volcanic eruptions. Avoid Surabaya on a rainy day. Avoid flights at airports immediately after icing closures because of delayed takeoffs which increases icing.
  • some airports don’t have adequate navigation aids for bad weather to land safely (chronic ILS inoperative at SFO)
  • the remarkable safety of airlines is due to having dispatchers and flying the same routes repeatedly. Don’t expect the same outcome from new airlines, maiden flights, charter flights or diversions
  • flying into airspace with different local customs is less safe: airspace like Russia and Brazil are examples, where language and military-style control can cause misunderstandings
  • wear jeans or cotton pants and a cotton hoodie – no hairspray or nylon
  • be observant – a passenger saw a fatigue crack on Aloha 243, but didn’t report it. Same with pax on Midlands 092 knew the wrong engine was shutdown after left engine caught fire, but didn’t say anything. ice, pitot covers, etc.
  • American regionals (which exist to shave costs) and discount Asian airlines are sketchy on maintenance and provide less pilot training than major airlines
  • Korean pilots can’t fly non-precision approaches (Guam KAL, SFO Asiana 214)
  • tail strikes are bad news on pressurized airplanes
  • safest place is rear of cabin, except for cargo door blowout
  • fires worst over wings. pilots rarely get burned
  • brown cigarette smoke on outside of fuselage indicates crack
  • choose airports with doppler weather radar if thunderstorms are possible
  • if your airline often runs late, choose flights earlier in the day to avoid rushing to make schedules and crew rest rules
  • for small planes, typically propeller, ensure operator weighs baggage before loading
  • original 747 rear cargo door latches have aluminum latches in steel mounts, so will eventually wear and fail (UA 811)
  • if 747 center fuel tank is not full and no nitrogen system, there is a vapor explosion risk. (TWA 800)
  • original ATRs can’t handle icing conditions
  • MD80 has non-redundant jackscrew in tail
  • original DC10 had non-redundant electrical equipment powered by engine #1.

Before Crash

  • an alert private pilot pax saved himself and seatmates on the Washington Air Florida Flight 90 accident (crash brace, expedited egress)
  • weightlifters could help with holding yoke/rudder pedals after flight controls problem to rest pilots
  • make a mental note of two exits and count floor lights
  • don’t inflate life vest before ditching: easier to swim, easier to exit door

During Impact

  • many survivors broke both ankles under seats, unless you’re really short

After Impact

  • if you can smell kerosene (Jet A), you’re alive
  • plug-type doors generally need to be opened and discarded through its doorway to not block passenger egress (USAir 1493)
  • 2 minutes to get out, one death every second after that
  • one breath of black smoke near ceiling makes your “lungs feel solid, 2 breaths kill you.” crawl. (Brit. Airtours)
  • smoke hoods would save lives, but slow down deplaning. crew may have smokehoods and oxygen bottles stashed in overhead bins (Brit. Airtours)
  • a survival strategy when crowded is to stay low to floor until other pax inhale near ceiling, however flashover will kill everybody (Brit. Airtours)
  • pax climb over seats if exits are blocked (exactly like a money race) (Brit. Airtours)
  • an engine fire will blowtorch the fuselage if positioned upwind (Brit. Airtours)
  • if emergency exit jammed, try pushing both top and bottom (Brit. Airtours)
  • burns can kill half of survivors due to post-accident organ failure
  • don’t jump into center of flames (USAir 1493.) if you’re on fire, drop and roll after stepping over jet fuel on ground
  • using axe on reinforced cockpit windows takes a long time, can break axe, best performed by uninjured person
  • “like being in a war. go go go” Little Rock, AK

After Egress

  • you can be on your own for an hour or more – days in the mountains – and freeze (AA 965.) For JAL 123, rescuers decided to wait until the next day to ascend the mountain, taking 14 hours to reach the accident site despite knowing the location. In France, 100 rescuers parked for 4 hours, waiting for “official” notification to search, so a journalist followed the smell of kerosene to the site.
  • “the first disaster was the crash. the second was being held in custody in a small room for hours.” (KAL Guam)
  • except in inverted dives into the ground, rescuers report that there are almost always initial survivors, so fight to get out of the airplane wreckage
  • don’t lay down in foam or in a vehicle route, or rescue vehicles can run over you (Asiana SFO).

Improving Airliner Safety

  • pilots need real-time camera views of control surfaces and engines in cockpit. Until then, cabin crew needs to relay engine fires, cabin smoke or damaged flight controls. (The locking cockpit door actually reduces safety during an emergency as it impedes communications amongst crew and creates a psychological barrier.) (Midlands 092 wrong engine shutdown, Chicago #1 engine fire, Alaska Air jackscrew failure, Schiphol El AL 747, etc.)
  • since pilots can’t see the aircraft wings or engines, cabin crew need to be trained how to observe and report on engine fires, fuel leaks and wing damage. They need to know airplane left from right, and what to look for even in low visibility (fuel leaks are nearly invisible at night.) They need to know time for useful consciousness and remind the flight crew every few minutes after a depressurization, as passenger oxygen only lasts 10 or 11 minutes.

Powerlines Can’t Hide from Safe Flight Detector
Baker Aviation Offers “Hot Deal” on Fire Containment Bags

Posted in Tech | Leave a comment

Bash Shellshock Fix for Old Macs

This chap has a shellshock fix for older Macs, including PPC and pre-Mountain Lion. I tested it on a Macbook Pro (Intel) with Leopard 10.5.8 and it works fine.

It is also an easy way to fix failed bash update attempts, as it’s a single file that you can copy over /bin/bash and /bin/sh. (If you borked bash and can’t open a Terminal window now, just type in the command “ksh”.)

The one good thing that has come out of shellshock is that the bash debugger runs on bash4, so that will be good for wider adoption.

Now if only Microsoft would get that Skype update out for older Macs. (Instead, they’re actively blocking old versions that used to work fine.)

SO: How unpack and pack pkg file?
Solving Snow Leopard Crashes on a 24″ iMac

Posted in Open Source, Retro, Tech | Leave a comment

Modern CPAN Module Tips

Perl LogoRecently, I uploaded a new Perl module, Getopt::ApacheCommonsCLI, to CPAN after a break of a few years.

Things have changed a bit … CPAN was originally just a place to upload your files. Now they do automated tests and graph dependencies based on the metadata you provide.

Creating a New Module

For a new pure perl (non-XS) module with no special requirements, this is all you need to get started with version 0.01:

h2xs -AX -n My::Module

An alternative is the ModuleMaker command:

cpan ExtUtils::ModuleMaker
modulemaker

Modernizing an Old CPAN Module

Here’s what I do to create a module tree if there’s an old 0.01 version:

h2xs -AX -v 0.02 -n My::Module

Modernizing Ancient Module Filenames

  • Check your old module CPAN Testers results for FAILs. Note that if you see less than 2% failures, and your module was “flat” (.pm in the top-level directory), that may be just testing noise.
  • Move modules into lib/
  • Move tests into t/
  • Use .pl extension and move sample scripts into eg/ (there’s no standard location for scripts, but eg/ is a good place and the files are indexed by CPAN if added to MANIFEST)
  • Add or update Changes and README
  • update MANIFEST with all the filenames that should be distributed, using relative pathnames. (No *META* entries should be added since those are auto-generated.)

Updating Makefile.PL

  • Edit Makefile.PL and add all the module dependencies, both core and other. (Core modules are sometimes deprecated, so you can’t rely on them staying in core.)
  • The license option most commonly used is ‘perl_5′
  • run perl Makefile.PL, then inspect MYMETA.yml and MYMETA.json. (These show the auto-generated metadata used by CPAN for automated module dependency graphs. These files are overwritten every time perl Makefile.PL is run, and the filenames should not be added manually to MANIFEST.)

Updating t/My-Module.t

  • h2xs emits a skeleton test file named t/My-Module.t
  • Test::More is used by default now, which requires a lot less typing
  • Test::More’s use_ok() is a great way to load your module in a verified way, and adds one to your tests count.

Updating POD

  • List markup tags require blank lines after =over, =item and =back
  • The link markup L<> works in a flaky manner, so just use bare URLs and CPAN will find them anyway
  • document return values and error conditions in a RETURN VALUES heading
  • POD does not read Makefile.PL, so update email addresses in POD
  • angle brackets should be encoded as E<lt> and E<gt>
  • a good practice is to write examples in eg/, test them, then paste into the POD last to avoid embarrassing errors
  • Run podchecker from POD::Checker on your module. It will emit an error if you have space on an otherwise blank line. podchecker returns 0 for success and 1 or 2 for failure, so can be easily added to Jenkins.
podchecker -warnings -warnings Module.pm # yes, twice for max warnings

Then just run make test && make tardist, and upload to PAUSE. :)

Suggestions

MakeMaker Improvements

  • add command line options (or read from ENV) to h2xs and modulemaker for author name, email address and licence (default perl_5)
  • add a make target like make podcheck
  • see if it’s possible to convert old-style tests to Test::More.

CPAN Testers Improvements

  • add podchecker to CPAN Testers results
  • on CPAN Testers page, default display to FAILs instead of all results (too many green PASSes).

Kudos to the CPAN maintainers and Testers for their amazing contributions.

Posted in API Programming, Open Source, Perl, Tech | Leave a comment

Viewing the October 2014 Blood Moon from Silicon Valley

I happened to be awake at 3:30 am, so I went outside to look at the “Blood Moon” lunar eclipse. In Silicon Valley the moon looked much darker than normal, and reddish-brown with a silver crescent to the right.

It looked textured like the dimpling on an orange. :)

According to CNN, there will be 4 such events (a tetrad) in 2014-2015, with only 9 in the past 2,000 years.

Famous early astronomers didn’t have such a viewing opportunity, which is a shame, since no telescope is needed.

cnn.com: Blood moon the sequel had millions gazing at the skies
W: Lunar Eclipse

Posted in Personal, San Jose Bay Area | Leave a comment