Skip to content

Commit 29c45ca

Browse files
committed
add more docs
1 parent e2800d6 commit 29c45ca

File tree

5 files changed

+476
-528
lines changed

5 files changed

+476
-528
lines changed

UPGRADE_GUIDE.md

Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
-->
20+
21+
# GoCQL Major Version Upgrade Guide
22+
23+
This guide helps you migrate between major versions of the GoCQL driver. Each major version introduces significant changes that may require code modifications.
24+
25+
## Available Upgrade Paths
26+
27+
- [v1.x → v2.x](#upgrading-from-v1x-to-v2x)
28+
- [Future version upgrades will be documented here as they become available]
29+
30+
---
31+
32+
## Upgrading from v1.x to v2.x
33+
34+
Version 2.0.0 introduced significant changes to the GoCQL driver. This section separates immediate breaking changes from deprecation notices to help you plan your migration.
35+
36+
**Important:** The minimum Go version was raised to **Go 1.19** in v2.0.0.
37+
38+
### Table of Contents
39+
40+
- [Breaking Changes](#breaking-changes)
41+
- [API Changes (Compilation Failures)](#api-changes-compilation-failures)
42+
- [Behavioral Changes (Runtime Changes)](#behavioral-changes-runtime-changes)
43+
- [Migration Steps](#migration-steps)
44+
- [Required Changes (All Users)](#required-changes-all-users)
45+
- [Advanced Changes (Advanced Users Only)](#advanced-changes-advanced-users-only)
46+
- [Detailed Migration Examples](#detailed-migration-examples)
47+
- [Deprecation Notices](#deprecation-notices)
48+
49+
---
50+
51+
## Breaking Changes
52+
53+
These changes will cause compilation failures or runtime behavior changes and must be addressed before upgrading to v2.0.0.
54+
55+
### API Changes (Compilation Failures)
56+
57+
These changes will cause your code to fail compilation and must be fixed immediately:
58+
59+
#### 1. Import Path Change
60+
**Required for all users**
61+
62+
```go
63+
// OLD (v1.x)
64+
import "github.com/gocql/gocql"
65+
66+
// NEW (v2.x)
67+
import "github.com/apache/cassandra-gocql-driver/v2"
68+
```
69+
70+
#### 2. Removed APIs
71+
**Action required if you use these APIs**
72+
73+
- **`Session.SetTrace()`** → Use `Query.Trace()` or `Batch.Trace()` instead
74+
- **`ClusterConfig.ProtoVersion` values 1 and 2** → Use version 3+ only
75+
- **`SimpleRetryPolicy`** → Use `ExponentialBackoffRetryPolicy` or implement `RetryPolicy`
76+
77+
### Behavioral Changes (Runtime Changes)
78+
79+
These changes modify existing behavior and may require code updates:
80+
81+
#### 1. Default Retry Policy
82+
- **Old:** No retries by default
83+
- **New:** `ExponentialBackoffRetryPolicy` with sensible defaults
84+
- **Impact:** Queries may now retry automatically on failures
85+
- **Action:** Review and adjust retry policies if needed
86+
87+
#### 2. Connection Pool Behavior
88+
- **Change:** Improved connection pool management and recovery
89+
- **Impact:** Better performance but may change timing of reconnections
90+
- **Action:** Monitor application behavior, adjust pool settings if needed
91+
92+
#### 3. Error Types
93+
- Some error types have been refined for better categorization
94+
- **Action:** Review error handling code, especially if you type-assert on specific error types
95+
96+
---
97+
98+
## Migration Steps
99+
100+
### Required Changes (All Users)
101+
102+
Follow these steps in order:
103+
104+
#### Step 1: Update Go Version
105+
Ensure you're using **Go 1.19 or later**:
106+
```bash
107+
go version # Should show 1.19 or higher
108+
```
109+
110+
#### Step 2: Update Import Statements
111+
Replace all import statements:
112+
```bash
113+
# Using find/replace in your editor, or:
114+
find . -name "*.go" -exec sed -i 's|github.com/gocql/gocql|github.com/apache/cassandra-gocql-driver/v2|g' {} +
115+
```
116+
117+
#### Step 3: Update go.mod
118+
```bash
119+
go mod edit -require=github.com/apache/cassandra-gocql-driver/v2@latest
120+
go mod edit -droprequire=github.com/gocql/gocql
121+
go mod tidy
122+
```
123+
124+
#### Step 4: Fix Removed APIs
125+
Review compilation errors and apply these fixes:
126+
127+
**SetTrace() Removal:**
128+
```go
129+
// OLD
130+
session.SetTrace(tracer)
131+
query := session.Query("SELECT ...")
132+
133+
// NEW
134+
query := session.Query("SELECT ...").Trace(tracer)
135+
```
136+
137+
**Unsupported Protocol Versions:**
138+
```go
139+
// OLD
140+
cluster.ProtoVersion = 2 // No longer supported
141+
142+
// NEW
143+
cluster.ProtoVersion = 3 // Minimum supported version
144+
// or omit to auto-negotiate
145+
```
146+
147+
#### Step 5: Test and Validate
148+
```bash
149+
go build ./... # Check for compilation errors
150+
go test ./... # Run your test suite
151+
```
152+
153+
### Advanced Changes (Advanced Users Only)
154+
155+
These changes only affect users of advanced features:
156+
157+
#### Custom Retry Policies
158+
If you implemented custom retry policies:
159+
```go
160+
// Review the RetryPolicy interface - it may have changed
161+
// Test your custom implementation thoroughly
162+
```
163+
164+
#### Custom Host Policies
165+
If you implemented custom host selection policies:
166+
```go
167+
// Verify your HostSelectionPolicy implementation
168+
// Check for interface changes
169+
```
170+
171+
#### Low-level Connection Management
172+
If you used internal APIs or connection-level features:
173+
- Review all code for removed/changed internal APIs
174+
- Consider using supported public APIs instead
175+
- Test connection handling thoroughly
176+
177+
---
178+
179+
## Detailed Migration Examples
180+
181+
### Example 1: Basic Application Migration
182+
183+
**Before (v1.x):**
184+
```go
185+
package main
186+
187+
import (
188+
"github.com/gocql/gocql"
189+
"log"
190+
)
191+
192+
func main() {
193+
cluster := gocql.NewCluster("127.0.0.1")
194+
cluster.ProtoVersion = 2
195+
session, err := cluster.CreateSession()
196+
if err != nil {
197+
log.Fatal(err)
198+
}
199+
defer session.Close()
200+
201+
// Set global trace
202+
session.SetTrace(gocql.NewTraceWriter(session, os.Stdout))
203+
204+
query := session.Query("SELECT * FROM users WHERE id = ?", userID)
205+
// ... rest of code
206+
}
207+
```
208+
209+
**After (v2.x):**
210+
```go
211+
package main
212+
213+
import (
214+
"github.com/apache/cassandra-gocql-driver/v2" // Updated import
215+
"log"
216+
"os"
217+
)
218+
219+
func main() {
220+
cluster := gocql.NewCluster("127.0.0.1")
221+
cluster.ProtoVersion = 3 // Updated minimum version
222+
session, err := cluster.CreateSession()
223+
if err != nil {
224+
log.Fatal(err)
225+
}
226+
defer session.Close()
227+
228+
// Per-query trace instead of global
229+
tracer := gocql.NewTraceWriter(session, os.Stdout)
230+
query := session.Query("SELECT * FROM users WHERE id = ?", userID).
231+
Trace(tracer) // Trace per query
232+
// ... rest of code
233+
}
234+
```
235+
236+
### Example 2: Custom Retry Policy Migration
237+
238+
**Before (v1.x):**
239+
```go
240+
// OLD - SimpleRetryPolicy no longer exists
241+
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: 3}
242+
```
243+
244+
**After (v2.x):**
245+
```go
246+
// NEW - Use ExponentialBackoffRetryPolicy or implement custom
247+
cluster.RetryPolicy = &gocql.ExponentialBackoffRetryPolicy{
248+
MaxRetries: 3,
249+
InitialInterval: time.Second,
250+
MaxInterval: 30 * time.Second,
251+
}
252+
253+
// OR implement your own:
254+
type MyRetryPolicy struct{}
255+
func (m *MyRetryPolicy) Attempt(q gocql.RetryableQuery) bool { /* implementation */ }
256+
func (m *MyRetryPolicy) GetRetryType(err error) gocql.RetryType { /* implementation */ }
257+
cluster.RetryPolicy = &MyRetryPolicy{}
258+
```
259+
260+
### Example 3: Batch with Tracing Migration
261+
262+
**Before (v1.x):**
263+
```go
264+
session.SetTrace(tracer) // Global trace
265+
batch := session.Batch(gocql.LoggedBatch)
266+
batch.Query("INSERT INTO users (id, name) VALUES (?, ?)", id, name)
267+
err := session.ExecuteBatch(batch)
268+
```
269+
270+
**After (v2.x):**
271+
```go
272+
// Per-batch trace
273+
batch := session.Batch(gocql.LoggedBatch).
274+
Query("INSERT INTO users (id, name) VALUES (?, ?)", id, name).
275+
Trace(tracer) // Trace per batch
276+
err := batch.Exec()
277+
```
278+
279+
---
280+
281+
## Deprecation Notices
282+
283+
The following features are deprecated but still functional in v2.x. Plan to migrate away from these in future releases:
284+
285+
### Deprecated (Will be removed in v3.x)
286+
287+
1. **`Session.ExecuteBatch()`** → Use `Batch.Exec()` fluent API
288+
2. **`Session.ExecuteBatchCAS()`** → Use `Batch.ExecCAS()` fluent API
289+
3. **`Session.MapExecuteBatchCAS()`** → Use `Batch.MapExecCAS()` fluent API
290+
291+
**Migration Timeline:**
292+
- v2.x: Deprecated APIs work but emit warnings
293+
- v3.x: Deprecated APIs will be removed
294+
295+
**Example Migration:**
296+
```go
297+
// DEPRECATED (still works in v2.x)
298+
batch := session.NewBatch(gocql.LoggedBatch)
299+
batch.Query("INSERT INTO users (id, name) VALUES (?, ?)", id, name)
300+
err := session.ExecuteBatch(batch)
301+
302+
// RECOMMENDED (future-proof)
303+
err := session.Batch(gocql.LoggedBatch).
304+
Query("INSERT INTO users (id, name) VALUES (?, ?)", id, name).
305+
Exec()
306+
```
307+
308+
---
309+
310+
## Need Help?
311+
312+
If you encounter issues during migration:
313+
314+
1. **Check the [CHANGELOG.md](CHANGELOG.md)** for detailed changes
315+
2. **Review the [examples](example_test.go)** for updated usage patterns
316+
3. **Search [GitHub Issues](https://github.com/apache/cassandra-gocql-driver/issues)** for similar problems
317+
4. **Create a new issue** if you find bugs or need clarification
318+
319+
## Version Compatibility Matrix
320+
321+
| GoCQL Version | Go Version | Cassandra Version | Protocol Version |
322+
|---------------|------------|------------------|------------------|
323+
| v1.x | 1.16+ | 2.1+ | 2, 3, 4 |
324+
| v2.x | 1.19+ | 2.1+ | 3, 4, 5 |
325+
326+
---
327+
328+
*Last updated: [Current Date] for GoCQL v2.0.0*

0 commit comments

Comments
 (0)