• Robert Haas's avatar
    Pass extra data to bgworkers, and use this to fix parallel contexts. · 64b2e7ad
    Robert Haas authored
    Up until now, the total amount of data that could be passed to a
    background worker at startup was one datum, which can be a small as
    4 bytes on some systems.  That's enough to pass a dsm_handle or an
    array index, but not much else.  Add a bgw_extra flag to the
    BackgroundWorker struct, allowing up to 128 bytes to be passed to
    a new worker on any platform.
    
    Use this to fix a problem I recently discovered with the parallel
    context machinery added in 9.5: the master assigns each worker an
    array index, and each worker subsequently assigns itself an array
    index, and there's nothing to guarantee that the two sets of indexes
    match, leading to chaos.
    
    Normally, I would not back-patch the change to add bgw_extra, since it
    is basically a feature addition.  However, since 9.5 is still in beta
    and there seems to be no other sensible way to repair the broken
    parallel context machinery, back-patch to 9.5.  Existing background
    worker code can ignore the bgw_extra field without a problem, but
    might need to be recompiled since the structure size has changed.
    
    Report and patch by me.  Review by Amit Kapila.
    64b2e7ad
bgworker.c 28.9 KB