~ubuntu-branches/ubuntu/vivid/pgpool2/vivid-proposed

« back to all changes in this revision

Viewing changes to pool_process_query.c

  • Committer: Package Import Robot
  • Author(s): Christoph Berg
  • Date: 2012-03-20 16:37:29 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120320163729-xpt9c0lb27c9zf9i
Tags: 3.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
376
376
                                }
377
377
                        }
378
378
 
379
 
                        if (!pool_read_buffer_is_empty(MASTER(backend)) || pool_is_query_in_progress())
 
379
                        /*
 
380
                         * ProcessFrontendResponse() may start query
 
381
                         * processing. We need to recheck
 
382
                         * pool_is_query_in_progress() here.
 
383
                         */
 
384
                        if (pool_is_query_in_progress())
380
385
                        {
381
386
                                status = ProcessBackendResponse(frontend, backend, &state, &num_fields);
382
387
                                if (status != POOL_CONTINUE)
383
388
                                        return status;
384
389
                        }
 
390
                        else
 
391
                        {
 
392
                                /* Ok, query is not in progress. To make sure that we
 
393
                                 * have any pending data in backends. */
 
394
 
 
395
                                /* If we have pending data in master, we need to process it */
 
396
                                if (!pool_ssl_pending(MASTER(backend)) &&
 
397
                                        !pool_read_buffer_is_empty(MASTER(backend)))
 
398
                                {
 
399
                                        status = ProcessBackendResponse(frontend, backend, &state, &num_fields);
 
400
                                        if (status != POOL_CONTINUE)
 
401
                                                return status;
 
402
                                }
 
403
                                else
 
404
                                {
 
405
                                        for (i=0;i<NUM_BACKENDS;i++)
 
406
                                        {
 
407
                                                if (!VALID_BACKEND(i))
 
408
                                                        continue;
 
409
 
 
410
                                                if (pool_ssl_pending(CONNECTION(backend, i)) ||
 
411
                                                        pool_read_buffer_is_empty(CONNECTION(backend, i)))
 
412
                                                {
 
413
                                                        /* If we have pending data in master, we need to process it */
 
414
                                                        if (IS_MASTER_NODE_ID(i))
 
415
                                                        {
 
416
                                                                status = ProcessBackendResponse(frontend, backend, &state, &num_fields);
 
417
                                                                if (status != POOL_CONTINUE)
 
418
                                                                        return status;
 
419
                                                                break;
 
420
                                                        }
 
421
                                                        else
 
422
                                                        {
 
423
                                                                char kind;
 
424
                                                                int len;
 
425
                                                                char *string;
 
426
 
 
427
                                                                /* If master does not have pending
 
428
                                                                 * data, we discard one packet from
 
429
                                                                 * other backend */
 
430
                                                                status = pool_read(CONNECTION(backend, i), &kind, sizeof(kind));
 
431
                                                                if (status < 0)
 
432
                                                                {
 
433
                                                                        pool_error("pool_process_query: error while reading message kind from backend %d", i);
 
434
                                                                        return POOL_END;
 
435
                                                                }
 
436
                                                                pool_log("pool_process_query: discard %c packet from backend %d", kind, i);
 
437
 
 
438
                                                                if (MAJOR(backend) == PROTO_MAJOR_V3)
 
439
                                                                {
 
440
                                                                        if (pool_read(CONNECTION(backend, i), &len, sizeof(len)) < 0)
 
441
                                                                        {
 
442
                                                                                pool_error("pool_process_query: error while reading message length from backend %d", i);
 
443
                                                                                return POOL_END;
 
444
                                                                        }
 
445
                                                                        len = ntohl(len) - 4;
 
446
                                                                        string = pool_read2(CONNECTION(backend, i), len);
 
447
                                                                        if (string == NULL)
 
448
                                                                        {
 
449
                                                                                pool_error("pool_process_query: error while reading rest of message from backend %d", i);
 
450
                                                                                return POOL_END;
 
451
                                                                        }
 
452
                                                                }
 
453
                                                                else
 
454
                                                                {
 
455
                                                                        string = pool_read_string(CONNECTION(backend, i), &len, 0);
 
456
                                                                        if (string == NULL)
 
457
                                                                        {
 
458
                                                                                pool_error("pool_process_query: error while reading rest of message from backend %d", i);
 
459
                                                                                return POOL_END;
 
460
                                                                        }
 
461
                                                                }
 
462
                                                        }
 
463
                                                }
 
464
                                        }
 
465
                                }
 
466
                        }
385
467
                }
386
468
 
387
469
                /* reload config file */