NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
386 stars 49 forks source link

feat: prevent duplicate table errors #260

Closed stakach closed 4 years ago

stakach commented 4 years ago

This will prevent duplicate table errors where multiple services start up simultaneously.

nobrainers lock table for the most part prevents this issue however in a micro-service environment we find the lock table itself becomes a duplicate table.

nviennot commented 4 years ago

Can you explain how this fixes the bug?

stakach commented 4 years ago

A race condition can occur when creating tables in rethinkdb. If you have two services sharing a database that create tables when they startup, a duplicate table might be created. Or if you have multiple instances of a single service.

If a duplicate table is created then this code removes the second table - allowing the services to continue to function, as rethink will not process any requests relating to the duplicate table.

We had this issue almost every time when launching a fresh cluster. Have been running this code in production since May without issues.

It's a workaround for this issue: rethinkdb/rethinkdb#4898 and the solution here is pulled from the comments there

nviennot commented 4 years ago

Cool, thank you