~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-proposed

« back to all changes in this revision

Viewing changes to src/backend/storage/ipc/sinvaladt.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-07-24 16:13:59 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140724161359-uk325qfv03euxuuh
Tags: 9.3.5-0ubuntu0.14.04.1
* New upstream bug fix release: (LP: #1348176)
  - pg_upgrade: Users who upgraded to version 9.3 using pg_upgrade may have
    an issue with transaction information which causes VACUUM to eventually
    fail. These users should run the script provided in the release notes to
    determine if their installation is affected, and then take the remedy
    steps outlined there.
  - Various data integrity and other bug fixes.
  - Secure Unix-domain sockets of temporary postmasters started during make
    check.
    Any local user able to access the socket file could connect as the
    server's bootstrap superuser, then proceed to execute arbitrary code as
    the operating-system user running the test, as we previously noted in
    CVE-2014-0067. This change defends against that risk by placing the
    server's socket in a temporary, mode 0700 subdirectory of /tmp.
  - See release notes for details:
    http://www.postgresql.org/about/news/1534/
* Remove pg_regress patches to support --host=/path, obsolete with above
  upstream changes and not applicable any more.
* Drop tcl8.6 patch, applied upstream.
* Add missing logrotate test dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 * In reality, the messages are stored in a circular buffer of MAXNUMMESSAGES
46
46
 * entries.  We translate MsgNum values into circular-buffer indexes by
47
47
 * computing MsgNum % MAXNUMMESSAGES (this should be fast as long as
48
 
 * MAXNUMMESSAGES is a constant and a power of 2).      As long as maxMsgNum
 
48
 * MAXNUMMESSAGES is a constant and a power of 2).  As long as maxMsgNum
49
49
 * doesn't exceed minMsgNum by more than MAXNUMMESSAGES, we have enough space
50
50
 * in the buffer.  If the buffer does overflow, we recover by setting the
51
51
 * "reset" flag for each backend that has fallen too far behind.  A backend
58
58
 * normal behavior is that at most one such interrupt is in flight at a time;
59
59
 * when a backend completes processing a catchup interrupt, it executes
60
60
 * SICleanupQueue, which will signal the next-furthest-behind backend if
61
 
 * needed.      This avoids undue contention from multiple backends all trying
 
61
 * needed.  This avoids undue contention from multiple backends all trying
62
62
 * to catch up at once.  However, the furthest-back backend might be stuck
63
63
 * in a state where it can't catch up.  Eventually it will get reset, so it
64
64
 * won't cause any more problems for anyone but itself.  But we don't want
89
89
 * the writer wants to change maxMsgNum while readers need to read it.
90
90
 * We deal with that by having a spinlock that readers must take for just
91
91
 * long enough to read maxMsgNum, while writers take it for just long enough
92
 
 * to write maxMsgNum.  (The exact rule is that you need the spinlock to
 
92
 * to write maxMsgNum.  (The exact rule is that you need the spinlock to
93
93
 * read maxMsgNum if you are not holding SInvalWriteLock, and you need the
94
94
 * spinlock to write maxMsgNum unless you are holding both locks.)
95
95
 *
410
410
        SISeg      *segP = shmInvalBuffer;
411
411
 
412
412
        /*
413
 
         * N can be arbitrarily large.  We divide the work into groups of no more
 
413
         * N can be arbitrarily large.  We divide the work into groups of no more
414
414
         * than WRITE_QUANTUM messages, to be sure that we don't hold the lock for
415
415
         * an unreasonably long time.  (This is not so much because we care about
416
416
         * letting in other writers, as that some just-caught-up backend might be
433
433
                 * If the buffer is full, we *must* acquire some space.  Clean the
434
434
                 * queue and reset anyone who is preventing space from being freed.
435
435
                 * Otherwise, clean the queue only when it's exceeded the next
436
 
                 * fullness threshold.  We have to loop and recheck the buffer state
 
436
                 * fullness threshold.  We have to loop and recheck the buffer state
437
437
                 * after any call of SICleanupQueue.
438
438
                 */
439
439
                for (;;)
501
501
 * executing on behalf of other backends, since each instance will modify only
502
502
 * fields of its own backend's ProcState, and no instance will look at fields
503
503
 * of other backends' ProcStates.  We express this by grabbing SInvalReadLock
504
 
 * in shared mode.      Note that this is not exactly the normal (read-only)
 
504
 * in shared mode.  Note that this is not exactly the normal (read-only)
505
505
 * interpretation of a shared lock! Look closely at the interactions before
506
506
 * allowing SInvalReadLock to be grabbed in shared mode for any other reason!
507
507
 *
508
 
 * NB: this can also run in parallel with SIInsertDataEntries.  It is not
 
508
 * NB: this can also run in parallel with SIInsertDataEntries.  It is not
509
509
 * guaranteed that we will return any messages added after the routine is
510
510
 * entered.
511
511
 *
525
525
 
526
526
        /*
527
527
         * Before starting to take locks, do a quick, unlocked test to see whether
528
 
         * there can possibly be anything to read.      On a multiprocessor system,
 
528
         * there can possibly be anything to read.  On a multiprocessor system,
529
529
         * it's possible that this load could migrate backwards and occur before
530
530
         * we actually enter this function, so we might miss a sinval message that
531
 
         * was just added by some other processor.      But they can't migrate
 
531
         * was just added by some other processor.  But they can't migrate
532
532
         * backwards over a preceding lock acquisition, so it should be OK.  If we
533
533
         * haven't acquired a lock preventing against further relevant
534
534
         * invalidations, any such occurrence is not much different than if the
619
619
 *
620
620
 * Caution: because we transiently release write lock when we have to signal
621
621
 * some other backend, it is NOT guaranteed that there are still minFree
622
 
 * free message slots at exit.  Caller must recheck and perhaps retry.
 
622
 * free message slots at exit.  Caller must recheck and perhaps retry.
623
623
 */
624
624
void
625
625
SICleanupQueue(bool callerHasWriteLock, int minFree)
640
640
        /*
641
641
         * Recompute minMsgNum = minimum of all backends' nextMsgNum, identify the
642
642
         * furthest-back backend that needs signaling (if any), and reset any
643
 
         * backends that are too far back.      Note that because we ignore sendOnly
 
643
         * backends that are too far back.  Note that because we ignore sendOnly
644
644
         * backends here it is possible for them to keep sending messages without
645
645
         * a problem even when they are the only active backend.
646
646
         */