私はこのgocqlパッケージを使用しています。Cassandraに接続するセッションを作成できません
私はこの例を動作させようとしています。カサンドラを使用して
func main() {
// connect to the cluster
cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
cluster.ProtoVersion = 3
cluster.Keyspace = "example"
cluster.Consistency = gocql.Quorum
session, err := cluster.CreateSession()
defer session.Close()
if err != nil {
fmt.Printf("%v\n", err)
return
}
uuid := gocql.TimeUUID()
fmt.Printf("UUID : %v", uuid)
query := session.Query(`INSERT INTO tweet (timeline, id, text) VALUES
(?, ?, ?)`, "me", uuid, "hello world")
fmt.Println("About to exec")
err = query.Exec()
// insert a tweet
if err != nil {
log.Fatal(err)
}
var id gocql.UUID
var text string
/* Search for a specific set of records whose 'timeline' column matches
* the value 'me'. The secondary index that we created earlier will be
* used for optimizing the search */
if err := session.Query(`SELECT id, text FROM tweet WHERE timeline = ?
LIMIT 1`,"me").Consistency(gocql.One).Scan(&id, &text); err != nil {
log.Fatal(err)
}
fmt.Println("Tweet:", id, text)
// list all tweets
iter := session.Query(`SELECT id, text FROM tweet WHERE timeline = ?`,
"me").Iter()
for iter.Scan(&id, &text) {
fmt.Println("Tweet:", id, text)
}
if err := iter.Close(); err != nil {
log.Fatal(err)
}
}
私は鍵空間「例」とテーブル「つぶやき」を作成しており、それらすべてが正常に動作シェル。私はプログラムを実行すると
は、しかし、それは私に、このエラーを与える:
2017/04/14 20:52:55 gocql: unable to dial control conn 192.168.1.3: dial tcp
192.168.1.3:9042: i/o timeout
gocql: unable to create session: control: unable to connect to initial
hosts: dial tcp 192.168.1.3:9042: i/o timeoutpanic: runtime error: invalid
memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x60236d]
goroutine 1 [running]:
github.com/gocql/gocql.(*Session).Close(0x0)
/home/mda/.local/go/src/github.com/gocql/gocql/session.go:344 +0x2d
何らかの理由で、gocqlはローカルホストの接続にダイヤルすることができず、それがタイムアウトします。私はこれを修正する方法とstackoverflowとGoogleの検索はこれまで助けていないとは分かりません。
アイデア?
この行をドロップしますか?私はプロトコルのバージョンを全く変更しません。 –
私は何を探すべきか全然分かりません。しかし、コマンドプロンプトに "nodetool status"と入力すると、これが表示されます。 ** Datacenter:datacenter1 ======================== ステータス=上/下 | /状態=正常/離脱/結合/移動 - - アドレスロードトークン所有(有効)ホストIDラック UN 127.0.0.1 182.43 KB 256 100.0%###一部のホストIDラック1 ** – SomeGuyFortune
cassandra.yamlファイルが大きい。あなたがcassandra.yamlファイルから特に必要とする情報はありますか?それが助けても、私はそれに何も変えていない。それは私がcassandraをダウンロードしたときとまったく同じです – SomeGuyFortune