Changeset 8667 for trunk/ippTools/src
- Timestamp:
- Aug 28, 2006, 6:47:05 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/chiptool.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/chiptool.c
r8661 r8667 12 12 static bool pendingimfileMode(pxConfig *config); 13 13 static bool addprocessedimfileMode(pxConfig *config); 14 static p2ProcessedImfileRow *p2 pendingToProcessedImfile(pxConfig *config, p2PendingImfileRow *imfile);14 static p2ProcessedImfileRow *p2PendingToProcessedImfile(pxConfig *config, p2PendingImfileRow *imfile); 15 15 static p2ProcessedExpRow *p2PendingToProcessedExp(pxConfig *config, p2PendingExpRow *pendingExp); 16 static p3PendingExpRow *p2PendingToP3PendingExp(pxConfig *config, p2PendingExpRow *pendingExp); 17 static bool p2ProcessedCompleteExp(pxConfig *config); 16 18 17 19 # define MODECASE(caseName, func) \ … … 227 229 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p2PendingImfile"); 228 230 psFree(where) 229 if (whereClaus ) {231 if (whereClause) { 230 232 psStringAppend(&query, " AND %s", whereClause); 231 233 psFree(whereClause); … … 247 249 } 248 250 249 // find pending250 psArray *pendingImfiles = p2searchPendingImfiles(config);251 if (!pendingImfiles) {252 psError(PS_ERR_UNKNOWN, false, "no p2PendingImfiles found");253 return false;254 }255 256 251 // start a transaction so we don't end up with an incremented iteration 257 252 // count but no detInputExps 258 253 if (!psDBTransaction(config->dbh)) { 259 254 psError(PS_ERR_UNKNOWN, false, "database error"); 260 psFree(pendingImfiles); 261 return false; 262 } 263 264 // insert into done 265 for (long i = 0; i < psArrayLength(pendingImfiles); i++) { 266 p2ProcessedImfileRow *imfile = p2pendingToProcessedImfile(config, pendingImfiles->data[0]); 255 psFree(output); 256 return false; 257 } 258 259 // insert into p2ProcessedImfile 260 // remove p2PendingImfile entry 261 for (long i = 0; i < psArrayLength(output); i++) { 262 psMetadata *row = output->data[i]; 263 // convert metadata into a p2PendingImfile object 264 p2PendingImfileRow *object = p2PendingImfileObjectFromMetadata(row); 265 // convert p2PendingImfile object into a p2ProcessedImfile object 266 p2ProcessedImfileRow *imfile = p2PendingToProcessedImfile(config, object); 267 267 if (!imfile) { 268 268 // rollback … … 271 271 } 272 272 psError(PS_ERR_UNKNOWN, false, "failed to convert p2PendingImfile to p2ProcessedImfile"); 273 psFree(pendingImfiles); 274 return false; 275 } 273 psFree(object); 274 psFree(output); 275 return false; 276 } 277 // insert p2ProccessedImfile object into the database 276 278 if (!p2ProcessedImfileInsertObject(config->dbh, imfile)) { 277 279 // rollback … … 279 281 psError(PS_ERR_UNKNOWN, false, "database error"); 280 282 } 281 psError(PS_ERR_UNKNOWN, false, "d bh access failed");283 psError(PS_ERR_UNKNOWN, false, "database error"); 282 284 psFree(imfile); 283 psFree(pendingImfiles); 285 psFree(object); 286 psFree(output); 284 287 return false; 285 288 } 286 289 psFree(imfile); 287 }288 289 // delete from pending290 if (p2PendingImfileDeleteRowObjects(config->dbh, pendingImfiles, MAX_ROWS) < 0) {291 // there must be atleast 1 Imfile to get this far292 // rollback293 if (!psDBRollback(config->dbh)) {290 // delete the p2PendingImfile object from the database 291 if (!p2PendingImfileDeleteObject(config->dbh, object)) { 292 // there must be atleast 1 Imfile to get this far 293 // rollback 294 if (!psDBRollback(config->dbh)) { 295 psError(PS_ERR_UNKNOWN, false, "database error"); 296 } 294 297 psError(PS_ERR_UNKNOWN, false, "database error"); 295 } 296 psError(PS_ERR_UNKNOWN, false, "dbh access failed"); 297 psFree(pendingImfiles); 298 return false; 299 } 300 psFree(pendingImfiles); 298 psFree(object); 299 psFree(output); 300 return false; 301 } 302 psFree(object); 303 } 304 305 psFree(output); 301 306 302 307 // XXX I've decided to make the transaction cover the Exp migration as … … 305 310 // migration can't happen. 306 311 307 // look for pending exposures 308 psArray *pendingExps = p2searchPendingExp(config); 309 if (!pendingExps) { 312 if (!p2ProcessedCompleteExp(config)) { 310 313 // rollback 311 314 if (!psDBRollback(config->dbh)) { 312 315 psError(PS_ERR_UNKNOWN, false, "database error"); 313 316 } 314 psError(PS_ERR_UNKNOWN, false, "no p2PendingExps found"); 315 return false; 316 } 317 318 for (long i = 0; i < pendingExps->n; i++) { 319 p2PendingExpRow *pendingExp = pendingExps->data[i]; 320 321 psMetadata *where = psMetadataAlloc(); 322 psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", pendingExp->exp_id); 323 psArray *pendingImfiles = p2PendingImfileSelectRowObjects(config->dbh, where, MAX_ROWS); 324 psFree(where) 325 if (!pendingImfiles) { 326 // exp has no coresponding imfiles 327 psMetadata *where = psMetadataAlloc(); 328 psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", pendingExp->exp_id); 329 long long count = p2PendingExpDelete(config->dbh, where, MAX_ROWS); 330 psFree(where); 331 if (count != 0) { 332 // rollback 333 if (!psDBRollback(config->dbh)) { 334 psError(PS_ERR_UNKNOWN, false, "database error"); 335 } 336 psError(PS_ERR_UNKNOWN, false, "dbh access failed"); 337 psFree(pendingExps); 338 return false; 339 } 340 341 p2ProcessedExpRow *doneExp = p2PendingToProcessedExp(config, pendingExp); 342 if (!doneExp) { 343 // rollback 344 if (!psDBRollback(config->dbh)) { 345 psError(PS_ERR_UNKNOWN, false, "database error"); 346 } 347 psError(PS_ERR_UNKNOWN, false, "p2PendingExp -> p2ProcessedExp failed"); 348 psFree(pendingExps); 349 return false; 350 } 351 if (!p2ProcessedExpInsertObject(config->dbh, doneExp)) { 352 // rollback 353 if (!psDBRollback(config->dbh)) { 354 psError(PS_ERR_UNKNOWN, false, "database error"); 355 } 356 psError(PS_ERR_UNKNOWN, false, "dbh access failed"); 357 psFree(doneExp); 358 psFree(pendingExps); 359 return false; 360 } 361 psFree(doneExp); 362 } 363 // XXX skip phase 3 for the time being 364 psFree(pendingImfiles); 365 } 366 367 psFree(pendingExps); 317 psError(PS_ERR_UNKNOWN, false, "database error"); 318 return false; 319 } 368 320 369 321 // point of no return for p2PendingImfile -> p2ProcessedImfile … … 373 325 return false; 374 326 } 375 /*376 psArray *doneFrames = p2pendingToDone(config, pendingFrames);377 if (!doneFrames) {378 psError(PS_ERR_UNKNOWN, false, "p2pendingToDone() failed");379 return false;380 }381 bool status = p2insertDoneFrames(config, doneFrames);382 if (!status) {383 psError(PS_ERR_UNKNOWN, false, "p2insertDoneFrames() failed");384 return false;385 }386 */387 327 388 328 return true; 389 329 } 390 330 391 static p2ProcessedImfileRow *p2pendingToProcessedImfile(pxConfig *config, p2PendingImfileRow *imfile) 331 static bool p2ProcessedCompleteExp(pxConfig *config) 332 { 333 PS_ASSERT_PTR_NON_NULL(config, false); 334 335 // look for completed p2PendingExp 336 // migrate them to p2ProccessedExp & p3PendingExp 337 338 // select * from p2PendingExp 339 // where exp_id is not in p2ProcessedExp 340 // where exp_id is not in p2PendingImfile 341 // where the number of entries in p2ProccessedImfile matches the .imfiles 342 // entry in rawScienceExp 343 psString query = psStringCopy( 344 "SELECT DISTINCT" 345 " p2PendingExp.*," 346 " rawScienceExp.imfiles," 347 " p2ProcessedImfile.class_id" 348 " FROM p2PendingExp" 349 " JOIN rawScienceExp" 350 " ON p2PendingExp.exp_id = rawScienceExp.exp_id" 351 " LEFT JOIN p2ProcessedExp" 352 " ON p2PendingExp.exp_id = p2ProcessedExp.exp_id" 353 " LEFT JOIN p2PendingImfile" 354 " ON p2PendingExp.exp_id = p2PendingImfile.exp_id" 355 " LEFT JOIN p2ProcessedImfile" 356 " ON p2PendingExp.exp_id = p2ProcessedImfile.exp_id" 357 " WHERE" 358 " p2ProcessedExp.exp_id IS NULL" 359 " AND p2PendingImfile.exp_id IS NULL" 360 " AND p2ProcessedImfile.exp_id IS NOT NULL" 361 " GROUP BY" 362 " p2PendingExp.exp_id" 363 " HAVING rawScienceExp.imfiles = COUNT(p2ProcessedImfile.class_id)" 364 ); 365 366 if (!p_psDBRunQuery(config->dbh, query)) { 367 psError(PS_ERR_UNKNOWN, false, "database error"); 368 psFree(query); 369 return false; 370 } 371 psFree(query); 372 373 psArray *output = p_psDBFetchResult(config->dbh); 374 if (!output) { 375 // XXX check psError here and decide if we need to rollback or commit 376 psError(PS_ERR_UNKNOWN, false, "no p2PendingExp rows found"); 377 // XXX temporarily returning true here as typically this wouldn't be a 378 // fatal error. false should be returned once psError() is fixed 379 //return false; 380 return true; 381 } 382 383 // insert into p2ProcessedExp 384 // insert into p3PendingExp 385 // remove p2PendingExp entry 386 for (long i = 0; i < psArrayLength(output); i++) { 387 psMetadata *row = output->data[i]; 388 // convert metadata into a p2PendingExp object 389 p2PendingExpRow *object = p2PendingExpObjectFromMetadata(row); 390 // do both *Exp type conversion first so we don't insert one and then 391 // have to rollback the change as the 2nd failed 392 // convert p2PendingExp object into a p2ProcesseExp object 393 p2ProcessedExpRow *processedExp = p2PendingToProcessedExp(config, object); 394 if (!processedExp) { 395 psError(PS_ERR_UNKNOWN, false, "failed to convert p2PendingExp to p2ProcessedExp"); 396 psFree(object); 397 psFree(output); 398 return false; 399 } 400 // convert p2PendingExp object into a p3PendingExp object 401 p3PendingExpRow *pendingExp = p2PendingToP3PendingExp(config, object); 402 if (!processedExp) { 403 psError(PS_ERR_UNKNOWN, false, "failed to convert p2PendingExp to p3PendingExp"); 404 psFree(processedExp); 405 psFree(object); 406 psFree(output); 407 return false; 408 } 409 // insert p2ProccessedExp object into the database 410 if (!p2ProcessedExpInsertObject(config->dbh, processedExp)) { 411 psError(PS_ERR_UNKNOWN, false, "database error"); 412 psFree(processedExp); 413 psFree(pendingExp); 414 psFree(object); 415 psFree(output); 416 return false; 417 } 418 psFree(processedExp); 419 // insert p3PendingExp object into the database 420 if (!p3PendingExpInsertObject(config->dbh, pendingExp)) { 421 psError(PS_ERR_UNKNOWN, false, "database error"); 422 psFree(pendingExp); 423 psFree(object); 424 psFree(output); 425 return false; 426 } 427 psFree(pendingExp); 428 // delete the p2PendingExp object from the database 429 if (!p2PendingExpDeleteObject(config->dbh, object)) { 430 // there must be atleast 1 Imfile to get this far 431 psError(PS_ERR_UNKNOWN, false, "database error"); 432 psFree(object); 433 psFree(output); 434 return false; 435 } 436 psFree(object); 437 } 438 439 psFree(output); 440 441 return true; 442 } 443 444 static p2ProcessedImfileRow *p2PendingToProcessedImfile(pxConfig *config, p2PendingImfileRow *imfile) 392 445 { 393 446 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 479 532 return p2ProcessedExpRowAlloc( 480 533 pendingExp->exp_id, 481 "my recipe",482 534 pendingExp->p1_version, 483 535 pendingExp->p2_version 484 536 ); 485 537 } 538 539 static p3PendingExpRow *p2PendingToP3PendingExp(pxConfig *config, p2PendingExpRow *pendingExp) 540 { 541 PS_ASSERT_PTR_NON_NULL(pendingExp, NULL); 542 543 return p3PendingExpRowAlloc( 544 pendingExp->exp_id, 545 pendingExp->p1_version, 546 pendingExp->p2_version 547 ); 548 }
Note:
See TracChangeset
for help on using the changeset viewer.
