|
|
|
@ -22,6 +22,7 @@ import ( |
|
|
|
|
"encoding/xml" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"net" |
|
|
|
|
"net/http" |
|
|
|
|
"net/url" |
|
|
|
|
"path" |
|
|
|
@ -51,15 +52,27 @@ import ( |
|
|
|
|
// -- If yes, check if the IP of entry matches local IP. This means entry is for this instance.
|
|
|
|
|
// -- If IP of the entry doesn't match, this means entry is for another instance. Log an error to console.
|
|
|
|
|
func initFederatorBackend(objLayer ObjectLayer) { |
|
|
|
|
// Get buckets in the backend
|
|
|
|
|
b, err := objLayer.ListBuckets(context.Background()) |
|
|
|
|
if err != nil { |
|
|
|
|
logger.LogIf(context.Background(), err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get buckets in the DNS
|
|
|
|
|
dnsBuckets, err := globalDNSConfig.List() |
|
|
|
|
if err != nil && err != dns.ErrNoEntriesFound { |
|
|
|
|
logger.LogIf(context.Background(), err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bucketSet := set.NewStringSet() |
|
|
|
|
|
|
|
|
|
// Add buckets that are not registered with the DNS
|
|
|
|
|
g := errgroup.WithNErrs(len(b)) |
|
|
|
|
for index := range b { |
|
|
|
|
index := index |
|
|
|
|
bucketSet.Add(b[index].Name) |
|
|
|
|
g.Go(func() error { |
|
|
|
|
r, gerr := globalDNSConfig.Get(b[index].Name) |
|
|
|
|
if gerr != nil { |
|
|
|
@ -79,7 +92,38 @@ func initFederatorBackend(objLayer ObjectLayer) { |
|
|
|
|
for _, err := range g.Wait() { |
|
|
|
|
if err != nil { |
|
|
|
|
logger.LogIf(context.Background(), err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
g = errgroup.WithNErrs(len(dnsBuckets)) |
|
|
|
|
// Remove buckets that are in DNS for this server, but aren't local
|
|
|
|
|
for index := range dnsBuckets { |
|
|
|
|
index := index |
|
|
|
|
|
|
|
|
|
g.Go(func() error { |
|
|
|
|
// This is a local bucket that exists, so we can continue
|
|
|
|
|
if bucketSet.Contains(dnsBuckets[index].Key) { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This is not for our server, so we can continue
|
|
|
|
|
hostPort := net.JoinHostPort(dnsBuckets[index].Host, fmt.Sprintf("%d", dnsBuckets[index].Port)) |
|
|
|
|
if globalDomainIPs.Intersection(set.CreateStringSet(hostPort)).IsEmpty() { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// We go to here, so we know the bucket no longer exists, but is registered in DNS to this server
|
|
|
|
|
if err := globalDNSConfig.DeleteRecord(dnsBuckets[index]); err != nil { |
|
|
|
|
return fmt.Errorf("Failed to remove DNS entry for %s due to %v", dnsBuckets[index].Key, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
}, index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, err := range g.Wait() { |
|
|
|
|
if err != nil { |
|
|
|
|
logger.LogIf(context.Background(), err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|