Обсуждение: hashtable issue - HASH_FIND??
Hi there, I'm looking to use the PostgreSQL Hash Table for some custom functions. However, the example, as per http://wiki.postgresql.org/wiki/HashTable crashes postmaster (or segfaults from the cmd line) when trying to retrieve an element from the hash. Specifically this line fails: elem = hash_search(hashtable, (void *)key, HASH_FIND, &found); I can't see anything obviously wrong, is this a bug? Either in the example's code or in the server code itself? Any help much appreciated!
Jay Flattery <jaycode@rocketmail.com> writes: > I'm looking to use the PostgreSQL Hash Table for some custom functions. > However, the example, as per http://wiki.postgresql.org/wiki/HashTable crashes > postmaster (or segfaults from the cmd line) when trying to retrieve an element > from the hash. I think the "palloc(sizeof(key))" bits ought to be "palloc(sizeof(*key))" ... or personally I'd have used sizeof(HashKey). Although offhand it looks like that should be the same size or larger, so it doesn't seem to explain a crash. Where's the crash happening exactly? regards, tom lane
Thanks for your reply. Actually I had already changed the sizeof()s.. Not sure of the actual error, postmaster just dies: NOTICE: Didn't find 9 -- good NOTICE: about to extract object at key 0 (extra notice added by me) LOG: server process (PID 55483) was terminated by signal 11: Segmentation fault Wondering if it was just me..? ----- Original Message ---- From: Tom Lane <tgl@sss.pgh.pa.us> To: Jay Flattery <jaycode@rocketmail.com> Cc: pgsql-general@postgresql.org Sent: Wed, August 4, 2010 3:46:24 PM Subject: Re: [GENERAL] hashtable issue - HASH_FIND?? Jay Flattery <jaycode@rocketmail.com> writes: > I'm looking to use the PostgreSQL Hash Table for some custom functions. > However, the example, as per http://wiki.postgresql.org/wiki/HashTable crashes > postmaster (or segfaults from the cmd line) when trying to retrieve an element > from the hash. I think the "palloc(sizeof(key))" bits ought to be "palloc(sizeof(*key))" ... or personally I'd have used sizeof(HashKey). Although offhand it looks like that should be the same size or larger, so it doesn't seem to explain a crash. Where's the crash happening exactly? regards, tom lane
Jay Flattery <jaycode@rocketmail.com> writes: > I'm looking to use the PostgreSQL Hash Table for some custom functions. > However, the example, as per http://wiki.postgresql.org/wiki/HashTable crashes > postmaster (or segfaults from the cmd line) when trying to retrieve an element > from the hash. BTW, I tested the example and it works for me ... regards, tom lane
Jay Flattery <jaycode@rocketmail.com> writes: > Actually I had already changed the sizeof()s.. > Not sure of the actual error, postmaster just dies: > NOTICE: Didn't find 9 -- good > NOTICE: about to extract object at key 0 (extra notice added by me) > LOG: server process (PID 55483) was terminated by signal 11: Segmentation fault > Wondering if it was just me..? Dunno, but how about a backtrace from that segfault? Also, what other changes did you make in the example? regards, tom lane
Jay Flattery <jaycode@rocketmail.com> writes: > Actually, if I just dump the example into a file, compile and install it as a > function, it works. > Only fails when I add the code (without changing anything!) to existing source > where I'd like to use it. Hmph, are you trying to incorporate this code into the core backend? It's depending on being in a dynamic library, because otherwise that _PG_init function won't get called. (Although that still seems like it doesn't explain the symptom ... should crash sooner if the hashtable's not been created.) FWIW, that backtrace looks like it's from the postmaster process, not from a crashing backend. You need to make sure you attach gdb to the right process ... regards, tom lane
Actually, if I just dump the example into a file, compile and install it as a function, it works. Only fails when I add the code (without changing anything!) to existing source where I'd like to use it. (gdb) next Single stepping until exit from function _sigtramp, which has no line number information. warning: Got an error handling event: "Cannot access memory at address 0x274". (gdb) next Single stepping until exit from function reaper, which has no line number information. 0x004455cf in dyld_stub___error () Not sure this is the correct bt, but #0 0x004455cf in dyld_stub___error () #1 0x001abc54 in reaper () #2 <signal handler called> #3 0x96c686fa in select$DARWIN_EXTSN () #4 0x001ad801 in ServerLoop () #5 0x001af407 in PostmasterMain () #6 0x0014c13b in main () Looks like something to do with linking. Needle in the haystack I think :( ----- Original Message ---- From: Tom Lane <tgl@sss.pgh.pa.us> To: Jay Flattery <jaycode@rocketmail.com> Cc: pgsql-general@postgresql.org Sent: Wed, August 4, 2010 4:51:30 PM Subject: Re: [GENERAL] hashtable issue - HASH_FIND?? Jay Flattery <jaycode@rocketmail.com> writes: > I'm looking to use the PostgreSQL Hash Table for some custom functions. > However, the example, as per http://wiki.postgresql.org/wiki/HashTable crashes > postmaster (or segfaults from the cmd line) when trying to retrieve an element > from the hash. BTW, I tested the example and it works for me ... regards, tom lane