Changeset 60
- Timestamp:
- 08/05/04 00:30:43 (4 years ago)
- Files:
-
- trunk/api/perl/MogileFS.pm (modified) (1 diff)
- trunk/devnotes/perl-interface.txt (modified) (1 diff)
- trunk/server/mogilefsd (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/api/perl/MogileFS.pm
r58 r60 122 122 } 123 123 124 # create a new domain 125 sub 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 136 sub 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 152 sub 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 124 160 # given a key, returns a scalar reference pointing at a string containing 125 161 # the contents of the file. takes one parameter; a scalar key to get the trunk/devnotes/perl-interface.txt
r59 r60 60 60 each class has two keys in the form of 'domainXclassYname' and 61 61 '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 684 684 } 685 685 686 sub 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 686 698 sub domain_id { 687 699 my $domain = shift; … … 1099 1111 1100 1112 return $self->ok_line($ret); 1113 } 1114 1115 sub 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 1140 sub 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 1179 sub 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 }); 1101 1185 } 1102 1186 … … 1193 1277 my $err_text = { 1194 1278 '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", 1195 1285 }->{$err_code}; 1196 1286
