1
1
package MySQL::Sandbox::Recipes;
3
our $VERSION="2.0.99f";
9
MySQL::Sandbox::Recipes - Collection of recipes for MySQL Sandbox
10
MySQL::Sandbox::Recipes - A cookbook for MySQL Sandbox
13
14
This package is a collection of HOW-TO brief tutorials and recipes for MySQL Sandbox
15
This is B<work in progress>. You may see that some of these recipes are still stubs. I am working on them in my free time, but I am definitely going to complete it.
17
16
=head1 Installing MySQL::Sandbox
19
18
All the recipes here need the MySQL Sandbox
192
191
This option will check if port 5134 is used. If it is, it will check the next available port, until it finds a free one.
193
192
In the previous statement context, 'free' means not only 'in use', but also allocated by another sandbox that is currently not running.
194
193
If the directory msb_5_1_34 is used, the sandbox is created in msb_5_1_34_a. The application keeps checking for free ports and unused directories until it finds a suitable combination.
194
Notice that this option is disabled when you use a group sandbox (replication or multiple). Even if you set NODE_OPTIONS=--check_port, it won't be used, because every group sandbox invokes make_sandbox with the --no_check_port option.
196
196
=head2 Creating a single sandbox with a specific option file
448
448
=head2 Creating a group sandbox with port checking
450
make_replication_sandbox --check_base_port \
451
--sandbox_directory=something_unique /path/to/tarball
453
make_multiple_sandbox --check_base_port \
454
--sandbox_directory=something_unique /path/to/tarball
450
When you create a multiple sandbox (make_replication_sandbox,
451
make_multiple_sandbox, make_multiple_custom_sandbox) the default behavior
452
is to overwrite the existing sandbox without asking for confirmation.
453
The rationale is that a multiple sandbox is definitely more likely to be a
454
created only for testing purposes, and overwriting it should not be a problem.
455
If you want to avoid overwriting, you can specify a different group name
456
(C<--replication_directory> C<--group_directory>), but this will use the
457
same base port number, unless you specify C<--check_base_port>.
459
make_replication_sandbox 5.0.79
460
# Creates a replication directory under $SANDBOX_HOME/rsandbox_5_0_79
461
# The default base_port is 7000
463
make_replication_sandbox 5.0.79
464
# Creates a replication directory under $SANDBOX_HOME/rsandbox_5_0_79
465
# overwriting the previous one. The default base port is still 7000
468
make_replication_sandbox --check_base_port 5.0.79
469
# Creates a replication directory under $SANDBOX_HOME/rsandbox_5_0_79
470
# overwriting the previous one.
473
make_replication_sandbox --replication_directory=newdir 5.0.79
474
# Created a replication directory under $SANDBOX_HOME/newdir.
475
# The previous one is preserved, but the new sandbox does not start
476
# because of port conflict.
479
make_replication_sandbox --replication_directory=newwdir \
480
--check_base_port 5.0.79
481
# Creates a replication directory under $SANDBOX_HOME/newdir
482
# The previous one is preserved. No conflicts happen
456
484
=head2 Creating a group sandbox with a specific option file
486
When you create a group sandbox, make_sanbox is invoked several times, with a predefined set of options. You can add options for each node by means of environmental variables.
487
If you create a replication sandbox, you can set different options for the master and for the slaves:
458
489
export MASTER_OPTIONS="--my_file=huge"
459
490
export SLAVE_OPTIONS="--my_file=large"
460
491
make_replication_sandbox 5.1.34
463
494
export SLAVE_OPTIONS="--my_file=/path/to/my_other.cnf"
464
495
make_replication_sandbox 5.1.34
497
If you don't need the distinction, then you can define the same option for all nodes at once:
466
499
export NODE_OPTIONS="--my_file=large"
467
500
make_replication_sandbox 5.1.34
502
For non-replication group sandboxes (or for circular replication), $NODE_OPTION is the appropriate way of setting options.
469
504
export NODE_OPTIONS="--my_file=large"
470
505
make_multiple_sandbox 5.1.34
472
507
=head2 Creating a group sandbox from a source directory
474
Same as for a single sandbox, but use the 'replication' or 'multiple' keyword when calling the script
509
Same as for a single sandbox, but use the 'replication' or 'multiple' keyword when calling the script.
511
make_sandbox_from_source $PWD replication [options]
512
make_sandbox_from_source $PWD multiple [options]
476
514
=head2 Starting or restarting a group sandbox with temporary options
478
./start_all [options]
479
./restart_all [options]
516
When you want to restart a group of sandboxes with some temporary options, all you need to do is to pass the option to the command line of ./start_all (if the group was not running) or ./restart_all.
518
./start_all --mysqld=mysqld-debug --gdb
519
./restart_all --max-allowed-packet=20M
481
521
=head2 Stopping a group sandbox
523
The natural way of stopping a group of sandboxes is to invoke the C<stop_all> script. This will work as expected most of the time.
527
If you are dealing with a potentially unresponsive server (for example when testing alpha code), then you may use C<send_kill_all>, which will attempt a gentle stop first, and then kill the server brutally, if it does not respond after a predefined timeout of 10 seconds.
486
531
=head2 Cleaning up a group sandbox
533
To revert a group sandbox to its original state, the quickest way is to call C<clear_all>, which will invoke the C<clear> script in every depending single sandbox.
537
In a replication sandbox, this command will also remove all replication settings. For this reason, C<clear_all> creates a dummy file called C<needs_initialization>, containing the date and time of the cleanup. This is a signal for C<start_all> to initialize the slaves at the next occurrence. No need for the user to do anything special. The sandbox is self healing.
490
539
=head2 Moving a group sandbox
541
This recipe is the same for single and multiple sandboxes. Using the sbtool will move a sandbox in a clean and safe way. All the elements of the sandbox will be changed to adapt to the new location.
493
544
-s /path/to/source/sandbox \
494
545
-d /path/to/destination/directory
496
547
=head2 Removing a group sandbox completely
549
The sbtool can delete completely any sandbox, either single or multiple.
498
551
sbtool -o delete \
499
552
-s /path/to/source/sandbox
554
This operation will fail if the sandbox has been made permanent. (See next recipe).
501
556
=head2 Making a group sandbox permanent
558
A sandbox is designed to be easy to create and to throw away, because its primary purpose is testing. However, there are cases when you want to keep the contents around for a while, and you therefore want to make sure that the sandbox is not cleaned up or deleted by mistake. C<sbtool> achieves this goal by disabling the C<clear_all> script and the C<clear> script in all depending sandboxes. In this state, also the 'delete' operation fails (see previous recipe).
503
560
sbtool -o preserve \
504
561
-s /path/to/source/sandbox
563
When you need to get rid of the sandbox contents quickly, you can 'unpreserve' it, and the clear* scripts will be enabled again.
506
565
sbtool -o unpreserve \
507
566
-s /path/to/source/sandbox
511
570
=head2 Using more than one SANDBOX_HOME
572
The default $SANDBOX_HOME is $HOME/sandboxes, which is suitable for most purposes. If your $HOME is not fit for this task (e.g. if it is located in a NFS partition), you may set a different one on the command line or in your shell startup file.
513
574
export SANDBOX_HOME=/my/alternative/directory
514
575
make_sandbox 5.1.34 --check_port
577
The above procedure is also useful when you, for any reasons, want a completely different set of sandboxes for a new batch of tests, and you want to be able to manage all of them at once. To avoid conflicts, you should always use the --check_port option.
516
579
=head2 Stopping all sandboxes at once
581
The $SANDBOX_HOME directory is the place containing all sandboxes, both single and multiple. This allows you to stop all of them at once with a single command.
518
583
$SANDBOX_HOME/stop_all
520
585
=head2 Starting all sandboxes at once
587
Similarly to the previous recipe, you can start all sandboxes at once with a single command.
522
589
$SANDBOX_HOME/start_all
524
=head2 Running the same query on all sandboxes
591
Notice that, if you created two or more sandboxes that use the same port, (create one with port X, stop it, create another with port X), there will be a conflict, and the second sandbox (and subsequent ones) won't start.
593
=head2 Running the same query on all active sandboxes
595
This is a quick way of getting a result from every sandbox under $SANDBOX_HOME. The query passed to C<use_all> will be passed to every C<use> or C<use_all> scripts of the depending sandboxes.
526
597
$SANDBOX_HOME/use_all 'select something_cool'
599
If you want to run several queries from a script, use the C<source> keyword:
601
$SANDBOX_HOME/use_all 'source /full/path/to/script.sql'
528
603
=head1 Testing with sandboxes
530
605
=head2 Running the built-in test suite
540
615
The TEST_VERSION environment variable contains a version or the path to a tarball used by the test suite. If no test version is provided, most of the tests are skipped.
541
616
The test suite creates a private SANDBOX_HOME under ./t/test_sb. All the sandboxes needed for the test are executed there. If something goes wrong, that is the place to inspect for clues.
618
IMPORTANT: When running test_sandbox, either standalone or within the test suite, it will stop all sandboxes inside $SANDBOX_HOME, to prevent conflicts with the sandboxes created during the tests.
543
620
=head2 Creating and running your own tests
545
622
Look at the ./t directory inside the MySQL Sandbox package (previous recipe).