Changeset 20173 for trunk/ippTools/src/pztool.c
- Timestamp:
- Oct 15, 2008, 10:16:29 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r20172 r20173 46 46 static bool advanceMode(pxConfig *config); 47 47 48 static bool copydoneCompleteExp(pxConfig *config , const char *exp_name, const char *camera, const char *telescope, bool rowLock);48 static bool copydoneCompleteExp(pxConfig *config); 49 49 static psArray *pzGetPendingCameras(pxConfig *config); 50 50 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); … … 404 404 // NOTE : the rest of the command-line args are parsed in copydoneCompleteExp 405 405 406 // start a transaction early so it will contain any row level locks 407 if (!psDBTransaction(config->dbh)) { 408 psError(PS_ERR_UNKNOWN, false, "database error"); 409 return false; 410 } 411 412 // query to get an excluse lock on this exposure in 413 // pzDownloadExp 414 psString lock_query = NULL; 415 if (row_lock) { 416 lock_query = psStringCopy("SELECT * FROM pzDownloadExp"); 417 418 psMetadata *where = psMetadataAlloc(); 419 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 420 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 421 PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "=="); 422 423 if (psListLength(where->list)) { 424 psString whereClause = psDBGenerateWhereSQL(where, NULL); 425 psStringAppend(&lock_query, " %s FOR UPDATE", whereClause); 426 psFree(whereClause); 427 } 428 psFree(where); 429 430 // aquire a lock on the pzDownloadExp record 431 // lock persists until the transaction is committed 432 if (!p_psDBRunQuery(config->dbh, lock_query)) { 433 psError(PS_ERR_UNKNOWN, false, "database error"); 434 psFree(lock_query); 435 return false; 436 } 437 psFree(lock_query); 438 } 439 406 440 if (!pzDownloadImfileInsert(config->dbh, 407 441 exp_name, … … 418 452 } 419 453 420 // start a transaction so it's all rows or nothing 421 if (!psDBTransaction(config->dbh)) { 422 psError(PS_ERR_UNKNOWN, false, "database error"); 423 return false; 424 } 425 426 if (!copydoneCompleteExp(config, exp_name, camera, telescope, row_lock)) { 454 if (!copydoneCompleteExp(config)) { 427 455 // rollback 428 456 if (!psDBRollback(config->dbh)) { … … 446 474 } 447 475 448 static bool copydoneCompleteExp(pxConfig *config , const char *exp_name, const char *camera, const char *telescope, bool row_lock)476 static bool copydoneCompleteExp(pxConfig *config) 449 477 { 450 478 // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!! … … 464 492 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 465 493 466 467 494 // find all exposures that have had all of their imfiles downloaded but do 468 495 // not appear in newExp … … 473 500 } 474 501 475 // XXX this is a bit ugly : could just use the PXOPT_COPY_* methods476 // and not pass exp_name, camera, or telescope as additional args477 502 psMetadata *where = psMetadataAlloc(); 478 if (exp_name) { 479 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_name", 0, "==", exp_name)) { 480 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_name"); 481 psFree(where); 482 return false; 483 } 484 } 485 486 if (camera) { 487 if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==", camera)) { 488 psError(PS_ERR_UNKNOWN, false, "failed to add item camera"); 489 psFree(where); 490 return false; 491 } 492 } 493 494 if (telescope) { 495 if (!psMetadataAddStr(where, PS_LIST_TAIL, "telescope", 0, "==", telescope)) { 496 psError(PS_ERR_UNKNOWN, false, "failed to add item telescope"); 497 psFree(where); 498 return false; 499 } 500 } 501 502 // query to get an excluse lock on all rows for this exposure in 503 // pzDownloadImfile 504 psString lock_query = NULL; 505 if (row_lock) { 506 lock_query = psStringCopy("SELECT * FROM pzDownloadImfile"); 507 } 503 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 504 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 505 PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "=="); 508 506 509 507 if (psListLength(where->list)) { 510 508 psString whereClause = psDBGenerateWhereSQL(where, NULL); 511 509 psStringAppend(&query, " %s", whereClause); 512 if (row_lock) {513 psStringAppend(&lock_query, " %s FOR UPDATE", whereClause);514 }515 510 psFree(whereClause); 516 511 } 517 512 psFree(where); 518 519 // aquire lock on pzDownloadImfile rows520 // lock persists until a transaction is committed521 if (row_lock) {522 if (!p_psDBRunQuery(config->dbh, lock_query)) {523 psError(PS_ERR_UNKNOWN, false, "database error");524 psFree(lock_query);525 psFree(query);526 return false;527 }528 psFree(lock_query);529 }530 513 531 514 // find completed exps … … 880 863 } 881 864 882 if (!copydoneCompleteExp(config , NULL, NULL, NULL, true)) {865 if (!copydoneCompleteExp(config)) { 883 866 // rollback 884 867 if (!psDBRollback(config->dbh)) {
Note:
See TracChangeset
for help on using the changeset viewer.
