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
package main
import (
"context"
"os"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, err := ydb.Open(
ctx,
os.Getenv("YDB_CONNECTION_STRING"),
ydb.WithBalancer(
balancers.PreferLocations(
balancers.RandomChoice(),
"a",
"b",
),
),
)
if err != nil {
panic(err)
}
defer func() {
_ = db.Close(ctx)
}()
}