Commit 34026bc9 authored by unknown's avatar unknown

Updated LOCK TABLES manual section

Applied patch for mysqlhotcopy
Fixed open-files-size option in safe_mysqld


Docs/manual.texi:
  Updated LOCK TABLES section
scripts/mysqlhotcopy.sh:
  Removed depricated DBI calls.
  Fixed bug which resulted in nothing being copied when a regexp was
  specified but no database name(s).
  Patch by Jeremy D. Zawodny
scripts/safe_mysqld.sh:
  Fixed open-files-size option
parent 44d4821e
...@@ -7585,7 +7585,7 @@ You should also add /etc/my.cnf: ...@@ -7585,7 +7585,7 @@ You should also add /etc/my.cnf:
@example @example
[safe_mysqld] [safe_mysqld]
open_files_limit=8192 open-files-limit=8192
@end example @end example
The above should allow @strong{MySQL} to create up to 8192 connections/files. The above should allow @strong{MySQL} to create up to 8192 connections/files.
...@@ -22952,17 +22952,9 @@ are locked by the current thread are automatically unlocked when the ...@@ -22952,17 +22952,9 @@ are locked by the current thread are automatically unlocked when the
thread issues another @code{LOCK TABLES}, or when the connection to the thread issues another @code{LOCK TABLES}, or when the connection to the
server is closed. server is closed.
The main reasons to use @code{LOCK TABLES} are: The main reasons to use @code{LOCK TABLES} are for emulating transactions
or getting more speed when updating tables. This is explained in more
@itemize @bullet detail later.
@item
Emulate transactions with not transaction safe tables.
@item
To get more speed with @code{MyISAM} tables when inserting/updating data
over many statements. The main reason this gives more speed is that
@strong{MySQL} will not flush the key cache for the locked tables until
@code{UNLOCK TABLES} is called.
@end itemize
If a thread obtains a @code{READ} lock on a table, that thread (and all other If a thread obtains a @code{READ} lock on a table, that thread (and all other
threads) can only read from the table. If a thread obtains a @code{WRITE} threads) can only read from the table. If a thread obtains a @code{WRITE}
...@@ -22975,8 +22967,10 @@ execute while the lock is held. This can't however be used if you are ...@@ -22975,8 +22967,10 @@ execute while the lock is held. This can't however be used if you are
going to manipulate the database files outside @strong{MySQL} while you going to manipulate the database files outside @strong{MySQL} while you
hold the lock. hold the lock.
Each thread waits (without timing out) until it obtains all the locks it has When you use @code{LOCK TABLES}, you must lock all tables that you are
requested. going to use and you must use the same alias that you are going to use
in your queries! If you are using a table multiple times in a query
(with aliases), you must get a lock for each alias!
@code{WRITE} locks normally have higher priority than @code{READ} locks, to @code{WRITE} locks normally have higher priority than @code{READ} locks, to
ensure that updates are processed as soon as possible. This means that if one ensure that updates are processed as soon as possible. This means that if one
...@@ -22988,15 +22982,32 @@ locks while the thread is waiting for the @code{WRITE} lock. You should only ...@@ -22988,15 +22982,32 @@ locks while the thread is waiting for the @code{WRITE} lock. You should only
use @code{LOW_PRIORITY WRITE} locks if you are sure that there will use @code{LOW_PRIORITY WRITE} locks if you are sure that there will
eventually be a time when no threads will have a @code{READ} lock. eventually be a time when no threads will have a @code{READ} lock.
@code{LOCK TABLES} and @code{UNLOCK TABLES} both commits any active @code{LOCK TABLES} works as follows:
transactions. @enumerate
@item
Sort all tables to be locked in a internally defined order (from the
user standpoint the order is undefined).
@item
If a table is locked with a read and a write lock, put the write lock
before the read lock.
@item
Lock one table at a time until the thread gets all locks.
@end enumerate
This policy ensures that table locking is deadlock free. There is
however other things one needs to be aware of with this schema:
When you use @code{LOCK TABLES}, you must lock all tables that you are If you are using a @code{LOW_PRIORITY_WRITE} lock for a table, this
going to use and you must use the same alias that you are going to use means only that @strong{MySQL} will wait for this particlar lock until
in your queries! If you are using a table multiple times in a query there is no threads that wants a @code{READ} lock. When the thread has
(with aliases), you must get a lock for each alias! This policy ensures got the @code{WRITE} lock and is waiting to get the lock for the next
that table locking is deadlock free and makes the locking code smaller, table in the lock table list, all other threads will wait for the
simpler and much faster. @code{WRITE} lock to be released. If this becomes a serious problem
with your application, you should consider converting some of your
tables to transactions safe tables.
You can safely kill a thread that is waiting for a table lock with
@code{KILL}. @xref{KILL}.
Note that you should @strong{NOT} lock any tables that you are using with Note that you should @strong{NOT} lock any tables that you are using with
@code{INSERT DELAYED}. This is because that in this case the @code{INSERT} @code{INSERT DELAYED}. This is because that in this case the @code{INSERT}
...@@ -23013,6 +23024,12 @@ If you are going to run many operations on a bunch of tables, it's much ...@@ -23013,6 +23024,12 @@ If you are going to run many operations on a bunch of tables, it's much
faster to lock the tables you are going to use. The downside is, of course, faster to lock the tables you are going to use. The downside is, of course,
that no other thread can update a @code{READ}-locked table and no other that no other thread can update a @code{READ}-locked table and no other
thread can read a @code{WRITE}-locked table. thread can read a @code{WRITE}-locked table.
The reason some things are faster under @code{LOCK TABLES} is that
@strong{MySQL} will not flush the key cache for the locked tables until
@code{UNLOCK TABLES} is called (normally the key cache is flushed after
each SQL statement). This speeds up inserting/updateing/deletes on
@code{MyISAM} tables.
@item @item
If you are using a table handler in @strong{MySQL} that doesn't support If you are using a table handler in @strong{MySQL} that doesn't support
transactions, you must use @code{LOCK TABLES} if you want to ensure that transactions, you must use @code{LOCK TABLES} if you want to ensure that
...@@ -23044,7 +23061,7 @@ table in the server and implemented with @code{pthread_mutex_lock()} and ...@@ -23044,7 +23061,7 @@ table in the server and implemented with @code{pthread_mutex_lock()} and
See @ref{Internal locking}, for more information on locking policy. See @ref{Internal locking}, for more information on locking policy.
You can also lock all tables in all databases with read locks with the You can lock all tables in all databases with read locks with the
@code{FLUSH TABLES WITH READ LOCK} command. @xref{FLUSH}. This is very @code{FLUSH TABLES WITH READ LOCK} command. @xref{FLUSH}. This is very
convenient way to get backups if you have a file system, like Veritas, convenient way to get backups if you have a file system, like Veritas,
that can take snapshots in time. that can take snapshots in time.
...@@ -43898,8 +43915,6 @@ more than one way to compute} ...@@ -43898,8 +43915,6 @@ more than one way to compute}
@item @uref{http://www.spylog.ru/, SpyLOG ; A very popular Web counter site} @item @uref{http://www.spylog.ru/, SpyLOG ; A very popular Web counter site}
@item @uref{http://www.tucows.com/, TuCows Network; Free Software archive}
@item @uref{http://www.jobvertise.com,Jobvertise: Post and search for jobs} @item @uref{http://www.jobvertise.com,Jobvertise: Post and search for jobs}
@item @uref{http://www.musicdatabase.com, The Music Database} @item @uref{http://www.musicdatabase.com, The Music Database}
...@@ -45486,8 +45501,6 @@ For making @code{mysqlaccess} more secure. ...@@ -45486,8 +45501,6 @@ For making @code{mysqlaccess} more secure.
@item Albert Chin-A-Young. @item Albert Chin-A-Young.
Configure updates for Tru64, large file support and better TCP wrappers Configure updates for Tru64, large file support and better TCP wrappers
support. support.
@item Valueclick Inc.
For sponsoring the optimize section in this manual.
@end table @end table
Other contributors, bugfinders, and testers: James H. Thompson, Maurizio Other contributors, bugfinders, and testers: James H. Thompson, Maurizio
...@@ -223,18 +223,27 @@ foreach my $rdb ( @db_desc ) { ...@@ -223,18 +223,27 @@ foreach my $rdb ( @db_desc ) {
my $db = $rdb->{src}; my $db = $rdb->{src};
eval { $dbh->do( "use $db" ); }; eval { $dbh->do( "use $db" ); };
die "Database '$db' not accessible: $@" if ( $@ ); die "Database '$db' not accessible: $@" if ( $@ );
my @dbh_tables = $dbh->func( '_ListTables' ); my @dbh_tables = $dbh->tables();
## generate regex for tables/files ## generate regex for tables/files
my $t_regex = $rdb->{t_regex}; ## assign temporary regex my $t_regex;
my $negated = $t_regex =~ tr/~//d; ## remove and count negation operator: we don't allow ~ in table names my $negated;
$t_regex = qr/$t_regex/; ## make regex string from user regex if ($rdb->{t_regex}) {
$t_regex = $rdb->{t_regex}; ## assign temporary regex
## filter (out) tables specified in t_regex $negated = $t_regex =~ tr/~//d; ## remove and count
print "Filtering tables with '$t_regex'\n" if $opt{debug}; ## negation operator: we
@dbh_tables = ( $negated ## don't allow ~ in table
? grep { $_ !~ $t_regex } @dbh_tables ## names
: grep { $_ =~ $t_regex } @dbh_tables );
$t_regex = qr/$t_regex/; ## make regex string from
## user regex
## filter (out) tables specified in t_regex
print "Filtering tables with '$t_regex'\n" if $opt{debug};
@dbh_tables = ( $negated
? grep { $_ !~ $t_regex } @dbh_tables
: grep { $_ =~ $t_regex } @dbh_tables );
}
## get list of files to copy ## get list of files to copy
my $db_dir = "$datadir/$db"; my $db_dir = "$datadir/$db";
...@@ -249,10 +258,18 @@ foreach my $rdb ( @db_desc ) { ...@@ -249,10 +258,18 @@ foreach my $rdb ( @db_desc ) {
closedir( DBDIR ); closedir( DBDIR );
## filter (out) files specified in t_regex ## filter (out) files specified in t_regex
my @db_files = ( $negated my @db_files;
? grep { $db_files{$_} !~ $t_regex } keys %db_files if ($rdb->{t_regex}) {
: grep { $db_files{$_} =~ $t_regex } keys %db_files ); @db_files = ($negated
? grep { $db_files{$_} !~ $t_regex } keys %db_files
: grep { $db_files{$_} =~ $t_regex } keys %db_files );
}
else {
@db_files = keys %db_files;
}
@db_files = sort @db_files; @db_files = sort @db_files;
my @index_files=(); my @index_files=();
## remove indices unless we're told to keep them ## remove indices unless we're told to keep them
...@@ -809,3 +826,7 @@ Ask Bjoern Hansen - Cleanup code to fix a few bugs and enable -w again. ...@@ -809,3 +826,7 @@ Ask Bjoern Hansen - Cleanup code to fix a few bugs and enable -w again.
Emil S. Hansen - Added resetslave and resetmaster. Emil S. Hansen - Added resetslave and resetmaster.
Jeremy D. Zawodny - Removed depricated DBI calls. Fixed bug which
resulted in nothing being copied when a regexp was specified but no
database name(s).
...@@ -46,10 +46,8 @@ parse_arguments() { ...@@ -46,10 +46,8 @@ parse_arguments() {
# safe_mysqld-specific options - must be set in my.cnf ([safe_mysqld])! # safe_mysqld-specific options - must be set in my.cnf ([safe_mysqld])!
--ledir=*) ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;; --ledir=*) ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;;
--err-log=*) err_log=`echo "$arg" | sed -e "s;--err-log=;;"` ;; --err-log=*) err_log=`echo "$arg" | sed -e "s;--err-log=;;"` ;;
# QQ The --open-files should be removed
--open-files=*) open_files=`echo "$arg" | sed -e "s;--open-files=;;"` ;;
--open-files-limit=*) open_files=`echo "$arg" | sed -e "s;--open-files-limit=;;"` ;; --open-files-limit=*) open_files=`echo "$arg" | sed -e "s;--open-files-limit=;;"` ;;
--core-file-size=*) core_file_size=`echo "$arg" | sed -e "s;--core_file_size=;;"` ;; --core-file-size=*) core_file_size=`echo "$arg" | sed -e "s;--core-file-size=;;"` ;;
--timezone=*) TZ=`echo "$arg" | sed -e "s;--timezone=;;"` ; export TZ; ;; --timezone=*) TZ=`echo "$arg" | sed -e "s;--timezone=;;"` ; export TZ; ;;
--mysqld=*) MYSQLD=`echo "$arg" | sed -e "s;--mysqld=;;"` ;; --mysqld=*) MYSQLD=`echo "$arg" | sed -e "s;--mysqld=;;"` ;;
--mysqld-version=*) --mysqld-version=*)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment