-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathconfig.go
613 lines (533 loc) · 21.4 KB
/
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
// Copyright 2015 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package server
import (
"bytes"
"fmt"
"io/ioutil"
"math"
"net"
"runtime"
"strconv"
"strings"
"text/tabwriter"
"time"
"github.com/dustin/go-humanize"
"github.com/elastic/gosigar"
"github.com/pkg/errors"
"golang.org/x/net/context"
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip/resolver"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/storage/engine"
"github.com/cockroachdb/cockroach/pkg/ts"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
)
// Context defaults.
const (
defaultCGroupMemPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
// DefaultCacheSize is the default size of the RocksDB cache. We default the
// cache size and SQL memory pool size to 128 MiB. Larger values might
// provide significantly better performance, but we're not sure what type of
// system we're running on (development or production or some shared
// environment). Production users should almost certainly override these
// settings and we'll warn in the logs about doing so.
DefaultCacheSize = 128 << 20 // 128 MB
defaultSQLMemoryPoolSize = 128 << 20 // 128 MB
defaultScanInterval = 10 * time.Minute
defaultScanMaxIdleTime = 200 * time.Millisecond
defaultMetricsSampleInterval = 10 * time.Second
defaultStorePath = "cockroach-data"
defaultTempStorageDirPrefix = "cockroach-temp"
// tempStorageDirsRecordFilename is the filename for the record file
// that keeps track of the paths of the temporary directories created.
// This file will be stored under the first store's root.
tempStorageDirsRecordFilename = "temp-storage-dirs.txt"
defaultEventLogEnabled = true
defaultEnableWebSessionAuthentication = false
maximumMaxClockOffset = 5 * time.Second
minimumNetworkFileDescriptors = 256
recommendedNetworkFileDescriptors = 5000
)
var productionSettingsWebpage = fmt.Sprintf(
"please see %s for more details",
base.DocsURL("recommended-production-settings.html"),
)
// MaxOffsetType stores the configured MaxOffset.
type MaxOffsetType time.Duration
// Type implements the pflag.Value interface.
func (mo *MaxOffsetType) Type() string {
return "MaxOffset"
}
// Set implements the pflag.Value interface.
func (mo *MaxOffsetType) Set(v string) error {
if v == "experimental-clockless" {
*mo = MaxOffsetType(timeutil.ClocklessMaxOffset)
return nil
}
nanos, err := time.ParseDuration(v)
if err != nil {
return err
}
if nanos > maximumMaxClockOffset {
return errors.Errorf("%s is not a valid MaxOffset", v)
}
*mo = MaxOffsetType(nanos)
return nil
}
// String implements the pflag.Value interface.
func (mo *MaxOffsetType) String() string {
if *mo == timeutil.ClocklessMaxOffset {
return "experimental-clockless"
}
return time.Duration(*mo).String()
}
// Config holds parameters needed to setup a server.
type Config struct {
// Embed the base context.
*base.Config
Settings *cluster.Settings
base.RaftConfig
base.LeaseManagerConfig
// Unix socket: for postgres only.
SocketFile string
// Stores is specified to enable durable key-value storage.
Stores base.StoreSpecList
// TempStorageConfig is used to store ephemeral data when processing large
// queries.
TempStorageConfig base.TempStorageConfig
// Attrs specifies a colon-separated list of node topography or machine
// capabilities, used to match capabilities or location preferences specified
// in zone configs.
Attrs string
// JoinList is a list of node addresses that act as bootstrap hosts for
// connecting to the gossip network. Each item in the list can actually be
// multiple comma-separated addresses, kept for backward-compatibility.
JoinList base.JoinListType
// RetryOptions controls the retry behavior of the server.
RetryOptions retry.Options
// CacheSize is the amount of memory in bytes to use for caching data.
// The value is split evenly between the stores if there are more than one.
CacheSize int64
// TimeSeriesServerConfig contains configuration specific to the time series
// server.
TimeSeriesServerConfig ts.ServerConfig
// SQLMemoryPoolSize is the amount of memory in bytes that can be
// used by SQL clients to store row data in server RAM.
SQLMemoryPoolSize int64
// Parsed values.
// NodeAttributes is the parsed representation of Attrs.
NodeAttributes roachpb.Attributes
// GossipBootstrapResolvers is a list of gossip resolvers used
// to find bootstrap nodes for connecting to the gossip network.
GossipBootstrapResolvers []resolver.Resolver
// The following values can only be set via environment variables and are
// for testing only. They are not meant to be set by the end user.
// Enables linearizable behaviour of operations on this node by making sure
// that no commit timestamp is reported back to the client until all other
// node clocks have necessarily passed it.
// Environment Variable: COCKROACH_LINEARIZABLE
Linearizable bool
// Maximum allowed clock offset for the cluster. If observed clock
// offsets exceed this limit, inconsistency may result, and servers
// will panic to minimize the likelihood of inconsistent data.
// Increasing this value will increase time to recovery after
// failures, and increase the frequency and impact of
// ReadWithinUncertaintyIntervalError.
MaxOffset MaxOffsetType
// MetricsSampleInterval determines the time between records of
// server internal metrics.
// Environment Variable: COCKROACH_METRICS_SAMPLE_INTERVAL
MetricsSampleInterval time.Duration
// ScanInterval determines a duration during which each range should be
// visited approximately once by the range scanner. Set to 0 to disable.
// Environment Variable: COCKROACH_SCAN_INTERVAL
ScanInterval time.Duration
// ScanMaxIdleTime is the maximum time the scanner will be idle between ranges.
// If enabled (> 0), the scanner may complete in less than ScanInterval for small
// stores.
// Environment Variable: COCKROACH_SCAN_MAX_IDLE_TIME
ScanMaxIdleTime time.Duration
// TestingKnobs is used for internal test controls only.
TestingKnobs base.TestingKnobs
// AmbientCtx is used to annotate contexts used inside the server.
AmbientCtx log.AmbientContext
// Locality is a description of the topography of the server.
Locality roachpb.Locality
// EventLogEnabled is a switch which enables recording into cockroach's SQL
// event log tables. These tables record transactional events about changes
// to cluster metadata, such as DDL statements and range rebalancing
// actions.
EventLogEnabled bool
// ListeningURLFile indicates the file to which the server writes
// its listening URL when it is ready.
ListeningURLFile string
// PIDFile indicates the file to which the server writes its PID when
// it is ready.
PIDFile string
// EnableWebSessionAuthentication enables session-based authentication for
// the Admin API's HTTP endpoints.
EnableWebSessionAuthentication bool
enginesCreated bool
}
// HistogramWindowInterval is used to determine the approximate length of time
// that individual samples are retained in in-memory histograms. Currently,
// it is set to the arbitrary length of six times the Metrics sample interval.
//
// The length of the window must be longer than the sampling interval due to
// issue #12998, which was causing histograms to return zero values when sampled
// because all samples had been evicted.
//
// Note that this is only intended to be a temporary fix for the above issue,
// as our current handling of metric histograms have numerous additional
// problems. These are tracked in github issue #7896, which has been given
// a relatively high priority in light of recent confusion around histogram
// metrics. For more information on the issues underlying our histogram system
// and the proposed fixes, please see issue #7896.
func (cfg Config) HistogramWindowInterval() time.Duration {
hwi := cfg.MetricsSampleInterval * 6
// Rudimentary overflow detection; this can result if MetricsSampleInterval
// is set to an extremely large number, likely in the context of a test or
// an intentional attempt to disable metrics collection. Just return
// cfg.MetricsSampleInterval in this case.
if hwi < cfg.MetricsSampleInterval {
return cfg.MetricsSampleInterval
}
return hwi
}
// GetTotalMemory returns either the total system memory or if possible the
// cgroups available memory.
func GetTotalMemory(ctx context.Context) (int64, error) {
totalMem, err := func() (int64, error) {
mem := gosigar.Mem{}
if err := mem.Get(); err != nil {
return 0, err
}
if mem.Total > math.MaxInt64 {
return 0, fmt.Errorf("inferred memory size %s exceeds maximum supported memory size %s",
humanize.IBytes(mem.Total), humanize.Bytes(math.MaxInt64))
}
return int64(mem.Total), nil
}()
if err != nil {
return 0, err
}
checkTotal := func(x int64) (int64, error) {
if x <= 0 {
// https://github.com/elastic/gosigar/issues/72
return 0, fmt.Errorf("inferred memory size %d is suspicious, considering invalid", x)
}
return x, nil
}
if runtime.GOOS != "linux" {
return checkTotal(totalMem)
}
var buf []byte
if buf, err = ioutil.ReadFile(defaultCGroupMemPath); err != nil {
log.Infof(ctx, "can't read available memory from cgroups (%s), using system memory %s instead", err,
humanizeutil.IBytes(totalMem))
return checkTotal(totalMem)
}
cgAvlMem, err := strconv.ParseUint(strings.TrimSpace(string(buf)), 10, 64)
if err != nil {
log.Infof(ctx, "can't parse available memory from cgroups (%s), using system memory %s instead", err,
humanizeutil.IBytes(totalMem))
return checkTotal(totalMem)
}
if cgAvlMem == 0 || cgAvlMem > math.MaxInt64 {
log.Infof(ctx, "available memory from cgroups (%s) is unsupported, using system memory %s instead",
humanize.IBytes(cgAvlMem), humanizeutil.IBytes(totalMem))
return checkTotal(totalMem)
}
if totalMem > 0 && int64(cgAvlMem) > totalMem {
log.Infof(ctx, "available memory from cgroups (%s) exceeds system memory %s, using system memory",
humanize.IBytes(cgAvlMem), humanizeutil.IBytes(totalMem))
return checkTotal(totalMem)
}
return checkTotal(int64(cgAvlMem))
}
// setOpenFileLimit sets the soft limit for open file descriptors to the hard
// limit if needed. Returns an error if the hard limit is too low. Returns the
// value to set maxOpenFiles to for each store.
//
// Minimum - 1700 per store, 256 saved for networking
//
// Constrained - 256 saved for networking, rest divided evenly per store
//
// Constrained (network only) - 10000 per store, rest saved for networking
//
// Recommended - 10000 per store, 5000 for network
//
// Please note that current and max limits are commonly referred to as the soft
// and hard limits respectively.
//
// On Windows there is no need to change the file descriptor, known as handles,
// limit. This limit cannot be changed and is approximately 16,711,680. See
// https://blogs.technet.microsoft.com/markrussinovich/2009/09/29/pushing-the-limits-of-windows-handles/
func setOpenFileLimit(physicalStoreCount int) (uint64, error) {
return setOpenFileLimitInner(physicalStoreCount)
}
// SetOpenFileLimitForOneStore sets the soft limit for open file descriptors
// when there is only one store.
func SetOpenFileLimitForOneStore() (uint64, error) {
return setOpenFileLimit(1)
}
// MakeConfig returns a Context with default values.
func MakeConfig(ctx context.Context, st *cluster.Settings) Config {
storeSpec, err := base.NewStoreSpec(defaultStorePath)
if err != nil {
panic(err)
}
cfg := Config{
Config: new(base.Config),
MaxOffset: MaxOffsetType(base.DefaultMaxClockOffset),
Settings: st,
CacheSize: DefaultCacheSize,
SQLMemoryPoolSize: defaultSQLMemoryPoolSize,
ScanInterval: defaultScanInterval,
ScanMaxIdleTime: defaultScanMaxIdleTime,
MetricsSampleInterval: defaultMetricsSampleInterval,
EventLogEnabled: defaultEventLogEnabled,
EnableWebSessionAuthentication: defaultEnableWebSessionAuthentication,
Stores: base.StoreSpecList{
Specs: []base.StoreSpec{storeSpec},
},
TempStorageConfig: base.TempStorageConfigFromEnv(
ctx, storeSpec, "" /* parentDir */, base.DefaultTempStorageMaxSizeBytes),
}
cfg.AmbientCtx.Tracer = st.Tracer
cfg.Config.InitDefaults()
cfg.RaftConfig.SetDefaults()
return cfg
}
// String implements the fmt.Stringer interface.
func (cfg *Config) String() string {
var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 2, 1, 2, ' ', 0)
fmt.Fprintln(w, "max offset\t", cfg.MaxOffset)
fmt.Fprintln(w, "cache size\t", humanizeutil.IBytes(cfg.CacheSize))
fmt.Fprintln(w, "SQL memory pool size\t", humanizeutil.IBytes(cfg.SQLMemoryPoolSize))
fmt.Fprintln(w, "scan interval\t", cfg.ScanInterval)
fmt.Fprintln(w, "scan max idle time\t", cfg.ScanMaxIdleTime)
fmt.Fprintln(w, "metrics sample interval\t", cfg.MetricsSampleInterval)
fmt.Fprintln(w, "event log enabled\t", cfg.EventLogEnabled)
fmt.Fprintln(w, "linearizable\t", cfg.Linearizable)
if cfg.ListeningURLFile != "" {
fmt.Fprintln(w, "listening URL file\t", cfg.ListeningURLFile)
}
if cfg.PIDFile != "" {
fmt.Fprintln(w, "PID file\t", cfg.PIDFile)
}
_ = w.Flush()
return buf.String()
}
// Report logs an overview of the server configuration parameters via
// the given context.
func (cfg *Config) Report(ctx context.Context) {
if memSize, err := GetTotalMemory(ctx); err != nil {
log.Infof(ctx, "unable to retrieve system total memory: %v", err)
} else {
log.Infof(ctx, "system total memory: %s", humanizeutil.IBytes(memSize))
}
log.Info(ctx, "server configuration:\n", cfg)
}
// Engines is a container of engines, allowing convenient closing.
type Engines []engine.Engine
// Close closes all the Engines.
// This method has a pointer receiver so that the following pattern works:
// func f() {
// engines := Engines(engineSlice)
// defer engines.Close() // make sure the engines are Closed if this
// // function returns early.
// ... do something with engines, pass ownership away...
// engines = nil // neutralize the preceding defer
// }
func (e *Engines) Close() {
for _, eng := range *e {
eng.Close()
}
*e = nil
}
// CreateEngines creates Engines based on the specs in cfg.Stores.
func (cfg *Config) CreateEngines(ctx context.Context) (Engines, error) {
engines := Engines(nil)
defer engines.Close()
if cfg.enginesCreated {
return Engines{}, errors.Errorf("engines already created")
}
cfg.enginesCreated = true
var details []string
details = append(details, fmt.Sprintf("RocksDB cache size: %s", humanizeutil.IBytes(cfg.CacheSize)))
cache := engine.NewRocksDBCache(cfg.CacheSize)
defer cache.Release()
var physicalStores int
for _, spec := range cfg.Stores.Specs {
if !spec.InMemory {
physicalStores++
}
}
openFileLimitPerStore, err := setOpenFileLimit(physicalStores)
if err != nil {
return Engines{}, err
}
skipSizeCheck := cfg.TestingKnobs.Store != nil &&
cfg.TestingKnobs.Store.(*storage.StoreTestingKnobs).SkipMinSizeCheck
for i, spec := range cfg.Stores.Specs {
var sizeInBytes = spec.SizeInBytes
if spec.InMemory {
if spec.SizePercent > 0 {
sysMem, err := GetTotalMemory(ctx)
if err != nil {
return Engines{}, errors.Errorf("could not retrieve system memory")
}
sizeInBytes = int64(float64(sysMem) * spec.SizePercent / 100)
}
if sizeInBytes != 0 && !skipSizeCheck && sizeInBytes < base.MinimumStoreSize {
return Engines{}, errors.Errorf("%f%% of memory is only %s bytes, which is below the minimum requirement of %s",
spec.SizePercent, humanizeutil.IBytes(sizeInBytes), humanizeutil.IBytes(base.MinimumStoreSize))
}
details = append(details, fmt.Sprintf("store %d: in-memory, size %s",
i, humanizeutil.IBytes(sizeInBytes)))
engines = append(engines, engine.NewInMem(spec.Attributes, sizeInBytes))
} else {
if spec.SizePercent > 0 {
fileSystemUsage := gosigar.FileSystemUsage{}
if err := fileSystemUsage.Get(spec.Path); err != nil {
return Engines{}, err
}
sizeInBytes = int64(float64(fileSystemUsage.Total) * spec.SizePercent / 100)
}
if sizeInBytes != 0 && !skipSizeCheck && sizeInBytes < base.MinimumStoreSize {
return Engines{}, errors.Errorf("%f%% of %s's total free space is only %s bytes, which is below the minimum requirement of %s",
spec.SizePercent, spec.Path, humanizeutil.IBytes(sizeInBytes), humanizeutil.IBytes(base.MinimumStoreSize))
}
details = append(details, fmt.Sprintf("store %d: RocksDB, max size %s, max open file limit %d",
i, humanizeutil.IBytes(sizeInBytes), openFileLimitPerStore))
rocksDBConfig := engine.RocksDBConfig{
Attrs: spec.Attributes,
Dir: spec.Path,
MaxSizeBytes: sizeInBytes,
MaxOpenFiles: openFileLimitPerStore,
WarnLargeBatchThreshold: 500 * time.Millisecond,
Settings: cfg.Settings,
}
eng, err := engine.NewRocksDB(rocksDBConfig, cache)
if err != nil {
return Engines{}, err
}
engines = append(engines, eng)
}
}
log.Infof(ctx, "%d storage engine%s initialized",
len(engines), util.Pluralize(int64(len(engines))))
for _, s := range details {
log.Info(ctx, s)
}
enginesCopy := engines
engines = nil
return enginesCopy, nil
}
// InitNode parses node attributes and initializes the gossip bootstrap
// resolvers.
func (cfg *Config) InitNode() error {
cfg.readEnvironmentVariables()
// Initialize attributes.
cfg.NodeAttributes = parseAttributes(cfg.Attrs)
// Expose HistogramWindowInterval to parts of the code that can't import the
// server package. This code should be cleaned up within a month or two.
cfg.Config.HistogramWindowInterval = cfg.HistogramWindowInterval()
// Get the gossip bootstrap resolvers.
resolvers, err := cfg.parseGossipBootstrapResolvers()
if err != nil {
return err
}
if len(resolvers) > 0 {
cfg.GossipBootstrapResolvers = resolvers
}
return nil
}
// FilterGossipBootstrapResolvers removes any gossip bootstrap resolvers which
// match either this node's listen address or its advertised host address.
func (cfg *Config) FilterGossipBootstrapResolvers(
ctx context.Context, listen, advert net.Addr,
) []resolver.Resolver {
filtered := make([]resolver.Resolver, 0, len(cfg.GossipBootstrapResolvers))
addrs := make([]string, 0, len(cfg.GossipBootstrapResolvers))
for _, r := range cfg.GossipBootstrapResolvers {
if r.Addr() == advert.String() || r.Addr() == listen.String() {
if log.V(1) {
log.Infof(ctx, "skipping -join address %q, because a node cannot join itself", r.Addr())
}
} else {
filtered = append(filtered, r)
addrs = append(addrs, r.Addr())
}
}
if log.V(1) {
log.Infof(ctx, "initial resolvers: %v", addrs)
}
return filtered
}
// RequireWebSession indicates whether the server should require authentication
// sessions when serving admin API requests.
func (cfg *Config) RequireWebSession() bool {
return !cfg.Insecure && cfg.EnableWebSessionAuthentication
}
// readEnvironmentVariables populates all context values that are environment
// variable based. Note that this only happens when initializing a node and not
// when NewContext is called.
func (cfg *Config) readEnvironmentVariables() {
// cockroach-linearizable
cfg.Linearizable = envutil.EnvOrDefaultBool("COCKROACH_LINEARIZABLE", cfg.Linearizable)
cfg.MetricsSampleInterval = envutil.EnvOrDefaultDuration("COCKROACH_METRICS_SAMPLE_INTERVAL", cfg.MetricsSampleInterval)
cfg.ScanInterval = envutil.EnvOrDefaultDuration("COCKROACH_SCAN_INTERVAL", cfg.ScanInterval)
cfg.ScanMaxIdleTime = envutil.EnvOrDefaultDuration("COCKROACH_SCAN_MAX_IDLE_TIME", cfg.ScanMaxIdleTime)
}
// parseGossipBootstrapResolvers parses list of gossip bootstrap resolvers.
func (cfg *Config) parseGossipBootstrapResolvers() ([]resolver.Resolver, error) {
var bootstrapResolvers []resolver.Resolver
for _, commaSeparatedAddresses := range cfg.JoinList {
addresses := strings.Split(commaSeparatedAddresses, ",")
for _, address := range addresses {
if len(address) == 0 {
continue
}
resolver, err := resolver.NewResolver(address)
if err != nil {
return nil, err
}
bootstrapResolvers = append(bootstrapResolvers, resolver)
}
}
return bootstrapResolvers, nil
}
// parseAttributes parses a colon-separated list of strings,
// filtering empty strings (i.e. "::" will yield no attributes.
// Returns the list of strings as Attributes.
func parseAttributes(attrsStr string) roachpb.Attributes {
var filtered []string
for _, attr := range strings.Split(attrsStr, ":") {
if len(attr) != 0 {
filtered = append(filtered, attr)
}
}
return roachpb.Attributes{Attrs: filtered}
}