|
@@ -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
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -422,6 +421,7 @@ type Query struct {
|
|
|
cons Consistency
|
|
cons Consistency
|
|
|
pageSize int
|
|
pageSize int
|
|
|
routingKey []byte
|
|
routingKey []byte
|
|
|
|
|
+ routingKeyBuffer []byte
|
|
|
pageState []byte
|
|
pageState []byte
|
|
|
prefetch float64
|
|
prefetch float64
|
|
|
trace Tracer
|
|
trace Tracer
|
|
@@ -532,8 +532,14 @@ func (q *Query) GetRoutingKey() ([]byte, error) {
|
|
|
return routingKey, nil
|
|
return routingKey, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // We allocate that buffer only once, so that further re-bind/exec of the
|
|
|
|
|
+ // same query don't allocate more memory.
|
|
|
|
|
+ if q.routingKeyBuffer == nil {
|
|
|
|
|
+ q.routingKeyBuffer = make([]byte, 0, 256)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// composite routing key
|
|
// composite routing key
|
|
|
- buf := &bytes.Buffer{}
|
|
|
|
|
|
|
+ buf := bytes.NewBuffer(q.routingKeyBuffer)
|
|
|
for i := range routingKeyInfo.indexes {
|
|
for i := range routingKeyInfo.indexes {
|
|
|
encoded, err := Marshal(
|
|
encoded, err := Marshal(
|
|
|
routingKeyInfo.types[i],
|
|
routingKeyInfo.types[i],
|
|
@@ -542,7 +548,9 @@ func (q *Query) GetRoutingKey() ([]byte, error) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
- binary.Write(buf, binary.BigEndian, int16(len(encoded)))
|
|
|
|
|
|
|
+ lenBuf := []byte{0x00, 0x00}
|
|
|
|
|
+ binary.BigEndian.PutUint16(lenBuf, uint16(len(encoded)))
|
|
|
|
|
+ buf.Write(lenBuf)
|
|
|
buf.Write(encoded)
|
|
buf.Write(encoded)
|
|
|
buf.WriteByte(0x00)
|
|
buf.WriteByte(0x00)
|
|
|
}
|
|
}
|