Changeset 1345
- Timestamp:
- 11/14/09 10:31:25 (4 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
r1339 r1345 1 * Add 'max_handles' config option to restart a DB connection if there2 are too many handles to it (victori).3 4 1 * Close possibly invalid DB connections as we go out of scope 5 2 (victori). -
trunk/server/lib/MogileFS/Config.pm
r1342 r1345 58 58 $reaper_jobs, 59 59 $monitor_jobs, 60 $max_handles,61 60 $min_free_space, 62 61 $max_disk_age, … … 94 93 'default_mindevcount=i' => \$cmdline{default_mindevcount}, 95 94 'node_timeout=i' => \$cmdline{node_timeout}, 96 'max_handles=i' => \$cmdline{max_handles},97 95 'pidfile=s' => \$cmdline{pidfile}, 98 96 'no_schema_check' => \$cmdline{no_schema_check}, … … 155 153 $min_free_space = choose_value( 'min_free_space', 100 ); 156 154 $max_disk_age = choose_value( 'max_disk_age', 5 ); 157 $max_handles = choose_value( 'max_handles', 0 );158 155 $DEBUG = choose_value( 'debug', $ENV{DEBUG} || 0 ); 159 156 $pidfile = choose_value( 'pidfile', "" ); -
trunk/server/lib/MogileFS/Store.pm
r1344 r1345 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 max_handles));23 return $class->new_from_dsn_user_pass(map { MogileFS->config($_) } qw(db_dsn db_user db_pass)); 24 24 } 25 25 26 26 sub new_from_dsn_user_pass { 27 my ($class, $dsn, $user, $pass , $max_handles) = @_;27 my ($class, $dsn, $user, $pass) = @_; 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 allow48 47 raise_errors => $subclass->want_raise_errors, 49 48 slave_list_cachetime => 0, … … 51 50 recheck_req_gen => 0, # incremented generation, of recheck of dbh being requested 52 51 recheck_done_gen => 0, # once recheck is done, copy of what the request generation was 53 handles_given => 0, # amount of handles given out.54 52 server_setting_cache => {}, # value-agnostic db setting cache. 55 53 }, $subclass; … … 252 250 sub dbh { 253 251 my $self = shift; 254 255 252 if ($self->{dbh}) { 256 253 if ($self->{recheck_done_gen} != $self->{recheck_req_gen}) { … … 258 255 $self->{recheck_done_gen} = $self->{recheck_req_gen}; 259 256 } 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; 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; 288 269 return $self->{dbh}; 289 270 } -
trunk/server/mogdbsetup
r1339 r1345 4 4 use lib 'lib'; 5 5 use MogileFS::Store; 6 use MogileFS::Config;7 6 8 7 # Rename binary in process list to make init scripts saner … … 109 108 $sclass->on_confirm(\&confirm); 110 109 111 MogileFS::Config->load_config;112 113 110 my $sto = $sclass->new_from_mogdbsetup( 114 111 map { $_ => $args{$_} }
