Changeset 1339
- Timestamp:
- 11/03/09 05:04:29 (5 months ago)
- Location:
- trunk/server
- Files:
-
- 4 modified
-
CHANGES (modified) (1 diff)
-
lib/MogileFS/Config.pm (modified) (3 diffs)
-
lib/MogileFS/Store.pm (modified) (5 diffs)
-
mogdbsetup (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/CHANGES
r1338 r1339 1 * Add 'max_handles' config option to restart a DB connection if there 2 are too many handles to it (victori). 3 1 4 * Close possibly invalid DB connections as we go out of scope 2 5 (victori). -
trunk/server/lib/MogileFS/Config.pm
r1331 r1339 59 59 $reaper_jobs, 60 60 $monitor_jobs, 61 $max_handles, 61 62 $min_free_space, 62 63 $max_disk_age, … … 94 95 'default_mindevcount=i' => \$cmdline{default_mindevcount}, 95 96 'node_timeout=i' => \$cmdline{node_timeout}, 97 'max_handles=i' => \$cmdline{max_handles}, 96 98 'pidfile=s' => \$cmdline{pidfile}, 97 99 'no_schema_check' => \$cmdline{no_schema_check}, … … 153 155 $min_free_space = choose_value( 'min_free_space', 100 ); 154 156 $max_disk_age = choose_value( 'max_disk_age', 5 ); 157 $max_handles = choose_value( 'max_handles', 0 ); 155 158 $DEBUG = choose_value( 'debug', $ENV{DEBUG} || 0 ); 156 159 $pidfile = choose_value( 'pidfile', "" ); -
trunk/server/lib/MogileFS/Store.pm
r1338 r1339 21 21 sub new { 22 22 my ($class) = @_; 23 return $class->new_from_dsn_user_pass(map { MogileFS->config($_) } qw(db_dsn db_user db_pass ));23 return $class->new_from_dsn_user_pass(map { MogileFS->config($_) } qw(db_dsn db_user db_pass max_handles)); 24 24 } 25 25 26 26 sub new_from_dsn_user_pass { 27 my ($class, $dsn, $user, $pass ) = @_;27 my ($class, $dsn, $user, $pass, $max_handles) = @_; 28 28 my $subclass; 29 29 if ($dsn =~ /^DBI:mysql:/i) { … … 45 45 user => $user, 46 46 pass => $pass, 47 max_handles => $max_handles, # Max number of handles to allow 47 48 raise_errors => $subclass->want_raise_errors, 48 49 slave_list_cachetime => 0, … … 50 51 recheck_req_gen => 0, # incremented generation, of recheck of dbh being requested 51 52 recheck_done_gen => 0, # once recheck is done, copy of what the request generation was 53 handles_given => 0, # amount of handles given out. 52 54 server_setting_cache => {}, # value-agnostic db setting cache. 53 55 }, $subclass; … … 250 252 sub dbh { 251 253 my $self = shift; 254 252 255 if ($self->{dbh}) { 253 256 if ($self->{recheck_done_gen} != $self->{recheck_req_gen}) { … … 255 258 $self->{recheck_done_gen} = $self->{recheck_req_gen}; 256 259 } 257 return $self->{dbh} if $self->{dbh}; 258 } 259 260 $self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{pass}, { 261 PrintError => 0, 262 AutoCommit => 1, 263 InactiveDestroy => 1, 264 # FUTURE: will default to on (have to validate all callers first): 265 RaiseError => ($self->{raise_errors} || 0), 266 }) or 267 die "Failed to connect to database: " . DBI->errstr; 268 $self->post_dbi_connect; 260 261 # If we have exceeded the number of handles/requests-for-dbh, then it 262 # is time to reset for a new connection. Reported to give a large 263 # performance boost on Solaris with Postgresql. 264 if ($self->{dbh} && 265 $self->{max_handles} && 266 $self->{max_handles} > 0 && 267 $self->{handles_given} > $self->{max_handles}) { 268 # TODO: Not sure about this disconnect. We probably want existing 269 # users of the connection to continue to do so. 270 $self->{dbh}->disconnect(); 271 $self->{dbh} = undef; 272 $self->{handles_given} = 0; 273 } 274 } 275 276 unless($self->{dbh}) { 277 $self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{pass}, { 278 PrintError => 0, 279 AutoCommit => 1, 280 InactiveDestroy => 1, 281 # FUTURE: will default to on (have to validate all callers first): 282 RaiseError => ($self->{raise_errors} || 0), 283 }) or 284 die "Failed to connect to database: " . DBI->errstr; 285 $self->post_dbi_connect; 286 } 287 $self->{handles_given} += 1; 269 288 return $self->{dbh}; 270 289 } -
trunk/server/mogdbsetup
r1282 r1339 4 4 use lib 'lib'; 5 5 use MogileFS::Store; 6 use MogileFS::Config; 6 7 7 8 # Rename binary in process list to make init scripts saner … … 108 109 $sclass->on_confirm(\&confirm); 109 110 111 MogileFS::Config->load_config; 112 110 113 my $sto = $sclass->new_from_mogdbsetup( 111 114 map { $_ => $args{$_} }
