Permalink
Browse files

Allow regeneration of DB connections if we have given out too many

handles to the same connection.

Thanks to <victoriggy@gmail.com> for the idea and the original
implementation. Refactored extensively and max_requests renamed to
max_handles to better represent the functionality. <robbat2>

Further refactored by dormando. Now is a measure of how many times
a handle may be *validated*. Validation is the known safe point for
when a database handle may be reset.

git-svn-id: http://code.sixapart.com/svn/mogilefs/trunk@1348 f67b2e87-0811-0410-a7e0-dd94e48410d6
  • Loading branch information...
dormando
dormando committed Nov 14, 2009
1 parent 42251db commit 3ad5e7e4392a0a8e15567395084d8d21d237314f
Showing with 18 additions and 2 deletions.
  1. +3 −0 CHANGES
  2. +3 −0 lib/MogileFS/Config.pm
  3. +9 −2 lib/MogileFS/Store.pm
  4. +3 −0 mogdbsetup
View
@@ -1,3 +1,6 @@
+ * Add 'max_handles' config option to restart a DB connection if there
+ are too many handles to it (victori).
+
2009-10-18: Release version 2.32
* No changes... MFS is hard to release due to mogdeps :/
View
@@ -57,6 +57,7 @@ our (
$fsck_jobs,
$reaper_jobs,
$monitor_jobs,
+ $max_handles,
$min_free_space,
$max_disk_age,
$node_timeout, # time in seconds to wait for storage node responses
@@ -92,6 +93,7 @@ sub load_config {
'min_free_space=i' => \$cmdline{min_free_space},
'default_mindevcount=i' => \$cmdline{default_mindevcount},
'node_timeout=i' => \$cmdline{node_timeout},
+ 'max_handles=i' => \$cmdline{max_handles},
'pidfile=s' => \$cmdline{pidfile},
'no_schema_check' => \$cmdline{no_schema_check},
'old_repl_compat=i' => \$cmdline{old_repl_compat},
@@ -152,6 +154,7 @@ sub load_config {
$monitor_jobs = choose_value( 'monitor_jobs', 1 );
$min_free_space = choose_value( 'min_free_space', 100 );
$max_disk_age = choose_value( 'max_disk_age', 5 );
+ $max_handles = choose_value( 'max_handles', 0 );
$DEBUG = choose_value( 'debug', $ENV{DEBUG} || 0 );
$pidfile = choose_value( 'pidfile', "" );
View
@@ -20,11 +20,11 @@ use constant SCHEMA_VERSION => 12;
sub new {
my ($class) = @_;
- return $class->new_from_dsn_user_pass(map { MogileFS->config($_) } qw(db_dsn db_user db_pass));
+ return $class->new_from_dsn_user_pass(map { MogileFS->config($_) } qw(db_dsn db_user db_pass max_handles));
}
sub new_from_dsn_user_pass {
- my ($class, $dsn, $user, $pass) = @_;
+ my ($class, $dsn, $user, $pass, $max_handles) = @_;
my $subclass;
if ($dsn =~ /^DBI:mysql:/i) {
$subclass = "MogileFS::Store::MySQL";
@@ -44,11 +44,13 @@ sub new_from_dsn_user_pass {
dsn => $dsn,
user => $user,
pass => $pass,
+ max_handles => $max_handles, # Max number of handles to allow
raise_errors => $subclass->want_raise_errors,
slave_list_cachetime => 0,
slave_list_cache => [],
recheck_req_gen => 0, # incremented generation, of recheck of dbh being requested
recheck_done_gen => 0, # once recheck is done, copy of what the request generation was
+ handles_left => 0, # amount of times this handle can still be verified
server_setting_cache => {}, # value-agnostic db setting cache.
}, $subclass;
$self->init;
@@ -249,9 +251,13 @@ sub recheck_dbh {
sub dbh {
my $self = shift;
+
if ($self->{dbh}) {
if ($self->{recheck_done_gen} != $self->{recheck_req_gen}) {
$self->{dbh} = undef unless $self->{dbh}->ping;
+ # Handles a memory leak under Solaris/Postgres.
+ $self->{dbh} = undef if ($self->{max_handles} &&
+ $self->{handles_left}-- < 0);
$self->{recheck_done_gen} = $self->{recheck_req_gen};
}
return $self->{dbh} if $self->{dbh};
@@ -265,6 +271,7 @@ sub dbh {
}) or
die "Failed to connect to database: " . DBI->errstr;
$self->post_dbi_connect;
+ $self->{handles_left} = $self->{max_handles} if $self->{max_handles};
return $self->{dbh};
}
View
@@ -3,6 +3,7 @@ use strict;
use Getopt::Long;
use lib 'lib';
use MogileFS::Store;
+use MogileFS::Config;
# Rename binary in process list to make init scripts saner
$0 = $_ = $0;
@@ -107,6 +108,8 @@ confirm("This will attempt to setup or upgrade your MogileFS database.\nIt won't
$sclass->on_status(\&status);
$sclass->on_confirm(\&confirm);
+MogileFS::Config->load_config;
+
my $sto = $sclass->new_from_mogdbsetup(
map { $_ => $args{$_} }
qw(dbhost dbport dbname

0 comments on commit 3ad5e7e

Please sign in to comment.