Bug fixes.
authorRobert Haas <rhaas@postgresql.org>
Wed, 1 Aug 2012 17:37:42 +0000 (17:37 +0000)
committerRobert Haas <rhaas@postgresql.org>
Wed, 1 Aug 2012 17:37:42 +0000 (17:37 +0000)
contrib/hashtest/hashtest.c

index e1d8205398241e3bf8651aa9393f59190c230126..440f1c5026d2e1f33c470bca206322c22338b781 100644 (file)
@@ -339,7 +339,7 @@ dynahash_insert(uint32 key, uint32 val)
 
        hashcode = get_hash_value(dynahash, (void *) &key);
        lockid = dynahash_get_lock(hashcode);
-       LWLockAcquire(lockid, LW_SHARED);
+       LWLockAcquire(lockid, LW_EXCLUSIVE);
        e = hash_search_with_hash_value(dynahash, (void *) &key,
                                                                        hashcode, HASH_ENTER, &found);
        if (!found)
@@ -377,7 +377,7 @@ dynahash_delete(uint32 key)
 
        hashcode = get_hash_value(dynahash, (void *) &key);
        lockid = dynahash_get_lock(hashcode);
-       LWLockAcquire(lockid, LW_SHARED);
+       LWLockAcquire(lockid, LW_EXCLUSIVE);
        e = hash_search_with_hash_value(dynahash, (void *) &key,
                                                                        hashcode, HASH_REMOVE, NULL);
        LWLockRelease(lockid);
@@ -467,9 +467,17 @@ dynahash_concurrent_test(PG_FUNCTION_ARGS)
 
                ok = dynahash_search(seed | i, &val);
                if (!ok)
+               {
+                       uint64  retry = 1;
                        elog(LOG, "search %u: not found", i);
-               else if (val != MyProcPid)
-                       elog(LOG, "search %u: expected %u found %u", i, (unsigned) MyProcPid, val);
+                       while (!dynahash_search(seed | i, &val))
+                               ++retry;
+                       elog(LOG, "search %u: eventually found it after "
+                               UINT64_FORMAT " retries", i, retry);
+               }
+               if (val != MyProcPid)
+                       elog(LOG, "search %u: expected %u found %u",
+                                i, (unsigned) MyProcPid, val);
        }
 
        for (i = 0; i < 10000; ++i)
@@ -478,7 +486,14 @@ dynahash_concurrent_test(PG_FUNCTION_ARGS)
 
                ok = dynahash_delete(seed | i);
                if (!ok)
+               {
+                       uint64  retry = 1;
                        elog(LOG, "delete %u: not found", i);
+                       while (!dynahash_delete(seed | i))
+                               ++retry;
+                       elog(LOG, "delete %u: eventually deleted it after "
+                               UINT64_FORMAT " retries", i, retry);
+               }
        }
 
        PG_RETURN_VOID();