BDR 0.9.3 and Index on Expression (Part 3 – Solved)

Go deeper into BDR and patched-PostgreSQL 9.4.5, eventually I find out the root cause. When new record INSERT-ed, BDR replicates it to other nodes. After simple_heap_insert, BDR calls UserTableUpdateOpenIndexes. For index on epression written in SQL, BDR code routes to GetActiveSnapshot() which fires Segmentation fault because ActiveSnapShot is invalid.

Snapshot
GetActiveSnapshot(void)
{
...
return ActiveSnapshot->as_snap;//invalid ActiveSnapshot fires Segmentation fault
}

Goes to bdr_apply.c in BDR package, I found out that ActiveSnapshot is set and cleared with PushActiveSnapshot and PopActiveSnapshot calls respectively in process_remote_update and process_remote_delete functions but not in process_remote_insert.

Then, I apply the function pair in process_remote_insert at the point before and after UserTableUpdateOpenIndexes calls :

...
PushActiveSnapshot(GetTransactionSnapshot());
if (conflict)
{

...
if (apply_update)
{

...
UserTableUpdateOpenIndexes(estate, newslot);
...

}

}
else
{

simple_heap_insert(rel->rel, newslot->tts_tuple);
UserTableUpdateOpenIndexes(estate, newslot);
...

}
PopActiveSnapshot();
...

Rebuild and reinstall the BDR package. Now no more replication crashes caused by updating index on expression written in SQL language. Case closed.

Advertisements
4 comments
  1. akretschmer said:

    I’m talking with Craig Ringer, he will aply the proposed change. Thank you!

  2. Abdul Yadi said:

    You are welcome. Happy new year.

  3. ringerc said:

    Good diagnostic work there. I agree with your explanation.

    Interestingly this breaks the ddl/sequence test in ‘make check’, so I won’t be applying it immediately. I’ll need to try to find time to dig into why but I suspect it’s related to global sequence voting issues.

    Thanks very much for the contribution. I’ll try to apply it to bdr-plugin/next and bdr-plugin/REL0_9_STABLE after I get time to track down why it breaks sequence voting.

    In future please feel free to send github pull requests to https://github.com/2ndQuadrant/bdr/tree/bdr-plugin/next . That way I or one of the other team members will see it reliably.

  4. ringerc said:

    It appears to have been a build issue on my side. I’ve been unable to reproduce the failure so I’ve applied the fix as-is. Thanks again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: