~dveeden/mysql-sandbox/mysql-sandbox

« back to all changes in this revision

Viewing changes to lib/MySQL/Sandbox/Recipes.pm

  • Committer: Giuseppe Maxia
  • Date: 2009-05-09 08:04:44 UTC
  • Revision ID: g.maxia@gmail.com-20090509080444-jy8a330el0mt425a
Tags: 3.0
- 3.0.00 GA release
- no code modification. Same codebase as 2.0.99f
- completed cookbook (41 recipes in MySQL::Sandbox::Recipes)
- added script_templates directory (No modification in current version, just preparation for 3.1.xx)
- added drafts directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package MySQL::Sandbox::Recipes;
2
2
 
3
 
our $VERSION="2.0.99f";
 
3
our $VERSION="3.0.00";
4
4
 
5
5
1;
6
6
__END__
 
7
 
7
8
=head1 NAME
8
9
 
9
 
MySQL::Sandbox::Recipes - Collection of recipes for MySQL Sandbox
 
10
MySQL::Sandbox::Recipes - A cookbook for MySQL Sandbox
10
11
 
11
12
=head1 PURPOSE
12
13
 
13
14
This package is a collection of HOW-TO brief tutorials and recipes for MySQL Sandbox
14
15
 
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.
16
 
 
17
16
=head1 Installing MySQL::Sandbox
18
17
 
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.
195
195
 
196
196
=head2 Creating a single sandbox with a specific option file
197
197
 
447
447
 
448
448
=head2 Creating a group sandbox with port checking
449
449
 
450
 
  make_replication_sandbox --check_base_port \
451
 
    --sandbox_directory=something_unique /path/to/tarball
452
 
 
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>.
 
458
 
 
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
 
462
 
 
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
 
466
 
 
467
 # WRONG
 
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. 
 
471
 
 
472
 # WRONG
 
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.
 
477
 
 
478
 # RIGHT
 
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
455
483
 
456
484
=head2 Creating a group sandbox with a specific option file
457
485
 
 
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:
 
488
 
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
465
496
 
 
497
If you don't need the distinction, then you can define the same option for all nodes at once:
 
498
 
466
499
  export NODE_OPTIONS="--my_file=large"
467
500
  make_replication_sandbox 5.1.34
468
501
 
 
502
For non-replication group sandboxes (or for circular replication), $NODE_OPTION is the appropriate way of setting options.
 
503
 
469
504
  export NODE_OPTIONS="--my_file=large"
470
505
  make_multiple_sandbox 5.1.34
471
506
 
472
507
=head2 Creating a group sandbox from a source directory
473
508
 
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.
 
510
 
 
511
  make_sandbox_from_source $PWD replication [options]
 
512
  make_sandbox_from_source $PWD multiple [options]
475
513
 
476
514
=head2 Starting or restarting a group sandbox with temporary options
477
515
 
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.
 
517
 
 
518
  ./start_all --mysqld=mysqld-debug --gdb
 
519
  ./restart_all --max-allowed-packet=20M
480
520
 
481
521
=head2 Stopping a group sandbox
482
522
 
 
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.
 
524
 
483
525
  ./stop_all
 
526
 
 
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.
 
528
 
484
529
  ./send_kill_all
485
530
 
486
531
=head2 Cleaning up a group sandbox
487
532
 
 
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.
 
534
 
488
535
  ./clear_all
489
536
 
 
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.
 
538
 
490
539
=head2 Moving a group sandbox
491
540
 
 
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.
 
542
 
492
543
  sbtool -o move \
493
544
    -s /path/to/source/sandbox \
494
545
    -d /path/to/destination/directory
495
546
 
496
547
=head2 Removing a group sandbox completely
497
548
 
 
549
The sbtool can delete completely any sandbox, either single or multiple.
 
550
 
498
551
  sbtool -o delete \
499
552
    -s /path/to/source/sandbox 
500
553
 
 
554
This operation will fail if the sandbox has been made permanent. (See next recipe).
 
555
 
501
556
=head2 Making a group sandbox permanent 
502
557
 
 
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).
 
559
 
503
560
  sbtool -o preserve \
504
561
    -s /path/to/source/sandbox 
505
562
 
 
563
When you need to get rid of the sandbox contents quickly, you can 'unpreserve' it, and the clear* scripts will be enabled again.
 
564
 
506
565
  sbtool -o unpreserve \
507
566
    -s /path/to/source/sandbox 
508
567
 
510
569
 
511
570
=head2 Using more than one SANDBOX_HOME
512
571
 
 
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.
 
573
 
513
574
   export SANDBOX_HOME=/my/alternative/directory
514
575
   make_sandbox 5.1.34 --check_port
515
576
 
 
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.
 
578
 
516
579
=head2 Stopping all sandboxes at once
517
580
 
 
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.
 
582
 
518
583
    $SANDBOX_HOME/stop_all
519
584
 
520
585
=head2 Starting all sandboxes at once
521
586
 
 
587
Similarly to the previous recipe, you can start all sandboxes at once with a single command.
 
588
 
522
589
    $SANDBOX_HOME/start_all
523
590
 
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.
 
592
 
 
593
=head2 Running the same query on all active sandboxes
 
594
 
 
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.
525
596
 
526
597
    $SANDBOX_HOME/use_all 'select something_cool'
527
598
 
 
599
If you want to run several queries from a script, use the C<source> keyword:
 
600
 
 
601
    $SANDBOX_HOME/use_all 'source /full/path/to/script.sql'
 
602
 
528
603
=head1 Testing with sandboxes
529
604
 
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.
542
617
 
 
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.
 
619
 
543
620
=head2 Creating and running your own tests
544
621
 
545
622
Look at the ./t directory inside the MySQL Sandbox package (previous recipe).