Changeset 13115
- Timestamp:
- May 1, 2007, 3:00:10 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (14 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (8 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (14 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r13092 r13115 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 8 2007-05-01 02:52:04jhoblitt Exp $3 # $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 120 120 } 121 121 122 sub create_object { 122 sub create_object 123 { 123 124 my $self = shift; 124 125 … … 143 144 $log->debug( "entered - @_" ); 144 145 145 $volume = $self->_get_storage_volume( $volume ); 146 147 my $object_id; 146 # Find the storage volume to use. We are doing this first as there's no 147 # point in creating a new storage object if we can't allocate a new 148 # instance. ->_get_storage_volume() throws an exception on failure. 149 my ($vol_id, $vol_path); 150 eval { 151 ($vol_id, $vol_path) = $self->_get_storage_volume($volume); 152 }; 153 if ($@) { 154 $log->logdie($@); 155 } 156 148 157 my $ins_id; 149 150 158 eval { 151 159 { 152 160 # create storage_object 153 # XXX prepare_cached() was causing test failures154 my $query = $db->prepare( $sql->new_object );155 $query->execute( 'NULL', $key );156 } 157 161 my $query = $db->prepare_cached( $sql->new_object ); 162 $query->execute('NULL', $key); 163 } 164 165 my $object_id; 158 166 { 159 167 # get object ID 160 my $query = $db->prepare _cached( $sql->last_insert_id );168 my $query = $db->prepare( $sql->last_insert_id ); 161 169 $query->execute; 162 ( $object_id ) = $query->fetchrow_array; 163 164 $query->finish; 170 ($object_id) = $query->fetchrow_array; 165 171 } 166 172 … … 168 174 # create storage_object_attr 169 175 my $query = $db->prepare_cached( $sql->new_object_attr ); 170 $query->execute( $object_id);176 $query->execute($object_id); 171 177 } 172 178 … … 179 185 { 180 186 # get instance ID 181 my $query = $db->prepare _cached( $sql->last_insert_id );187 my $query = $db->prepare( $sql->last_insert_id ); 182 188 $query->execute; 183 ( $ins_id) = $query->fetchrow_array;184 185 $query->finish;186 }187 };188 if ( $@ ) {189 $db->rollback;190 $log->logdie( "database error: $@" ); 191 }192 193 my $uri = URI::file->new("$volume/$key.$ins_id");194 195 $log->debug( "generated uri $uri");189 ($ins_id) = $query->fetchrow_array; 190 } 191 }; 192 if ($@) { 193 $db->rollback; 194 $log->logdie("database error: $@"); 195 } 196 197 # Unfortunately, since we want to use the instance row's ID as part of the 198 # actual on disk file name we can't try to create the file until after 199 # we've create both a new storage_storage object and instance. 200 my $uri = URI::file->new("$vol_path/$key.$ins_id"); 201 $log->debug("generated uri $uri"); 196 202 197 203 # TODO add some stuff here to retry if unsucessful … … 199 205 _create_empty_file($uri->file); 200 206 }; 201 if ( $@) {202 $db->rollback; 203 $log->logdie( $@);207 if ($@) { 208 $db->rollback; 209 $log->logdie($@); 204 210 } 205 211 … … 207 213 { 208 214 my $query = $db->prepare_cached( $sql->update_instance_uri ); 209 $query->execute( $uri, $ins_id ); 215 # vol_id, uri, ins_id 216 $query->execute($vol_id, $uri, $ins_id); 210 217 } 211 218 212 219 $db->commit; 213 220 }; 214 $log->logdie( "database error: $@" ) if $@; 215 216 $log->debug( "leaving" ); 221 if ($@) { 222 $db->rollback; 223 $log->logdie("database error: $@"); 224 } 225 226 $log->debug("leaving"); 217 227 218 228 return "$uri"; 219 229 } 220 230 221 sub rename_object { 222 my $self = shift; 223 224 my ( $key, $newkey ) = validate_pos( @_, 225 { 226 type => SCALAR, 227 }, 228 { 229 type => SCALAR, 230 }, 231 ); 232 233 my $log = $self->log; 234 my $sql = $self->sql; 235 my $db =$self->db; 236 237 $log->debug( "entered - @_" ); 231 sub rename_object 232 { 233 my $self = shift; 234 235 my ($key, $newkey) = validate_pos(@_, 236 { 237 type => SCALAR, 238 }, 239 { 240 type => SCALAR, 241 }, 242 ); 243 244 my $log = $self->log; 245 my $sql = $self->sql; 246 my $db =$self->db; 247 248 $log->debug("entered - @_"); 238 249 239 250 eval { … … 244 255 245 256 # if we affected more then one row something very bad has happened. 246 unless ( $rows == 1 ) { 247 $log->logdie( "affected row count is $rows instead of 1" ); 248 } 249 }; 250 if ($@) { 251 $db->rollback; 252 $log->logdie( "database error: $@" ); 253 } 254 255 eval { 257 unless ($rows == 1) { 258 $log->logdie("affected row count is $rows instead of 1"); 259 } 260 256 261 $db->commit; 257 262 }; 258 if ( $@) {259 $db->rollback; 260 $log->logdie( "database error: $@");261 } 262 263 $log->debug( "leaving");263 if ($@) { 264 $db->rollback; 265 $log->logdie("database error: $@"); 266 } 267 268 $log->debug("leaving"); 264 269 265 270 return $newkey; 266 271 } 267 272 268 sub replicate_object { 269 my $self = shift; 270 271 my ( $key, $volume ) = validate_pos( @_, 273 sub replicate_object 274 { 275 my $self = shift; 276 277 my ($key, $volume) = validate_pos(@_, 272 278 { 273 279 type => SCALAR, … … 283 289 my $db =$self->db; 284 290 285 $log->debug( "entered - @_" ); 286 287 # TODO 288 $volume = $self->_get_storage_volume(); 289 290 my $path; 291 my $uri; 292 293 my $so_id; 291 $log->debug("entered - @_"); 292 293 my ($vol_id, $vol_path); 294 eval { 295 ($vol_id, $vol_path) = $self->_get_storage_volume($volume); 296 }; 297 if ($@) { 298 $log->logdie($@); 299 } 300 294 301 my $ins_id; 295 302 eval { 303 my $so_id; 296 304 { 297 305 my $query = $db->prepare_cached( $sql->get_object_instances ); … … 310 318 { 311 319 my $query = $db->prepare_cached( $sql->new_instance ); 312 $query->execute( $so_id);313 } 314 315 { 316 my $query = $db->prepare _cached( $sql->last_insert_id );320 $query->execute($so_id); 321 } 322 323 { 324 my $query = $db->prepare( $sql->last_insert_id ); 317 325 $query->execute(); 318 326 319 ( $ins_id ) = $query->fetchrow_array; 320 321 $query->finish; 322 } 323 324 { 325 $uri = URI::file->new("$volume/$key.$ins_id"); 326 $log->debug("generated uri $uri"); 327 327 ($ins_id) = $query->fetchrow_array; 328 } 329 }; 330 if ($@) { 331 $db->rollback; 332 $log->logdie( "database error: $@" ); 333 } 334 335 my $uri = URI::file->new("$vol_path/$key.$ins_id"); 336 $log->debug("generated uri $uri"); 337 338 # TODO add some stuff here to retry if unsucessful 339 eval { 340 _create_empty_file($uri->file); 341 }; 342 if ($@) { 343 $db->rollback; 344 $log->logdie($@); 345 } 346 347 eval { 348 { 328 349 my $query = $db->prepare_cached( $sql->update_instance_uri ); 329 $query->execute( $uri, $ins_id ); 330 } 331 }; 332 if ( $@ ) { 333 $db->rollback; 334 $log->logdie( "database error: $@" ); 335 } 336 337 338 eval { 339 _create_empty_file($uri->file); 340 }; 341 if ( $@ ) { 342 $db->rollback; 343 $log->logdie( $@ ); 344 } 345 346 $db->commit; 347 348 $log->debug( "leaving" ); 350 # vol_id, uri, ins_id 351 $query->execute($vol_id, $uri, $ins_id); 352 } 353 354 $db->commit; 355 }; 356 if ($@) { 357 $db->rollback; 358 $log->logdie("database error: $@"); 359 } 360 361 $log->debug("leaving"); 349 362 350 363 return "$uri"; … … 1000 1013 # select *, total - used as free, (used / total) * 100 as perused from mount; 1001 1014 1002 sub _get_storage_volume { 1015 sub _get_storage_volume 1016 { 1003 1017 my $self = shift; 1004 1018 … … 1013 1027 my $name = shift; 1014 1028 1015 my $volume; 1016 my $query; 1017 eval { 1018 # ask the db to generate the table of mounted Nebulous volume 1019 $query = $db->prepare_cached("call getmountedvol()"); 1020 $query->execute(); 1029 my ($vol_id, $vol_path); 1030 eval { 1031 { 1032 # ask the db to generate the table of mounted Nebulous volume 1033 my $query = $db->prepare_cached("call getmountedvol()"); 1034 $query->execute(); 1035 } 1021 1036 1022 1037 # TODO cache this? 1038 my $query; 1023 1039 my $rows; 1024 1040 if ( $name ) { … … 1031 1047 1032 1048 # there has to be atleast one storage volume 1033 unless ( $rows > 0) {1034 $log->logdie( "affected row count is $rows instead of 1" );1035 } 1036 1037 $volume = $query->fetchrow_hashref->{ 'volume' };1038 1049 unless ($rows > 0) { 1050 $log->logdie( "affected row count is $rows instead of > 0" ); 1051 } 1052 1053 my $free; 1054 ($vol_id, $vol_path, $free) = $query->fetchrow_array; 1039 1055 $query->finish; 1040 $db->commit; 1041 }; 1042 if ( $@ ) { 1043 $query->finish; 1044 $db->rollback; 1045 $log->logdie( "database error: $@" ) if $@; 1046 } 1047 1048 $log->logdie( "failed to find a suitable volume" ) unless defined $volume; 1056 }; 1057 if ($@) { 1058 $db->rollback; 1059 $log->logdie("database error: $@"); 1060 } 1061 1062 $log->logdie("failed to find a suitable volume" ) 1063 unless defined $vol_id and defined $vol_path; 1049 1064 1050 1065 $log->debug( "leaving" ); 1051 1066 1052 return $volume;1067 return ($vol_id, $vol_path); 1053 1068 } 1054 1069 … … 1060 1075 my $db =$self->db; 1061 1076 1062 my $volume;1077 my ($vol_id, $vol_path); 1063 1078 eval { 1064 1079 my $query = $db->prepare_cached( $sql->get_volume_by_name ); 1065 1080 $query->execute( $vol_name ); 1066 ( $volume ) = $query->fetchrow_array;1067 1081 my $free; 1082 ($vol_id, $vol_path, $free) = $query->fetchrow_array; 1068 1083 $query->finish; 1069 1084 }; 1070 if ( $@) {1085 if ($@) { 1071 1086 $db->rollback; 1072 1087 $log->logdie( "database error: $@" ); 1073 1088 } 1074 1089 1075 return ( defined $volume ) ? 1 : undef; 1090 if (defined $vol_id and defined $vol_path) { 1091 return 1; 1092 } 1093 1094 return; 1076 1095 } 1077 1096 -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13092 r13115 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 0 2007-05-01 02:52:04jhoblitt Exp $3 # $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 17 17 }, 18 18 update_instance_uri => qq{ 19 UPDATE instance SET uri = ? WHERE ins_id = ?19 UPDATE instance SET vol_id = ?, uri = ? WHERE ins_id = ? 20 20 }, 21 21 last_insert_id => qq{ … … 38 38 WHERE storage_object.so_id = ? 39 39 }, 40 new_object_instance => qq{40 new_object_instance => qq{ 41 41 INSERT INTO instance 42 VALUES (NULL, LAST_INSERT_ID(), 'error', NULL, NULL, NULL, NULL)42 VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL) 43 43 }, 44 44 new_instance => qq{ 45 45 INSERT INTO instance 46 VALUES (NULL, ?, 'error', NULL,NULL, NULL, NULL)46 VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL) 47 47 }, 48 48 get_object => qq{ … … 154 154 get_storage_volume_byname => qq{ 155 155 SELECT 156 path as volume, 156 vol_id, 157 path, 157 158 total - used as free 158 159 FROM mountedvol … … 165 166 get_storage_volume => qq{ 166 167 SELECT 167 path as volume, 168 vol_id, 169 path, 168 170 total - used as free 169 171 FROM mountedvol … … 210 212 { 211 213 my @clear = split /;/, <<END; 214 SET FOREIGN_KEY_CHECKS=0; 212 215 DROP TABLE IF EXISTS storage_object; 213 216 DROP TABLE IF EXISTS storage_object_attr; … … 219 222 DROP TABLE IF EXISTS class; 220 223 DROP TABLE IF EXISTS log; 221 DROP PROCEDURE IF EXISTS getmountedvol 224 DROP PROCEDURE IF EXISTS getmountedvol; 225 SET FOREIGN_KEY_CHECKS=1 222 226 END 223 227 $sql{get_db_clear} = \@clear; … … 273 277 ins_id BIGINT NOT NULL AUTO_INCREMENT, 274 278 so_id BIGINT NOT NULL, 279 vol_id INT NOT NULL, 275 280 uri VARCHAR(255) NOT NULL, 276 281 sha1sum CHAR(40) ASCII, -
trunk/Nebulous/lib/Nebulous/Server.pm
r13092 r13115 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 8 2007-05-01 02:52:04jhoblitt Exp $3 # $Id: Server.pm,v 1.29 2007-05-02 01:00:10 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 120 120 } 121 121 122 sub create_object { 122 sub create_object 123 { 123 124 my $self = shift; 124 125 … … 143 144 $log->debug( "entered - @_" ); 144 145 145 $volume = $self->_get_storage_volume( $volume ); 146 147 my $object_id; 146 # Find the storage volume to use. We are doing this first as there's no 147 # point in creating a new storage object if we can't allocate a new 148 # instance. ->_get_storage_volume() throws an exception on failure. 149 my ($vol_id, $vol_path); 150 eval { 151 ($vol_id, $vol_path) = $self->_get_storage_volume($volume); 152 }; 153 if ($@) { 154 $log->logdie($@); 155 } 156 148 157 my $ins_id; 149 150 158 eval { 151 159 { 152 160 # create storage_object 153 # XXX prepare_cached() was causing test failures154 my $query = $db->prepare( $sql->new_object );155 $query->execute( 'NULL', $key );156 } 157 161 my $query = $db->prepare_cached( $sql->new_object ); 162 $query->execute('NULL', $key); 163 } 164 165 my $object_id; 158 166 { 159 167 # get object ID 160 my $query = $db->prepare _cached( $sql->last_insert_id );168 my $query = $db->prepare( $sql->last_insert_id ); 161 169 $query->execute; 162 ( $object_id ) = $query->fetchrow_array; 163 164 $query->finish; 170 ($object_id) = $query->fetchrow_array; 165 171 } 166 172 … … 168 174 # create storage_object_attr 169 175 my $query = $db->prepare_cached( $sql->new_object_attr ); 170 $query->execute( $object_id);176 $query->execute($object_id); 171 177 } 172 178 … … 179 185 { 180 186 # get instance ID 181 my $query = $db->prepare _cached( $sql->last_insert_id );187 my $query = $db->prepare( $sql->last_insert_id ); 182 188 $query->execute; 183 ( $ins_id) = $query->fetchrow_array;184 185 $query->finish;186 }187 };188 if ( $@ ) {189 $db->rollback;190 $log->logdie( "database error: $@" ); 191 }192 193 my $uri = URI::file->new("$volume/$key.$ins_id");194 195 $log->debug( "generated uri $uri");189 ($ins_id) = $query->fetchrow_array; 190 } 191 }; 192 if ($@) { 193 $db->rollback; 194 $log->logdie("database error: $@"); 195 } 196 197 # Unfortunately, since we want to use the instance row's ID as part of the 198 # actual on disk file name we can't try to create the file until after 199 # we've create both a new storage_storage object and instance. 200 my $uri = URI::file->new("$vol_path/$key.$ins_id"); 201 $log->debug("generated uri $uri"); 196 202 197 203 # TODO add some stuff here to retry if unsucessful … … 199 205 _create_empty_file($uri->file); 200 206 }; 201 if ( $@) {202 $db->rollback; 203 $log->logdie( $@);207 if ($@) { 208 $db->rollback; 209 $log->logdie($@); 204 210 } 205 211 … … 207 213 { 208 214 my $query = $db->prepare_cached( $sql->update_instance_uri ); 209 $query->execute( $uri, $ins_id ); 215 # vol_id, uri, ins_id 216 $query->execute($vol_id, $uri, $ins_id); 210 217 } 211 218 212 219 $db->commit; 213 220 }; 214 $log->logdie( "database error: $@" ) if $@; 215 216 $log->debug( "leaving" ); 221 if ($@) { 222 $db->rollback; 223 $log->logdie("database error: $@"); 224 } 225 226 $log->debug("leaving"); 217 227 218 228 return "$uri"; 219 229 } 220 230 221 sub rename_object { 222 my $self = shift; 223 224 my ( $key, $newkey ) = validate_pos( @_, 225 { 226 type => SCALAR, 227 }, 228 { 229 type => SCALAR, 230 }, 231 ); 232 233 my $log = $self->log; 234 my $sql = $self->sql; 235 my $db =$self->db; 236 237 $log->debug( "entered - @_" ); 231 sub rename_object 232 { 233 my $self = shift; 234 235 my ($key, $newkey) = validate_pos(@_, 236 { 237 type => SCALAR, 238 }, 239 { 240 type => SCALAR, 241 }, 242 ); 243 244 my $log = $self->log; 245 my $sql = $self->sql; 246 my $db =$self->db; 247 248 $log->debug("entered - @_"); 238 249 239 250 eval { … … 244 255 245 256 # if we affected more then one row something very bad has happened. 246 unless ( $rows == 1 ) { 247 $log->logdie( "affected row count is $rows instead of 1" ); 248 } 249 }; 250 if ($@) { 251 $db->rollback; 252 $log->logdie( "database error: $@" ); 253 } 254 255 eval { 257 unless ($rows == 1) { 258 $log->logdie("affected row count is $rows instead of 1"); 259 } 260 256 261 $db->commit; 257 262 }; 258 if ( $@) {259 $db->rollback; 260 $log->logdie( "database error: $@");261 } 262 263 $log->debug( "leaving");263 if ($@) { 264 $db->rollback; 265 $log->logdie("database error: $@"); 266 } 267 268 $log->debug("leaving"); 264 269 265 270 return $newkey; 266 271 } 267 272 268 sub replicate_object { 269 my $self = shift; 270 271 my ( $key, $volume ) = validate_pos( @_, 273 sub replicate_object 274 { 275 my $self = shift; 276 277 my ($key, $volume) = validate_pos(@_, 272 278 { 273 279 type => SCALAR, … … 283 289 my $db =$self->db; 284 290 285 $log->debug( "entered - @_" ); 286 287 # TODO 288 $volume = $self->_get_storage_volume(); 289 290 my $path; 291 my $uri; 292 293 my $so_id; 291 $log->debug("entered - @_"); 292 293 my ($vol_id, $vol_path); 294 eval { 295 ($vol_id, $vol_path) = $self->_get_storage_volume($volume); 296 }; 297 if ($@) { 298 $log->logdie($@); 299 } 300 294 301 my $ins_id; 295 302 eval { 303 my $so_id; 296 304 { 297 305 my $query = $db->prepare_cached( $sql->get_object_instances ); … … 310 318 { 311 319 my $query = $db->prepare_cached( $sql->new_instance ); 312 $query->execute( $so_id);313 } 314 315 { 316 my $query = $db->prepare _cached( $sql->last_insert_id );320 $query->execute($so_id); 321 } 322 323 { 324 my $query = $db->prepare( $sql->last_insert_id ); 317 325 $query->execute(); 318 326 319 ( $ins_id ) = $query->fetchrow_array; 320 321 $query->finish; 322 } 323 324 { 325 $uri = URI::file->new("$volume/$key.$ins_id"); 326 $log->debug("generated uri $uri"); 327 327 ($ins_id) = $query->fetchrow_array; 328 } 329 }; 330 if ($@) { 331 $db->rollback; 332 $log->logdie( "database error: $@" ); 333 } 334 335 my $uri = URI::file->new("$vol_path/$key.$ins_id"); 336 $log->debug("generated uri $uri"); 337 338 # TODO add some stuff here to retry if unsucessful 339 eval { 340 _create_empty_file($uri->file); 341 }; 342 if ($@) { 343 $db->rollback; 344 $log->logdie($@); 345 } 346 347 eval { 348 { 328 349 my $query = $db->prepare_cached( $sql->update_instance_uri ); 329 $query->execute( $uri, $ins_id ); 330 } 331 }; 332 if ( $@ ) { 333 $db->rollback; 334 $log->logdie( "database error: $@" ); 335 } 336 337 338 eval { 339 _create_empty_file($uri->file); 340 }; 341 if ( $@ ) { 342 $db->rollback; 343 $log->logdie( $@ ); 344 } 345 346 $db->commit; 347 348 $log->debug( "leaving" ); 350 # vol_id, uri, ins_id 351 $query->execute($vol_id, $uri, $ins_id); 352 } 353 354 $db->commit; 355 }; 356 if ($@) { 357 $db->rollback; 358 $log->logdie("database error: $@"); 359 } 360 361 $log->debug("leaving"); 349 362 350 363 return "$uri"; … … 1000 1013 # select *, total - used as free, (used / total) * 100 as perused from mount; 1001 1014 1002 sub _get_storage_volume { 1015 sub _get_storage_volume 1016 { 1003 1017 my $self = shift; 1004 1018 … … 1013 1027 my $name = shift; 1014 1028 1015 my $volume; 1016 my $query; 1017 eval { 1018 # ask the db to generate the table of mounted Nebulous volume 1019 $query = $db->prepare_cached("call getmountedvol()"); 1020 $query->execute(); 1029 my ($vol_id, $vol_path); 1030 eval { 1031 { 1032 # ask the db to generate the table of mounted Nebulous volume 1033 my $query = $db->prepare_cached("call getmountedvol()"); 1034 $query->execute(); 1035 } 1021 1036 1022 1037 # TODO cache this? 1038 my $query; 1023 1039 my $rows; 1024 1040 if ( $name ) { … … 1031 1047 1032 1048 # there has to be atleast one storage volume 1033 unless ( $rows > 0) {1034 $log->logdie( "affected row count is $rows instead of 1" );1035 } 1036 1037 $volume = $query->fetchrow_hashref->{ 'volume' };1038 1049 unless ($rows > 0) { 1050 $log->logdie( "affected row count is $rows instead of > 0" ); 1051 } 1052 1053 my $free; 1054 ($vol_id, $vol_path, $free) = $query->fetchrow_array; 1039 1055 $query->finish; 1040 $db->commit; 1041 }; 1042 if ( $@ ) { 1043 $query->finish; 1044 $db->rollback; 1045 $log->logdie( "database error: $@" ) if $@; 1046 } 1047 1048 $log->logdie( "failed to find a suitable volume" ) unless defined $volume; 1056 }; 1057 if ($@) { 1058 $db->rollback; 1059 $log->logdie("database error: $@"); 1060 } 1061 1062 $log->logdie("failed to find a suitable volume" ) 1063 unless defined $vol_id and defined $vol_path; 1049 1064 1050 1065 $log->debug( "leaving" ); 1051 1066 1052 return $volume;1067 return ($vol_id, $vol_path); 1053 1068 } 1054 1069 … … 1060 1075 my $db =$self->db; 1061 1076 1062 my $volume;1077 my ($vol_id, $vol_path); 1063 1078 eval { 1064 1079 my $query = $db->prepare_cached( $sql->get_volume_by_name ); 1065 1080 $query->execute( $vol_name ); 1066 ( $volume ) = $query->fetchrow_array;1067 1081 my $free; 1082 ($vol_id, $vol_path, $free) = $query->fetchrow_array; 1068 1083 $query->finish; 1069 1084 }; 1070 if ( $@) {1085 if ($@) { 1071 1086 $db->rollback; 1072 1087 $log->logdie( "database error: $@" ); 1073 1088 } 1074 1089 1075 return ( defined $volume ) ? 1 : undef; 1090 if (defined $vol_id and defined $vol_path) { 1091 return 1; 1092 } 1093 1094 return; 1076 1095 } 1077 1096 -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13092 r13115 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 0 2007-05-01 02:52:04jhoblitt Exp $3 # $Id: SQL.pm,v 1.31 2007-05-02 01:00:10 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 17 17 }, 18 18 update_instance_uri => qq{ 19 UPDATE instance SET uri = ? WHERE ins_id = ?19 UPDATE instance SET vol_id = ?, uri = ? WHERE ins_id = ? 20 20 }, 21 21 last_insert_id => qq{ … … 38 38 WHERE storage_object.so_id = ? 39 39 }, 40 new_object_instance => qq{40 new_object_instance => qq{ 41 41 INSERT INTO instance 42 VALUES (NULL, LAST_INSERT_ID(), 'error', NULL, NULL, NULL, NULL)42 VALUES (NULL, LAST_INSERT_ID(), 0, 'error', NULL, NULL, NULL, NULL) 43 43 }, 44 44 new_instance => qq{ 45 45 INSERT INTO instance 46 VALUES (NULL, ?, 'error', NULL,NULL, NULL, NULL)46 VALUES (NULL, ?, 0, 'error', NULL,NULL, NULL, NULL) 47 47 }, 48 48 get_object => qq{ … … 154 154 get_storage_volume_byname => qq{ 155 155 SELECT 156 path as volume, 156 vol_id, 157 path, 157 158 total - used as free 158 159 FROM mountedvol … … 165 166 get_storage_volume => qq{ 166 167 SELECT 167 path as volume, 168 vol_id, 169 path, 168 170 total - used as free 169 171 FROM mountedvol … … 210 212 { 211 213 my @clear = split /;/, <<END; 214 SET FOREIGN_KEY_CHECKS=0; 212 215 DROP TABLE IF EXISTS storage_object; 213 216 DROP TABLE IF EXISTS storage_object_attr; … … 219 222 DROP TABLE IF EXISTS class; 220 223 DROP TABLE IF EXISTS log; 221 DROP PROCEDURE IF EXISTS getmountedvol 224 DROP PROCEDURE IF EXISTS getmountedvol; 225 SET FOREIGN_KEY_CHECKS=1 222 226 END 223 227 $sql{get_db_clear} = \@clear; … … 273 277 ins_id BIGINT NOT NULL AUTO_INCREMENT, 274 278 so_id BIGINT NOT NULL, 279 vol_id INT NOT NULL, 275 280 uri VARCHAR(255) NOT NULL, 276 281 sha1sum CHAR(40) ASCII,
Note:
See TracChangeset
for help on using the changeset viewer.
