Nico D'Cotta
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 177 additions and 37 deletions
-
2weed/command/benchmark.go
-
6weed/command/filer.go
-
4weed/command/server.go
-
3weed/filer/filer.go
-
7weed/filer/leveldb/leveldb_store_test.go
-
5weed/filer/leveldb2/leveldb2_store_test.go
-
5weed/filer/leveldb3/leveldb3_store_test.go
-
6weed/filer/rocksdb/rocksdb_store_test.go
-
2weed/iamapi/iamapi_server.go
-
2weed/mq/broker/broker_server.go
-
37weed/pb/server_address.go
-
36weed/pb/server_address_test.go
-
62weed/pb/server_discovery.go
-
2weed/server/filer_grpc_server_admin.go
-
10weed/server/filer_server.go
-
2weed/server/master_server.go
-
2weed/shell/commands.go
-
1weed/stats/metrics.go
-
13weed/wdclient/masterclient.go
-
5weed/wdclient/vid_map_test.go
@ -0,0 +1,36 @@ |
|||
package pb |
|||
|
|||
import ( |
|||
"reflect" |
|||
"testing" |
|||
) |
|||
|
|||
func TestServerAddresses_ToAddressMapOrSrv_shouldRemovePrefix(t *testing.T) { |
|||
str := ServerAddresses("dnssrv+hello.srv.consul") |
|||
|
|||
d := str.ToServiceDiscovery() |
|||
|
|||
expected := ServerSrvAddress("hello.srv.consul") |
|||
if *d.srvRecord != expected { |
|||
t.Fatalf(`ServerAddresses("dnssrv+hello.srv.consul") = %s, expected %s`, *d.srvRecord, expected) |
|||
} |
|||
} |
|||
|
|||
func TestServerAddresses_ToAddressMapOrSrv_shouldHandleIPPortList(t *testing.T) { |
|||
str := ServerAddresses("10.0.0.1:23,10.0.0.2:24") |
|||
|
|||
d := str.ToServiceDiscovery() |
|||
|
|||
if d.srvRecord != nil { |
|||
t.Fatalf(`ServerAddresses("dnssrv+hello.srv.consul") = %s, expected nil`, *d.srvRecord) |
|||
} |
|||
|
|||
expected := []ServerAddress{ |
|||
ServerAddress("10.0.0.1:23"), |
|||
ServerAddress("10.0.0.2:24"), |
|||
} |
|||
|
|||
if !reflect.DeepEqual(d.list, expected) { |
|||
t.Fatalf(`Expected %q, got %q`, expected, d.list) |
|||
} |
|||
} |
@ -0,0 +1,62 @@ |
|||
package pb |
|||
|
|||
import ( |
|||
"github.com/seaweedfs/seaweedfs/weed/glog" |
|||
"reflect" |
|||
) |
|||
|
|||
// ServerDiscovery encodes a way to find at least 1 instance of a service,
|
|||
// and provides utility functions to refresh the instance list
|
|||
type ServerDiscovery struct { |
|||
list []ServerAddress |
|||
srvRecord *ServerSrvAddress |
|||
} |
|||
|
|||
func NewServiceDiscoveryFromMap(m map[string]ServerAddress) (sd *ServerDiscovery) { |
|||
sd = &ServerDiscovery{} |
|||
for _, s := range m { |
|||
sd.list = append(sd.list, s) |
|||
} |
|||
return sd |
|||
} |
|||
|
|||
// RefreshBySrvIfAvailable performs a DNS SRV lookup and updates list with the results
|
|||
// of the lookup
|
|||
func (sd *ServerDiscovery) RefreshBySrvIfAvailable() { |
|||
if sd.srvRecord == nil { |
|||
return |
|||
} |
|||
newList, err := sd.srvRecord.LookUp() |
|||
if err != nil { |
|||
glog.V(0).Infof("failed to lookup SRV for %s: %v", *sd.srvRecord, err) |
|||
} |
|||
if newList == nil || len(newList) == 0 { |
|||
glog.V(0).Infof("looked up SRV for %s, but found no well-formed names", *sd.srvRecord) |
|||
return |
|||
} |
|||
if !reflect.DeepEqual(sd.list, newList) { |
|||
sd.list = newList |
|||
} |
|||
} |
|||
|
|||
// GetInstances returns a copy of the latest known list of addresses
|
|||
// call RefreshBySrvIfAvailable prior to this in order to get a more up-to-date view
|
|||
func (sd *ServerDiscovery) GetInstances() (addresses []ServerAddress) { |
|||
for _, a := range sd.list { |
|||
addresses = append(addresses, a) |
|||
} |
|||
return addresses |
|||
} |
|||
func (sd *ServerDiscovery) GetInstancesAsStrings() (addresses []string) { |
|||
for _, i := range sd.list { |
|||
addresses = append(addresses, string(i)) |
|||
} |
|||
return addresses |
|||
} |
|||
func (sd *ServerDiscovery) GetInstancesAsMap() (addresses map[string]ServerAddress) { |
|||
addresses = make(map[string]ServerAddress) |
|||
for _, i := range sd.list { |
|||
addresses[string(i)] = i |
|||
} |
|||
return addresses |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue