Comment 3 for bug 1178165

Revision history for this message
crayze (crayze7) wrote :

To make it work on postgress 9.1+
1. open pggearman.c and make 2 changes:
a) now in posgress 9.1+ DefineCustomStringVariable takes 1 additional parameter, this is hook function, but I pass there NULL and it works, correct code from line 88:

//###################################
DefineCustomStringVariable("pggearman.default_servers",
                                   "Comma-separated list of gearman servers "
                                   "to connect to.",
                                   "Specified as a comma-separated list of "
                                   "host:port (port is optional).",
                                   &gearman_servers,
#if defined(PG_VERSION_NUM) && (80400 <= PG_VERSION_NUM)
                                   NULL,
#endif
                                   PGC_USERSET,
#if defined(PG_VERSION_NUM) && (80400 <= PG_VERSION_NUM)
                                   GUC_LIST_INPUT,
#endif

#if defined(PG_VERSION_NUM) && (90100 <= PG_VERSION_NUM)
                                   NULL, // GucStringCheckHook parameter for postgres 9.1+ <<== here additional parameter
#endif
                                   (GucStringAssignHook) assign_gearman_servers_guc,
                                   (GucShowHook) show_gearman_servers_guc);
//###################################

I also read that in 9.1+ you cant call gearman_client_add_servers if host parameter is NULL (which probably can happen - but i dont know :>), this is correct code for do_servers_add function, about line 138 in code, im not sure is it ok, but works:

//###################################
static gearman_return_t do_servers_add(char *host_str)
{
    gearman_return_t ret;
    MemoryContext old_ctx;

    old_ctx = MemoryContextSwitchTo(globals.pg_ctx);
    gearman_client_remove_servers(globals.client);
 #if defined(PG_VERSION_NUM) && (90100 <= PG_VERSION_NUM)
    // for version 9.1+ u cannot call gearman_client_add_servers if host is null
    if(host_str) ret = gearman_client_add_servers(globals.client, host_str);
    else ret = GEARMAN_SUCCESS; // ret success anyway, but dont call
 #else
    ret = gearman_client_add_servers(globals.client, host_str);
 #endif
    MemoryContextSwitchTo(old_ctx);

    if (ret != GEARMAN_SUCCESS)
        elog(ERROR, "%s", gearman_client_error(globals.client));

    PG_RETURN_BOOL(ret == GEARMAN_SUCCESS);
}
//##############################

If you want also install pggearman in postgress 9.1+, queries from pggearman.sl.in are also incompatible, cuz syntax: LANGUAGE 'C' is now incorrect, to fix it you need delete queries from 'C', valid syntax: LANGUAGE C, for example:

CREATE OR REPLACE FUNCTION gman_do(TEXT, TEXT) RETURNS TEXT
AS '/path/where/is/your/compiled/pggearman/so_library', 'gman_do' LANGUAGE 'C';

change to

CREATE OR REPLACE FUNCTION gman_do(TEXT, TEXT) RETURNS TEXT
AS '/path/where/is/your/compiled/pggearman/so_library', 'gman_do' LANGUAGE C;

after thatt all should work for 9.1+