Changeset 13041
- Timestamp:
- Apr 26, 2007, 10:27:33 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (11 diffs)
-
Nebulous/bin/neb-df (modified) (2 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13027 r13041 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.2 5 2007-04-25 21:40:29jhoblitt Exp $3 # $Id: SQL.pm,v 1.26 2007-04-26 20:27:33 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 158 158 my @schema; 159 159 160 local $/ = ' ;';160 local $/ = '###'; 161 161 162 162 foreach my $statement (<DATA>) { 163 163 last unless ( $statement =~ /\S+/ ); 164 $statement =~ s/###//g; 164 165 push @schema, $statement; 165 166 } … … 177 178 DROP TABLE IF EXISTS mount; 178 179 DROP TABLE IF EXISTS class; 179 DROP TABLE IF EXISTS log 180 DROP TABLE IF EXISTS log; 181 DROP PROCEDURE IF EXISTS getmountedvol 180 182 END 181 183 $sql{get_db_clear} = \@clear; … … 205 207 KEY(type) 206 208 ) ENGINE=innodb; 209 210 ### 207 211 208 212 CREATE TABLE storage_object_attr ( … … 217 221 KEY(class_id) 218 222 ) ENGINE=innodb; 223 224 ### 219 225 220 226 CREATE TABLE instance ( … … 231 237 ) ENGINE=innodb; 232 238 239 ### 240 233 241 CREATE TABLE lock_record ( 234 242 so_id BIGINT NOT NULL, … … 237 245 KEY(so_ID) 238 246 ) ENGINE=innodb; 247 248 ### 239 249 240 250 CREATE TABLE volume ( … … 246 256 ) ENGINE=innodb; 247 257 258 ### 259 248 260 CREATE TABLE mount ( 249 261 mountpoint VARCHAR(255) NOT NULL, … … 253 265 ) ENGINE=innodb; 254 266 267 ### 268 255 269 CREATE TABLE class ( 256 270 class_id TINYINT NOT NULL, … … 260 274 ) ENGINE=innodb; 261 275 276 ### 277 262 278 INSERT INTO class VALUES(0,0, 'default class ID'); 279 280 ### 263 281 264 282 CREATE TABLE log ( … … 270 288 PRIMARY KEY(timestamp) 271 289 ) ENGINE=innodb; 290 291 ### 292 293 CREATE PROCEDURE getmountedvol() DETERMINISTIC 294 BEGIN 295 DECLARE done BOOLEAN DEFAULT FALSE; 296 DECLARE vol_idvar INT; 297 DECLARE namevar VARCHAR(255); 298 DECLARE pathvar VARCHAR(255); 299 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume; 300 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 301 302 -- create a temp table to hold the merged results of the volume & mount 303 -- tables. One would hope the that the transaction isolation level will 304 -- stop one session from stomping on another sessions version of this 305 -- table. 306 307 DROP TABLE IF EXISTS mountedvol; 308 CREATE TEMPORARY TABLE mountedvol( 309 mountpoint VARCHAR(255) NOT NULL, 310 total BIGINT NOT NULL, 311 used BIGINT NOT NULL, 312 vol_id INT NOT NULL, 313 name VARCHAR(255) NOT NULL, 314 path VARCHAR(255) NOT NULL 315 ) ENGINE=MEMORY; 316 317 -- iterator over the volume table finding the coresponding entry in the 318 -- mount table and inserting union of the volume & mount row into the 319 -- mountedvol table 320 321 OPEN cur1; 322 323 myloop: LOOP 324 FETCH cur1 INTO vol_idvar, namevar, pathvar; 325 IF `done` THEN LEAVE myloop; END IF; 326 INSERT INTO mountedvol 327 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar 328 FROM 329 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring 330 FROM mount 331 ORDER BY substring DESC, LENGTH(mountpoint) DESC 332 LIMIT 1) as bar; 333 END LOOP myloop; 334 335 CLOSE cur1; 336 END -
trunk/Nebulous/bin/neb-df
r13023 r13041 3 3 # Copyright (C) 2005 Joshua Hoblitt 4 4 # 5 # $Id: neb-df,v 1. 1 2007-04-25 19:52:49jhoblitt Exp $5 # $Id: neb-df,v 1.2 2007-04-26 20:27:33 jhoblitt Exp $ 6 6 7 7 use strict; … … 47 47 my $sql = Nebulous::Server::SQL->new(); 48 48 49 # get a list of Nebulous volume names 50 my $query = $dbh->prepare("SELECT * FROM volume"); 49 # ask the db to generate the table of mounted Nebulous volume 50 $dbh->do("call getmountedvol()"); 51 52 # suck that table into an AoH 53 my $query = $dbh->prepare("SELECT * FROM mountedvol"); 51 54 $query->execute(); 52 55 53 my $mount_query = $dbh->prepare("SELECT *, INSTR(?, mountpoint) = 1 as substring FROM mount ORDER BY substring DESC, LENGTH(mountpoint) DESC LIMIT 1");54 55 56 my @stats; 56 57 # use the list of Nebulous volume names to look for the corresponding 58 # mountpoint 59 while (my $volume_row = $query->fetchrow_hashref) { 60 $mount_query->execute($volume_row->{path}); 61 my $mount_row = $mount_query->fetchrow_hashref; 62 63 # assemble a hash that combines the neb volume info with the filesystem 64 # info 65 my $vol = {%{$volume_row}, %{$mount_row}}; 66 push @stats, $vol; 57 while (my $mountedvol = $query->fetchrow_hashref) { 58 push @stats, $mountedvol; 67 59 } 68 60 -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13027 r13041 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.2 5 2007-04-25 21:40:29jhoblitt Exp $3 # $Id: SQL.pm,v 1.26 2007-04-26 20:27:33 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 158 158 my @schema; 159 159 160 local $/ = ' ;';160 local $/ = '###'; 161 161 162 162 foreach my $statement (<DATA>) { 163 163 last unless ( $statement =~ /\S+/ ); 164 $statement =~ s/###//g; 164 165 push @schema, $statement; 165 166 } … … 177 178 DROP TABLE IF EXISTS mount; 178 179 DROP TABLE IF EXISTS class; 179 DROP TABLE IF EXISTS log 180 DROP TABLE IF EXISTS log; 181 DROP PROCEDURE IF EXISTS getmountedvol 180 182 END 181 183 $sql{get_db_clear} = \@clear; … … 205 207 KEY(type) 206 208 ) ENGINE=innodb; 209 210 ### 207 211 208 212 CREATE TABLE storage_object_attr ( … … 217 221 KEY(class_id) 218 222 ) ENGINE=innodb; 223 224 ### 219 225 220 226 CREATE TABLE instance ( … … 231 237 ) ENGINE=innodb; 232 238 239 ### 240 233 241 CREATE TABLE lock_record ( 234 242 so_id BIGINT NOT NULL, … … 237 245 KEY(so_ID) 238 246 ) ENGINE=innodb; 247 248 ### 239 249 240 250 CREATE TABLE volume ( … … 246 256 ) ENGINE=innodb; 247 257 258 ### 259 248 260 CREATE TABLE mount ( 249 261 mountpoint VARCHAR(255) NOT NULL, … … 253 265 ) ENGINE=innodb; 254 266 267 ### 268 255 269 CREATE TABLE class ( 256 270 class_id TINYINT NOT NULL, … … 260 274 ) ENGINE=innodb; 261 275 276 ### 277 262 278 INSERT INTO class VALUES(0,0, 'default class ID'); 279 280 ### 263 281 264 282 CREATE TABLE log ( … … 270 288 PRIMARY KEY(timestamp) 271 289 ) ENGINE=innodb; 290 291 ### 292 293 CREATE PROCEDURE getmountedvol() DETERMINISTIC 294 BEGIN 295 DECLARE done BOOLEAN DEFAULT FALSE; 296 DECLARE vol_idvar INT; 297 DECLARE namevar VARCHAR(255); 298 DECLARE pathvar VARCHAR(255); 299 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume; 300 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 301 302 -- create a temp table to hold the merged results of the volume & mount 303 -- tables. One would hope the that the transaction isolation level will 304 -- stop one session from stomping on another sessions version of this 305 -- table. 306 307 DROP TABLE IF EXISTS mountedvol; 308 CREATE TEMPORARY TABLE mountedvol( 309 mountpoint VARCHAR(255) NOT NULL, 310 total BIGINT NOT NULL, 311 used BIGINT NOT NULL, 312 vol_id INT NOT NULL, 313 name VARCHAR(255) NOT NULL, 314 path VARCHAR(255) NOT NULL 315 ) ENGINE=MEMORY; 316 317 -- iterator over the volume table finding the coresponding entry in the 318 -- mount table and inserting union of the volume & mount row into the 319 -- mountedvol table 320 321 OPEN cur1; 322 323 myloop: LOOP 324 FETCH cur1 INTO vol_idvar, namevar, pathvar; 325 IF `done` THEN LEAVE myloop; END IF; 326 INSERT INTO mountedvol 327 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar 328 FROM 329 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring 330 FROM mount 331 ORDER BY substring DESC, LENGTH(mountpoint) DESC 332 LIMIT 1) as bar; 333 END LOOP myloop; 334 335 CLOSE cur1; 336 END
Note:
See TracChangeset
for help on using the changeset viewer.
