Changeset 31038 for trunk/ippTools
- Timestamp:
- Mar 24, 2011, 2:09:53 PM (15 years ago)
- Location:
- trunk/ippTools
- Files:
-
- 12 edited
-
share/pxadmin_create_tables.sql (modified) (7 diffs)
-
share/pztool_find_completed_exp.sql (modified) (2 diffs)
-
share/pztool_pendingimfile.sql (modified) (1 diff)
-
share/regtool_checkburntoolimfile.sql (modified) (1 diff)
-
share/regtool_checkstatus.sql (modified) (1 diff)
-
share/regtool_pendingburntoolimfile.sql (modified) (1 diff)
-
src/pxinject.c (modified) (1 diff)
-
src/pzgetexp.c (modified) (1 diff)
-
src/pzgetimfiles.c (modified) (9 diffs)
-
src/pztool.c (modified) (16 diffs)
-
src/pztoolConfig.c (modified) (3 diffs)
-
src/regtool.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/share/pxadmin_create_tables.sql
r30945 r31038 14 14 15 15 CREATE TABLE summitExp ( 16 summit_id BIGINT NOT NULL AUTO_INCREMENT, 16 17 exp_name VARCHAR(64), 17 18 camera VARCHAR(64), … … 23 24 fault SMALLINT NOT NULL, 24 25 epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 25 PRIMARY KEY(exp_name, camera, telescope), 26 PRIMARY KEY(summit_id), 27 KEY(exp_name, camera, telescope), 26 28 KEY(fault) 27 29 ) ENGINE=innodb DEFAULT CHARSET=latin1; 28 30 29 31 CREATE TABLE summitImfile ( 32 summit_id BIGINT, 30 33 exp_name VARCHAR(64), 31 34 camera VARCHAR(64), … … 38 41 uri VARCHAR(255), 39 42 epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 40 PRIMARY KEY(exp_name, camera, telescope, class, class_id), 43 PRIMARY KEY(summit_id, class, class_id), 44 KEY(exp_name, camera, telescope, class, class_id), 41 45 KEY(file_id), 46 FOREIGN KEY(summit_id) REFERENCES summitExp(summit_id), 42 47 FOREIGN KEY(exp_name, camera, telescope) REFERENCES summitExp(exp_name, camera, telescope) 43 48 ) ENGINE=innodb DEFAULT CHARSET=latin1; 44 49 45 50 CREATE TABLE pzDownloadExp ( 51 summit_id BIGINT, 46 52 exp_name VARCHAR(64), 47 53 camera VARCHAR(64), … … 49 55 state VARCHAR(64), 50 56 epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 51 PRIMARY KEY(exp_name, camera, telescope), 57 PRIMARY KEY(summit_id), 58 KEY(exp_name, camera, telescope), 52 59 KEY(state), 60 FOREIGN KEY(summit_id) REFERENCES summitExp(summit_id), 53 61 FOREIGN KEY(exp_name, camera, telescope) REFERENCES summitExp(exp_name, camera, telescope) 54 62 ) ENGINE=innodb DEFAULT CHARSET=latin1; 55 63 56 64 CREATE TABLE pzDownloadImfile ( 65 summit_id BIGINT, 57 66 exp_name VARCHAR(64), 58 67 camera VARCHAR(64), … … 66 75 bytes INT, 67 76 md5sum VARCHAR(32), 68 PRIMARY KEY(exp_name, camera, telescope, class, class_id), 69 KEY(fault), 77 PRIMARY KEY(summit_id, class, class_id), 78 KEY(exp_name, camera, telescope, class, class_id), 79 KEY(fault), 80 FOREIGN KEY(summit_id) REFERENCES pzDownloadExp(summit_id), 81 FOREIGN KEY(summit_id, class, class_id) REFERENCES summitImfile(summit_id, class, class_id), 70 82 FOREIGN KEY (exp_name, camera, telescope) REFERENCES pzDownloadExp(exp_name, camera, telescope), 71 83 FOREIGN KEY(exp_name, camera, telescope, class, class_id) REFERENCES summitImfile(exp_name, camera, telescope, class, class_id) … … 74 86 CREATE TABLE newExp ( 75 87 exp_id BIGINT AUTO_INCREMENT, 88 summit_id BIGINT, 76 89 tmp_exp_name VARCHAR(64), 77 90 tmp_camera VARCHAR(64), … … 88 101 PRIMARY KEY(exp_id), 89 102 KEY(exp_id), 103 KEY(summit_id), 90 104 KEY(tmp_exp_name), 91 105 KEY(tmp_camera), -
trunk/ippTools/share/pztool_find_completed_exp.sql
r23643 r31038 1 1 SELECT DISTINCT 2 summit_id, 2 3 exp_name, 3 4 camera, … … 13 14 FROM pzDownloadExp 14 15 JOIN summitExp 15 USING( exp_name, camera, telescope)16 USING(summit_id) 16 17 LEFT JOIN pzDownloadImfile 17 USING( exp_name, camera, telescope)18 USING(summit_id) 18 19 LEFT JOIN newExp 19 ON pzDownloadExp.exp_name = newExp.tmp_exp_name 20 AND pzDownloadExp.camera = newExp.tmp_camera 21 AND pzDownloadExp.telescope = newExp.tmp_telescope 20 USING(summit_id) 22 21 WHERE 23 22 pzDownloadExp.state = 'run' 23 AND newExp.summit_id IS NULL 24 24 AND newExp.tmp_exp_name IS NULL 25 25 AND newExp.tmp_camera IS NULL 26 26 AND newExp.tmp_telescope IS NULL 27 27 GROUP BY 28 pzDownloadExp.exp_name, 29 pzDownloadExp.camera, 30 pzDownloadExp.telescope 28 pzDownloadExp.summit_id, 31 29 -- it doesn't matter which field in pzDownloadImfile we count as we've 32 30 -- already Download a group by -
trunk/ippTools/share/pztool_pendingimfile.sql
r18305 r31038 6 6 FROM summitImfile 7 7 JOIN pzDownloadExp 8 USING(exp_name, camera, telescope)8 USING(summit_id) 9 9 LEFT JOIN pzDownloadImfile 10 USING( exp_name, camera, telescope, class, class_id)10 USING(summit_id, class, class_id) 11 11 JOIN summitExp 12 USING(exp_name, camera, telescope)12 USING(summit_id) 13 13 WHERE 14 14 pzDownloadExp.state = 'run' 15 AND pzDownloadImfile.summit_id IS NULL 15 16 AND pzDownloadImfile.exp_name IS NULL 16 17 AND pzDownloadImfile.camera IS NULL -
trunk/ippTools/share/regtool_checkburntoolimfile.sql
r30283 r31038 21 21 FROM 22 22 summitExp 23 JOIN summitImfile USING( exp_name)24 LEFT JOIN pzDownloadExp USING( exp_name)25 LEFT JOIN newExp ON summitExp.exp_name = tmp_exp_name23 JOIN summitImfile USING(summit_id) 24 LEFT JOIN pzDownloadExp USING(summit_id) 25 LEFT JOIN newExp USING(summit_id) 26 26 LEFT JOIN newImfile ON (summitImfile.class_id = newImfile.tmp_class_id AND newExp.exp_id = newImfile.exp_id) 27 27 LEFT JOIN rawExp ON rawExp.exp_id = newExp.exp_id -
trunk/ippTools/share/regtool_checkstatus.sql
r30997 r31038 20 20 (rawImfile.burntool_state IS NOT NULL) AS is_registered 21 21 FROM summitExp 22 JOIN summitImfile USING( exp_name)23 LEFT JOIN pzDownloadExp USING( exp_name)24 LEFT JOIN newExp ON summitExp.exp_name = tmp_exp_name22 JOIN summitImfile USING(summit_id) 23 LEFT JOIN pzDownloadExp USING(summit_id) 24 LEFT JOIN newExp USING(summit_id) 25 25 LEFT JOIN newImfile ON (summitImfile.class_id = newImfile.tmp_class_id AND newExp.exp_id = newImfile.exp_id) 26 26 LEFT JOIN rawExp ON rawExp.exp_id = newExp.exp_id -
trunk/ippTools/share/regtool_pendingburntoolimfile.sql
r30283 r31038 22 22 FROM 23 23 summitExp 24 JOIN summitImfile USING( exp_name)25 LEFT JOIN pzDownloadExp USING( exp_name)26 LEFT JOIN newExp ON summitExp.exp_name = tmp_exp_name24 JOIN summitImfile USING(summit_id) 25 LEFT JOIN pzDownloadExp USING(summit_id) 26 LEFT JOIN newExp USING(summit_id) 27 27 LEFT JOIN newImfile ON (summitImfile.class_id = newImfile.tmp_class_id AND newExp.exp_id = newImfile.exp_id) 28 28 LEFT JOIN rawExp ON rawExp.exp_id = newExp.exp_id -
trunk/ippTools/src/pxinject.c
r25418 r31038 92 92 if (!newExpInsert(config->dbh, 93 93 0, // exp_id 94 0, // summit_id 94 95 tmp_exp_name, 95 96 tmp_camera, -
trunk/ippTools/src/pzgetexp.c
r21402 r31038 215 215 char *query = 216 216 "INSERT INTO summitExp" 217 " SElECT" 217 " SELECT" 218 " NULL," // summit_id 218 219 " incoming.*," 219 220 " NULL," // imfiles -
trunk/ippTools/src/pzgetimfiles.c
r21402 r31038 99 99 int status = pclose(output); 100 100 101 // We have an id value now, let's get it and use it 102 char *id_query = "SELECT summit_id FROM summitExp WHERE exp_name = '%s' AND camera = '%s' AND telescope = '%s'"; 103 104 if (!p_psDBRunQueryF(config->dbh, id_query, filesetid, camera, telescope)) { 105 psError(PS_ERR_UNKNOWN, false, "database error"); 106 return false; 107 } 108 109 psArray *id_output = p_psDBFetchResult(config->dbh); 110 if (!id_output) { 111 psError(PS_ERR_UNKNOWN, false, "database error"); 112 return false; 113 } 114 if (psArrayLength(id_output) != 1) { 115 psError(PS_ERR_UNKNOWN, false, "database error: incorrect number of results"); 116 return false; 117 } 118 119 psMetadata *id_result = id_output->data[0]; 120 121 psS64 summit_id = psMetadataLookupS64(NULL, id_result, "summit_id"); 122 psFree(id_output); 123 // End of summit_id block. 124 101 125 if (status != 0) { 102 126 // mark the summitExp row as faulted 103 if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE exp_name = '%s' AND camera = '%s' AND telescope = '%s'", WEXITSTATUS(status), filesetid, camera, telescope)) {127 if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE summit_id = %ld", WEXITSTATUS(status), summit_id)) { 104 128 psError(PS_ERR_UNKNOWN, false, "database error"); 105 129 } … … 117 141 // download an "empty" fileset. 118 142 // mark the summitExp row as faulted 119 if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE exp_name = '%s' AND camera = '%s' AND telescope = '%s'", 250, filesetid, camera, telescope)) {143 if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE summit_id = %ld", 250, summit_id)) { 120 144 psError(PS_ERR_UNKNOWN, false, "database error"); 121 145 } … … 142 166 "UPDATE summitExp" 143 167 " SET imfiles = %d" 144 " WHERE exp_name = '%s'" 145 " AND camera = '%s'" 146 " AND telescope = '%s'"; 147 if (!p_psDBRunQueryF(config->dbh, query, imfiles, filesetid, camera, telescope)) { 168 " WHERE summit_id = %ld"; 169 if (!p_psDBRunQueryF(config->dbh, query, imfiles, summit_id)) { 148 170 // rollback 149 171 if (!psDBRollback(config->dbh)) { … … 159 181 "DELETE FROM pzDownloadExp" 160 182 " WHERE" 161 " exp_name = '%s'" 162 " AND camera = '%s'" 163 " AND telescope = '%s'"; 164 if (!p_psDBRunQueryF(config->dbh, query, filesetid, camera, telescope)) { 183 " summit_id = %ld"; 184 if (!p_psDBRunQueryF(config->dbh, query, summit_id)) { 165 185 // rollback 166 186 if (!psDBRollback(config->dbh)) { … … 245 265 "INSERT IGNORE INTO summitImfile" 246 266 " SELECT" 267 " %ld," // summit_id 247 268 " incoming.exp_name," 248 269 " incoming.camera," … … 256 277 " NULL" // epoch 257 278 " FROM incoming"; 258 if (!p_psDBRunQuery (config->dbh, query)) {279 if (!p_psDBRunQueryF(config->dbh, query,summit_id)) { 259 280 // rollback 260 281 if (!psDBRollback(config->dbh)) { … … 272 293 " SET imfiles = (SELECT COUNT(*) FROM summitImfile" 273 294 " WHERE" 274 " exp_name = '%s'" 275 " AND camera = '%s'" 276 " AND telescope = '%s'" 295 " summit_id = %ld" 277 296 ")" 278 297 " WHERE" 279 " exp_name = '%s'" 280 " AND camera = '%s'" 281 " AND telescope = '%s'" 298 " summit_id = %ld" 282 299 " AND imfiles IS NULL"; 283 if (!p_psDBRunQueryF(config->dbh, query, filesetid, camera, telescope, filesetid, camera, telescope)) {300 if (!p_psDBRunQueryF(config->dbh, query, summit_id, summit_id)) { 284 301 // rollback 285 302 if (!psDBRollback(config->dbh)) { … … 308 325 "INSERT IGNORE INTO pzDownloadExp" 309 326 " SELECT" 327 " %ld," // summit_id 310 328 " incoming.exp_name," 311 329 " incoming.camera," … … 319 337 " incoming.telescope"; 320 338 321 if (!p_psDBRunQuery (config->dbh, query)) {339 if (!p_psDBRunQueryF(config->dbh, query,summit_id)) { 322 340 // rollback 323 341 if (!psDBRollback(config->dbh)) { -
trunk/ippTools/src/pztool.c
r30907 r31038 53 53 static psArray *pzGetPendingCameras(pxConfig *config); 54 54 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); 55 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state);55 static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state); 56 56 57 57 # define MODECASE(caseName, func) \ … … 222 222 223 223 psMetadata *where = psMetadataAlloc(); 224 PXOPT_COPY_S64(config->args, where, "-summit_id", "summit_id", "=="); 224 225 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 225 226 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 237 238 " FROM summitExp" 238 239 " LEFT JOIN pzDownloadExp" 239 " USING(exp_name, camera, telescope)"240 " USING(summit_id)" 240 241 " WHERE" 241 " pzDownloadExp.exp_name IS NULL" 242 " AND pzDownloadExp.camera IS NULL" 243 " AND pzDownloadExp.telescope IS NULL" 242 " pzDownloadExp.summit_id IS NULL" 244 243 " AND summitExp.fault = 0" 245 244 ); … … 260 259 if (limit) { 261 260 psString limitString = psDBGenerateLimitSQL(limit); 261 262 262 psStringAppend(&query, " %s", limitString); 263 263 psFree(limitString); … … 299 299 300 300 psMetadata *where = psMetadataAlloc(); 301 PXOPT_COPY_S64(config->args, where, "-summit_id", "summit_id", "=="); 301 302 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 302 303 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 401 402 402 403 // required 404 PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false); 403 405 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 404 406 PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false); … … 428 430 429 431 psMetadata *where = psMetadataAlloc(); 432 PXOPT_COPY_S64(config->args, where, "-summit_id", "summit_id", "=="); 430 433 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 431 434 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 459 462 460 463 if (!pzDownloadImfileInsert(config->dbh, 464 summit_id, 461 465 exp_name, 462 466 camera, … … 505 509 506 510 psMetadata *where = psMetadataAlloc(); 511 PXOPT_COPY_STR(config->args, where, "-summit_id", "summit_id", "=="); 507 512 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 508 513 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 560 565 561 566 // required 567 PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false); 562 568 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 563 569 PXOPT_LOOKUP_STR(inst, config->args, "-inst", true, false); … … 579 585 if (!newExpInsert(config->dbh, 580 586 0x0, // exp_id 587 summit_id, // summit_id 581 588 exp_name, // tmp_exp_name 582 589 inst, // tmp_camera … … 597 604 } 598 605 599 psS64 exp_id = psDBLastInsertID(config->dbh);600 601 // insert newImfiles602 {603 char *query =606 psS64 exp_id = psDBLastInsertID(config->dbh); 607 608 // insert newImfiles 609 { 610 char *query = 604 611 "INSERT INTO newImfile" 605 " SE lECT"612 " SELECT" 606 613 " %" PRId64 "," // exp_id 614 " %" PRId64 "," // summit_id 607 615 " pzDownloadImfile.class_id," // tmp_class_id 608 616 " pzDownloadImfile.uri," // uri … … 616 624 " AND pzDownloadImfile.telescope = '%s'"; 617 625 618 if (!p_psDBRunQueryF(config->dbh, query, exp_id, exp_name, inst, telescope)) {619 psError(PS_ERR_UNKNOWN, false, "database error");620 return false;621 }622 623 // sanity check: we should have inserted at least one row624 psU64 affected = psDBAffectedRows(config->dbh);625 if (psDBAffectedRows(config->dbh) < 1) {626 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);627 return false;628 }626 if (!p_psDBRunQueryF(config->dbh, query, exp_id, summit_id, exp_name, inst, telescope)) { 627 psError(PS_ERR_UNKNOWN, false, "database error"); 628 return false; 629 } 630 631 // sanity check: we should have inserted at least one row 632 psU64 affected = psDBAffectedRows(config->dbh); 633 if (psDBAffectedRows(config->dbh) < 1) { 634 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected); 635 return false; 636 } 629 637 } 630 638 631 639 // set pzDownloadExp.state to 'stop' 632 if (!pzDownloadExpSetState(config, exp_name, inst, telescope, "stop")) {633 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for % s:%s:%s", exp_name, inst, telescope);640 if (!pzDownloadExpSetState(config, summit_id, "stop")) { 641 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %ld", summit_id); 634 642 return false; 635 643 } … … 887 895 888 896 889 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)897 static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state) 890 898 { 891 899 PS_ASSERT_PTR_NON_NULL(state, false); … … 904 912 } 905 913 906 char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE exp_name = '%s' and camera = '%s' and telescope = '%s'";907 if (!p_psDBRunQueryF(config->dbh, query, state, exp_name, camera, telescope)) {908 psError(PS_ERR_UNKNOWN, false, "failed to change state for % s:%s:%s", exp_name, camera, telescope);914 char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE summit_id = %ld"; 915 if (!p_psDBRunQueryF(config->dbh, query, state, summit_id)) { 916 psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id); 909 917 return false; 910 918 } … … 916 924 { 917 925 PS_ASSERT_PTR_NON_NULL(config, false); 918 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 919 PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false); 920 PXOPT_LOOKUP_STR(telescope,config->args, "-telescope",true, false); 926 PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false); 921 927 PXOPT_LOOKUP_STR(state, config->args, "-set_state",true, false); 922 928 923 if (!pzDownloadExpSetState(config, exp_name,camera,telescope,state)) {924 psError(PS_ERR_UNKNOWN, false, "failed to change state for % s:%s:%s", exp_name, camera, telescope);929 if (!pzDownloadExpSetState(config,summit_id, state)) { 930 psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id); 925 931 return false; 926 932 } -
trunk/ippTools/src/pztoolConfig.c
r30437 r31038 63 63 // -pendingexp 64 64 psMetadata *pendingexpArgs = psMetadataAlloc(); 65 psMetadataAddS64(pendingexpArgs, PS_LIST_TAIL, "-summit_id", 0, "define summit_id", 0); 65 66 psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_name", 0, "define exposure ID", NULL); 66 67 psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-inst", 0, "define camera ID", NULL); … … 73 74 // -pendingimfile 74 75 psMetadata *pendingimfileArgs = psMetadataAlloc(); 76 psMetadataAddS64(pendingimfileArgs, PS_LIST_TAIL, "-summit_id", 0, "define summit_id", 0); 75 77 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_name", 0, "define exposure ID", NULL); 76 78 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-inst", 0, "define camera ID", NULL); … … 85 87 // -copydone 86 88 psMetadata *copydoneArgs = psMetadataAlloc(); 89 psMetadataAddS64(copydoneArgs, PS_LIST_TAIL, "-summit_id", 0, "define summit_id (required)", 0); 87 90 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_name", 0, "define exposure ID (required)", NULL); 88 91 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-inst", 0, "define camera ID (required)", NULL); -
trunk/ippTools/src/regtool.c
r30927 r31038 311 311 312 312 // required 313 PXOPT_LOOKUP_STR(dateobs_begin, config->args, "-dateobs_begin",true, false);314 PXOPT_LOOKUP_STR(dateobs_end, config->args, "-dateobs_end", true, false);315 PXOPT_LOOKUP_S32(valid_burntool, config->args, "-valid_burntool", true, false);313 PXOPT_LOOKUP_STR(dateobs_begin, config->args, "-dateobs_begin", true, false); 314 PXOPT_LOOKUP_STR(dateobs_end, config->args, "-dateobs_end", true, false); 315 PXOPT_LOOKUP_S32(valid_burntool, config->args, "-valid_burntool", true, false); 316 316 // optional 317 317 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
Note:
See TracChangeset
for help on using the changeset viewer.
