Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ This eliminates passing data between shards and significantly reduces latency.

There are open pull requests to merge the functionality to the upstream project:

* [gocql/gocql#1210](https://github.com/gocql/gocql/pull/1210)
* [gocql/gocql#1211](https://github.com/gocql/gocql/pull/1211).
* [gocql/gocql#1210](https://github.com/scylladb/gocql/v2/pull/1210)
* [gocql/gocql#1211](https://github.com/scylladb/gocql/v2/pull/1211).

It also provides support for shard aware ports, a faster way to connect to all shards, details available in [blogpost](https://www.scylladb.com/2021/04/27/connect-faster-to-scylla-with-a-shard-aware-port/).

Expand All @@ -40,32 +40,39 @@ It also provides support for shard aware ports, a faster way to connect to all s
- [5.2 Iterator](#52-iterator)
- [6. Contributing](#6-contributing)

## 1. Sunsetting Model
## Sunsetting Model

> [!WARNING]
> 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.

## 2. Installation
## Installation

This is a drop-in replacement to gocql, it reuses the `github.com/gocql/gocql` import path.
Import package:
```sh
go get github.com/scylladb-solutions/gocql/v2
```

Add the following line to your project `go.mod` file.
And you ready to go.

```mod
replace github.com/gocql/gocql => github.com/scylladb/gocql latest
```
## Migrate from v1

and run
To migrate from v1 follow steps:
1. Upgrade go to at least `1.24`
2. In `go.mod` replace `github.com/gocql/gocql` with `github.com/scylladb-solutions/gocql/v2` with proper version.
3. In `go.mod` remove `replace` directive for `github.com/gocql/gocql`.
4. Run `go mod tidy`
5. Resolve conflicts

```sh
go mod tidy
```
## Migrate from [gocql/gocql](https://github.com/gocql/gocql) or [apache/cassandra-gocql-driver](https://github.com/apache/cassandra-gocql-driver)

to evaluate `latest` to a concrete tag.
To switch from other driver forks following steps:
1. Replace any references from `github.com/gocql/gocql` to `github.com/scylladb-solutions/gocql/v2` in the code and `go.mod`
2. Run `go mod tidy`
3. Resolve conflicts

Your project now uses the Scylla driver fork, make sure you are using the `TokenAwareHostPolicy` to enable the shard-awareness, continue reading for details.
APIs of all forks are similar, but there could be some differences, resolve conflicts manually.

## 3. Quick Start
## Quick Start

Spawn a ScyllaDB Instance using Docker Run command:

Expand All @@ -82,7 +89,7 @@ package main

import (
"fmt"
"github.com/gocql/gocql"
"github.com/scylladb/gocql/v2"
)

func main() {
Expand All @@ -107,9 +114,9 @@ func main() {
}
```

## 4. Data Types
## Data Types

Here's an list of all CQL Types reflected in the GoCQL environment:
Here's a list of all CQL Types reflected in the GoCQL environment:

| ScyllaDB Type | Go Type |
| ---------------- | ------------------ |
Expand Down Expand Up @@ -137,7 +144,7 @@ Here's an list of all CQL Types reflected in the GoCQL environment:
| `varchar` | `string` |
| `varint` | `int64` |

## 5. Configuration
## Configuration

In order to make shard-awareness work, token aware host selection policy has to be enabled.
Please make sure that the gocql configuration has `PoolConfig.HostSelectionPolicy` properly set like in the example below.
Expand All @@ -163,7 +170,7 @@ if localDC != "" {
// c.NumConns = 4
```

### 5.1 Shard-aware port
### Shard-aware port

This version of gocql supports a more robust method of establishing connection for each shard by using _shard aware port_ for native transport.
It greatly reduces time and the number of connections needed to establish a connection per shard in some cases - ex. when many clients connect at once, or when there are non-shard-aware clients connected to the same cluster.
Expand Down Expand Up @@ -210,7 +217,7 @@ Issues with shard-aware port not being reachable are not reported in non-debug m

If you suspect that this feature is causing you problems, you can completely disable it by setting the `ClusterConfig.DisableShardAwarePort` flag to true.

### 5.2 Iterator
### Iterator

Paging is a way to parse large result sets in smaller chunks.
The driver provides an iterator to simplify this process.
Expand All @@ -237,6 +244,6 @@ In case of range and `ALLOW FILTERING` queries server can send empty responses f
That is why you should never consider empty response as the end of the result set.
Always check `iter.Scan()` result to know if there are more results, or `Iter.LastPage()` to know if the last page was reached.

## 6. Contributing
## Contributing

If you have any interest to be contributing in this GoCQL Fork, please read the [CONTRIBUTING.md](CONTRIBUTING.md) before initialize any Issue or Pull Request.
2 changes: 1 addition & 1 deletion address_translators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package gocql

import (
"github.com/gocql/gocql/internal/tests"
"github.com/scylladb/gocql/v2/internal/tests"
"net"
"testing"
)
Expand Down
6 changes: 3 additions & 3 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"context"
"errors"
"fmt"
"github.com/gocql/gocql/internal/tests"
"github.com/scylladb/gocql/v2/internal/tests"
"math"
"math/big"
"net"
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestUseStatementError(t *testing.T) {

if err := session.Query("USE gocql_test").Exec(); err != nil {
if err != ErrUseStmt {
t.Fatalf("expected ErrUseStmt, got " + err.Error())
t.Fatalf("expected ErrUseStmt, got %v", err)
}
} else {
t.Fatal("expected err, got nil.")
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestCAS(t *testing.T) {

if _, err := session.Query(`DELETE FROM cas_table WHERE title = ? and revid = ? IF last_modified = ?`,
title, revid, tenSecondsLater).ScanCAS(); !strings.HasPrefix(err.Error(), "gocql: not enough columns to scan into") {
t.Fatalf("delete: was expecting count mismatch error but got: %q", err.Error())
t.Fatalf("delete: was expecting count mismatch error but got: %v", err)
}

if applied, err := session.Query(`DELETE FROM cas_table WHERE title = ? and revid = ? IF last_modified = ?`,
Expand Down
4 changes: 2 additions & 2 deletions cloud_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"testing"
"time"

"github.com/gocql/gocql"
"github.com/gocql/gocql/scyllacloud"
"github.com/scylladb/gocql/v2"
"github.com/scylladb/gocql/v2/scyllacloud"
"sigs.k8s.io/yaml"
)

Expand Down
2 changes: 1 addition & 1 deletion cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package gocql

import (
"github.com/gocql/gocql/internal/tests"
"github.com/scylladb/gocql/v2/internal/tests"
"net"
"reflect"
"testing"
Expand Down
6 changes: 3 additions & 3 deletions compressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

"github.com/klauspost/compress/s2"

"github.com/gocql/gocql"
"github.com/scylladb/gocql/v2"
)

type frameExample struct {
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestSnappyCompressor(t *testing.T) {
}

if bytes.Compare(decoded, frame.Frame) != 0 {
t.Fatalf("failed to match the decoded value with the original value")
t.Fatal("failed to match the decoded value with the original value")
}
t.Logf("Compression rate %f", float64(len(encoded))/float64(len(frame.Frame)))
})
Expand All @@ -156,7 +156,7 @@ func TestSnappyCompressor(t *testing.T) {
}

if len(decoded) == 0 {
t.Fatalf("frame was decoded to empty slice")
t.Fatal("frame was decoded to empty slice")
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/gocql/gocql/tablets"
"github.com/scylladb/gocql/v2/tablets"
"io"
"io/ioutil"
"net"
Expand All @@ -40,8 +40,8 @@ import (
"sync/atomic"
"time"

"github.com/gocql/gocql/internal/lru"
"github.com/gocql/gocql/internal/streams"
"github.com/scylladb/gocql/v2/internal/lru"
"github.com/scylladb/gocql/v2/internal/streams"
)

// approve the authenticator with the list of allowed authenticators. If the provided list is empty,
Expand Down
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/gocql/gocql/internal/streams"
"github.com/scylladb/gocql/v2/internal/streams"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions connectionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ package gocql

import (
"fmt"
"github.com/gocql/gocql/tablets"
"github.com/scylladb/gocql/v2/tablets"
"math/rand"
"net"
"sync"
"time"

"github.com/gocql/gocql/debounce"
"github.com/scylladb/gocql/v2/debounce"
)

// interface to implement to receive the host information
Expand Down
4 changes: 2 additions & 2 deletions debounce/refresh_debouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestErrorBroadcaster_MultipleListeners(t *testing.T) {
}()
wg.Wait()
if loadedVal := result.Load(); loadedVal != nil {
t.Errorf(loadedVal.(error).Error())
t.Error(loadedVal.(error).Error())
}
}

Expand Down Expand Up @@ -249,6 +249,6 @@ func TestErrorBroadcaster_StopWithoutBroadcast(t *testing.T) {
}()
wg.Wait()
if loadedVal := result.Load(); loadedVal != nil {
t.Errorf(loadedVal.(error).Error())
t.Error(loadedVal.(error).Error())
}
}
4 changes: 2 additions & 2 deletions dialer/recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"path"
"time"

"github.com/gocql/gocql"
"github.com/gocql/gocql/dialer"
"github.com/scylladb/gocql/v2"
"github.com/scylladb/gocql/v2/dialer"
)

func NewRecordDialer(dir string) *RecordDialer {
Expand Down
4 changes: 2 additions & 2 deletions dialer/replayer/replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"path"
"time"

"github.com/gocql/gocql"
"github.com/gocql/gocql/dialer"
"github.com/scylladb/gocql/v2"
"github.com/scylladb/gocql/v2/dialer"
)

func NewReplayDialer(dir string) *ReplayDialer {
Expand Down
2 changes: 1 addition & 1 deletion dialer/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dialer

import (
"github.com/gocql/gocql/internal/murmur"
"github.com/scylladb/gocql/v2/internal/murmur"
)

type Record struct {
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,4 @@
// There is also a new implementation of Tracer - TracerEnhanced, that is intended to be more reliable and convinient to use.
// It has a funcionality to check if trace is ready to be extracted and only actually gets it if requested which makes
// the impact on a performance smaller.
package gocql // import "github.com/gocql/gocql"
package gocql // import "github.com/scylladb/gocql/v2"
2 changes: 1 addition & 1 deletion example_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"fmt"
"log"

"github.com/gocql/gocql"
"github.com/scylladb/gocql/v2"
)

// Example_batch demonstrates how to execute a batch of statements.
Expand Down
2 changes: 1 addition & 1 deletion example_dynamic_columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"reflect"
"text/tabwriter"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// Example_dynamicColumns demonstrates how to handle dynamic column list.
Expand Down
2 changes: 1 addition & 1 deletion example_lwt_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"fmt"
"log"

"github.com/gocql/gocql"
"github.com/scylladb/gocql/v2"
)

// ExampleSession_MapExecuteBatchCAS demonstrates how to execute a batch lightweight transaction.
Expand Down
2 changes: 1 addition & 1 deletion example_lwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"fmt"
"log"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// ExampleQuery_MapScanCAS demonstrates how to execute a single-statement lightweight transaction.
Expand Down
2 changes: 1 addition & 1 deletion example_marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"strconv"
"strings"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// MyMarshaler implements Marshaler and Unmarshaler.
Expand Down
2 changes: 1 addition & 1 deletion example_nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"fmt"
"log"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// Example_nulls demonstrates how to distinguish between null and zero value when needed.
Expand Down
2 changes: 1 addition & 1 deletion example_paging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"fmt"
"log"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// Example_paging demonstrates how to manually fetch pages and use page state.
Expand Down
2 changes: 1 addition & 1 deletion example_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"log"
"sort"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// Example_set demonstrates how to use sets.
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"fmt"
"log"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

func Example() {
Expand Down
2 changes: 1 addition & 1 deletion example_udt_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"fmt"
"log"

gocql "github.com/gocql/gocql"
gocql "github.com/scylladb/gocql/v2"
)

// Example_userDefinedTypesMap demonstrates how to work with user-defined types as maps.
Expand Down
Loading