Skip to content

Commit

Permalink
Epic Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Feb 17, 2021
1 parent 98a7bf5 commit f980df7
Show file tree
Hide file tree
Showing 185 changed files with 5,131 additions and 5,271 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ PLAN.todo
.travis/badwan.ldif
.travis/access.ldif
tools/
cmd/
cmd/
.revive.toml
Makefile
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Change History

## February 16 2021: v4.3.0
## February 15 2021: v4.3.0
Minor fix and major clean up release. While there aren't many user facing changes, the quality of the code has been markedly improved.
This release puts us on a good footing for the next few bigger releases.

* **Fixes**

- Fixes an issue where if errors and filtered records happened at the msame time in Batch requests, no error would be returned to the user.

* **Improvements**

- Fixes copy/paste naming errors in the documentation. Shame on me! Thanks to [Yevgeny Rizhkov](https://github.com/reugn)
- Fixes code samples in documentation, typos, etc.
- Fixes copy/paste naming errors in the documentation. Thanks to [Yevgeny Rizhkov](https://github.com/reugn)
- Removes a few unreachable lines from the code. Thanks to [Yevgeny Rizhkov](https://github.com/reugn)

## February 12 2021: v4.2.0
Expand Down
40 changes: 18 additions & 22 deletions admin_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"fmt"
"time"

// . "github.com/aerospike/aerospike-client-go/logger"
"github.com/aerospike/aerospike-client-go/pkg/bcrypt"
. "github.com/aerospike/aerospike-client-go/types"
"github.com/aerospike/aerospike-client-go/types"
Buffer "github.com/aerospike/aerospike-client-go/utils/buffer"
)

Expand Down Expand Up @@ -263,7 +262,7 @@ func (acmd *adminCommand) writePrivileges(privileges []Privilege) error {
if privilege.canScope() {

if len(privilege.SetName) > 0 && len(privilege.Namespace) == 0 {
return NewAerospikeError(INVALID_PRIVILEGE, fmt.Sprintf("Admin privilege '%v' has a set scope with an empty namespace.", privilege))
return types.NewAerospikeError(types.INVALID_PRIVILEGE, fmt.Sprintf("Admin privilege '%v' has a set scope with an empty namespace.", privilege))
}

acmd.dataBuffer[offset] = byte(len(privilege.Namespace))
Expand All @@ -277,7 +276,7 @@ func (acmd *adminCommand) writePrivileges(privileges []Privilege) error {
offset += len(privilege.SetName)
} else {
if len(privilege.Namespace) > 0 || len(privilege.SetName) > 0 {
return NewAerospikeError(INVALID_PRIVILEGE, fmt.Sprintf("Admin global rivilege '%v' can't have a namespace or set.", privilege))
return types.NewAerospikeError(types.INVALID_PRIVILEGE, fmt.Sprintf("Admin global rivilege '%v' can't have a namespace or set.", privilege))
}
}
}
Expand Down Expand Up @@ -360,25 +359,22 @@ func (acmd *adminCommand) executeCommand(cluster *Cluster, policy *AdminPolicy)
node.tendConnLock.Lock()
defer node.tendConnLock.Unlock()

if err := node.initTendConn(timeout); err != nil {
if err = node.initTendConn(timeout); err != nil {
return err
}

conn := node.tendConn
if _, err := conn.Write(acmd.dataBuffer[:acmd.dataOffset]); err != nil {
return err
}
if err != nil {
if _, err = conn.Write(acmd.dataBuffer[:acmd.dataOffset]); err != nil {
return err
}

if _, err := conn.Read(acmd.dataBuffer, _HEADER_SIZE); err != nil {
if _, err = conn.Read(acmd.dataBuffer, _HEADER_SIZE); err != nil {
return err
}

result := acmd.dataBuffer[_RESULT_CODE]
if result != 0 {
return NewAerospikeError(ResultCode(result))
return types.NewAerospikeError(types.ResultCode(result))
}

return nil
Expand All @@ -398,12 +394,12 @@ func (acmd *adminCommand) readUsers(cluster *Cluster, policy *AdminPolicy) ([]*U
node.tendConnLock.Lock()
defer node.tendConnLock.Unlock()

if err := node.initTendConn(timeout); err != nil {
if err = node.initTendConn(timeout); err != nil {
return nil, err
}

conn := node.tendConn
if _, err := conn.Write(acmd.dataBuffer[:acmd.dataOffset]); err != nil {
if _, err = conn.Write(acmd.dataBuffer[:acmd.dataOffset]); err != nil {
return nil, err
}

Expand All @@ -413,7 +409,7 @@ func (acmd *adminCommand) readUsers(cluster *Cluster, policy *AdminPolicy) ([]*U
}

if status > 0 {
return nil, NewAerospikeError(ResultCode(status))
return nil, types.NewAerospikeError(types.ResultCode(status))
}
return list, nil
}
Expand Down Expand Up @@ -468,19 +464,19 @@ func (acmd *adminCommand) parseUsers(receiveSize int) (int, []*UserRoles, error)
acmd.dataOffset += _HEADER_REMAINING

for i := 0; i < fieldCount; i++ {
len := int(Buffer.BytesToInt32(acmd.dataBuffer, acmd.dataOffset))
flen := int(Buffer.BytesToInt32(acmd.dataBuffer, acmd.dataOffset))
acmd.dataOffset += 4
id := acmd.dataBuffer[acmd.dataOffset]
acmd.dataOffset++
len--
flen--

if id == _USER {
userRoles.User = string(acmd.dataBuffer[acmd.dataOffset : acmd.dataOffset+len])
acmd.dataOffset += len
userRoles.User = string(acmd.dataBuffer[acmd.dataOffset : acmd.dataOffset+flen])
acmd.dataOffset += flen
} else if id == _ROLES {
acmd.parseRoles(userRoles)
} else {
acmd.dataOffset += len
acmd.dataOffset += flen
}
}

Expand Down Expand Up @@ -535,12 +531,12 @@ func (acmd *adminCommand) readRoles(cluster *Cluster, policy *AdminPolicy) ([]*R
node.tendConnLock.Lock()
defer node.tendConnLock.Unlock()

if err := node.initTendConn(timeout); err != nil {
if err = node.initTendConn(timeout); err != nil {
return nil, err
}

conn := node.tendConn
if _, err := conn.Write(acmd.dataBuffer[:acmd.dataOffset]); err != nil {
if _, err = conn.Write(acmd.dataBuffer[:acmd.dataOffset]); err != nil {
return nil, err
}

Expand All @@ -550,7 +546,7 @@ func (acmd *adminCommand) readRoles(cluster *Cluster, policy *AdminPolicy) ([]*R
}

if status > 0 {
return nil, NewAerospikeError(ResultCode(status))
return nil, types.NewAerospikeError(types.ResultCode(status))
}
return list, nil
}
Expand Down
16 changes: 8 additions & 8 deletions aerospike_bench_reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ package aerospike_test
import (
"runtime"

. "github.com/aerospike/aerospike-client-go"
as "github.com/aerospike/aerospike-client-go"

"testing"
)

func benchGetObj(times int, client *Client, key *Key, obj interface{}) {
func benchGetObj(times int, client *as.Client, key *as.Key, obj interface{}) {
for i := 0; i < times; i++ {
if err = client.GetObject(nil, key, obj); err != nil {
panic(err)
}
}
}

func benchPutObj(times int, client *Client, key *Key, wp *WritePolicy, obj interface{}) {
func benchPutObj(times int, client *as.Client, key *as.Key, wp *as.WritePolicy, obj interface{}) {
for i := 0; i < times; i++ {
if err = client.PutObject(wp, key, obj); err != nil {
panic(err)
Expand All @@ -41,12 +41,12 @@ func benchPutObj(times int, client *Client, key *Key, wp *WritePolicy, obj inter
}

func Benchmark_GetObject(b *testing.B) {
client, err := NewClientWithPolicy(clientPolicy, *host, *port)
client, err := as.NewClientWithPolicy(clientPolicy, *host, *port)
if err != nil {
b.Fail()
}

key, _ := NewKey(*namespace, "databases", "Aerospike")
key, _ := as.NewKey(*namespace, "databases", "Aerospike")

obj := &OBJECT{198, "Jack Shaftoe and Company", []int64{1, 2, 3, 4, 5, 6}}
client.PutObject(nil, key, obj)
Expand All @@ -58,15 +58,15 @@ func Benchmark_GetObject(b *testing.B) {
}

func Benchmark_PutObject(b *testing.B) {
client, err := NewClient(*host, *port)
client, err := as.NewClient(*host, *port)
if err != nil {
b.Fail()
}

// obj := &OBJECT{198, "Jack Shaftoe and Company", []byte(bytes.Repeat([]byte{32}, 1000))}
obj := &OBJECT{198, "Jack Shaftoe and Company", []int64{1, 2, 3, 4, 5, 6}}
key, _ := NewKey(*namespace, "databases", "Aerospike")
writepolicy := NewWritePolicy(0, 0)
key, _ := as.NewKey(*namespace, "databases", "Aerospike")
writepolicy := as.NewWritePolicy(0, 0)

b.N = 100
runtime.GC()
Expand Down
40 changes: 20 additions & 20 deletions aerospike_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package aerospike_test
import (
"runtime"

. "github.com/aerospike/aerospike-client-go"
as "github.com/aerospike/aerospike-client-go"

"testing"
)

var r *Record
var rs []*Record
var r *as.Record
var rs []*as.Record
var err error

type OBJECT struct {
Expand All @@ -33,26 +33,26 @@ type OBJECT struct {
Blob []int64
}

func benchGet(times int, client *Client, key *Key) {
func benchGet(times int, client *as.Client, key *as.Key) {
for i := 0; i < times; i++ {
if r, err = client.Get(nil, key); err != nil {
panic(err)
}
}
}

func benchBatchGet(times int, client *Client, keys []*Key) {
func benchBatchGet(times int, client *as.Client, keys []*as.Key) {
for i := 0; i < times; i++ {
if rs, err = client.BatchGet(nil, keys); err != nil {
panic(err)
}
}
}

func benchPut(times int, client *Client, key *Key, wp *WritePolicy) {
dbName := NewBin("dbname", "CouchDB")
price := NewBin("price", 0)
keywords := NewBin("keywords", []string{"concurrent", "fast"})
func benchPut(times int, client *as.Client, key *as.Key, wp *as.WritePolicy) {
dbName := as.NewBin("dbname", "CouchDB")
price := as.NewBin("price", 0)
keywords := as.NewBin("keywords", []string{"concurrent", "fast"})
for i := 0; i < times; i++ {
if err = client.PutBins(wp, key, dbName, price, keywords); err != nil {
panic(err)
Expand All @@ -61,17 +61,17 @@ func benchPut(times int, client *Client, key *Key, wp *WritePolicy) {
}

func Benchmark_Get(b *testing.B) {
client, err := NewClientWithPolicy(clientPolicy, *host, *port)
client, err := as.NewClientWithPolicy(clientPolicy, *host, *port)
if err != nil {
b.Fail()
}

key, _ := NewKey(*namespace, "test", "Aerospike")
key, _ := as.NewKey(*namespace, "test", "Aerospike")
// obj := &OBJECT{198, "Jack Shaftoe and Company", []byte(bytes.Repeat([]byte{32}, 1000))}
// obj := &OBJECT{198, "Jack Shaftoe and Company", []int64{1}}
client.Delete(nil, key)
client.PutBins(nil, key, NewBin("b", []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, "a", "b"}))
// client.PutBins(nil, key, NewBin("b", 1))
client.PutBins(nil, key, as.NewBin("b", []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, "a", "b"}))
// client.PutBins(nil, key, as.NewBin("b", 1))
// client.PutObject(nil, key, &obj)

b.N = 100
Expand All @@ -81,13 +81,13 @@ func Benchmark_Get(b *testing.B) {
}

func Benchmark_Put(b *testing.B) {
client, err := NewClient(*host, *port)
client, err := as.NewClient(*host, *port)
if err != nil {
b.Fail()
}

key, _ := NewKey(*namespace, "test", "Aerospike")
writepolicy := NewWritePolicy(0, 0)
key, _ := as.NewKey(*namespace, "test", "Aerospike")
writepolicy := as.NewWritePolicy(0, 0)

b.N = 100
runtime.GC()
Expand All @@ -96,15 +96,15 @@ func Benchmark_Put(b *testing.B) {
}

func Benchmark_BatchGet(b *testing.B) {
client, err := NewClientWithPolicy(clientPolicy, *host, *port)
client, err := as.NewClientWithPolicy(clientPolicy, *host, *port)
if err != nil {
b.Fail()
}

var keys []*Key
var keys []*as.Key
for i := 0; i < 10; i++ {
key, _ := NewKey(*namespace, "test", i)
if err := client.PutBins(nil, key, NewBin("b", 1)); err == nil {
key, _ := as.NewKey(*namespace, "test", i)
if err := client.PutBins(nil, key, as.NewBin("b", 1)); err == nil {
keys = append(keys, key)
}
}
Expand Down
17 changes: 11 additions & 6 deletions aerospike_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

as "github.com/aerospike/aerospike-client-go"
asl "github.com/aerospike/aerospike-client-go/logger"
ast "github.com/aerospike/aerospike-client-go/types"

gg "github.com/onsi/ginkgo"
gm "github.com/onsi/gomega"
)

var (
Expand Down Expand Up @@ -99,15 +99,20 @@ func initTestVars() {
}
}

func TestAerospike(t *testing.T) {
func TestMain(m *testing.M) {
rand.Seed(time.Now().UnixNano())
flag.Parse()

// setup the client object
initTestVars()
os.Exit(m.Run())
}

func TestAerospike(t *testing.T) {
// TestMain will be called here, no need to do more

RegisterFailHandler(Fail)
RunSpecs(t, "Aerospike Client Library Suite")
gm.RegisterFailHandler(gg.Fail)
gg.RunSpecs(t, "Aerospike Client Library Suite")
}

func featureEnabled(feature string) bool {
Expand Down
Loading

0 comments on commit f980df7

Please sign in to comment.