ソースを参照

reset statements LRU after getting a schema change update

Chris Bannister 10 年 前
コミット
ed8274a131
2 ファイル変更12 行追加0 行削除
  1. 9 0
      cluster.go
  2. 3 0
      conn.go

+ 9 - 0
cluster.go

@@ -32,6 +32,15 @@ func (p *preparedLRU) max(max int) {
 	p.lru.MaxEntries = max
 }
 
+func (p *preparedLRU) clear() {
+	p.Lock()
+	defer p.Unlock()
+
+	for p.lru.Len() > 0 {
+		p.lru.RemoveOldest()
+	}
+}
+
 // PoolConfig configures the connection pool used by the driver, it defaults to
 // using a round robbin host selection policy and a round robbin connection selection
 // policy for each host.

+ 3 - 0
conn.go

@@ -785,6 +785,9 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
 	case *resultKeyspaceFrame:
 		return &Iter{framer: framer}
 	case *resultSchemaChangeFrame, *schemaChangeKeyspace, *schemaChangeTable, *schemaChangeFunction:
+		// Clear the statments cache so that we dont use stale table info for requests.
+		// TODO: only reset a specific table/keyapce and only when it is changed.
+		c.session.stmtsLRU.clear()
 		iter := &Iter{framer: framer}
 		if err := c.awaitSchemaAgreement(); err != nil {
 			// TODO: should have this behind a flag