Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replicateonly support #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/MogileFS/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ sub can_read_from {
return $_[0]->dstate->can_read_from;
}

sub is_replicateonly {
return $_[0]->dstate->is_replicateonly;
}

# FIXME: Is there a (unrelated to this code) bug where new files aren't tested
# against the free space limit before being stored or replicated somewhere?
sub should_get_new_files {
Expand Down
8 changes: 7 additions & 1 deletion lib/MogileFS/DeviceState.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ my $singleton = {
read => 1,
monitor => 1,
}),
'replicateonly' => bless({
replicateonly => 1,
write => 1,
monitor => 1,
new_files => 1,
}),
'drain' => bless({
read => 1,
write => 1,
Expand All @@ -42,6 +48,7 @@ sub of_string {
sub should_drain { $_[0]->{drain} }
sub can_delete_from { $_[0]->{write} }
sub can_read_from { $_[0]->{read} }
sub is_replicateonly { $_[0]->{replicateonly} }
sub should_get_new_files { $_[0]->{new_files} }
sub should_get_repl_files { $_[0]->{new_files} }
sub should_have_files { ! ($_[0]->{drain} || $_[0]->{dead}) }
Expand All @@ -50,7 +57,6 @@ sub should_monitor { $_[0]->{monitor} }
# named inconveniently so it's not taken to mean equalling string
# "dead"
sub is_perm_dead { $_[0]->{dead} }

sub should_wake_reaper { $_[0]->{dead} }

sub should_fsck_search_on {
Expand Down
4 changes: 3 additions & 1 deletion lib/MogileFS/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use List::Util qw(shuffle);
# also adds a TEXT 'arg' column to file_to_queue for passing arguments
# 14: modifies 'device' mb_total, mb_used to INT for devs > 16TB
# 15: adds checksum table, adds 'hashtype' column to 'class' table
use constant SCHEMA_VERSION => 15;
# 16: adds 'replicateonly' device status
use constant SCHEMA_VERSION => 16;

sub new {
my ($class) = @_;
Expand Down Expand Up @@ -529,6 +530,7 @@ sub setup_database {
$sto->upgrade_add_device_weight;
$sto->upgrade_add_device_readonly;
$sto->upgrade_add_device_drain;
$sto->upgrade_add_device_replicateonly;
$sto->upgrade_add_class_replpolicy;
$sto->upgrade_modify_server_settings_value;
$sto->upgrade_add_file_to_queue_arg;
Expand Down
7 changes: 7 additions & 0 deletions lib/MogileFS/Store/MySQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ sub upgrade_add_device_drain {
}
}

sub upgrade_add_device_replicateonly {
my $self = shift;
unless ($self->column_type("device", "status") =~ /replicateonly/) {
$self->dowell("ALTER TABLE device MODIFY COLUMN status ENUM('alive', 'dead', 'down', 'readonly', 'replicateonly', 'drain')");
}
}

sub upgrade_modify_server_settings_value {
my $self = shift;
unless ($self->column_type("server_settings", "value") =~ /text/i) {
Expand Down
10 changes: 9 additions & 1 deletion lib/MogileFS/Store/Postgres.pm
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ sub TABLE_device {
hostid SMALLINT NOT NULL,

status VARCHAR(8),
CHECK (status IN ('alive','dead','down','readonly','drain')),
CHECK (status IN ('alive','dead','down','readonly','replicateonly','drain')),
weight INT DEFAULT 100,

mb_total INT,
Expand Down Expand Up @@ -291,6 +291,14 @@ sub upgrade_add_device_drain {
}
}

sub upgrade_add_device_replicateonly {
my $self = shift;
unless ($self->column_constraint("device", "status") =~ /replicateonly/) {
$self->dowell("ALTER TABLE device MODIFY COLUMN status VARCHAR(8) CHECK(status IN ('alive', 'dead', 'down', 'readonly','drain','replicateonly'))");
}
}


sub upgrade_modify_server_settings_value {
my $self = shift;
unless ($self->column_type("server_settings", "value" =~ /text/i)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/MogileFS/Store/SQLite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ sub TABLE_device {
devid MEDIUMINT UNSIGNED NOT NULL,
hostid MEDIUMINT UNSIGNED NOT NULL,

status ENUM('alive','dead','down','readonly','drain'),
status ENUM('alive','dead','down','readonly','replicateonly','drain'),
weight MEDIUMINT DEFAULT 100,

mb_total INT UNSIGNED,
Expand Down
2 changes: 2 additions & 0 deletions lib/MogileFS/Worker/Query.pm
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ sub cmd_create_open {

last unless $ddev;
next unless $ddev->not_on_hosts(map { $_->host } @dests);
next if $ddev->is_replicateonly;

push @dests, $ddev;
}

return $self->err_line("no_devices") unless @dests;

my $fidid = eval {
Expand Down