Re: [GSOC] [Weekly report 2] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Mengxing Liu <liu-mx15(at)mails(dot)tsinghua(dot)edu(dot)cn>, "alvaro(dot)herrera" <alvaro(dot)herrera(at)2ndquadrant(dot)com>, kgrittn <kgrittn(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GSOC] [Weekly report 2] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions
Date: 2017-06-15 06:34:12
Message-ID: 9d42fe1e-774c-769c-a228-886e58771502@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 06/15/2017 08:51 AM, Mengxing Liu wrote:
> My design is as follow:
>
> For hash table, key is the pointer of SerializableXact; Value is the RWConflictData object.
> Hashcode is generated based on the SerializableXact pointer.
> So, given a SerializableXact, we can quickly find if it is conflict with another SerializableXact.
>
> Every SerializableXact has two tables: inConflictsTab and outConflictsTab.
> They are allocated and initialized when creating PredXactList (in the function InitPredicateLocks).
> When a SerializableXact object is released, it will release all its RWConflict objects, the hash tables are empty again.
> Thus They can be reused directly after releasing.
>
> NOTE: I stored RWConflictData in hash tables, instead of RWConflict object allocated by RWConflictPool.
> After I remove other linked lists, the RWConflictPool can be omitted.

Sounds good!

> My code is on the :
> https://github.com/liumx10/postgresql/commit/3fd9a7488de5ae19ce2ce19eae5f303153a079ff

Once you've ironed out the obvious bugs, make sure to also post it as a
patch to this mailing list. For the sake of the archives, and to make it
clear that you're submitting this for inclusion in PostgreSQL, under the
PostgreSQL license.

Couple of little things caught my eye at a quick glance:

> * Test whether a hash table is empty.
> + * I didn't find any function in dynamic hash supports the requirement.

You can do: hash_get_num_entries(hashp) == 0

> sprintf(name, "PredXact inConflictsTab %d", i);

Better to use snprintf() instead. sprintf() is safe here, but many
static analysis tools will complain on any sight of plain sprintf(), so
better to just never use it.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Petr Jelinek 2017-06-15 06:41:16 Re: Refreshing subscription relation state inside a transaction block
Previous Message Mahi Gurram 2017-06-15 06:32:00 Re: Regarding Postgres Dynamic Shared Memory (DSA)