Przeglądaj źródła

session: No need to include keyspace in routingKeyInfoCache key

Adrien Bustany 10 lat temu
rodzic
commit
d04c94f520
1 zmienionych plików z 6 dodań i 7 usunięć
  1. 6 7
      session.go

+ 6 - 7
session.go

@@ -260,9 +260,8 @@ func (s *Session) KeyspaceMetadata(keyspace string) (*KeyspaceMetadata, error) {
 // returns routing key indexes and type info
 // returns routing key indexes and type info
 func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 	s.routingKeyInfoCache.mu.Lock()
 	s.routingKeyInfoCache.mu.Lock()
-	cacheKey := s.cfg.Keyspace + stmt
 
 
-	entry, cached := s.routingKeyInfoCache.lru.Get(cacheKey)
+	entry, cached := s.routingKeyInfoCache.lru.Get(stmt)
 	if cached {
 	if cached {
 		// done accessing the cache
 		// done accessing the cache
 		s.routingKeyInfoCache.mu.Unlock()
 		s.routingKeyInfoCache.mu.Unlock()
@@ -286,7 +285,7 @@ func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 	inflight := new(inflightCachedEntry)
 	inflight := new(inflightCachedEntry)
 	inflight.wg.Add(1)
 	inflight.wg.Add(1)
 	defer inflight.wg.Done()
 	defer inflight.wg.Done()
-	s.routingKeyInfoCache.lru.Add(cacheKey, inflight)
+	s.routingKeyInfoCache.lru.Add(stmt, inflight)
 	s.routingKeyInfoCache.mu.Unlock()
 	s.routingKeyInfoCache.mu.Unlock()
 
 
 	var (
 	var (
@@ -300,14 +299,14 @@ func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 		// no connections
 		// no connections
 		inflight.err = ErrNoConnections
 		inflight.err = ErrNoConnections
 		// don't cache this error
 		// don't cache this error
-		s.routingKeyInfoCache.Remove(cacheKey)
+		s.routingKeyInfoCache.Remove(stmt)
 		return nil, inflight.err
 		return nil, inflight.err
 	}
 	}
 
 
 	prepared, inflight.err = conn.prepareStatement(stmt, nil)
 	prepared, inflight.err = conn.prepareStatement(stmt, nil)
 	if inflight.err != nil {
 	if inflight.err != nil {
 		// don't cache this error
 		// don't cache this error
-		s.routingKeyInfoCache.Remove(cacheKey)
+		s.routingKeyInfoCache.Remove(stmt)
 		return nil, inflight.err
 		return nil, inflight.err
 	}
 	}
 
 
@@ -323,7 +322,7 @@ func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 	keyspaceMetadata, inflight.err = s.KeyspaceMetadata(s.cfg.Keyspace)
 	keyspaceMetadata, inflight.err = s.KeyspaceMetadata(s.cfg.Keyspace)
 	if inflight.err != nil {
 	if inflight.err != nil {
 		// don't cache this error
 		// don't cache this error
-		s.routingKeyInfoCache.Remove(cacheKey)
+		s.routingKeyInfoCache.Remove(stmt)
 		return nil, inflight.err
 		return nil, inflight.err
 	}
 	}
 
 
@@ -334,7 +333,7 @@ func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 		// in the metadata code, or that the table was just dropped.
 		// in the metadata code, or that the table was just dropped.
 		inflight.err = ErrNoMetadata
 		inflight.err = ErrNoMetadata
 		// don't cache this error
 		// don't cache this error
-		s.routingKeyInfoCache.Remove(cacheKey)
+		s.routingKeyInfoCache.Remove(stmt)
 		return nil, inflight.err
 		return nil, inflight.err
 	}
 	}