Giter Site home page Giter Site logo

gocql / gocql Goto Github PK

View Code? Open in Web Editor NEW
2.5K 68.0 593.0 3.55 MB

Package gocql implements a fast and robust Cassandra client for the Go programming language.

Home Page: http://gocql.github.io/

License: BSD 3-Clause "New" or "Revised" License

Go 99.67% Shell 0.33%
go cassandra driver database client nosql golang

gocql's Introduction

gocql

Join the chat at https://gitter.im/gocql/gocql go build GoDoc

Package gocql implements a fast and robust Cassandra client for the Go programming language.

Project Website: https://gocql.github.io/
API documentation: https://godoc.org/github.com/gocql/gocql
Discussions: https://groups.google.com/forum/#!forum/gocql

Supported Versions

The following matrix shows the versions of Go and Cassandra that are tested with the integration test suite as part of the CI build:

Go/Cassandra 4.0.x 4.1.x
1.19 yes yes
1.20 yes yes

Gocql has been tested in production against many versions of Cassandra. Due to limits in our CI setup we only test against the latest 2 GA releases.

Sunsetting Model

In general, the gocql team will focus on supporting the current and previous versions of Go. gocql may still work with older versions of Go, but official support for these versions will have been sunset.

Installation

go get github.com/gocql/gocql

Features

  • Modern Cassandra client using the native transport
  • Automatic type conversions between Cassandra and Go
    • Support for all common types including sets, lists and maps
    • Custom types can implement a Marshaler and Unmarshaler interface
    • Strict type conversions without any loss of precision
    • Built-In support for UUIDs (version 1 and 4)
  • Support for logged, unlogged and counter batches
  • Cluster management
    • Automatic reconnect on connection failures with exponential falloff
    • Round robin distribution of queries to different hosts
    • Round robin distribution of queries to different connections on a host
    • Each connection can execute up to n concurrent queries (whereby n is the limit set by the protocol version the client chooses to use)
    • Optional automatic discovery of nodes
    • Policy based connection pool with token aware and round-robin policy implementations
  • Support for password authentication
  • Iteration over paged results with configurable page size
  • Support for TLS/SSL
  • Optional frame compression (using snappy)
  • Automatic query preparation
  • Support for query tracing
  • Support for Cassandra 2.1+ binary protocol version 3
    • Support for up to 32768 streams
    • Support for tuple types
    • Support for client side timestamps by default
    • Support for UDTs via a custom marshaller or struct tags
  • Support for Cassandra 3.0+ binary protocol version 4
  • An API to access the schema metadata of a given keyspace

Performance

While the driver strives to be highly performant, there are cases where it is difficult to test and verify. The driver is built with maintainability and code readability in mind first and then performance and features, as such every now and then performance may degrade, if this occurs please report and issue and it will be looked at and remedied. The only time the driver copies data from its read buffer is when it Unmarshal's data into supplied types.

Some tips for getting more performance from the driver:

  • Use the TokenAware policy
  • Use many goroutines when doing inserts, the driver is asynchronous but provides a synchronous API, it can execute many queries concurrently
  • Tune query page size
  • Reading data from the network to unmarshal will incur a large amount of allocations, this can adversely affect the garbage collector, tune GOGC
  • Close iterators after use to recycle byte buffers

Important Default Keyspace Changes

gocql no longer supports executing "use " statements to simplify the library. The user still has the ability to define the default keyspace for connections but now the keyspace can only be defined before a session is created. Queries can still access keyspaces by indicating the keyspace in the query:

SELECT * FROM example2.table;

Example of correct usage:

	cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
	cluster.Keyspace = "example"
	...
	session, err := cluster.CreateSession()

Example of incorrect usage:

	cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
	cluster.Keyspace = "example"
	...
	session, err := cluster.CreateSession()

	if err = session.Query("use example2").Exec(); err != nil {
		log.Fatal(err)
	}

This will result in an err being returned from the session.Query line as the user is trying to execute a "use" statement.

Example

See package documentation.

Data Binding

There are various ways to bind application level data structures to CQL statements:

  • You can write the data binding by hand, as outlined in the Tweet example. This provides you with the greatest flexibility, but it does mean that you need to keep your application code in sync with your Cassandra schema.
  • You can dynamically marshal an entire query result into an []map[string]interface{} using the SliceMap() API. This returns a slice of row maps keyed by CQL column names. This method requires no special interaction with the gocql API, but it does require your application to be able to deal with a key value view of your data.
  • As a refinement on the SliceMap() API you can also call MapScan() which returns map[string]interface{} instances in a row by row fashion.
  • The Bind() API provides a client app with a low level mechanism to introspect query meta data and extract appropriate field values from application level data structures.
  • The gocqlx package is an idiomatic extension to gocql that provides usability features. With gocqlx you can bind the query parameters from maps and structs, use named query parameters (:identifier) and scan the query results into structs and slices. It comes with a fluent and flexible CQL query builder that supports full CQL spec, including BATCH statements and custom functions.
  • Building on top of the gocql driver, cqlr adds the ability to auto-bind a CQL iterator to a struct or to bind a struct to an INSERT statement.
  • Another external project that layers on top of gocql is cqlc which generates gocql compliant code from your Cassandra schema so that you can write type safe CQL statements in Go with a natural query syntax.
  • gocassa is an external project that layers on top of gocql to provide convenient query building and data binding.
  • gocqltable provides an ORM-style convenience layer to make CRUD operations with gocql easier.

Ecosystem

The following community maintained tools are known to integrate with gocql:

  • gocqlx is a gocql extension that automates data binding, adds named queries support, provides flexible query builders and plays well with gocql.
  • journey is a migration tool with Cassandra support.
  • negronicql is gocql middleware for Negroni.
  • cqlr adds the ability to auto-bind a CQL iterator to a struct or to bind a struct to an INSERT statement.
  • cqlc generates gocql compliant code from your Cassandra schema so that you can write type safe CQL statements in Go with a natural query syntax.
  • gocassa provides query building, adds data binding, and provides easy-to-use "recipe" tables for common query use-cases.
  • gocqltable is a wrapper around gocql that aims to simplify common operations.
  • gockle provides simple, mockable interfaces that wrap gocql types
  • scylladb is a fast Apache Cassandra-compatible NoSQL database
  • go-cql-driver is an CQL driver conforming to the built-in database/sql interface. It is good for simple use cases where the database/sql interface is wanted. The CQL driver is a wrapper around this project.

Other Projects

  • gocqldriver is the predecessor of gocql based on Go's database/sql package. This project isn't maintained anymore, because Cassandra wasn't a good fit for the traditional database/sql API. Use this package instead.

SEO

For some reason, when you Google golang cassandra, this project doesn't feature very highly in the result list. But if you Google go cassandra, then we're a bit higher up the list. So this is note to try to convince Google that golang is an alias for Go.

License

Copyright (c) 2012-2016 The gocql Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

gocql's People

Contributors

0x6e6562 avatar abustany avatar alourie avatar annismckenzie avatar beltran avatar cwndrws avatar dahankzter avatar dancannon avatar hsawhney09 avatar jameshartig avatar joao-r-reis avatar jshwright avatar justinretailnext avatar martin-sucha avatar matope avatar mattheath avatar mattrobenolt avatar mmatczuk avatar nemosupremo avatar nightlyone avatar nikandfor avatar phillipcouto avatar skoikovs avatar titanous avatar turettn avatar tux21b avatar vrischmann avatar xoraes avatar zariel avatar zllak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocql's Issues

Protocol errors after long idle times

I create a ClusterConfig with ProtoVersion=1, then a Session, make a few queries, and then leave the session idle for a long time, maybe 15 minutes. When I come back and try to make more queries, I consistently get protocol error.

I suspect the connection has timed out or otherwise failed, and whatever logic responsible for reconnecting is misbehaving. Please let me know what additional information I can provide.

Tests fail with -race enabled

go test -race .
--- FAIL: TestSimple-4 (0.00 seconds)
    conn_test.go:34: unavailable
--- FAIL: TestClosed-4 (0.00 seconds)
    conn_test.go:220: EOF
    conn_test.go:220: EOF
2014/01/12 11:16:14 failed to connect to "127.0.0.1:50530": dial tcp 127.0.0.1:50530: connection refused
2014/01/12 11:16:15 failed to connect to "127.0.0.1:50530": dial tcp 127.0.0.1:50530: connection refused
FAIL
FAIL    github.com/zariel/gocql 2.082s

Unknown code 256 for a consistency level

Testing against 2.0.2, intermittently I get the following error:

Unknown code 256 for a consistency level

This only seems to happen with very large batch sizes. If I reduce the batch size, this issue doesn't seem to occur.

Thrift / Port 9160

Hello, I am loving this package you guys have created. However, I am running into a problem trying to connect to external cassandra servers using the default ports.

Simple code example


package main

import (
    "fmt"
    "log"

    "tux21b.org/v1/gocql"
)

func main() {
    //connect to our cluster
    cluster := gocql.NewCluster("101.25.154.238")
  // use this keyspace
  cluster.Keyspace = "merchant_400"
  cluster.DefaultPort = 9160
  cluster.ProtoVersion = 2
  cluster.CQLVersion = "3.0.0"
  //cluster.Consistency = gocql.Quorum
  session := cluster.CreateSession()
  defer session.Close()

  // should be a struct, but this is just a test
  var k,c string
  var v int

  iter := session.Query(`SELECT * FROM INDEXES LIMIT 10`).Iter()
  for iter.Scan(&k, &c, &v) {
    fmt.Println(k,c,v)
  }
  if err := iter.Close(); err != nil {
    log.Fatal(err)
  }
}

I get errors, when changing the ports from default (9042) to thrift, which is the only way I can connect to them via cqlsh/cassandra-cli

Here's the error messages


2013/08/30 14:19:33 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:33 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:34 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:34 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:36 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:36 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:40 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused
2013/08/30 14:19:40 failed to connect to "101.25.154.238:9042": dial tcp 101.25.154.238:9042: connection refused

When using thrift port 9160, this is the error

2013/08/30 14:24:42 failed to connect to "101.25.154.238:9160": EOF
2013/08/30 14:24:42 failed to connect to "101.25.154.238:9160": EOF
2013/08/30 14:24:43 failed to connect to "101.25.154.238:9160": EOF
2013/08/30 14:24:43 failed to connect to "101.25.154.238:9160": EOF:  

Any help greatly appreciated.

Question: long-lived handle to Cassandra

If I want to keep a long-lived handle to Cassandra in my service, is it expected that I keep a ClusterConfig and spawn new Sessions for every request, or keep a Session and query against it directly?

Assuming it's the latter, can you confirm the Session handle e.g. network errors transparently to my app code, or do I need to implement retries (or pooling) myself?

Getting Cannot Assign Address errors

I am using Cassandra 1.2.8 when I try to execute a query I get these errors repeatedly:

failed to connect to "127.0.0.1:9042": dial tcp 127.0.0.1:9042: cannot assign requested address

I have tested the port by using just net.DialTimeout to see if there was any misconfiguration on my Cassandra server but it connects fine.

Here is my code:

    cluster := gocql.NewCluster("127.0.0.1")
    cluster.CQLVersion = "3.0.0"
    cluster.ProtoVersion = 1
    session := cluster.CreateSession()
    defer session.Close()

    // insert a tweet
    if err := session.Query(`INSERT INTO stemblog.Posts (ID, Title, Post,AuthorID,Created) VALUES (?, ?, ?,?,?)`,
        1,"Test Title","Test Post",1,time.Now()).Exec(); err != nil {
        log.Fatal(err)
    }

Crash in connection pool under high load

 panic: runtime error: invalid memory address or nil pointer dereference
 [signal 0xb code=0x1 addr=0x20 pc=0x4cae07]

 goroutine 12890 [running]:
 [redacted]/gocql.(*connection).close(0xc20053bf60)
   [redacted]/gocql/gocql.go:207 +0x27
 [redacted]/gocql.(*connection).recv(0xc20053bf60, 0x6b0e01, 0xc201dcfcd4, 0x16, 0x40, ...)
   [redacted]/gocql/gocql.go:262 +0x16b
 [redacted]/gocql.(*connection).open(0xc20053bf60) 
   [redacted]/gocql/gocql.go:189 +0x609
 [redacted]/gocql.(*pool).reconnect(0xc20188a960)
   [redacted]/gocql/gocql.go:355 +0x5d
 [redacted]/gocql.func·001()
   [redacted]/gocql/gocql.go:345 +0x68
 created by [redacted]/gocql.(*pool).join
   [redacted]/gocql/gocql.go:349 +0x70
 ...

From here. I guess it is related to recent connection pool changes?

String literal column families inside batches cause panic

p.saveMatchStmt, err = p.db.Prepare(`BEGIN BATCH INSERT INTO "from" (key, column1, value) VALUES (?, ?, ?) USING TTL 7776000 INSERT INTO "to" (key, column1, value) VALUES (?, ?, ?) USING TTL 7776000 APPLY BATCH;`)

And here's the panic:

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/tux21b/gocql.parseMeta(0xc210037256, 0x74, 0x74, 0x8a, 0x8a, ...)
    /home/mjoiner/gopath/src/github.com/tux21b/gocql/gocql.go:345 +0x690
github.com/tux21b/gocql.(*connection).Prepare(0xc21002ecf0, 0x785bf0, 0xae, 0x7f21f51f99c8, 0x10027010, ...)
    /home/mjoiner/gopath/src/github.com/tux21b/gocql/gocql.go:302 +0x412
database/sql.(*driverConn).prepareLocked(0xc210041480, 0x785bf0, 0xae, 0x0, 0xc210042500, ...)
    /home/mjoiner/src/go/src/pkg/database/sql/sql.go:233 +0x47
database/sql.(*DB).prepare(0xc2100413c0, 0x785bf0, 0xae, 0xc210042500, 0x0, ...)
    /home/mjoiner/src/go/src/pkg/database/sql/sql.go:635 +0xa4
database/sql.(*DB).Prepare(0xc2100413c0, 0x785bf0, 0xae, 0xc210042500, 0x0, ...)
    /home/mjoiner/src/go/src/pkg/database/sql/sql.go:615 +0x5a
main.OpenPartner(0x2, 0xc21002e9c0, 0x22, 0xc2100369c0, 0x0, ...)
    /home/mjoiner/gopath/src/code.brandscreen.net/cortex/uniques-proxy/main.go:76 +0x256
main.main()
    /home/mjoiner/gopath/src/code.brandscreen.net/cortex/uniques-proxy/main.go:146 +0x12e7

New API

database/sql has great minimum viable functionality, but due to the unique features of Cassandra it's quite limiting. Here are some things that a new API should support:

  • Maintain a pool of connections to multiple servers and load balance across them.
  • Listen for TOPOLOGY_CHANGE / STATUS_CHANGE events and add/remove nodes from the connection pool.
  • Support query-level consistency specification.
  • Handle collection types.
  • Maintain a pool of prepared statements and transparently reuse them for performance.

I'm sure there are other unique features that could be leveraged, but these are some off the top of my head. Most of them would be hard/impossible to do properly within the confines of the database/sql package, but we could have an adapter for backwards compatibility.

Merge state of gocql

Hi

@tux21b @titanous @mattrobenolt @phillipCouto @vuleetu @pepin @ingardm @mekishizufu @DPanth3r @serbaut @tve @tobert @biinilya @Kimbsen @haibinpark @fsouza @hkeide @allydm @nemothekid @coxx @peterbourgon @ghais @haruki-sugarsun

Sorry to make such a large CC list, but the old way of contacting people on Github has long been retired and I wanted to start a discussion with everybody that has some interest in the gocql project.

So I'm using the gocql driver in earnest and I've noticed in the last couple of months that a bunch of pull requests have been made to the upstream that have not been discussed or merged. I'm currently running my stuff off my own fork as well. In addition to this, I've found that intermittently, doing a go get for the tux21b.org namespace fails, which has caused builds to fail on my CI server.

The last thing I want to do is to hijack a well written project, but I was wondering how other people feel about the fact that the codebase has fractured because people need to knock solutions for their individual problems.

In addition, I was wondering whether people would join a Google Group (or some other mailing list) to discuss this project, rather than just relying on Github issues.

I want to apologize in advance if I am treading on anybody's toes :-)

Cheers,

Ben

Basic tutorial for gocql

This issue is there to track topics that should be covered by a small tutorial, since they seem to cause confusion regularly:

  • cluster setup (with code snippets for Cassandra 1.2 and 2.0)
  • Exec() and Scan()
  • iterating over columns
  • iterating over columns in batches (Cassandra 2.0 only)
  • dynamic columns (i.e. usage of iter.Columns())
  • Batches in Cassandra 1.2 (Exec() only) and Cassandra 2.0
  • Usage of ScanCAS
  • Usage of the marshal / unmarshal interface

How to handle dynamic columns?

We're are using cassandra with dynamic columns, how would you use this library for that? The examples show how to use it for static columns.

Thanks for your help

makeslice: len out of range

Running some stress test I came across this error:

panic: runtime error: makeslice: len out of range

goroutine 261 [running]:
github.com/titanous/gocql.(*connection).recv(0xf8400aeb70, 0x6800000009, 0xf84101d310, 0x6c0000006c)
    /usr/local/go/src/pkg/github.com/titanous/gocql/gocql.go:198 +0x253
github.com/titanous/gocql.(*connection).Prepare(0xf8400aeb70, 0xf84101d2a0, 0x7f3000000068, 0x0, 0x0, ...)
    /usr/local/go/src/pkg/github.com/titanous/gocql/gocql.go:242 +0x242

which is in func (cn *connection) recv() (byte, []byte, error) { (I'm using titanous' fork) at the line:

body = make([]byte, length)

I'll add some debugging code to see what is happening, but this also lead me to wonder whether I should add some retry logic into gocql to retry queries that time out or otherwise fail. Any thoughts on that?

Batch: CounterBatch fails on a batch query operation

Using counterbatch type, the batch query execution fails.

Steps to reproduce:
Create a counter CF;
example:
CREATE TABLE urlcounters (
url text PRIMARY KEY,
hits counter)

A batch query failed with the error: Cannot include counter statement in a non-counter batch

    batch := gocql.NewBatch(gocql.CounterBatch)

batch.Query(`UPDATE urlcounters USING TTL 2592000 SET hits = hits+1 WHERE url=?`, someUrl)

    // add other batch.Query statements
session.ExecuteBatch(batch)

database/sql bug affects gocql

Thanks much for gocql, I'm enjoying it!!!
I did hit a nasty snag, which is a bug is database.sql in Go 1.0.3 (and earlier). Without the fix described at https://groups.google.com/forum/?fromgroups=#!topic/golang-dev/Fgio7drYB2o I can't use (*Stmt).Query at all. I had to patch database/sql locally myself. This is not something that needs fixing in gocql, but it may be good to keep this issue open so others see it up-front, and also, it would be great if you could chime in to get the database/sql patch into Go 1.0.4...

Pool race condition.

Happens in a moments after CreateSession()

panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
tux21b.org/v1/gocql.(_RoundRobin).Pick(0xc20007c840, 0x0, 0x1)
/Users/Ilya/.goenv/1.1.2/otacache/src/tux21b.org/v1/gocql/topology.go:61 +0xcc
tux21b.org/v1/gocql.(_RoundRobin).Pick(0xc20007c680, 0x0, 0x2034f)
/Users/Ilya/.goenv/1.1.2/otacache/src/tux21b.org/v1/gocql/topology.go:61 +0xd2
tux21b.org/v1/gocql.(_clusterImpl).Pick(0xc20004fa00, 0x0, 0x0)
/Users/Ilya/.goenv/1.1.2/otacache/src/tux21b.org/v1/gocql/cluster.go:207 +0x36
tux21b.org/v1/gocql.(_Session).executeQuery(0xc20008f880, 0xc200092150, 0xc200092150)
/Users/Ilya/.goenv/1.1.2/otacache/src/tux21b.org/v1/gocql/session.go:44 +0x36
tux21b.org/v1/gocql.(*Query).Exec(0xc200092150, 0x16b370, 0xa)
/Users/Ilya/.goenv/1.1.2/otacache/src/tux21b.org/v1/gocql/session.go:96 +0x2e

Rre-prepare evicted statements

For a long running application, a prepared statement may be evicted causing the PreparedQueryNotFound response:

Prepared query with ID a59ea8d5e562d5da2b83bc54c38cb496 not found (either the query was not prepared on this host (maybe the host has been restarted?) or you have prepared more than 100000 queries and query a59ea8d5e562d5da2b83bc54c38cb496 has been evicted from the internal cache)

The godriver should do what the datastax java driver does and silently re-prepare and re-execute the query.

Standalone API

The database/sql interface has several limitations. To support all features of the upcoming Cassandra 2 release it would be better to implement a custom API. This gives us a greater flexibility and has the following advantages:

  • Strongly typed and extendable conversion of data types
    Currently everything is converted to very limited set of basic "database/sql" types without taking the metadata of the database into account and the reconverted by gocql. Many types are probably converted incorrectly and it's hard to support more complex types (e.g. custom types, sets, lists, maps, UUIDs, etc.)
  • Better Connection Pooling and Failover management
    Currently "database/sql" maintains its own pool of connections and has no idea that it is handling connections to different servers. Connections are picked randomly. The new API should be be aware of the existence of data centers, racks, nodes, connections and streams (it's possible to use a Cassandra connection for up to 127 concurrent queries).
  • Better Query Interface
    "database/sql" does not support queries with additional attributes that are not part of the SQL query. It should be possible to specify the consistency level, the failover strategy, the token (and maybe other things) with the new query interface. Iterators should iterate over large results in batches and requery the next batch automatically. Cassandra's atomic batches should also be supported. We might also support a Decode method in addition to Scan to decode a row into a tagged struct.
  • Handling of TOPOLOGY_CHANGED (we can add the node to the pool automatically), SCHEMA_CHANGED (we might want to invalidate the metadata of some of the prepared queries) and STATUS_CHANGED events.

The change is obviously not backward compatible and I do not intend to maintain the old API anymore. It would be great if some of you could participate in the design of the new API, because I would like to freeze the API and switch branches with the Cassandra 2 release.

ErrNotFound isn't thrown

According to the docs ErrNotFound should be thrown if no rows are returned when using Scan(), but no error is thrown.

Scan executes the query, copies the columns of the first selected row into the values pointed at by dest and discards the rest. If no rows were selected, ErrNotFound is returned.

failed to connect to XXX: error "unavailable" forever

connections are never re-established. This causes sessions to return ErrUnavailable forever even when a connection has been re-established.

Steps to reproduce

  1. try to execute any query. Retry if ErrUnavailable is returned
  2. in another terminal, restart the cluster

gocql will never reconnect and every query will return "uavailable" no matter what. I do not see a workaround against 3c37a4e

No way to BATCH with Cassandra 1.2

I want to use BATCH with Cassandra 1.2.8.

  1. If I specify ProtoVersion = 1, BATCH is rejected outright.
  2. If I specify ProtoVersion = 2, I can't communicate with my server due to protocol errors.

BATCH definitely works with my server version, so at least one of these two conditions is a bug, I'm pretty sure.

make errorFrame exportable?

While working with the library, I've found that it's hard to distinguish between error codes, as long as errorFrame is not exportable. I see it has Code as public, so I wonder if it's intentional to hide it?

What do you think is the best way to get an error code from native protocol (as it's sometimes is pretty useful)

I'm ready to volunteer and add the proper solution, just wanted to discuss it first.

Thanks,
Sasha

Timeouts

i don't think the new nocql gocql handles timeout error responses from cassandra

2013/08/23 11:44:00 error producing keys: iterating results: Operation timed out - received only 0 responses.

here's how i solved them with the old api:

anacrolix@00141cd

Protocol Error when creating session

I am using the latest stable release of Cassandra 1.2.8 and with everything default I am getting protocol errors when trying to create a session.

I used the code from the readme with minor changes to node up which is 127.0.0.1 and keyspace name to the one I created.

CreateSession can block forever, MaxRetries?

When a cluster is completely inaccessible, gocql will continue trying to connect forever.

Maybe this is the correct behaviour for some use cases, but I believe a MaxRetries option would be a useful addition.

For instance, I have some cluster logic of my own (unrelated to Cassandra) and need to deal with failures (such as being unable to establish a Cassandra session) rather than blocking forever.

Would you be interested in a PR for this?

Edit

Possibly, rather than MaxRetries, you could perhaps expose a way to interrupt CreateSession, or monitor it?

Protocol Error on TRUNCATE

I am getting Protocol Error when issuing a TRUNCATE. This Gist produces the error for me.

And my setup according to cqlsh: Cassandra 1.2.12 | CQL spec 3.0.0 | Thrift protocol 19.36.1

Any ideas what's going on?

hosts are removed from the hostpool when they reach 0 connections but are not added back when reconnected

This seems to happen because the connection pool is not removed from c.connPool when its Size() reaches 0, but it is removed from c.hostPool. When a connection then reconnects the connection pool already exists in c.connPool and thus it is not added to c.hostPool in addConn(conn *Conn,keyspace string)

So the host essentially disappears if all its connections are dropped at the same time and will not reappear even if the connections are reestablised.

i'm not sure how you want to fix it, but i removed the connectionpool from c.connPool at the same time as the it was removed from c.hostPool

    func (c *clusterImpl) removeConn(conn *Conn)
        ...
    if connPool.Size() == 0 {
        c.hostPool.RemoveNode(connPool)
        delete(c.connPool, conn.addr) // new line
    }
    delete(c.conns, conn)
    }

Connecting to Cassandra 2.0.0

I've installed cassandra 2.0.0 and using gocql to try and connect however I am getting the error:

2013/09/07 17:36:20 no keyspace has been specified

The code I am using is:

// connect to the cassandra cluster
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "example"
cluster.DefaultPort = 9042
cluster.CQLVersion = "3.1.0"
cluster.Consistency = gocql.Quorum
session := cluster.CreateSession()
defer session.Close()

When I use cqlsh I get the following info

Connected to Test Cluster at localhost:9160.
[cqlsh 4.0.0 | Cassandra 2.0.0 | CQL spec 3.1.0 | Thrift protocol 19.37.0]

select * from system.schema_keyspaces;
 keyspace_name     | durable_writes | strategy_class                              | strategy_options
-------------------+----------------+---------------------------------------------+----------------------------
            system |           True |  org.apache.cassandra.locator.LocalStrategy |                         {}
     system_traces |           True | org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"1"}
           example |           True | org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"1"}

I'm pretty new to Go and Cassandra so would appreciate any help.
Thanks,
Lenny

.Exec hangs when trying to INSERT int32 into bigint

See https://github.com/ChannelMeter/gocql/blob/c58bba0779ecff95018b5092c00647e29960c88a/gocql_test.go

The TestNullColumnValues, on line 204 change
if _, err := db.Exec(INSERT INTO stuff (id, subid, foo) VALUES (?, ?, ?);, id, int64(4), "test"); err != nil {
to
if _, err := db.Exec(INSERT INTO stuff (id, subid, foo) VALUES (?, ?, ?);, id, 4, "test"); err != nil {

(Remove the int64 cast)

The function just hangs, not sure why or if its the intended behavior. Is it possible the driver is sending the wrong type, or the server expecting a different type?

Infinite connection creation loop after session termination

netstat -tn | grep 9042 | wc -l && go run gocql_demo.go && netstat -tn | grep 9042 | wc -l
0
2013/08/22 13:44:49 failed to connect to "127.0.0.1:9042": dial tcp 127.0.0.1:9042: cannot assign requested address
2013/08/22 13:44:49 failed to connect to "127.0.0.1:9042": dial tcp 127.0.0.1:9042: cannot assign requested address
28231

Sample demo app to reproduce

package main

import (
"time"
"tux21b.org/v1/gocql"
)

func main() {
conn := gocql.NewCluster("build-12-04")
sess := conn.CreateSession()
sess.Close()

time.Sleep(60 * time.Second)

}

TimeUUID timebase

I was wondering how the timebase is designed to work. So I can successfully insert a uuid into Cassandra and the CQL shell renders it correctly, but if I try to just log the timestamp locally, it seems to shift the rendered time forwards.

For example:

timestamp := uuid.TimeUUID()
fmt.Println(timestamp.Time())

results in

2018-02-08 19:10:53.487083841.

How can fix this?

ClusterConfig.Keyspace doesn't seem to do anything

I may be missing something. I thought the following spec for setting ClusterConfig.Keyspace should pass.

func TestSetKeyspaceFromClusterConfig(t *testing.T) {
        cluster := NewCluster("localhost")
        cluster.Keyspace = "test"

        session := cluster.CreateSession()
        defer session.Close()

        iter := session.Query("SELECT * FROM blah").Iter()
        if err := iter.Close(); err != nil && err.Error() == "no keyspace has been specified" {
                t.Error("it should 'use' the given keyspace for each connection")
        }
}

Variable amount of columns when using CAS

When issuing a CAS request, you get a variable number of columns back, depending on the linearized consistency of the server. The Iter type doesn't expose a way to access this data without calling Scan(...), which in turn matches the arity of the result set with the arity of the binding parameters. In the instance of a CAS request, this varies, and hence you get the "count mismatch" error.

I would ordinarily fork this repo, but I've noticed that this fork 7212a47 has already done something similar.

Is there a way we can sort this out?

.Query() hangs on non-existant table (column family)

When querying a table that is not in the database the program seems to hang inside the call.

To reproduce use the example in the readme, except change the tablename in the query to something that is not in the database, like:

Change:
db.Query("SELECT keyspace_name FROM schema_keyspaces")

To:
db.Query("SELECT keyspace_name FROM not_here")

Expected behavior is to return an error.

This used to work last week, so it seems to be a newly introduced problem.

Protocol Error

Cassandra startup dumps the following:

INFO 03:31:31,203 Cassandra version: 1.2.9
INFO 03:31:31,203 Thrift API version: 19.36.0
INFO 03:31:31,203 CQL supported versions: 2.0.0,3.0.5 (default: 3.0.5)

gocql dumps following on 'go test'

2013/12/23 04:26:51 failed to connect to "127.0.0.1:9042": protocol error

CQL Version is set to default: 3.0.0 as cloned code from github

Similar protocol error from the Go App.

Am I missing something... Thank you.

Stability

Hi!

I'm looking at different technology options for a new project (web service (REST) that is going to handle a fairly high load). Go/Cassandra would be a real contender, but I'm a bit worried by the alpha state of this client.

Is it possible to say anything about the maturity of this client? Would it be a bad idea to depend on this client in production environment?

Is it possible to say anything about how far down the line a stable release would be?

IO timeout when use http.ListenAndServe together

func main() {
if err := initSchema(); err != nil {
log.Fatal("initSchema: ", err)
}
http.HandleFunc("/view/", viewHandler)
http.ListenAndServe(":8080", nil)

}
got error

failed to connect to "127.0.0.1:9042": dial tcp 127.0.0.1:9042: i/o timeout

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.