Documentation
¶
Overview ¶
Package discoverer implements a discoverer for Tarantool 3.0.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTypedStorageNil is returned when typed storage is nil. ErrTypedStorageNil = errors.New("typed storage cannot be nil") // ErrRangeDataFailed is returned when range operation on storage fails. ErrRangeDataFailed = errors.New("failed to range data from storage") // ErrValidateDataFailed is returned when data validation fails. ErrValidateDataFailed = errors.New("failed to validate data") // ErrParseConfigFailed is returned when configuration parsing fails. ErrParseConfigFailed = errors.New("failed to parse configuration") )
var ErrMissingDiscoverer = fmt.Errorf("an inner discoverer is missing")
ErrMissingDiscoverer is an error that tells that the provided inner discoverer is nil.
var ErrMissingEtcd = fmt.Errorf("etcd object is missing")
ErrMissingEtcd is an error that tells that the provided etcd object is nil.
var ErrMissingFactory = fmt.Errorf("a dialer factory is missing")
ErrMissingFactory is an error that tells that the provided DialerFactory is nil.
var ErrMissingTarantool = errors.New("no Tarantool connector was applied")
ErrMissingTarantool for case of wrong initialization.
Functions ¶
This section is empty.
Types ¶
type Cache ¶ added in v1.1.0
type Cache struct {
// contains filtered or unexported fields
}
Cache wraps a Discoverer and caches its result so that subsequent calls to Discovery return the cached result immediately. This implementation is not thread-safe.
func NewCache ¶ added in v1.1.0
func NewCache(d discovery.Discoverer) *Cache
NewCache creates a new Cache that wraps the provided discoverer.
type Connectable ¶
type Connectable struct {
// contains filtered or unexported fields
}
Connectable gets a list of nodes from the inner discoverer and returns only those that are available for connection.
func NewConnectable ¶
func NewConnectable(factory discovery.DialerFactory, discoverer discovery.Discoverer) *Connectable
NewConnectable creates a Connectable with a given dialer factory and an inner discoverer.
type Etcd ¶
type Etcd struct {
// contains filtered or unexported fields
}
Etcd discovers a list of instance configurations from etcd.
func NewEtcd ¶
NewEtcd creates a new etcd discoverer to retrieve a list of instance configurations from etcd.
The prefix must have the same value as config.etcd.prefix.
func (*Etcd) Discovery ¶
Discovery retrieves a list of instance configurations from etcd.
Example ¶
package main
import (
"context"
"fmt"
"io"
"log"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/integration"
"github.com/tarantool/go-discovery/discoverer"
)
func init() {
log.SetOutput(io.Discard)
}
func main() {
cluster := integration.NewLazyCluster()
defer cluster.Terminate()
etcd, err := clientv3.New(clientv3.Config{
Endpoints: cluster.EndpointsGRPC(),
})
if err != nil {
fmt.Println("Unable to start etcd client:", err)
return
}
defer func() { _ = etcd.Close() }()
etcddiscoverer := discoverer.NewEtcd(etcd, "foo")
instances, err := etcddiscoverer.Discovery(context.Background())
fmt.Println("Without keys in the prefix:")
fmt.Println("Instances:", instances)
fmt.Println("Error:", err)
_, err = etcd.Put(context.Background(), "foo/config/key", `
database:
mode: ro
groups:
foo:
replicasets:
bar:
instances:
zoo:
iproto:
advertise:
client: localhost:3011
peer:
params:
transport: ssl
roles: [crud]
labels:
tags: "any,bar,3"
`)
if err != nil {
fmt.Println("Unable to put configuration into etcd:", err)
return
}
instances, err = etcddiscoverer.Discovery(context.Background())
fmt.Println("After publishing:")
fmt.Println("Instances")
for _, instance := range instances {
fmt.Println("Group:", instance.Group)
fmt.Println("Replicaset:", instance.Replicaset)
fmt.Println("Name:", instance.Name)
fmt.Println("Mode:", instance.Mode.String())
fmt.Println("URI:", instance.URI)
fmt.Println("Roles:", instance.Roles)
fmt.Println("Labels:", instance.Labels)
}
fmt.Println("Error:", err)
fmt.Println("Done.")
}
Output: Without keys in the prefix: Instances: [] Error: <nil> After publishing: Instances Group: foo Replicaset: bar Name: zoo Mode: ro URI: [localhost:3011] Roles: [crud] Labels: map[tags:any,bar,3] Error: <nil> Done.
Example (Cancelled) ¶
package main
import (
"context"
"fmt"
"io"
"log"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/integration"
"github.com/tarantool/go-discovery/discoverer"
)
func init() {
log.SetOutput(io.Discard)
}
func main() {
cluster := integration.NewLazyCluster()
defer cluster.Terminate()
etcd, err := clientv3.New(clientv3.Config{
Endpoints: cluster.EndpointsGRPC(),
})
if err != nil {
fmt.Println("Unable to start etcd client:", err)
return
}
defer func() { _ = etcd.Close() }()
ctx, cancel := context.WithCancel(context.Background())
cancel()
etcddiscoverer := discoverer.NewEtcd(etcd, "foo")
instances, err := etcddiscoverer.Discovery(ctx)
fmt.Println(instances)
fmt.Println(err)
fmt.Println("Done.")
}
Output: [] context canceled Done.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter filters the list of discovered nodes by some set of filters. It serves as a wrapper to another Discoverer.
func NewFilter ¶
func NewFilter(discoverer discovery.Discoverer, filters ...discovery.Filter) *Filter
NewFilter creates a new Filter discoverer. It wraps the inner discoverer to filter its results according to passed filters.
type Storage ¶ added in v1.1.0
type Storage struct {
// contains filtered or unexported fields
}
Storage discovers a list of instance configurations from a storage.
func NewStorageDiscoverer ¶ added in v1.1.0
NewStorageDiscoverer creates a new storage discoverer to retrieve a list of instance configurations from a storage.
type Tarantool ¶
type Tarantool struct {
// contains filtered or unexported fields
}
Tarantool discovers a list of instance configurations from TcS.
func NewTarantool ¶
NewTarantool create decorator with Discovery method.
func (*Tarantool) Discovery ¶
Discovery retrieves a list of instance configurations from the Storage.
Example ¶
package main
import (
"context"
"errors"
"fmt"
"log"
"github.com/tarantool/go-discovery/discoverer"
tcshelper "github.com/tarantool/go-tarantool/v2/test_helpers/tcs"
)
func main() {
tcs, err := tcshelper.Start(0)
if err != nil {
if errors.Is(err, tcshelper.ErrNotSupported) {
fmt.Println("TcS is not supported:", err)
return
}
log.Fatalf("Failed to start TcS: %s", err)
}
discoverer := discoverer.NewTarantool(tcs.Doer(), "/foo")
instances, err := discoverer.Discovery(context.Background())
fmt.Println("Without keys in the prefix:")
fmt.Println("Instances:", instances)
fmt.Println("Error:", err)
err = tcs.Put(context.Background(), "/foo/config/key", `
database:
mode: ro
groups:
foo:
replicasets:
bar:
instances:
zoo:
iproto:
advertise:
client: localhost:3011
peer:
params:
transport: ssl
roles: [crud]
labels:
tags: "any,bar,3"
`)
if err != nil {
fmt.Println("Unable to put configuration into etcd:", err)
return
}
instances, err = discoverer.Discovery(context.Background())
fmt.Println("After publishing:")
fmt.Println("Instances")
for _, instance := range instances {
fmt.Println("Group:", instance.Group)
fmt.Println("Replicaset:", instance.Replicaset)
fmt.Println("Name:", instance.Name)
fmt.Println("Mode:", instance.Mode.String())
fmt.Println("URI:", instance.URI)
fmt.Println("Roles:", instance.Roles)
fmt.Println("Labels:", instance.Labels)
}
fmt.Println("Error:", err)
fmt.Println("Done.")
}
Output: