v2.0 Azure Elk
Election Support
Pot supports election support from version 2.0. This can be seeon on the test for election and re-election. These functionalities help with a simple implementation for when multiple replicas need to decide on the primary/secondary states.
Code Example:
The code example below runs in an infinite loop. The WithNoRewrite
flag disables writing for all clients but the current one unless the provided time of 10 seconds has passed. In case the object is stall for 10 seconds, another such loop can can take over the leadership and will be able to write and rewrite the object.
for {
_, err := client.Create(testPath, []testStruct{obj}, WithNoRewrite(time.Second * 10))
if errors.Is(err, pot.ErrNoRewriteViolated) {
slog.Info("I became secondary")
} else if err != nil {
slog.Error("Whoopsie", slog.String("err", err.Error()))
} else {
slog.Info("I am primary!")
}
time.Sleep(time.Second * 5)
}
What's Changed
- feat: add possibility to lock certain objects for primary / replica elections by @petomalina in #9
Full Changelog: v1.1...v2.0