Skip to content

Commit

Permalink
Remove deprecated features
Browse files Browse the repository at this point in the history
Some features marced as "Deprecated" were removed:
Global TimeoutLimit variable;
MustParseConsistency() function;
New() method for typeInfo{} interface;
View field for the KeyspaceMetadata structure;

patch by Oleksandr Luzhniy; reviewed by João Reis, for CASSGO-12
  • Loading branch information
tengu-alt committed Nov 18, 2024
1 parent 7b7e6af commit a8fcedb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 151 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Don't restrict server authenticator unless PasswordAuthentictor.AllowedAuthenticators is provided (CASSGO-19)

- Cleanup of deprecated elements (CASSGO-12)

### Fixed

## [1.7.0] - 2024-09-23
Expand Down
46 changes: 1 addition & 45 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
"time"
"unicode"

inf "gopkg.in/inf.v0"
"gopkg.in/inf.v0"
)

func TestEmptyHosts(t *testing.T) {
Expand Down Expand Up @@ -2223,45 +2223,6 @@ func TestGetColumnMetadata(t *testing.T) {
}
}

func TestViewMetadata(t *testing.T) {
session := createSession(t)
defer session.Close()
createViews(t, session)

views, err := getViewsMetadata(session, "gocql_test")
if err != nil {
t.Fatalf("failed to query view metadata with err: %v", err)
}
if views == nil {
t.Fatal("failed to query view metadata, nil returned")
}

if len(views) != 1 {
t.Fatal("expected one view")
}

textType := TypeText
if flagCassVersion.Before(3, 0, 0) {
textType = TypeVarchar
}

expectedView := ViewMetadata{
Keyspace: "gocql_test",
Name: "basicview",
FieldNames: []string{"birthday", "nationality", "weight", "height"},
FieldTypes: []TypeInfo{
NativeType{typ: TypeTimestamp},
NativeType{typ: textType},
NativeType{typ: textType},
NativeType{typ: textType},
},
}

if !reflect.DeepEqual(views[0], expectedView) {
t.Fatalf("view is %+v, but expected %+v", views[0], expectedView)
}
}

func TestMaterializedViewMetadata(t *testing.T) {
if flagCassVersion.Before(3, 0, 0) {
return
Expand Down Expand Up @@ -2544,11 +2505,6 @@ func TestKeyspaceMetadata(t *testing.T) {
if aggregate.StateFunc.Name != "avgstate" {
t.Fatalf("expected state function %s, but got %s", "avgstate", aggregate.StateFunc.Name)
}

_, found = keyspaceMetadata.Views["basicview"]
if !found {
t.Fatal("failed to find the view in metadata")
}
_, found = keyspaceMetadata.UserTypes["basicview"]
if !found {
t.Fatal("failed to find the types in metadata")
Expand Down
10 changes: 1 addition & 9 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ func (fn connErrorHandlerFn) HandleError(conn *Conn, err error, closed bool) {
fn(conn, err, closed)
}

// If not zero, how many timeouts we will allow to occur before the connection is closed
// and restarted. This is to prevent a single query timeout from killing a connection
// which may be serving more queries just fine.
// Default is 0, should not be changed concurrently with queries.
//
// Deprecated.
var TimeoutLimit int64 = 0

// Conn is a single connection to a Cassandra node. It can be used to execute
// queries, but users are usually advised to use a more reliable, higher
// level API.
Expand Down Expand Up @@ -764,7 +756,7 @@ func (c *Conn) releaseStream(call *callReq) {
}

func (c *Conn) handleTimeout() {
if TimeoutLimit > 0 && atomic.AddInt64(&c.timeouts, 1) > TimeoutLimit {
if atomic.AddInt64(&c.timeouts, 1) > 0 {
c.closeWithError(ErrTooManyTimeouts)
}
}
Expand Down
11 changes: 0 additions & 11 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,6 @@ func ParseConsistencyWrapper(s string) (consistency Consistency, err error) {
return
}

// MustParseConsistency is the same as ParseConsistency except it returns
// an error (never). It is kept here since breaking changes are not good.
// DEPRECATED: use ParseConsistency if you want a panic on parse error.
func MustParseConsistency(s string) (Consistency, error) {
c, err := ParseConsistencyWrapper(s)
if err != nil {
panic(err)
}
return c, nil
}

type SerialConsistency uint16

const (
Expand Down
40 changes: 0 additions & 40 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2455,14 +2455,6 @@ type TypeInfo interface {
Version() byte
Custom() string

// New creates a pointer to an empty version of whatever type
// is referenced by the TypeInfo receiver.
//
// If there is no corresponding Go type for the CQL type, New panics.
//
// Deprecated: Use NewWithError instead.
New() interface{}

// NewWithError creates a pointer to an empty version of whatever type
// is referenced by the TypeInfo receiver.
//
Expand All @@ -2488,14 +2480,6 @@ func (t NativeType) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (t NativeType) New() interface{} {
val, err := t.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

func (s NativeType) Type() Type {
return s.typ
}
Expand Down Expand Up @@ -2531,14 +2515,6 @@ func (t CollectionType) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (t CollectionType) New() interface{} {
val, err := t.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

func (c CollectionType) String() string {
switch c.typ {
case TypeMap:
Expand Down Expand Up @@ -2576,14 +2552,6 @@ func (t TupleTypeInfo) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (t TupleTypeInfo) New() interface{} {
val, err := t.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

type UDTField struct {
Name string
Type TypeInfo
Expand All @@ -2604,14 +2572,6 @@ func (u UDTTypeInfo) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (u UDTTypeInfo) New() interface{} {
val, err := u.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

func (u UDTTypeInfo) String() string {
buf := &bytes.Buffer{}

Expand Down
68 changes: 22 additions & 46 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ import (

// schema metadata for a keyspace
type KeyspaceMetadata struct {
Name string
DurableWrites bool
StrategyClass string
StrategyOptions map[string]interface{}
Tables map[string]*TableMetadata
Functions map[string]*FunctionMetadata
Aggregates map[string]*AggregateMetadata
// Deprecated: use the MaterializedViews field for views and UserTypes field for udts instead.
Views map[string]*ViewMetadata
Name string
DurableWrites bool
StrategyClass string
StrategyOptions map[string]interface{}
Tables map[string]*TableMetadata
Functions map[string]*FunctionMetadata
Aggregates map[string]*AggregateMetadata
MaterializedViews map[string]*MaterializedViewMetadata
UserTypes map[string]*UserTypeMetadata
}
Expand Down Expand Up @@ -109,15 +107,6 @@ type AggregateMetadata struct {
finalFunc string
}

// ViewMetadata holds the metadata for views.
// Deprecated: this is kept for backwards compatibility issues. Use MaterializedViewMetadata.
type ViewMetadata struct {
Keyspace string
Name string
FieldNames []string
FieldTypes []TypeInfo
}

// MaterializedViewMetadata holds the metadata for materialized views.
type MaterializedViewMetadata struct {
Keyspace string
Expand Down Expand Up @@ -304,7 +293,7 @@ func (s *schemaDescriber) refreshSchema(keyspaceName string) error {
if err != nil {
return err
}
views, err := getViewsMetadata(s.session, keyspaceName)
userTypes, err := getUserTypeMetadata(s.session, keyspaceName)
if err != nil {
return err
}
Expand All @@ -314,7 +303,7 @@ func (s *schemaDescriber) refreshSchema(keyspaceName string) error {
}

// organize the schema data
compileMetadata(s.session.cfg.ProtoVersion, keyspace, tables, columns, functions, aggregates, views,
compileMetadata(s.session.cfg.ProtoVersion, keyspace, tables, columns, functions, aggregates, userTypes,
materializedViews, s.session.logger)

// update the cache
Expand All @@ -335,7 +324,7 @@ func compileMetadata(
columns []ColumnMetadata,
functions []FunctionMetadata,
aggregates []AggregateMetadata,
views []ViewMetadata,
uTypes []UserTypeMetadata,
materializedViews []MaterializedViewMetadata,
logger StdLogger,
) {
Expand All @@ -355,22 +344,9 @@ func compileMetadata(
aggregates[i].StateFunc = *keyspace.Functions[aggregates[i].stateFunc]
keyspace.Aggregates[aggregates[i].Name] = &aggregates[i]
}
keyspace.Views = make(map[string]*ViewMetadata, len(views))
for i := range views {
keyspace.Views[views[i].Name] = &views[i]
}
// Views currently holds the types and hasn't been deleted for backward compatibility issues.
// That's why it's ok to copy Views into Types in this case. For the real Views use MaterializedViews.
types := make([]UserTypeMetadata, len(views))
for i := range views {
types[i].Keyspace = views[i].Keyspace
types[i].Name = views[i].Name
types[i].FieldNames = views[i].FieldNames
types[i].FieldTypes = views[i].FieldTypes
}
keyspace.UserTypes = make(map[string]*UserTypeMetadata, len(views))
for i := range types {
keyspace.UserTypes[types[i].Name] = &types[i]
keyspace.UserTypes = make(map[string]*UserTypeMetadata, len(uTypes))
for i := range uTypes {
keyspace.UserTypes[uTypes[i].Name] = &uTypes[i]
}
keyspace.MaterializedViews = make(map[string]*MaterializedViewMetadata, len(materializedViews))
for i, _ := range materializedViews {
Expand Down Expand Up @@ -954,7 +930,7 @@ func getTypeInfo(t string, logger StdLogger) TypeInfo {
return getCassandraType(t, logger)
}

func getViewsMetadata(session *Session, keyspaceName string) ([]ViewMetadata, error) {
func getUserTypeMetadata(session *Session, keyspaceName string) ([]UserTypeMetadata, error) {
if session.cfg.ProtoVersion == protoVersion1 {
return nil, nil
}
Expand All @@ -972,31 +948,31 @@ func getViewsMetadata(session *Session, keyspaceName string) ([]ViewMetadata, er
FROM %s
WHERE keyspace_name = ?`, tableName)

var views []ViewMetadata
var uTypes []UserTypeMetadata

rows := session.control.query(stmt, keyspaceName).Scanner()
for rows.Next() {
view := ViewMetadata{Keyspace: keyspaceName}
uType := UserTypeMetadata{Keyspace: keyspaceName}
var argumentTypes []string
err := rows.Scan(&view.Name,
&view.FieldNames,
err := rows.Scan(&uType.Name,
&uType.FieldNames,
&argumentTypes,
)
if err != nil {
return nil, err
}
view.FieldTypes = make([]TypeInfo, len(argumentTypes))
uType.FieldTypes = make([]TypeInfo, len(argumentTypes))
for i, argumentType := range argumentTypes {
view.FieldTypes[i] = getTypeInfo(argumentType, session.logger)
uType.FieldTypes[i] = getTypeInfo(argumentType, session.logger)
}
views = append(views, view)
uTypes = append(uTypes, uType)
}

if err := rows.Err(); err != nil {
return nil, err
}

return views, nil
return uTypes, nil
}

func getMaterializedViewsMetadata(session *Session, keyspaceName string) ([]MaterializedViewMetadata, error) {
Expand Down

0 comments on commit a8fcedb

Please sign in to comment.