Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Client v7.6.0 #444

Merged
merged 15 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
run: go run github.com/onsi/ginkgo/v2/ginkgo build -tags="as_performance" .
- name: Build for Google App Engine (unsafe package removed)
run: go run github.com/onsi/ginkgo/v2/ginkgo build -tags="app_engine" .
- name: Build for DBAAS (proxy mode)
run: go run github.com/onsi/ginkgo/v2/ginkgo build -tags="as_proxy" .
- name: Run the tests
run: go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile=./cover_native.out -covermode=atomic -coverpkg=./... -race -keep-going -succinct -randomize-suites -skip="HyperLogLog"
- name: Combine Cover Profiles
Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

An Aerospike library for Go.

This library is compatible with Go 1.21+ and supports the following operating systems: Linux, Mac OS X (Windows builds are possible, but untested).
This library is compatible with Go 1.20+ and supports the following operating systems: Linux, Mac OS X (Windows builds are possible, but untested).

Up-to-date documentation is available in the [![Godoc](https://godoc.org/github.com/aerospike/aerospike-client-go/v7?status.svg)](https://pkg.go.dev/github.com/aerospike/aerospike-client-go/v7).

Expand All @@ -26,6 +26,7 @@ Please refer to [`CHANGELOG.md`](CHANGELOG.md) for release notes, or if you enco
- [API Documentation](#api-documentation)
- [Google App Engine](#google-app-engine)
- [Reflection, and Object API](#reflection-and-object-api)
- [Proxy Client / DBAAS](#proxy-client--dbaas)
- [License](#license)

## Usage
Expand Down Expand Up @@ -87,7 +88,7 @@ Details about the API are available in the [`docs`](docs) directory.
<a name="Prerequisites"></a>
## Prerequisites

[Go](http://golang.org) version v1.21+ is required.
[Go](http://golang.org) version v1.20+ is required.

To install the latest stable version of Go, visit
[http://golang.org/dl/](http://golang.org/dl/)
Expand Down Expand Up @@ -138,40 +139,46 @@ To run all the test cases with race detection:
$ ginkgo -r -race


<a name="Examples"></a>
<a name="examples"></a>
## Examples

A variety of example applications are provided in the [`examples`](examples) directory.

<a name="Tools"></a>
<a name="tools"></a>
### Tools

A variety of clones of original tools are provided in the [`tools`](tools) directory.
They show how to use more advanced features of the library to re-implement the same functionality in a more concise way.

<a name="Benchmarks"></a>
<a name="benchmarks"></a>
## Benchmarks

Benchmark utility is provided in the [`tools/benchmark`](tools/benchmark) directory.
See the [`tools/benchmark/README.md`](tools/benchmark/README.md) for details.

<a name="API-Documentation"></a>
<a name="api-documentation"></a>
## API Documentation

A simple API documentation is available in the [`docs`](docs/README.md) directory. The latest up-to-date docs can be found in [![Godoc](https://godoc.org/github.com/aerospike/aerospike-client-go?status.svg)](https://pkg.go.dev/github.com/aerospike/aerospike-client-go/v7).

<a name="App-Engine"></a>
<a name="google-app-engine"></a>
## Google App Engine

To build the library for App Engine, build it with the build tag `app_engine`. Aggregation functionality is not available in this build.


<a name="Reflection"></a>
<a name="reflection-and-object-api"></a>
## Reflection, and Object API

To make the library both flexible and fast, we had to integrate the reflection API (methods with `[Get/Put/...]Object` names) tightly in the library. In case you wanted to avoid mixing those API in your app inadvertently, you can use the build tag `as_performance` to remove those APIs from the build.


<a name="proxy-client--dbaas"></a>
## Proxy Client / DBAAS

To compile the client for the proxy server in out database as a service environment, pass `-tags as_proxy` to the compiler on build.
khaf marked this conversation as resolved.
Show resolved Hide resolved

<a name="license"></a>
## License

The Aerospike Go Client is made available under the terms of the Apache License, Version 2, as stated in the file `LICENSE`.
Expand Down
1 change: 0 additions & 1 deletion aerospike_bench_reflect_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance
// +build !as_performance

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
1 change: 0 additions & 1 deletion anonymous_fields_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance
// +build !as_performance

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
1 change: 0 additions & 1 deletion batch_command_get_reflect.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance
// +build !as_performance

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
67 changes: 0 additions & 67 deletions batch_command_operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
package aerospike

import (
"math/rand"
"reflect"

kvs "github.com/aerospike/aerospike-client-go/v7/proto/kvs"
"github.com/aerospike/aerospike-client-go/v7/types"
Buffer "github.com/aerospike/aerospike-client-go/v7/utils/buffer"
)
Expand Down Expand Up @@ -303,68 +301,3 @@ func (cmd *batchCommandOperate) transactionType() transactionType {
func (cmd *batchCommandOperate) generateBatchNodes(cluster *Cluster) ([]*batchNode, Error) {
return newBatchOperateNodeListIfcRetry(cluster, cmd.policy, cmd.records, cmd.sequenceAP, cmd.sequenceSC, cmd.batch)
}

func (cmd *batchCommandOperate) ExecuteGRPC(clnt *ProxyClient) Error {
defer cmd.grpcPutBufferBack()

err := cmd.prepareBuffer(cmd, cmd.policy.deadline())
if err != nil {
return err
}

req := kvs.AerospikeRequestPayload{
Id: rand.Uint32(),
Iteration: 1,
Payload: cmd.dataBuffer[:cmd.dataOffset],
ReadPolicy: cmd.policy.grpc(),
WritePolicy: cmd.policy.grpc_write(),
}

conn, err := clnt.grpcConn()
if err != nil {
return err
}

client := kvs.NewKVSClient(conn)

ctx, cancel := cmd.policy.grpcDeadlineContext()
defer cancel()

streamRes, gerr := client.BatchOperate(ctx, &req)
if gerr != nil {
return newGrpcError(!cmd.isRead(), gerr, gerr.Error())
}

cmd.commandWasSent = true

readCallback := func() ([]byte, Error) {
if cmd.grpcEOS {
return nil, errGRPCStreamEnd
}

res, gerr := streamRes.Recv()
if gerr != nil {
e := newGrpcError(!cmd.isRead(), gerr)
return nil, e
}

if res.GetStatus() != 0 {
e := newGrpcStatusError(res)
return res.GetPayload(), e
}

cmd.grpcEOS = !res.GetHasNext()

return res.GetPayload(), nil
}

cmd.conn = newGrpcFakeConnection(nil, readCallback)
err = cmd.parseResult(cmd, cmd.conn)
if err != nil && err != errGRPCStreamEnd {
return err
}

clnt.returnGrpcConnToPool(conn)

return nil
}
1 change: 0 additions & 1 deletion batch_command_reflect.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance
// +build !as_performance

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
12 changes: 0 additions & 12 deletions batch_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

package aerospike

import (
kvs "github.com/aerospike/aerospike-client-go/v7/proto/kvs"
)

// BatchPolicy encapsulates parameters for policy attributes used in write operations.
// This object is passed into methods where database writes can occur.
type BatchPolicy struct {
Expand Down Expand Up @@ -124,11 +120,3 @@ func (p *BatchPolicy) toWritePolicy() *WritePolicy {
}
return wp
}

func (p *BatchPolicy) grpc_write() *kvs.WritePolicy {
return &kvs.WritePolicy{
Replica: p.ReplicaPolicy.grpc(),
ReadModeSC: p.ReadModeSC.grpc(),
ReadModeAP: p.ReadModeAP.grpc(),
}
}
1 change: 0 additions & 1 deletion batch_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !app_engine
// +build !app_engine

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
1 change: 0 additions & 1 deletion cdt_map_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance && !app_engine
// +build !as_performance,!app_engine

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
12 changes: 0 additions & 12 deletions client_appengine_exclusions.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !app_engine
// +build !app_engine

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down Expand Up @@ -153,14 +152,3 @@ func (clnt *Client) QueryAggregate(policy *QueryPolicy, statement *Statement, pa

return recSet, nil
}

// QueryAggregate executes a Map/Reduce query and returns the results.
// The query executor puts records on the channel from separate goroutines.
// The caller can concurrently pop records off the channel through the
// Recordset.Records channel.
//
// This method is only supported by Aerospike 3+ servers.
// If the policy is nil, the default relevant policy will be used.
func (clnt *ProxyClient) QueryAggregate(policy *QueryPolicy, statement *Statement, packageName, functionName string, functionArgs ...Value) (*Recordset, Error) {
panic("NOT SUPPORTED")
}
22 changes: 0 additions & 22 deletions client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package aerospike

import "github.com/aerospike/aerospike-client-go/v7/types"

// ClientType determines the type of client to build.
type ClientType int

Expand All @@ -26,23 +24,3 @@ const (
// CTProxy means: Create a proxy client.
CTProxy
)

// CreateClientWithPolicyAndHost generates a new Client of the specified type
// with the specified ClientPolicy and sets up the cluster using the provided hosts.
// If the policy is nil, the default relevant policy will be used.
func CreateClientWithPolicyAndHost(typ ClientType, policy *ClientPolicy, hosts ...*Host) (ClientIfc, Error) {
if len(hosts) == 0 {
return nil, newError(types.SERVER_NOT_AVAILABLE, "No hosts were provided")
}

switch typ {
case CTNative:
return NewClientWithPolicyAndHost(policy, hosts...)
case CTProxy:
if len(hosts) > 1 {
return nil, newError(types.GRPC_ERROR, "Only one proxy host is acceptable")
}
return NewProxyClientWithPolicyAndHost(policy, hosts[0])
}
return nil, newError(types.SERVER_NOT_AVAILABLE, "Invalid client type")
}
36 changes: 36 additions & 0 deletions client_builder_native.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build !as_proxy

// Copyright 2014-2022 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package aerospike

import "github.com/aerospike/aerospike-client-go/v7/types"

// CreateClientWithPolicyAndHost generates a new Client of the specified type
// with the specified ClientPolicy and sets up the cluster using the provided hosts.
// If the policy is nil, the default relevant policy will be used.
func CreateClientWithPolicyAndHost(typ ClientType, policy *ClientPolicy, hosts ...*Host) (ClientIfc, Error) {
if len(hosts) == 0 {
return nil, newError(types.SERVER_NOT_AVAILABLE, "No hosts were provided")
}

switch typ {
case CTNative:
return NewClientWithPolicyAndHost(policy, hosts...)
case CTProxy:
return nil, newError(types.GRPC_ERROR, "Proxy client mode not enabled. Pass -tags as_proxy during build")
}
return nil, newError(types.SERVER_NOT_AVAILABLE, "Invalid client type")
}
39 changes: 39 additions & 0 deletions client_builder_proxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//go:build as_proxy

// Copyright 2014-2022 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package aerospike

import "github.com/aerospike/aerospike-client-go/v7/types"

// CreateClientWithPolicyAndHost generates a new Client of the specified type
// with the specified ClientPolicy and sets up the cluster using the provided hosts.
// If the policy is nil, the default relevant policy will be used.
func CreateClientWithPolicyAndHost(typ ClientType, policy *ClientPolicy, hosts ...*Host) (ClientIfc, Error) {
if len(hosts) == 0 {
return nil, newError(types.SERVER_NOT_AVAILABLE, "No hosts were provided")
}

switch typ {
case CTNative:
return NewClientWithPolicyAndHost(policy, hosts...)
case CTProxy:
if len(hosts) > 1 {
return nil, newError(types.GRPC_ERROR, "Only one proxy host is acceptable")
}
return NewProxyClientWithPolicyAndHost(policy, hosts[0])
}
return nil, newError(types.SERVER_NOT_AVAILABLE, "Invalid client type")
}
1 change: 0 additions & 1 deletion client_ifc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance && !app_engine
// +build !as_performance,!app_engine

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
1 change: 0 additions & 1 deletion client_ifc_app_engine.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !as_performance && app_engine
// +build !as_performance,app_engine

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down
14 changes: 13 additions & 1 deletion client_ifc_app_engine_perf.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build as_performance && app_engine
// +build as_performance,app_engine

// Copyright 2014-2022 Aerospike, Inc.
//
Expand Down Expand Up @@ -103,6 +102,19 @@ type ClientIfc interface {

// TODO: Synchronization here for the sake of dynamic config in the future

getUsablePolicy(*BasePolicy) *BasePolicy
getUsableWritePolicy(*WritePolicy) *WritePolicy
getUsableScanPolicy(*ScanPolicy) *ScanPolicy
getUsableQueryPolicy(*QueryPolicy) *QueryPolicy
getUsableAdminPolicy(*AdminPolicy) *AdminPolicy
getUsableInfoPolicy(*InfoPolicy) *InfoPolicy

getUsableBatchPolicy(*BatchPolicy) *BatchPolicy
getUsableBatchReadPolicy(*BatchReadPolicy) *BatchReadPolicy
getUsableBatchWritePolicy(*BatchWritePolicy) *BatchWritePolicy
getUsableBatchDeletePolicy(*BatchDeletePolicy) *BatchDeletePolicy
getUsableBatchUDFPolicy(*BatchUDFPolicy) *BatchUDFPolicy

GetDefaultPolicy() *BasePolicy
GetDefaultBatchPolicy() *BatchPolicy
GetDefaultBatchWritePolicy() *BatchWritePolicy
Expand Down
Loading