Concurrency test function for chash.
authorRobert Haas <rhaas@postgresql.org>
Fri, 27 Jul 2012 16:10:13 +0000 (16:10 +0000)
committerRobert Haas <rhaas@postgresql.org>
Fri, 27 Jul 2012 16:10:13 +0000 (16:10 +0000)
contrib/hashtest/hashtest--1.0.sql
contrib/hashtest/hashtest.c

index d6e3fba8bf430f0713627c10774bf9fb021c7208..b35a520af6373b0b770a6ab66e3557dd02ec806b 100644 (file)
@@ -16,6 +16,11 @@ RETURNS void
 AS 'MODULE_PATHNAME', 'chash_delete_test'
 LANGUAGE C;
 
+CREATE FUNCTION chash_concurrent_test()
+RETURNS void
+AS 'MODULE_PATHNAME', 'chash_concurrent_test'
+LANGUAGE C;
+
 CREATE FUNCTION dynahash_insert_test()
 RETURNS void
 AS 'MODULE_PATHNAME', 'dynahash_insert_test'
index c155f7a1a42ac954807e29a38323466b4a53ec65..655b2a123d82e8dc3897a7859e74e81813ce802e 100644 (file)
@@ -17,6 +17,7 @@ void          _PG_init(void);
 Datum          chash_insert_test(PG_FUNCTION_ARGS);
 Datum          chash_search_test(PG_FUNCTION_ARGS);
 Datum          chash_delete_test(PG_FUNCTION_ARGS);
+Datum          chash_concurrent_test(PG_FUNCTION_ARGS);
 Datum          dynahash_insert_test(PG_FUNCTION_ARGS);
 Datum          dynahash_search_test(PG_FUNCTION_ARGS);
 Datum          dynahash_delete_test(PG_FUNCTION_ARGS);
@@ -166,6 +167,50 @@ chash_delete_test(PG_FUNCTION_ARGS)
        PG_RETURN_VOID();
 }
 
+Datum
+chash_concurrent_test(PG_FUNCTION_ARGS)
+{
+       uint32  i;
+       hentry  e;
+       uint32  seed = MyProcPid << 16;
+
+       for (i = 0; i < 10000; ++i)
+       {
+               bool ok;
+
+               e.key = seed | i;
+               e.val = MyProcPid;
+               ok = CHashInsert(chash, &e);
+               if (!ok)
+                       elog(LOG, "insert %u: found", i);
+       }
+
+       for (i = 0; i < 10000; ++i)
+       {
+               bool ok;
+
+               e.key = seed | i;
+               e.val = 0;
+               ok = CHashSearch(chash, &e);
+               if (!ok)
+                       elog(LOG, "search %u: not found", i);
+               if (e.val != MyProcPid)
+                       elog(LOG, "search %u: expected %u found %u", i, (unsigned) MyProcPid, e.val);
+       }
+
+       for (i = 0; i < 10000; ++i)
+       {
+               bool ok;
+
+               e.key = seed | i;
+               ok = CHashDelete(chash, &e);
+               if (!ok)
+                       elog(LOG, "delete %u: not found", i);
+       }
+
+       PG_RETURN_VOID();
+}
+
 static bool
 dynahash_insert(uint32 key, uint32 val)
 {