viabtc / viabtc_exchange_server

A trading engine with high-speed performance and real-time notification
MIT License
2.68k stars 1.49k forks source link

matchengine should keep state to prevent data loss in case of unexpected exit. #156

Open jduarter opened 5 years ago

jduarter commented 5 years ago

In case matchengine quits unexpectedly (crash, SIGINIT, power issue... etc), application status is completely lost. State should be completely consistent to prevent critical data loss.

As an example case, consider MySQL connection is gone, some queries were pending to be committed to the database. If then the process unexpectedly quits, these pending MySQL statements will be lost.

This is a critical issue since queries will never be executed again when the process is restarted.

I'm working on a patch to store failed SQL queries in jobs so they can be re-executed again when the process restarts, causing the daemon to shutdown if any of the queries fail after restarting and successfully connecting to the database.

Any input/ideas are highly appreciated, I will try to publish the patch as soon as I've done testing.

objectt commented 5 years ago

@jduarter I am willing to contribute. Please let me know.

yihuang commented 5 years ago

This design is following some popular MMORPG server design, where lose some data when a crash is accepted. The right answer to this is something like WAL log system. I'm working on a proper exchange architecture, which is both high performance and persistence, and provide high availability guarantee. The early introduction is here.