Algorithms for doing leader election and name resolving with the help of another HA system, serve as anticorruption layers.
Перейти к файлу
Xiang Li 3d84e01f88
Update Azure pipelines (#18)
* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines

* Update azure-pipelines.yml for Azure Pipelines
2022-10-13 14:02:01 +08:00
HighAvailabilityModule.Algorithm Add IMembershipAlgorithm for extensibility 2020-02-21 13:33:31 +08:00
HighAvailabilityModule.Client.InMemory Fix test cases and change namespace 2019-09-29 10:00:56 +08:00
HighAvailabilityModule.Client.Rest Fix test cases and change namespace 2019-09-29 10:00:56 +08:00
HighAvailabilityModule.Client.SQL Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.E2ETest.Runner Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.E2ETest.TestCases Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.Interface Add IMembershipAlgorithm for extensibility 2020-02-21 13:33:31 +08:00
HighAvailabilityModule.Sample.RestClient Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.Sample.SQLClient Log and style improvement 2019-10-31 14:19:40 +08:00
HighAvailabilityModule.Server.InMemory Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.Server.Rest Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.Server.SQL Fix overflow bug for DATEDIFF 2020-06-01 16:45:34 +08:00
HighAvailabilityModule.Storage.Client Preserve inner exception when getting exception R/W data from database 2021-11-22 14:24:35 +08:00
HighAvailabilityModule.Storage.Server Modify codes. 2019-10-01 21:57:00 +08:00
HighAvailabilityModule.UnitTest Set ConfigureAwait to false 2019-10-23 13:29:14 +08:00
HighAvailabilityModule.UnitTest.SQL Fix bug 2019-10-08 18:01:59 +08:00
HighAvailabilityModule.util.SQL Modify SQLUtil. 2019-10-10 13:50:58 +08:00
HighAvailablityModule.Storage.Sample.Client Fix test cases and change namespace 2019-09-29 10:00:56 +08:00
keys Add TraceSource. 2019-10-08 12:08:07 +08:00
nuspec Pack Release Binaries 2019-11-01 15:52:38 +08:00
.gitignore Code Complete 2019-08-13 13:50:03 +08:00
CODE_OF_CONDUCT.md Initial commit 2019-08-12 22:37:40 -07:00
LICENSE Initial commit 2019-08-12 22:37:41 -07:00
README.md Use new build badge 2019-08-13 15:43:07 +08:00
SECURITY.md Microsoft mandatory file 2022-07-25 19:03:28 +00:00
azure-pipelines.yml Update Azure pipelines (#18) 2022-10-13 14:02:01 +08:00
codecov.yml Code Complete 2019-08-13 13:50:03 +08:00
ha-module.sln Add nuspec file and update azure-pipelines.yml 2019-08-30 12:15:28 +08:00
ha-module.sln.licenseheader Code Complete 2019-08-13 13:50:03 +08:00
hpcha.tla Code Complete 2019-08-13 13:50:03 +08:00

README.md

Anticorruption HA Module

Build Status

Algorithms for doing leader election and name resolving with the help of another HA system, serves as anticorruption layer.

Specification

Parameters

  • I: intervalfor heartbeat (e.g. 1 sec)
  • T: heartbeat timeout (e.g. 5 secs)
  • T > 2 * I

Data

  • Heartbeat Table: A table in the external HA system contains heartbeat entry.
  • Heartbeat Entry: in the format {uuid, utype, timestamp}
  • ha_time: current date time of the external HA system
  • All time is in UTC time

Procedures

  • UpdateHeartBeat(uuid, utype):

    For each type, update entry {old_uuid, utype, old_timestamp} in heartbeat table with {uuid, utype, ha_time}.

    For each type, if uuid is not equal to old_uuid, then (ha_time – old_timestamp > T) must be satisfied.

    The update process uses optimistic concurrency control. e.g. if the heartbeat entry has been updated before another heartbeat reaches, the later heartbeat is discarded.

  • GetPrimary(utype):

    Return (uuid, utype) in heartbeat entry with the corresponding query utype if (ha_time - timestamp <= T). Else return empty value.

Algorithm

  1. After a client S started, it generates a unique instance ID uuid to identify itself and marks itself with the exact utype, which it will work as in the future.

  2. S calls GetPrimary(utype) every I secs.

  3. If GetPrimary(utype) returned empty value, S calls UpdateHeartbeat(uuid, utype).

  4. Continue to call GetPrimary(utype) every I secs.

    a. If subsequent call to GetPrimary(utype) returns (uuid, utype) generated in 1, S will then work as primary.

    b. If subsequent call to GetPrimary(utype) returns a unique ID which is different from uuid and the same type with utype generated in 1, go back to 2.

    c. If subsequent call to GetPrimary(utype) returns an empty value / a corrupted message, error occurred in 3. Retry 3.

  5. S call UpdateHeartBeat(uuid, utype) and GetPrimary(utype) every I sec.

    a. If GetPrimary(utype) returns anything except (uuid, utype), or didn't return for (T - I) secs, exit itself and restart.

Spec in TLA+

Source Code

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.