Changeset 60

Show
Ignore:
Timestamp:
08/05/04 00:30:43 (4 years ago)
Author:
marksmith
Message:

Add three new commands to mogilefsd: CREATE_DOMAIN, CREATE_CLASS, UPDATE_CLASS

These correspond to the new MogileFS methods: create_domain, create_class, update_class

These give you the ability to use a MogileFS object to create domains and
classes on the fly. You are also given the ability to update the minimum
replica count of an existing class in a domain using the update_class method.

$MogileFS->create_domain( $domain_name );
$MogileFS->create_class( $domain_name, $class_name, $minimum_replica_count );
$MogileFS->update_class( $domain_name, $class_name, $minimum_replica_count );

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/api/perl/MogileFS.pm

    r58 r60  
    122122} 
    123123 
     124# create a new domain 
     125sub create_domain { 
     126    my MogileFS $self = shift; 
     127    my $domain = shift; 
     128 
     129    my $res = $self->{backend}->do_request("create_domain", { domain => $domain }); 
     130    return undef unless $res->{domain} eq $domain; 
     131     
     132    return 1; 
     133} 
     134 
     135# create a new class within a domain 
     136sub create_class { 
     137    my MogileFS $self = shift; 
     138    my ($domain, $class, $mindevcount, $verb) = @_; 
     139    $verb ||= 'create'; 
     140     
     141    my $res = $self->{backend}->do_request("${verb}_class", { 
     142        domain => $domain, 
     143        class => $class, 
     144        mindevcount => $mindevcount, 
     145    }); 
     146    return undef unless $res->{class} eq $class; 
     147     
     148    return 1; 
     149} 
     150 
     151# update a class's mindevcount within a domain 
     152sub update_class { 
     153    my MogileFS $self = shift; 
     154 
     155    # a simple passthrough to create, but specify that it should be doing 
     156    # an update 
     157    return $self->create_class(@_, 'update'); 
     158} 
     159 
    124160# given a key, returns a scalar reference pointing at a string containing 
    125161# the contents of the file. takes one parameter; a scalar key to get the 
  • trunk/devnotes/perl-interface.txt

    r59 r60  
    6060           each class has two keys in the form of 'domainXclassYname' and 
    6161           'domainXclassYmindevcount' where Y is in the range of 1..N. 
     62 
     63            
     64    6) create a new domain on the fly 
     65     
     66        < CREATE_DOMAIN domain=mynewdomain 
     67        > OK domain=mynewdomain 
     68 
     69        -- returns the domain you just created as the only response value 
     70 
     71 
     72    7) create a new class 
     73 
     74        < CREATE_CLASS domain=mynewdomain&class=theclass&mindevcount=2 
     75        > OK domain=mynewdomain&class=theclass&mindevcount=2 
     76 
     77        -- creates a new class under the domain you specify named 'class' with 
     78           the minimum device replication count of 'mindevcount' 
     79 
     80 
     81    8) updates a class's minimum device replica count 
     82 
     83        < UPDATE_CLASS domain=mynewdomain&class=theclass&mindevcount=3 
     84        > OK domain=mynewdomain&class=theclass&mindevcount=3 
     85 
     86        -- same as create_class except it overwrites the mindevcount of the class 
     87           you are specifying.  useful if you want to change the replica count 
     88           for a class. 
  • trunk/server/mogilefsd

    r57 r60  
    684684} 
    685685 
     686sub class_id { 
     687    my ($dmid, $class) = @_; 
     688    return undef unless $dmid > 0 && length $class; 
     689 
     690    my $dbh = Mgd::get_dbh; 
     691    my $classid = $dbh->selectrow_array 
     692        ("SELECT classid FROM class WHERE dmid=? AND classname=?", undef, $dmid, $class) 
     693            or return undef; 
     694    return undef unless $classid; 
     695    return $classid; 
     696} 
     697 
    686698sub domain_id { 
    687699    my $domain = shift; 
     
    10991111 
    11001112    return $self->ok_line($ret); 
     1113} 
     1114 
     1115sub cmd_create_domain { 
     1116    my Client $self = shift; 
     1117    my $args = shift; 
     1118 
     1119    my $dbh = Mgd::get_dbh() 
     1120        or return $self->err_line("nodb"); 
     1121 
     1122    my $domain = $args->{domain}; 
     1123    return $self->err_line('no_domain') unless length $domain; 
     1124 
     1125    # FIXME: add some sort of authentication/limitation on this? 
     1126     
     1127    my $dmid = Mgd::domain_id($domain); 
     1128    return $self->err_line('domain_exists') if $dmid; 
     1129 
     1130    # get the max domain id 
     1131    my $maxid = $dbh->selectrow_array('SELECT MAX(dmid) FROM domain'); 
     1132    $dbh->do('INSERT INTO domain (dmid, namespace) VALUES (?, ?)', 
     1133             undef, $maxid + 1, $domain); 
     1134    return $self->err_line('failure') if $dbh->err; 
     1135 
     1136    # return the domain id we created 
     1137    return $self->ok_line({ domain => $domain }); 
     1138} 
     1139 
     1140sub cmd_create_class { 
     1141    my Client $self = shift; 
     1142    my $args = shift; 
     1143 
     1144    my $dbh = Mgd::get_dbh() 
     1145        or return $self->err_line("nodb"); 
     1146 
     1147    my $domain = $args->{domain}; 
     1148    return $self->err_line('no_domain') unless length $domain; 
     1149 
     1150    my $class = $args->{class}; 
     1151    return $self->err_line('no_class') unless length $class; 
     1152 
     1153    my $mindevcount = $args->{mindevcount}+0; 
     1154    return $self->err_line('invalid_mindevcount') unless $mindevcount > 0; 
     1155 
     1156    # FIXME: add some sort of authentication/limitation on this? 
     1157     
     1158    my $dmid = Mgd::domain_id($domain); 
     1159    return $self->err_line('no_domain') unless $dmid; 
     1160 
     1161    my $cid = Mgd::class_id($dmid, $class); 
     1162    return $self->err_line('class_exists') if $cid && !$args->{update}; 
     1163 
     1164    # setup verb; if we have the update option set on, then we're doing a 
     1165    # replace so we update our class 
     1166    my $verb = $args->{update} ? 'REPLACE' : 'INSERT'; 
     1167 
     1168    # get the max class id in this domain 
     1169    my $maxid = $dbh->selectrow_array 
     1170        ('SELECT MAX(classid) FROM class WHERE dmid = ?', undef, $dmid); 
     1171    $dbh->do("$verb INTO class (dmid, classid, classname, mindevcount) VALUES (?, ?, ?, ?)", 
     1172             undef, $dmid, $maxid + 1, $class, $mindevcount); 
     1173    return $self->err_line('failure') if $dbh->err; 
     1174 
     1175    # return success 
     1176    return $self->ok_line({ class => $class, mindevcount => $mindevcount, domain => $domain }); 
     1177} 
     1178 
     1179sub cmd_update_class { 
     1180    my Client $self = shift; 
     1181    my $args = shift; 
     1182 
     1183    # simply passes through to create_class with update set 
     1184    $self->cmd_create_class({ %$args, update => 1 }); 
    11011185} 
    11021186 
     
    11931277    my $err_text = { 
    11941278        'unknown_command' => "Unknown server command", 
     1279        'no_domain' => "No domain provided", 
     1280        'no_class' => "No class provided", 
     1281        'class_exists' => "That class already exists in that domain", 
     1282        'domain_exists' => "That domain already exists", 
     1283        'invalid_mindevcount' => "The mindevcount must be at least 1", 
     1284        'failure' => "Operation failed", 
    11951285    }->{$err_code}; 
    11961286