From 49104c51d7f10f57eb4ba992bd5be5a5fdb87ebc Mon Sep 17 00:00:00 2001 From: illia-li Date: Thu, 21 Dec 2023 11:53:58 -0400 Subject: [PATCH] 1) conversation fixes 2) remake ColumnRaw to string instead []byte --- pkg/store/comp/compare_info.go | 2 +- pkg/store/comp/compare_info_mv_test.go | 2 +- pkg/store/comp/interface.go | 2 +- pkg/store/comp/utils_4test.go | 12 +++---- pkg/store/cqlstore.go | 6 ++-- pkg/store/mv/c_list.go | 8 ++--- pkg/store/mv/c_list_test.go | 10 +++--- pkg/store/mv/c_map.go | 8 ++--- pkg/store/mv/c_map_test.go | 13 +++++--- pkg/store/mv/c_raw.go | 45 ++++++++------------------ pkg/store/mv/c_raw_test.go | 18 +++++------ pkg/store/mv/c_tuple.go | 8 ++--- pkg/store/mv/c_tuple_test.go | 8 +++-- pkg/store/mv/c_udt.go | 8 ++--- pkg/store/mv/c_udt_test.go | 8 +++-- pkg/store/mv/delete_equal_test.go | 2 +- pkg/store/mv/init_column.go | 12 ++++--- pkg/store/mv/interface.go | 2 +- pkg/store/mv/result.go | 2 +- pkg/store/mv/results.go | 2 +- pkg/store/mv/row.go | 2 +- pkg/store/mv/rows.go | 2 +- pkg/store/mv/utils.go | 2 +- pkg/store/mv/utils_4test.go | 19 +++++------ pkg/store/store.go | 24 +++++++------- pkg/store/sv/delete_equal_test.go | 5 ++- pkg/store/sv/raw.go | 11 ++++--- pkg/store/sv/raw_test.go | 8 ++--- pkg/store/sv/result.go | 2 +- pkg/store/sv/results.go | 2 +- pkg/store/sv/row.go | 12 ++----- pkg/store/sv/rows.go | 2 +- pkg/store/ver/check.go | 2 +- pkg/store/ver/check_test.go | 2 +- 34 files changed, 122 insertions(+), 151 deletions(-) diff --git a/pkg/store/comp/compare_info.go b/pkg/store/comp/compare_info.go index 90d83d8..97c2e67 100644 --- a/pkg/store/comp/compare_info.go +++ b/pkg/store/comp/compare_info.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/comp/compare_info_mv_test.go b/pkg/store/comp/compare_info_mv_test.go index bf62e8a..85b0247 100644 --- a/pkg/store/comp/compare_info_mv_test.go +++ b/pkg/store/comp/compare_info_mv_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/comp/interface.go b/pkg/store/comp/interface.go index a1b98e5..43bc22a 100644 --- a/pkg/store/comp/interface.go +++ b/pkg/store/comp/interface.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/comp/utils_4test.go b/pkg/store/comp/utils_4test.go index 832d1d5..55dc0e7 100644 --- a/pkg/store/comp/utils_4test.go +++ b/pkg/store/comp/utils_4test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -214,16 +214,14 @@ func rndSameRowSV(columns, columnLen int) (sv.RowSV, sv.RowSV) { } func rndSameRawSV(columnLen int) (sv.ColumnRaw, sv.ColumnRaw) { - out1 := []byte(utils.RandString(rnd, columnLen)) - out2 := make(sv.ColumnRaw, columnLen) - copy(out2, out1) + out1 := sv.ColumnRaw(utils.RandString(rnd, columnLen)) + out2 := out1 return out1, out2 } func rndSameRaw(columnLen int) (mv.ColumnRaw, mv.ColumnRaw) { - out1 := []byte(utils.RandString(rnd, columnLen)) - out2 := make(mv.ColumnRaw, columnLen) - copy(out2, out1) + out1 := mv.ColumnRaw(utils.RandString(rnd, columnLen)) + out2 := out1 return out1, out2 } diff --git a/pkg/store/cqlstore.go b/pkg/store/cqlstore.go index 34f8042..e6ed7ea 100644 --- a/pkg/store/cqlstore.go +++ b/pkg/store/cqlstore.go @@ -92,21 +92,21 @@ func (cs *cqlStore) doMutate(ctx context.Context, builder qb.Builder, ts time.Ti return nil } -func (cs *cqlStore) loadSV(ctx context.Context, builder qb.Builder, values []interface{}) (sv.Result, error) { +func (cs *cqlStore) loadSingleVersion(ctx context.Context, builder qb.Builder, values []interface{}) (sv.Result, error) { query, _ := builder.ToCql() iter := cs.session.Query(query, values...).WithContext(ctx).Iter() cs.ops.WithLabelValues(cs.system, opType(builder)).Inc() return sv.GetResult(iter), iter.Close() } -func (cs *cqlStore) loadMV(ctx context.Context, builder qb.Builder, values []interface{}) (mv.Result, error) { +func (cs *cqlStore) loadMultiVersion(ctx context.Context, builder qb.Builder, values []interface{}) (mv.Result, error) { query, _ := builder.ToCql() iter := cs.session.Query(query, values...).WithContext(ctx).Iter() cs.ops.WithLabelValues(cs.system, opType(builder)).Inc() return mv.GetResult(iter), iter.Close() } -func (cs *cqlStore) loadVerCheck(ctx context.Context, builder qb.Builder, values []interface{}) (mv.Result, error) { +func (cs *cqlStore) loadCheckVersion(ctx context.Context, builder qb.Builder, values []interface{}) (mv.Result, error) { query, _ := builder.ToCql() iter := cs.session.Query(query, values...).WithContext(ctx).Iter() cs.ops.WithLabelValues(cs.system, opType(builder)).Inc() diff --git a/pkg/store/mv/c_list.go b/pkg/store/mv/c_list.go index fcf8eef..e0d6468 100644 --- a/pkg/store/mv/c_list.go +++ b/pkg/store/mv/c_list.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,8 +35,7 @@ func (l List) ToString(colInfo gocql.TypeInfo) string { for idx := range l { out += fmt.Sprintf("%d:%s;", idx, l[idx].ToString(listInfo.Elem)) } - out = out[:len(out)-1] - return out + ">" + return out[:len(out)-1] + ">" } func (l List) ToStringRaw() string { @@ -47,8 +46,7 @@ func (l List) ToStringRaw() string { for idx := range l { out += fmt.Sprintf("%d:%s;", idx, l[idx].ToStringRaw()) } - out = out[:len(out)-1] - return out + ">" + return out[:len(out)-1] + ">" } func (l List) EqualColumn(colT interface{}) bool { diff --git a/pkg/store/mv/c_list_test.go b/pkg/store/mv/c_list_test.go index 0cb90c7..e7608ae 100644 --- a/pkg/store/mv/c_list_test.go +++ b/pkg/store/mv/c_list_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -43,7 +43,8 @@ func TestList_UnmarshalCQL(t *testing.T) { expected, data := rndDataElems(elems, maxElemLen, old, true) // List initialization. testColumn := make(List, 1) - testColumn[0] = &ColumnRaw{} + tmp := ColumnRaw("") + testColumn[0] = &tmp // Unmarshall. if old { err = testColumn.unmarshalOld(gocql.CollectionType{}, data) @@ -56,7 +57,7 @@ func TestList_UnmarshalCQL(t *testing.T) { t.Fatalf("%s error:%s", errorMsg, err) } // With correction needed, because List and Map initialization required fist elem - if len(expected) == 0 && len(testColumn) == 1 && testColumn[0].EqualColumn(ColumnRaw{}) { + if len(expected) == 0 && len(testColumn) == 1 && testColumn[0].EqualColumn(ColumnRaw("")) { continue } if len(testColumn) != len(expected) { @@ -83,8 +84,9 @@ func TestList_Equal(t *testing.T) { if !testColumn1.EqualElem(&testColumn2) { t.Fatal("List.EqualElem should return true") } + tmp := ColumnRaw("123") testColumn2 = []Elem{ - &ColumnRaw{1, 2, 3}, + &tmp, } // EqualColumn test on unequal if testColumn1.EqualColumn(testColumn2) { diff --git a/pkg/store/mv/c_map.go b/pkg/store/mv/c_map.go index 34a40b0..9c1f8a0 100644 --- a/pkg/store/mv/c_map.go +++ b/pkg/store/mv/c_map.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,8 +35,7 @@ func (m Map) ToString(colInfo gocql.TypeInfo) string { for idx := range m.Keys { out += fmt.Sprintf("%s:%s;", m.Keys[idx].ToString(mapInfo.Key), m.Values[idx].ToString(mapInfo.Elem)) } - out = out[:len(out)-1] - return out + ")" + return out[:len(out)-1] + ">" } func (m Map) ToStringRaw() string { @@ -47,8 +46,7 @@ func (m Map) ToStringRaw() string { for idx := range m.Keys { out += fmt.Sprintf("key%d%s:value%s;", idx, m.Keys[idx].ToStringRaw(), m.Values[idx].ToStringRaw()) } - out = out[:len(out)-1] - return out + ")" + return out[:len(out)-1] + ">" } func (m Map) EqualColumn(colT interface{}) bool { diff --git a/pkg/store/mv/c_map_test.go b/pkg/store/mv/c_map_test.go index 36ab1b9..2aa80da 100644 --- a/pkg/store/mv/c_map_test.go +++ b/pkg/store/mv/c_map_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,8 +45,10 @@ func TestMap_UnmarshalCQL(t *testing.T) { // Map initialization. testColumn.Keys = make([]Elem, 1) testColumn.Values = make([]Elem, 1) - testColumn.Keys[0] = &ColumnRaw{} - testColumn.Values[0] = &ColumnRaw{} + tmpKey := ColumnRaw("") + tmpValue := ColumnRaw("") + testColumn.Keys[0] = &tmpKey + testColumn.Values[0] = &tmpValue // Unmarshall. if old { err = testColumn.oldUnmarshalCQL(gocql.CollectionType{}, data) @@ -95,8 +97,9 @@ func TestMap_Equal(t *testing.T) { } // Corrupt values + tmp := ColumnRaw("123") testColumn2.Values = []Elem{ - &ColumnRaw{1, 2, 3}, + &tmp, } // EqualColumn test on unequal if testColumn1.EqualColumn(testColumn2) { @@ -110,7 +113,7 @@ func TestMap_Equal(t *testing.T) { // Corrupt keys testColumn1.Values, testColumn2.Values = rndSameElems(testCeases[i].elems, testCeases[i].elemLen) testColumn2.Keys = []Elem{ - &ColumnRaw{1, 2, 3}, + &tmp, } // EqualColumn test on unequal if testColumn1.EqualColumn(testColumn2) { diff --git a/pkg/store/mv/c_raw.go b/pkg/store/mv/c_raw.go index 1e7a558..1690bc6 100644 --- a/pkg/store/mv/c_raw.go +++ b/pkg/store/mv/c_raw.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,19 +16,20 @@ package mv import ( "fmt" + "unsafe" "github.com/gocql/gocql" ) // ColumnRaw for most cases. -type ColumnRaw []byte +type ColumnRaw string func (col ColumnRaw) ToString(colInfo gocql.TypeInfo) string { if len(col) == 0 { return "" } tmpVal := colInfo.New() - if err := gocql.Unmarshal(colInfo, col, tmpVal); err != nil { + if err := gocql.Unmarshal(colInfo, unsafe.Slice(unsafe.StringData((string)(col)), len(col)), tmpVal); err != nil { panic(err) } out := fmt.Sprintf("%v", dereference(tmpVal)) @@ -49,49 +50,28 @@ func (col ColumnRaw) ToString(colInfo gocql.TypeInfo) string { } func (col ColumnRaw) ToStringRaw() string { - return fmt.Sprint(col) + return fmt.Sprint(unsafe.Slice(unsafe.StringData((string)(col)), len(col))) } func (col ColumnRaw) EqualColumn(colT interface{}) bool { col2, ok := colT.(ColumnRaw) - if len(col) != len(col2) || !ok { - // Columns len are different - means columns are unequal + if !ok { return false } - if len(col) < 1 { - // Columns len==0 and same - means columns are equal - // Conditions "<" or ">" works faster that "==" - return true - } - for idx := range col { - if col[idx] != col2[idx] { - return false - } - } - return true + return col == col2 } func (col ColumnRaw) EqualElem(colT interface{}) bool { col2, ok := colT.(*ColumnRaw) - if len(col) != len(*col2) || !ok { + if !ok { // Columns len are different - means columns are unequal return false } - if len(col) < 1 { - // Columns len==0 and same - means columns are equal - // Conditions "<" or ">" works faster that "==" - return true - } - for idx := range col { - if col[idx] != (*col2)[idx] { - return false - } - } - return true + return col == *col2 } func (col ColumnRaw) NewSameColumn() Column { - return ColumnRaw{} + return ColumnRaw("") } func (col ColumnRaw) ToUnmarshal() interface{} { @@ -99,13 +79,14 @@ func (col ColumnRaw) ToUnmarshal() interface{} { } func (col ColumnRaw) NewSameElem() Elem { - return &ColumnRaw{} + tmp := ColumnRaw("") + return &tmp } func (col *ColumnRaw) UnmarshalCQL(_ gocql.TypeInfo, data []byte) error { if len(data) > 0 { // Puts data without copying - *col = data + *col = (ColumnRaw)(unsafe.String(&data[0], len(data))) } return nil } diff --git a/pkg/store/mv/c_raw_test.go b/pkg/store/mv/c_raw_test.go index e48529b..f5ccdd1 100644 --- a/pkg/store/mv/c_raw_test.go +++ b/pkg/store/mv/c_raw_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,28 +25,28 @@ import ( func TestColumnRaw_UnmarshalCQL(t *testing.T) { errorMsg := "wrong ColumnRaw.UnmarshalCQL work:" - testColumn := make(ColumnRaw, 0) + testColumn := ColumnRaw("") testsCount := 1000 for i := 0; i < testsCount; i++ { expected := utils.RandBytes(rnd, rnd.Intn(1000)) if i == 0 { - expected = ColumnRaw{} + expected = make([]byte, 0) } _ = testColumn.UnmarshalCQL(nil, expected) if !reflect.DeepEqual(expected, ([]byte)(testColumn)) { t.Fatalf("%s\nreceived:%+v \nexpected:%+v", errorMsg, testColumn, expected) } - testColumn = make(ColumnRaw, 0) + testColumn = ColumnRaw("") } } func TestColumnRaw_Equal(t *testing.T) { - testColumn1 := make(ColumnRaw, 0) - testColumn2 := make(ColumnRaw, 0) + testColumn1 := ColumnRaw("") + testColumn2 := ColumnRaw("") tests := []ColumnRaw{ - utils.RandBytes(rnd, rnd.Intn(1000)), - []byte{}, + ColumnRaw(utils.RandBytes(rnd, rnd.Intn(1000))), + ColumnRaw(""), } for i := range tests { testColumn1 = tests[i] @@ -59,7 +59,7 @@ func TestColumnRaw_Equal(t *testing.T) { if !testColumn1.EqualElem(&testColumn2) { t.Fatal("ColumnRaw.EqualElem should return true") } - testColumn2 = utils.RandBytes(rnd, rnd.Intn(30)) + testColumn2 = ColumnRaw(utils.RandBytes(rnd, rnd.Intn(30))) // EqualColumn test on unequal if testColumn1.EqualColumn(testColumn2) { t.Fatal("ColumnRaw.EqualColumn should return false") diff --git a/pkg/store/mv/c_tuple.go b/pkg/store/mv/c_tuple.go index 27e7164..e00c034 100644 --- a/pkg/store/mv/c_tuple.go +++ b/pkg/store/mv/c_tuple.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -32,8 +32,7 @@ func (t Tuple) ToString(colInfo gocql.TypeInfo) string { for i, elem := range tuple.Elems { out += fmt.Sprintf("%d:%s;", i, t[i].ToString(elem)) } - out = out[:len(out)-1] - return out + ">" + return out[:len(out)-1] + ">" } func (t Tuple) ToStringRaw() string { @@ -44,8 +43,7 @@ func (t Tuple) ToStringRaw() string { for i := range t { out += fmt.Sprintf("%d:%s;", i, t[i].ToStringRaw()) } - out = out[:len(out)-1] - return out + ">" + return out[:len(out)-1] + ">" } func (t Tuple) EqualColumn(colT interface{}) bool { diff --git a/pkg/store/mv/c_tuple_test.go b/pkg/store/mv/c_tuple_test.go index 69b6405..5878c9e 100644 --- a/pkg/store/mv/c_tuple_test.go +++ b/pkg/store/mv/c_tuple_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,8 @@ func TestTuple_UnmarshalCQL(t *testing.T) { // Tuple initialization. testColumn := make(Tuple, elems) for idx := range testColumn { - testColumn[idx] = &ColumnRaw{} + tmp := ColumnRaw("") + testColumn[idx] = &tmp } // Unmarshall. err := testColumn.UnmarshalCQL(gocql.TupleTypeInfo{Elems: make([]gocql.TypeInfo, elems)}, data) @@ -71,8 +72,9 @@ func TestTuple_Equal(t *testing.T) { if !testColumn1.EqualElem(&testColumn2) { t.Fatal("Tuple.EqualElem should return true") } + tmp := ColumnRaw("123") testColumn2 = []Elem{ - &ColumnRaw{1, 2, 3}, + &tmp, } // EqualColumn test on unequal if testColumn1.EqualColumn(testColumn2) { diff --git a/pkg/store/mv/c_udt.go b/pkg/store/mv/c_udt.go index d3964c6..53137da 100644 --- a/pkg/store/mv/c_udt.go +++ b/pkg/store/mv/c_udt.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -36,8 +36,7 @@ func (u UDT) ToString(colInfo gocql.TypeInfo) string { for idx := range u.Values { out += u.pairToString(idx, udt.Elements[idx].Type) } - out = out[:len(out)-1] - return out + ">" + return out[:len(out)-1] + ">" } func (u UDT) pairToString(idx int, colType gocql.TypeInfo) string { @@ -52,8 +51,7 @@ func (u UDT) ToStringRaw() string { for idx := range u.Values { out += u.pairToStringRaw(idx) } - out = out[:len(out)-1] - return out + ">" + return out[:len(out)-1] + ">" } func (u UDT) pairToStringRaw(idx int) string { diff --git a/pkg/store/mv/c_udt_test.go b/pkg/store/mv/c_udt_test.go index f9dafaf..154e9b5 100644 --- a/pkg/store/mv/c_udt_test.go +++ b/pkg/store/mv/c_udt_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,7 +39,8 @@ func TestUDT_UnmarshalCQL(t *testing.T) { testColumn.Names = make([]string, elems) testColumn.Values = make([]Elem, elems) for idx := range testColumn.Values { - testColumn.Values[idx] = &ColumnRaw{} + tmp := ColumnRaw("") + testColumn.Values[idx] = &tmp } // Unmarshall. err := testColumn.UnmarshalCQL(gocql.UDTTypeInfo{Elements: make([]gocql.UDTField, elems)}, data) @@ -74,8 +75,9 @@ func TestUDT_Equal(t *testing.T) { t.Fatal("UDT.EqualElem should return true") } // Corrupt values + tmp := ColumnRaw("123") testColumn2.Values = []Elem{ - &ColumnRaw{1, 2, 3}, + &tmp, } // EqualColumn test on unequal if testColumn1.EqualColumn(testColumn2) { diff --git a/pkg/store/mv/delete_equal_test.go b/pkg/store/mv/delete_equal_test.go index 1147580..0ebf9ac 100644 --- a/pkg/store/mv/delete_equal_test.go +++ b/pkg/store/mv/delete_equal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/init_column.go b/pkg/store/mv/init_column.go index 87ff847..b2590fc 100644 --- a/pkg/store/mv/init_column.go +++ b/pkg/store/mv/init_column.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import "github.com/gocql/gocql" // So initColumn checks all these cases and returns right Column implementation. func initColumn(colType gocql.TypeInfo) Column { if !haveCollection(colType) { - return ColumnRaw{} + return ColumnRaw("") } switch colType.Type() { @@ -57,7 +57,7 @@ func initColumn(colType gocql.TypeInfo) Column { } return udt default: - return ColumnRaw{} + return ColumnRaw("") } } @@ -87,7 +87,8 @@ func haveCollection(typeInfo gocql.TypeInfo) bool { // initElem returns Elem implementation for the specified type. func initElem(elemType gocql.TypeInfo) Elem { if !haveCollection(elemType) { - return &ColumnRaw{} + tmp := ColumnRaw("") + return &tmp } switch elemType.Type() { @@ -121,6 +122,7 @@ func initElem(elemType gocql.TypeInfo) Elem { } return &udt default: - return &ColumnRaw{} + tmp := ColumnRaw("") + return &tmp } } diff --git a/pkg/store/mv/interface.go b/pkg/store/mv/interface.go index 5bb77fb..679b09c 100644 --- a/pkg/store/mv/interface.go +++ b/pkg/store/mv/interface.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/result.go b/pkg/store/mv/result.go index 3011bd4..dcc4146 100644 --- a/pkg/store/mv/result.go +++ b/pkg/store/mv/result.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/results.go b/pkg/store/mv/results.go index 0e68c4f..0becb15 100644 --- a/pkg/store/mv/results.go +++ b/pkg/store/mv/results.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/row.go b/pkg/store/mv/row.go index d2b79ac..666db2d 100644 --- a/pkg/store/mv/row.go +++ b/pkg/store/mv/row.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/rows.go b/pkg/store/mv/rows.go index 326b44f..6ce726c 100644 --- a/pkg/store/mv/rows.go +++ b/pkg/store/mv/rows.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/utils.go b/pkg/store/mv/utils.go index 2327715..ba8255c 100644 --- a/pkg/store/mv/utils.go +++ b/pkg/store/mv/utils.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/mv/utils_4test.go b/pkg/store/mv/utils_4test.go index 852ab97..92edf42 100644 --- a/pkg/store/mv/utils_4test.go +++ b/pkg/store/mv/utils_4test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -88,8 +88,10 @@ func rndDataElemsMap(elems, elemLenMax int, old bool) ([]Elem, []Elem, []byte) { } if elems < 1 { // With correction needed, because List and Map initialization required fist elem. - outKeys = append(outKeys, &ColumnRaw{}) - outValues = append(outValues, &ColumnRaw{}) + tmpKey := ColumnRaw("") + tmpValue := ColumnRaw("") + outKeys = append(outKeys, &tmpKey) + outValues = append(outValues, &tmpValue) } return outKeys, outValues, outData } @@ -97,8 +99,7 @@ func rndDataElemsMap(elems, elemLenMax int, old bool) ([]Elem, []Elem, []byte) { func rndRow(columns, columnLen int) RowMV { out := make(RowMV, columns) for idx := range out { - col := utils.RandBytes(rnd, columnLen) - out[idx] = *(*ColumnRaw)(&col) + out[idx] = ColumnRaw(utils.RandBytes(rnd, columnLen)) } return out } @@ -133,12 +134,8 @@ func rndSameRow(columns, columnLen int) (RowMV, RowMV) { } func rndSameRaw(columnLen int) (ColumnRaw, ColumnRaw) { - out1 := make(ColumnRaw, columnLen) - for idx := range out1 { - out1[idx] = byte(rnd.Intn(256)) - } - out2 := make(ColumnRaw, columnLen) - copy(out2, out1) + out1 := ColumnRaw(utils.RandBytes(rnd, columnLen)) + out2 := out1 return out1, out2 } diff --git a/pkg/store/store.go b/pkg/store/store.go index ed945ba..c3feeb0 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -38,9 +38,9 @@ import ( var errorResponseDiffer = errors.New("response from test and oracle store have difference") type loader interface { - loadSV(context.Context, qb.Builder, []interface{}) (sv.Result, error) - loadMV(context.Context, qb.Builder, []interface{}) (mv.Result, error) - loadVerCheck(context.Context, qb.Builder, []interface{}) (mv.Result, error) + loadSingleVersion(context.Context, qb.Builder, []interface{}) (sv.Result, error) + loadMultiVersion(context.Context, qb.Builder, []interface{}) (mv.Result, error) + loadCheckVersion(context.Context, qb.Builder, []interface{}) (mv.Result, error) } type storer interface { @@ -128,15 +128,15 @@ func (n *noOpStore) mutate(context.Context, qb.Builder, ...interface{}) error { return nil } -func (n *noOpStore) loadSV(context.Context, qb.Builder, []interface{}) (sv.Result, error) { +func (n *noOpStore) loadSingleVersion(context.Context, qb.Builder, []interface{}) (sv.Result, error) { return sv.Result{}, nil } -func (n *noOpStore) loadMV(context.Context, qb.Builder, []interface{}) (mv.Result, error) { +func (n *noOpStore) loadMultiVersion(context.Context, qb.Builder, []interface{}) (mv.Result, error) { return mv.Result{}, nil } -func (n *noOpStore) loadVerCheck(context.Context, qb.Builder, []interface{}) (mv.Result, error) { +func (n *noOpStore) loadCheckVersion(context.Context, qb.Builder, []interface{}) (mv.Result, error) { return mv.Result{}, nil } @@ -207,26 +207,26 @@ func (ds delegatingStore) Check(ctx context.Context, _ *typedef.Table, builder q case ver.Check.ModeSV(): resultsSV := sv.Results{} go func() { - resultsSV.Test, testErr = ds.testStore.loadSV(ctx, builder, values) + resultsSV.Test, testErr = ds.testStore.loadSingleVersion(ctx, builder, values) wg.Done() }() - resultsSV.Oracle, oracleErr = ds.oracleStore.loadSV(ctx, builder, values) + resultsSV.Oracle, oracleErr = ds.oracleStore.loadSingleVersion(ctx, builder, values) results = &resultsSV case ver.Check.Done(): resultsMV := mv.Results{} go func() { - resultsMV.Test, testErr = ds.testStore.loadMV(ctx, builder, values) + resultsMV.Test, testErr = ds.testStore.loadMultiVersion(ctx, builder, values) wg.Done() }() - resultsMV.Oracle, oracleErr = ds.oracleStore.loadMV(ctx, builder, values) + resultsMV.Oracle, oracleErr = ds.oracleStore.loadMultiVersion(ctx, builder, values) results = &resultsMV default: resultsMV := mv.Results{} go func() { - resultsMV.Test, testErr = ds.testStore.loadVerCheck(ctx, builder, values) + resultsMV.Test, testErr = ds.testStore.loadCheckVersion(ctx, builder, values) wg.Done() }() - resultsMV.Oracle, oracleErr = ds.oracleStore.loadVerCheck(ctx, builder, values) + resultsMV.Oracle, oracleErr = ds.oracleStore.loadCheckVersion(ctx, builder, values) results = &resultsMV } if oracleErr != nil { diff --git a/pkg/store/sv/delete_equal_test.go b/pkg/store/sv/delete_equal_test.go index f5db7e8..97de45f 100644 --- a/pkg/store/sv/delete_equal_test.go +++ b/pkg/store/sv/delete_equal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -132,8 +132,7 @@ func getRandomRawRows(rowsCount, columns, columnLen int) RowsSV { func rndRow(columns, columnLen int) RowSV { out := make(RowSV, columns) for idx := range out { - col := utils.RandBytes(rnd, columnLen) - out[idx] = *(*ColumnRaw)(&col) + out[idx] = ColumnRaw(utils.RandBytes(rnd, columnLen)) } return out } diff --git a/pkg/store/sv/raw.go b/pkg/store/sv/raw.go index 5ac5b055..ea09468 100644 --- a/pkg/store/sv/raw.go +++ b/pkg/store/sv/raw.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,19 +17,20 @@ package sv import ( "fmt" "reflect" + "unsafe" "github.com/gocql/gocql" ) // ColumnRaw for most cases. -type ColumnRaw []byte +type ColumnRaw string func (col ColumnRaw) ToString(colInfo gocql.TypeInfo) string { if len(col) == 0 { return "" } tmpVal := colInfo.New() - if err := gocql.Unmarshal(colInfo, col, tmpVal); err != nil { + if err := gocql.Unmarshal(colInfo, unsafe.Slice(unsafe.StringData((string)(col)), len(col)), tmpVal); err != nil { panic(err) } out := fmt.Sprintf("%v", reflect.Indirect(reflect.ValueOf(tmpVal)).Interface()) @@ -50,7 +51,7 @@ func (col ColumnRaw) ToString(colInfo gocql.TypeInfo) string { } func (col ColumnRaw) ToStringRaw() string { - return fmt.Sprint(col) + return fmt.Sprint(unsafe.Slice(unsafe.StringData((string)(col)), len(col))) } func (col ColumnRaw) ToInterface() interface{} { @@ -60,7 +61,7 @@ func (col ColumnRaw) ToInterface() interface{} { func (col *ColumnRaw) UnmarshalCQL(_ gocql.TypeInfo, data []byte) error { if len(data) > 0 { // Puts data without copying - *col = data + *col = (ColumnRaw)(unsafe.String(&data[0], len(data))) } return nil } diff --git a/pkg/store/sv/raw_test.go b/pkg/store/sv/raw_test.go index 331b03d..416af31 100644 --- a/pkg/store/sv/raw_test.go +++ b/pkg/store/sv/raw_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,18 +25,18 @@ import ( func TestColumnRaw_UnmarshalCQL(t *testing.T) { errorMsg := "wrong ColumnRaw.UnmarshalCQL work:" - testColumn := make(ColumnRaw, 0) + var testColumn ColumnRaw testsCount := 1000 for i := 0; i < testsCount; i++ { expected := utils.RandBytes(rnd, rnd.Intn(1000)) if i == 0 { - expected = ColumnRaw{} + expected = make([]byte, 0) } _ = testColumn.UnmarshalCQL(nil, expected) if !reflect.DeepEqual(expected, ([]byte)(testColumn)) { t.Fatalf("%s\nreceived:%+v \nexpected:%+v", errorMsg, testColumn, expected) } - testColumn = make(ColumnRaw, 0) + testColumn = "" } } diff --git a/pkg/store/sv/result.go b/pkg/store/sv/result.go index d58f2c0..00bd7d8 100644 --- a/pkg/store/sv/result.go +++ b/pkg/store/sv/result.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/sv/results.go b/pkg/store/sv/results.go index 3b66880..7e35f10 100644 --- a/pkg/store/sv/results.go +++ b/pkg/store/sv/results.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/sv/row.go b/pkg/store/sv/row.go index f191024..66d9464 100644 --- a/pkg/store/sv/row.go +++ b/pkg/store/sv/row.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -50,17 +50,9 @@ func (row RowSV) Equal(row2 RowSV) bool { return true } for idx := range row { - if len(row[idx]) != len(row2[idx]) { + if row[idx] != row2[idx] { return false } - if len(row[idx]) < 1 { - continue - } - for id := range row[idx] { - if row[idx][id] != row2[idx][id] { - return false - } - } } return true } diff --git a/pkg/store/sv/rows.go b/pkg/store/sv/rows.go index 6750505..b6aeb12 100644 --- a/pkg/store/sv/rows.go +++ b/pkg/store/sv/rows.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/ver/check.go b/pkg/store/ver/check.go index c2fc69b..24c5beb 100644 --- a/pkg/store/ver/check.go +++ b/pkg/store/ver/check.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/store/ver/check_test.go b/pkg/store/ver/check_test.go index 373ac47..b3ab819 100644 --- a/pkg/store/ver/check_test.go +++ b/pkg/store/ver/check_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 ScyllaDB +// Copyright 2023 ScyllaDB // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.