MogileFS-Server

 view release on metacpan or  search on metacpan

lib/MogileFS/FID.pm  view on Meta::CPAN

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
            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

1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
    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

1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
    $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

1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
        $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

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
        }
    }
 
}
 
# --------------------------------------------------------------------------
# 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

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    }
 
    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

578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
    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

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
    }
 
    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 1.312 second using v1.01-cache-2.11-cpan-49f99fa48dc )