Prefer the availability zone
Note
The article is being updated.
Below are examples of the code for setting the “prefer the availability zone” balancing algorithm option in different YDB SDKs
Go
1. package main
3. import (
4. "context"
5. "os"
7. "github.com/ydb-platform/ydb-go-sdk/v3"
8. "github.com/ydb-platform/ydb-go-sdk/v3/balancers"
9. )
11. func main() {
12. ctx, cancel := context.WithCancel(context.Background())
13. defer cancel()
14. db, err := ydb.Open(
15. ctx,
16. os.Getenv("YDB_CONNECTION_STRING"),
17. ydb.WithBalancer(
18. balancers.PreferLocations(
19. balancers.RandomChoice(),
20. "a",
21. "b",
22. ),
23. ),
24. )
25. if err != nil {
26. panic(err)
27. }
28. defer func() {
29. _ = db.Close(ctx)
30. }()
31. }

