MogileFS-Server
view release on metacpan or search on metacpan
lib/MogileFS/FID.pm view on Meta::CPAN
sub _tryload {
return 1 if $_[0]{_loaded};
my $self = shift;
my $row = Mgd::get_store()->file_row_from_fidid($self->{fidid})
or return 0;
$self->{$_} = $row->{$_} foreach qw(dmid dkey length classid devcount);
$self->{_loaded} = 1;
return 1;
}
sub update_devcount {
my ($self, %opts) = @_;
my $no_lock = delete $opts{no_lock};
croak "Bogus options" if %opts;
return 1 if MogileFS::Config->server_setting_cached('skip_devcount');
my $fidid = $self->{fidid};
my $sto = Mgd::get_store();
if ($no_lock) {
return $sto->update_devcount($fidid);
} else {
return $sto->update_devcount_atomic($fidid);
}
}
sub update_class {
my ($self, %opts) = @_;
my $classid = delete $opts{classid};
croak "Bogus options" if %opts;
my $sto = Mgd::get_store();
return $sto->update_classid($self->{fidid}, $classid);
}
sub enqueue_for_replication {
lib/MogileFS/Store.pm view on Meta::CPAN
if ($dbh->{AutoCommit} == 0) { eval { $dbh->rollback }; }
throw("dup");
}
}
$self->condthrow; # this will rollback on errors
return $clsid if $rv;
die;
}
# return 1 on success, throw "dup" on duplicate name error, die otherwise
sub update_class_name {
my $self = shift;
my %arg = $self->_valid_params([qw(dmid classid classname)], @_);
my $rv = eval {
$self->dbh->do("UPDATE class SET classname=? WHERE dmid=? AND classid=?",
undef, $arg{classname}, $arg{dmid}, $arg{classid});
};
throw("dup") if $self->was_duplicate_error;
$self->condthrow;
return 1;
}
# return 1 on success, die otherwise
sub update_class_mindevcount {
my $self = shift;
my %arg = $self->_valid_params([qw(dmid classid mindevcount)], @_);
eval {
$self->dbh->do("UPDATE class SET mindevcount=? WHERE dmid=? AND classid=?",
undef, $arg{mindevcount}, $arg{dmid}, $arg{classid});
};
$self->condthrow;
return 1;
}
# return 1 on success, die otherwise
sub update_class_replpolicy {
my $self = shift;
my %arg = $self->_valid_params([qw(dmid classid replpolicy)], @_);
eval {
$self->dbh->do("UPDATE class SET replpolicy=? WHERE dmid=? AND classid=?",
undef, $arg{replpolicy}, $arg{dmid}, $arg{classid});
};
$self->condthrow;
return 1;
}
# return 1 on success, die otherwise
sub update_class_hashtype {
my $self = shift;
my %arg = $self->_valid_params([qw(dmid classid hashtype)], @_);
eval {
$self->dbh->do("UPDATE class SET hashtype=? WHERE dmid=? AND classid=?",
undef, $arg{hashtype}, $arg{dmid}, $arg{classid});
};
$self->condthrow;
}
sub nfiles_with_dmid_classid_devcount {
lib/MogileFS/Store.pm view on Meta::CPAN
my ($self, $devid, $hostid, $status) = @_;
my $rv = $self->conddup(sub {
$self->dbh->do("INSERT INTO device (devid, hostid, status) VALUES (?,?,?)", undef,
$devid, $hostid, $status);
});
$self->condthrow;
die "error making device $devid\n" unless $rv > 0;
return 1;
}
sub update_device {
my ($self, $devid, $to_update) = @_;
my @keys = sort keys %$to_update;
return unless @keys;
$self->conddup(sub {
$self->dbh->do("UPDATE device SET " . join('=?, ', @keys)
. "=? WHERE devid=?", undef, (map { $to_update->{$_} } @keys),
$devid);
});
return 1;
}
sub update_device_usage {
my $self = shift;
my %arg = $self->_valid_params([qw(mb_total mb_used devid mb_asof)], @_);
eval {
$self->dbh->do("UPDATE device SET ".
"mb_total = ?, mb_used = ?, mb_asof = ?" .
" WHERE devid = ?",
undef, $arg{mb_total}, $arg{mb_used}, $arg{mb_asof},
$arg{devid});
};
$self->condthrow;
}
# MySQL has an optimized version
sub update_device_usages {
my ($self, $updates, $cb) = @_;
foreach my $upd (@$updates) {
$self->update_device_usage(%$upd);
$cb->();
}
}
# This is unimplemented at the moment as we must verify:
# - no file_on rows exist
# - nothing in file_to_queue is going to attempt to use it
lib/MogileFS/Store.pm view on Meta::CPAN
$self->condthrow;
$sth->execute;
my @return;
while (my $row = $sth->fetchrow_hashref) {
push @return, $row;
}
return @return;
}
# update the device count for a given fidid
sub update_devcount {
my ($self, $fidid) = @_;
my $dbh = $self->dbh;
my $ct = $dbh->selectrow_array("SELECT COUNT(*) FROM file_on WHERE fid=?",
undef, $fidid);
eval { $dbh->do("UPDATE file SET devcount=? WHERE fid=?", undef,
$ct, $fidid); };
$self->condthrow;
return 1;
}
# update the classid for a given fidid
sub update_classid {
my ($self, $fidid, $classid) = @_;
my $dbh = $self->dbh;
$dbh->do("UPDATE file SET classid=? WHERE fid=?", undef,
$classid, $fidid);
$self->condthrow;
return 1;
}
lib/MogileFS/Store.pm view on Meta::CPAN
$dbh->do('INSERT INTO domain (dmid, namespace) VALUES (?, ?)',
undef, $maxid + 1, $name);
};
if ($self->was_duplicate_error) {
throw("dup");
}
return $maxid+1 if $rv;
die "failed to make domain"; # FIXME: the above is racy.
}
sub update_host {
my ($self, $hid, $to_update) = @_;
my @keys = sort keys %$to_update;
return unless @keys;
$self->conddup(sub {
$self->dbh->do("UPDATE host SET " . join('=?, ', @keys)
. "=? WHERE hostid=?", undef, (map { $to_update->{$_} } @keys),
$hid);
});
return 1;
}
lib/MogileFS/Store/MySQL.pm view on Meta::CPAN
}
}
}
# --------------------------------------------------------------------------
# Data-access things we override
# --------------------------------------------------------------------------
# update the device count for a given fidid
sub update_devcount_atomic {
my ($self, $fidid) = @_;
my $lockname = "mgfs:fid:$fidid";
my $lock = eval { $self->get_lock($lockname, 10) };
# Check to make sure the lock didn't timeout, then we want to bail.
return 0 if defined $lock && $lock == 0;
# Checking $@ is pointless for the time because we just want to plow ahead
# even if the get_lock trapped a recursion and threw a fatal error.
lib/MogileFS/Store/MySQL.pm view on Meta::CPAN
}
return $self->SUPER::pre_daemonize_checks();
}
sub get_keys_like_operator {
my $bool = MogileFS::Config->server_setting_cached('case_sensitive_list_keys');
return $bool ? "LIKE /*! BINARY */" : "LIKE";
}
sub update_device_usages {
my ($self, $updates, $cb) = @_;
$cb->();
my $chunk = 10000; # in case we hit max_allowed_packet size(!)
while (scalar @$updates) {
my @cur = splice(@$updates, 0, $chunk);
my @set;
foreach my $fld (qw(mb_total mb_used mb_asof)) {
my $s = "$fld = CASE devid\n";
foreach my $upd (@cur) {
my $devid = $upd->{devid};
lib/MogileFS/Store/Postgres.pm view on Meta::CPAN
my $dbh = $self->dbh;
eval {
$dbh->do("INSERT INTO file_on (fid, devid) VALUES (?, ?)", undef, $fidid, $devid);
};
return 1 if !$@ && !$dbh->err;
return 0;
}
# update the device count for a given fidid
sub update_devcount_atomic {
my ($self, $fidid) = @_;
my $rv;
$self->dbh->begin_work;
$rv = $self->dbh->do("SELECT devcount FROM file WHERE fid=? FOR UPDATE", undef, $fidid);
$self->condthrow;
if($rv == 0) {
$self->dbh->rollback;
return 1;
}
lib/MogileFS/Store/SQLite.pm view on Meta::CPAN
}
return $sql;
}
# eh. this is really atomic at all, but a) this is a demo db module,
# nobody should use SQLite in production, b) this method is going
# away, c) everything in SQLite is pretty atomic anyway with the
# db-level locks, d) the devcount field is no longer used. so i'm not
# caring much about doing this correctly.
sub update_devcount_atomic {
my ($self, $fidid) = @_;
$self->update_devcount($fidid);
}
# SQLite is just for testing, so don't upgrade
sub upgrade_add_device_drain {
return 1;
}
sub upgrade_modify_server_settings_value { 1 }
sub upgrade_add_file_to_queue_arg { 1 }
( run in 0.293 second using v1.01-cache-2.11-cpan-cc502c75498 )