-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdriver_config.go
94 lines (79 loc) · 3.44 KB
/
driver_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package ydb
import "time"
// DriverConfig contains driver configuration options.
type DriverConfig struct {
// Database is a required database name.
Database string
// Credentials is an ydb client credentials.
// In most cases Credentials are required.
Credentials Credentials
// Trace contains driver tracing options.
Trace DriverTrace
// RequestTimeout is the maximum amount of time a Call() will wait for an
// operation to complete.
// If RequestTimeout is zero then no timeout is used.
RequestTimeout time.Duration
// StreamTimeout is the maximum amount of time a StreamRead() will wait for
// an operation to complete.
// If StreamTimeout is zero then no timeout is used.
StreamTimeout time.Duration
// OperationTimeout is the maximum amount of time a YDB server will process
// an operation. After timeout exceeds YDB will try to cancel operation and
// regardless of the cancellation appropriate error will be returned to
// the client.
// If OperationTimeout is zero then no timeout is used.
OperationTimeout time.Duration
// OperationCancelAfter is the maximum amount of time a YDB server will process an
// operation. After timeout exceeds YDB will try to cancel operation and if
// it succeeds appropriate error will be returned to the client; otherwise
// processing will be continued.
// If OperationCancelAfter is zero then no timeout is used.
OperationCancelAfter time.Duration
// DiscoveryInterval is the frequency of background tasks of ydb endpoints
// discovery.
// If DiscoveryInterval is zero then the DefaultDiscoveryInterval is used.
// If DiscoveryInterval is negative, then no background discovery prepared.
DiscoveryInterval time.Duration
// BalancingMethod is an algorithm used by the driver for endpoint
// selection.
// If BalancingMethod is zero then the DefaultBalancingMethod is used.
BalancingMethod BalancingMethod
// BalancingConfig is an optional configuration related to selected
// BalancingMethod. That is, some balancing methods allow to be configured.
BalancingConfig interface{}
// PreferLocalEndpoints adds endpoint selection logic when local endpoints
// are always used first.
// When no alive local endpoints left other endpoints will be used.
//
// NOTE: some balancing methods (such as p2c) also may use knowledge of
// endpoint's locality. Difference is that with PreferLocalEndpoints local
// endpoints selected separately from others. That is, if there at least
// one local endpoint it will be used regardless of its performance
// indicators.
//
// NOTE: currently driver (and even ydb itself) does not track load factor
// of each endpoint properly. Enabling this option may lead to the
// situation, when all but one nodes in local datacenter become inactive
// and all clients will overload this single instance very quickly. That
// is, currently this option may be called as experimental.
// You have been warned.
PreferLocalEndpoints bool
// RequestsType set an additional type hint to all requests.
// It is needed only for debug purposes and advanced cases.
RequestsType string
// FastDial will make dialer return Driver as soon as 1st connection succeeds.
// NB: it may be not the fastest node to serve requests.
FastDial bool
}
func (d *DriverConfig) withDefaults() (c DriverConfig) {
if d != nil {
c = *d
}
if c.DiscoveryInterval == 0 {
c.DiscoveryInterval = DefaultDiscoveryInterval
}
if c.BalancingMethod == 0 {
c.BalancingMethod = DefaultBalancingMethod
}
return c
}