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
  2. import (
  3. "context"
  4. "os"
  5. "github.com/ydb-platform/ydb-go-sdk/v3"
  6. "github.com/ydb-platform/ydb-go-sdk/v3/balancers"
  7. )
  8. func main() {
  9. ctx, cancel := context.WithCancel(context.Background())
  10. defer cancel()
  11. db, err := ydb.Open(
  12. ctx,
  13. os.Getenv("YDB_CONNECTION_STRING"),
  14. ydb.WithBalancer(
  15. balancers.PreferLocations(
  16. balancers.RandomChoice(),
  17. "a",
  18. "b",
  19. ),
  20. ),
  21. )
  22. if err != nil {
  23. panic(err)
  24. }
  25. defer func() {
  26. _ = db.Close(ctx)
  27. }()
  28. }

Prefer the availability zone - 图1