Changeset 16588 for trunk/ippTools/src/pztool.c
- Timestamp:
- Feb 21, 2008, 6:09:46 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r16509 r16588 45 45 static psArray *pzGetPendingCameras(pxConfig *config); 46 46 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); 47 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state); 47 48 48 49 # define MODECASE(caseName, func) \ … … 204 205 "SELECT" 205 206 " summitExp.*" 206 " FROM pzPendingExp"207 " JOIN summitExp"207 " FROM summitExp" 208 " LEFT JOIN pzDownloadExp" 208 209 " USING(exp_name, camera, telescope)" 210 " WHERE" 211 " pzDownloadExp.exp_name IS NULL" 212 " AND pzDownloadExp.camera IS NULL" 213 " AND pzDownloadExp.telescope IS NULL" 209 214 ); 210 215 211 216 if (config->where) { 212 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pz PendingExp");217 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadExp"); 213 218 psStringAppend(&query, " AND %s", whereClause); 214 219 psFree(whereClause); … … 281 286 282 287 if (config->where) { 283 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pz PendingImfile");288 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadImfile"); 284 289 psStringAppend(&query, " AND %s", whereClause); 285 290 psFree(whereClause); … … 355 360 356 361 // need to know exp_name, camera, telescope, class, class_id (to find the 357 // pz PendingImfile entry and the URI for the newImfile entry.362 // pzDownloadImfile entry and the URI for the newImfile entry. 358 363 359 364 // start a transaction so it's all rows or nothing … … 363 368 } 364 369 365 // cp the imfile into pzDo neImfile370 // cp the imfile into pzDownloadImfile 366 371 { 367 372 char *query = 368 "INSERT INTO pzDo neImfile"373 "INSERT INTO pzDownloadImfile" 369 374 " SELECT" 370 " pzPendingImfile.*," 375 " exp_name," 376 " camera," 377 " telescope," 378 " class," 379 " class_id," 371 380 " '%s'," // uri of downloaded file 372 381 " '%d'" // fault code 373 " FROM pzPendingImfile"382 " FROM summitImfile" 374 383 " WHERE" 375 " pzPendingImfile.exp_name = '%s'"376 " AND pzPendingImfile.camera = '%s'"377 " AND pzPendingImfile.telescope = '%s'"378 " AND pzPendingImfile.class = '%s'"379 " AND pzPendingImfile.class_id = '%s'";384 " summitImfile.exp_name = '%s'" 385 " AND summitImfile.camera = '%s'" 386 " AND summitImfile.telescope = '%s'" 387 " AND summitImfile.class = '%s'" 388 " AND summitImfile.class_id = '%s'"; 380 389 381 390 if (!p_psDBRunQuery(config->dbh, query, uri, code, exp_name, camera, telescope, class, class_id)) { … … 400 409 } 401 410 402 // removve the entry from pzPendingImfile 403 { 404 char *query = 405 "DELETE FROM pzPendingImfile" 406 " WHERE" 407 " pzPendingImfile.exp_name = '%s'" 408 " AND pzPendingImfile.camera = '%s'" 409 " AND pzPendingImfile.telescope = '%s'" 410 " AND pzPendingImfile.class = '%s'" 411 " AND pzPendingImfile.class_id = '%s'"; 412 413 if (!p_psDBRunQuery(config->dbh, query, exp_name, camera, telescope, class, class_id)) { 414 // rollback 415 if (!psDBRollback(config->dbh)) { 416 psError(PS_ERR_UNKNOWN, false, "database error"); 417 } 411 if (!copydoneCompleteExp(config)) { 412 // rollback 413 if (!psDBRollback(config->dbh)) { 418 414 psError(PS_ERR_UNKNOWN, false, "database error"); 419 return false; 420 } 421 422 // sanity check: we should have removed only one row 423 psU64 affected = psDBAffectedRows(config->dbh); 424 if (psDBAffectedRows(config->dbh) != 1) { 425 // rollback 426 if (!psDBRollback(config->dbh)) { 427 psError(PS_ERR_UNKNOWN, false, "database error"); 428 } 429 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected); 430 return false; 431 } 415 } 416 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed"); 417 return false; 432 418 } 433 419 … … 439 425 } 440 426 psError(PS_ERR_UNKNOWN, false, "database error"); 441 return false;442 }443 444 if (!copydoneCompleteExp(config)) {445 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");446 427 return false; 447 428 } … … 493 474 } 494 475 495 // start a transaction so all newExp's can start off with a state of run496 if (!psDBTransaction(config->dbh)) {497 psError(PS_ERR_UNKNOWN, false, "database error");498 psFree(output);499 return false;500 }501 502 503 476 for (long i = 0; i < psArrayLength(output); i++) { 504 477 psMetadata *row = output->data[i]; 505 478 506 pzDo neExpRow *doneExp = pzDoneExpObjectFromMetadata(row);479 pzDownloadExpRow *doneExp = pzDownloadExpObjectFromMetadata(row); 507 480 508 481 if (!newExpInsert(config->dbh, … … 521 494 ) 522 495 ) { 523 // rollback524 if (!psDBRollback(config->dbh)) {525 psError(PS_ERR_UNKNOWN, false, "database error");526 }527 496 psError(PS_ERR_UNKNOWN, false, "database error"); 528 497 psFree(doneExp); … … 533 502 psS64 exp_id = psDBLastInsertID(config->dbh); 534 503 535 // insert new all pzDoneImfile for the exp into newImfile504 // insert newImfiles 536 505 { 537 506 char *query = … … 539 508 " SElECT" 540 509 " %" PRId64 "," // exp_id 541 " pzDo neImfile.class_id," // tmp_class_id542 " pzDo neImfile.uri" // uri543 " FROM pzDo neImfile"510 " pzDownloadImfile.class_id," // tmp_class_id 511 " pzDownloadImfile.uri" // uri 512 " FROM pzDownloadImfile" 544 513 " WHERE" 545 " pzDo neImfile.exp_name = '%s'"546 " AND pzDo neImfile.camera = '%s'"547 " AND pzDo neImfile.telescope = '%s'";514 " pzDownloadImfile.exp_name = '%s'" 515 " AND pzDownloadImfile.camera = '%s'" 516 " AND pzDownloadImfile.telescope = '%s'"; 548 517 549 518 if (!p_psDBRunQuery(config->dbh, query, exp_id, doneExp->exp_name, doneExp->camera, doneExp->telescope)) { 550 // rollback551 if (!psDBRollback(config->dbh)) {552 psError(PS_ERR_UNKNOWN, false, "database error");553 }554 519 psError(PS_ERR_UNKNOWN, false, "database error"); 555 520 psFree(doneExp); … … 561 526 psU64 affected = psDBAffectedRows(config->dbh); 562 527 if (psDBAffectedRows(config->dbh) < 1) { 563 // rollback564 if (!psDBRollback(config->dbh)) {565 psError(PS_ERR_UNKNOWN, false, "database error");566 }567 528 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected); 568 529 psFree(doneExp); … … 572 533 } 573 534 535 // set pzDownloadExp.state to 'stop' 536 if (!pzDownloadExpSetState(config, doneExp->exp_name, doneExp->camera, doneExp->telescope, "stop")) { 537 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", doneExp->exp_name, doneExp->camera, doneExp->telescope); 538 psFree(doneExp); 539 psFree(output); 540 return false; 541 } 542 574 543 psFree(doneExp); 575 544 } … … 577 546 psFree(output); 578 547 579 if (!psDBCommit(config->dbh)) {580 psError(PS_ERR_UNKNOWN, false, "database error");581 return false;582 }583 584 548 return true; 585 549 } … … 588 552 { 589 553 // get a list of cameras we've seen exps for 590 if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM pz PendingImfile")) {554 if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM pzDownloadExp")) { 591 555 psError(PS_ERR_UNKNOWN, false, "database error"); 592 556 return false; … … 666 630 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 667 631 668 psString query = psStringCopy("SELECT * FROM pzDo neImfile");632 psString query = psStringCopy("SELECT * FROM pzDownloadImfile"); 669 633 670 634 if (faulted) { 671 635 // list only faulted rows 672 psStringAppend(&query, " %s", "WHERE pzDo neImfile.fault != 0");636 psStringAppend(&query, " %s", "WHERE pzDownloadImfile.fault != 0"); 673 637 } else { 674 638 // don't list faulted rows 675 psStringAppend(&query, " %s", "WHERE pzDo neImfile.fault = 0");639 psStringAppend(&query, " %s", "WHERE pzDownloadImfile.fault = 0"); 676 640 } 677 641 678 642 if (psListLength(where->list)) { 679 psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDo neImfile");643 psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDownloadImfile"); 680 644 psStringAppend(&query, " AND %s", whereClause); 681 645 psFree(whereClause); … … 727 691 PXOPT_LOOKUP_S16(code, config->args, "-code", true, false); 728 692 729 if (!pxSetFaultCode(config->dbh, "pzDo neImfile", config->where, code)) {693 if (!pxSetFaultCode(config->dbh, "pzDownloadImfile", config->where, code)) { 730 694 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 731 695 return false; … … 747 711 748 712 if (config->where) { 749 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDo neImfile");713 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadImfile"); 750 714 psStringAppend(&query, " AND %s", whereClause); 751 715 psFree(whereClause); … … 768 732 769 733 734 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state) 735 { 736 PS_ASSERT_PTR_NON_NULL(state, false); 737 738 // check that state is a valid string value 739 if (!( 740 (strncmp(state, "run", 4) == 0) 741 || (strncmp(state, "stop", 5) == 0) 742 || (strncmp(state, "reg", 4) == 0) 743 ) 744 ) { 745 psError(PS_ERR_UNKNOWN, false, 746 "invalid pzDownloadExp state: %s", state); 747 return false; 748 } 749 750 char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE exp_name = '%s' and camera = '%s' and telescope = '%s'"; 751 if (!p_psDBRunQuery(config->dbh, query, state, exp_name, camera, telescope)) { 752 psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope); 753 return false; 754 } 755 756 return true; 757 } 758 759 770 760 #if 0 771 761 static psArray *pzArrayAddArray(psArray *array, psArray *input)
Note:
See TracChangeset
for help on using the changeset viewer.
