diff --git a/libnetwork/drivers/overlay/peerdb.go b/libnetwork/drivers/overlay/peerdb.go index 4835204014..fd0a37d7f4 100644 --- a/libnetwork/drivers/overlay/peerdb.go +++ b/libnetwork/drivers/overlay/peerdb.go @@ -62,7 +62,7 @@ func (p *peerEntryDB) UnMarshalDB() peerEntry { type peerMap struct { // set of peerEntry, note the values have to be objects and not pointers to maintain the proper equality checks - mp setmatrix.SetMatrix[string, peerEntryDB] + mp setmatrix.SetMatrix[peerEntryDB] sync.Mutex } diff --git a/libnetwork/internal/setmatrix/setmatrix.go b/libnetwork/internal/setmatrix/setmatrix.go index 4e19a9aa16..b3b68e165c 100644 --- a/libnetwork/internal/setmatrix/setmatrix.go +++ b/libnetwork/internal/setmatrix/setmatrix.go @@ -13,14 +13,14 @@ import ( // The zero value is an empty set matrix ready to use. // // SetMatrix values are safe for concurrent use. -type SetMatrix[K, V comparable] struct { - matrix map[K]mapset.Set[V] +type SetMatrix[T comparable] struct { + matrix map[string]mapset.Set[T] mu sync.Mutex } // Get returns the members of the set for a specific key as a slice. -func (s *SetMatrix[K, V]) Get(key K) ([]V, bool) { +func (s *SetMatrix[T]) Get(key string) ([]T, bool) { s.mu.Lock() defer s.mu.Unlock() set, ok := s.matrix[key] @@ -31,7 +31,7 @@ func (s *SetMatrix[K, V]) Get(key K) ([]V, bool) { } // Contains is used to verify if an element is in a set for a specific key. -func (s *SetMatrix[K, V]) Contains(key K, value V) (containsElement, setExists bool) { +func (s *SetMatrix[T]) Contains(key string, value T) (containsElement, setExists bool) { s.mu.Lock() defer s.mu.Unlock() set, ok := s.matrix[key] @@ -43,13 +43,13 @@ func (s *SetMatrix[K, V]) Contains(key K, value V) (containsElement, setExists b // Insert inserts the value in the set of a key and returns whether the value is // inserted (was not already in the set) and the number of elements in the set. -func (s *SetMatrix[K, V]) Insert(key K, value V) (inserted bool, cardinality int) { +func (s *SetMatrix[T]) Insert(key string, value T) (inserted bool, cardinality int) { s.mu.Lock() defer s.mu.Unlock() set, ok := s.matrix[key] if !ok { if s.matrix == nil { - s.matrix = make(map[K]mapset.Set[V]) + s.matrix = make(map[string]mapset.Set[T]) } s.matrix[key] = mapset.NewThreadUnsafeSet(value) return true, 1 @@ -59,7 +59,7 @@ func (s *SetMatrix[K, V]) Insert(key K, value V) (inserted bool, cardinality int } // Remove removes the value in the set for a specific key. -func (s *SetMatrix[K, V]) Remove(key K, value V) (removed bool, cardinality int) { +func (s *SetMatrix[T]) Remove(key string, value T) (removed bool, cardinality int) { s.mu.Lock() defer s.mu.Unlock() set, ok := s.matrix[key] @@ -80,7 +80,7 @@ func (s *SetMatrix[K, V]) Remove(key K, value V) (removed bool, cardinality int) } // Cardinality returns the number of elements in the set for a key. -func (s *SetMatrix[K, V]) Cardinality(key K) (cardinality int, ok bool) { +func (s *SetMatrix[T]) Cardinality(key string) (cardinality int, ok bool) { s.mu.Lock() defer s.mu.Unlock() set, ok := s.matrix[key] @@ -93,7 +93,7 @@ func (s *SetMatrix[K, V]) Cardinality(key K) (cardinality int, ok bool) { // String returns the string version of the set. // The empty string is returned if there is no set for key. -func (s *SetMatrix[K, V]) String(key K) (v string, ok bool) { +func (s *SetMatrix[T]) String(key string) (v string, ok bool) { s.mu.Lock() defer s.mu.Unlock() set, ok := s.matrix[key] @@ -104,10 +104,10 @@ func (s *SetMatrix[K, V]) String(key K) (v string, ok bool) { } // Keys returns all the keys in the map. -func (s *SetMatrix[K, V]) Keys() []K { +func (s *SetMatrix[T]) Keys() []string { s.mu.Lock() defer s.mu.Unlock() - keys := make([]K, 0, len(s.matrix)) + keys := make([]string, 0, len(s.matrix)) for k := range s.matrix { keys = append(keys, k) } diff --git a/libnetwork/internal/setmatrix/setmatrix_test.go b/libnetwork/internal/setmatrix/setmatrix_test.go index fc0ebc8af7..b14c04de1e 100644 --- a/libnetwork/internal/setmatrix/setmatrix_test.go +++ b/libnetwork/internal/setmatrix/setmatrix_test.go @@ -9,7 +9,7 @@ import ( ) func TestSetSerialInsertDelete(t *testing.T) { - var s SetMatrix[string, string] + var s SetMatrix[string] b, i := s.Insert("a", "1") if !b || i != 1 { @@ -135,7 +135,7 @@ func TestSetSerialInsertDelete(t *testing.T) { } } -func insertDeleteRotuine(ctx context.Context, endCh chan int, s *SetMatrix[string, string], key, value string) { +func insertDeleteRotuine(ctx context.Context, endCh chan int, s *SetMatrix[string], key, value string) { for { select { case <-ctx.Done(): @@ -158,7 +158,7 @@ func insertDeleteRotuine(ctx context.Context, endCh chan int, s *SetMatrix[strin } func TestSetParallelInsertDelete(t *testing.T) { - var s SetMatrix[string, string] + var s SetMatrix[string] parallelRoutines := 6 endCh := make(chan int) // Let the routines running and competing for 10s diff --git a/libnetwork/libnetwork_internal_test.go b/libnetwork/libnetwork_internal_test.go index cfe4840d28..994b5d7abb 100644 --- a/libnetwork/libnetwork_internal_test.go +++ b/libnetwork/libnetwork_internal_test.go @@ -457,7 +457,7 @@ func getSvcRecords(t *testing.T, n *Network, key string) (addrs []netip.Addr, fo sr, ok := n.ctrlr.svcRecords[n.id] assert.Assert(t, ok) - lookup := func(svcMap *setmatrix.SetMatrix[string, svcMapEntry]) bool { + lookup := func(svcMap *setmatrix.SetMatrix[svcMapEntry]) bool { mapEntryList, ok := svcMap.Get(key) if !ok { return false diff --git a/libnetwork/network.go b/libnetwork/network.go index f9110810cd..6f0f4588d0 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -57,9 +57,9 @@ type svcMapEntry struct { } type svcInfo struct { - svcMap setmatrix.SetMatrix[string, svcMapEntry] - svcIPv6Map setmatrix.SetMatrix[string, svcMapEntry] - ipMap setmatrix.SetMatrix[string, ipInfo] + svcMap setmatrix.SetMatrix[svcMapEntry] + svcIPv6Map setmatrix.SetMatrix[svcMapEntry] + ipMap setmatrix.SetMatrix[ipInfo] service map[string][]servicePorts } @@ -1370,7 +1370,7 @@ func (n *Network) updateSvcRecord(ctx context.Context, ep *Endpoint, isAdd bool) } } -func addIPToName(ipMap *setmatrix.SetMatrix[string, ipInfo], name, serviceID string, ip net.IP) { +func addIPToName(ipMap *setmatrix.SetMatrix[ipInfo], name, serviceID string, ip net.IP) { reverseIP := netutils.ReverseIP(ip.String()) ipMap.Insert(reverseIP, ipInfo{ name: name, @@ -1378,7 +1378,7 @@ func addIPToName(ipMap *setmatrix.SetMatrix[string, ipInfo], name, serviceID str }) } -func delIPToName(ipMap *setmatrix.SetMatrix[string, ipInfo], name, serviceID string, ip net.IP) { +func delIPToName(ipMap *setmatrix.SetMatrix[ipInfo], name, serviceID string, ip net.IP) { reverseIP := netutils.ReverseIP(ip.String()) ipMap.Remove(reverseIP, ipInfo{ name: name, @@ -1386,7 +1386,7 @@ func delIPToName(ipMap *setmatrix.SetMatrix[string, ipInfo], name, serviceID str }) } -func addNameToIP(svcMap *setmatrix.SetMatrix[string, svcMapEntry], name, serviceID string, epIP net.IP) { +func addNameToIP(svcMap *setmatrix.SetMatrix[svcMapEntry], name, serviceID string, epIP net.IP) { // Since DNS name resolution is case-insensitive, Use the lower-case form // of the name as the key into svcMap lowerCaseName := strings.ToLower(name) @@ -1396,7 +1396,7 @@ func addNameToIP(svcMap *setmatrix.SetMatrix[string, svcMapEntry], name, service }) } -func delNameToIP(svcMap *setmatrix.SetMatrix[string, svcMapEntry], name, serviceID string, epIP net.IP) { +func delNameToIP(svcMap *setmatrix.SetMatrix[svcMapEntry], name, serviceID string, epIP net.IP) { lowerCaseName := strings.ToLower(name) svcMap.Remove(lowerCaseName, svcMapEntry{ ip: epIP.String(), diff --git a/libnetwork/service.go b/libnetwork/service.go index fc77629602..f7a46fb37f 100644 --- a/libnetwork/service.go +++ b/libnetwork/service.go @@ -57,7 +57,7 @@ type service struct { // associated with it. At stable state the endpoint ID expected is 1 // but during transition and service change it is possible to have // temporary more than 1 - ipToEndpoint setmatrix.SetMatrix[string, string] + ipToEndpoint setmatrix.SetMatrix[string] deleted bool