Skip to content

Commit 09339bd

Browse files
committed
Merge branch 'master' into community
2 parents dfcc293 + f032358 commit 09339bd

File tree

241 files changed

+2775
-841
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+2775
-841
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ tmp/
88
.DS_Store
99
TODO
1010
PLAN.todo
11+
.go_metalinter
12+
.go_style
13+
.golangci.yml
14+
.travis/read-write-udf.ldif
15+
.travis/people.ldif
16+
.travis/modify.ldif
17+
.travis/badwan.ldif
18+
.travis/access.ldif
19+
tools/
20+
cmd/

CHANGELOG.md

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Change History
22

3+
## February 12 2021: v4.2.0
4+
5+
Major feature and improvements release.
6+
7+
* **New Features**:
8+
9+
- [CLIENT-1192] Adds Support for partition scans. Queries which lack a `Statement.Filter` will be automatically converted to partition scans. If the cluster supports partition scans, all Scans and Queries will use the new protocol to allow retrying in case of some errors.
10+
- [CLIENT-1237] Adds Support for `MultiPolicy.MaxRecords` in scans and queries without `Statement.Filter`.
11+
- Adds `NewHosts` convenience function. (Github #320) thanks to [Yegor Myskin](https://github.com/un000)
12+
13+
* **Improvements**
14+
15+
- Adds a few missing error checks.
16+
- Moves examples files to dedicated folders to avoid `multiple main function` errors for new users.
17+
- Some documentation clean up. (Github #314) thanks to [Shin Uozumi](https://github.com/sinozu)
18+
- Fix typo in example `NewKey()`. (Github #331) thanks to [Patrick Kuca](https://github.com/pkuca)
19+
- Adds an example to list operations (using operate and list policy).
20+
- Runs the XDR tests only when XDR is configured on the server.
21+
- Add TLS config to test params.
22+
- Mark `NewPredExpXXX` return value as the PredExp interface instead of concrete type. It will now group them under the `PredExp` interface in the docs.
23+
24+
* **Changes**
25+
- Only use `Policy.Priority` and `MultiPolicy.FailOnClusterChange` on server versions < 4.9. `Priority` is now deprecated and replaced with `MultiPolicy.RecordPerSecond`.
26+
- `Statement.TaskID` is deprecated and will be removed in the next major version.
27+
- `ScanPolicy.ConcurrentNodes` is deprecated and will be removed in the next major version.
28+
29+
… versions < 4.9
30+
331
## January 25 2021: v4.1.0
432

533
Major feature release.
@@ -10,6 +38,10 @@
1038
- [CLIENT-1410] Adds `Client.SetXDRFilter()`.
1139
- [CLIENT-1433] Adds `ExpMemorySize()` to expression filters.
1240

41+
* **Fixes**
42+
43+
- Fixes an issue where remainder miscalculation would cause the connection pool to be smaller than it should have been. (Github #332) thanks to [ShawnZhang](https://github.com/xqzhang2015)
44+
1345
* **Improvements**
1446

1547
- [CLIENT-1434] Reset peers, partition and rebalance generations on node tend errors.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Please refer to the [`CHANGELOG.md`](CHANGELOG.md) for details.
3939
- [Tools](#Tools)
4040

4141

42-
## Usage:
42+
## Usage
4343

4444
The following is a very simple example of CRUD operations in an Aerospike database.
4545

@@ -114,7 +114,7 @@ Supported operating systems:
114114
- Windows (untested)
115115

116116
<a name="Installation"></a>
117-
## Installation:
117+
## Installation
118118

119119
1. Install Go 1.9+ and setup your environment as [Documented](http://golang.org/doc/code.html#GOPATH) here.
120120
2. Get the client in your ```GOPATH``` : ```go get github.com/aerospike/aerospike-client-go```

admin_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use acmd file except in compliance with the License.

admin_policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

aerospike.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
151
// Package aerospike provides a client to connect and interact with an Aerospike cluster.
2+
// This is the official Go implementation of the Aerospike Client.
163
package aerospike

aerospike_bench_reflect_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build !as_performance
22

3-
// Copyright 2013-2020 Aerospike, Inc.
3+
// Copyright 2014-2021 Aerospike, Inc.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

aerospike_bench_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

aerospike_suite_test.go

+128-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,7 +16,12 @@ package aerospike_test
1616

1717
import (
1818
"bytes"
19+
"crypto/tls"
20+
"crypto/x509"
21+
"encoding/pem"
1922
"flag"
23+
"fmt"
24+
"io/ioutil"
2025
"log"
2126
"math/rand"
2227
"os"
@@ -29,6 +34,7 @@ import (
2934

3035
as "github.com/aerospike/aerospike-client-go"
3136
asl "github.com/aerospike/aerospike-client-go/logger"
37+
ast "github.com/aerospike/aerospike-client-go/types"
3238
)
3339

3440
var (
@@ -41,6 +47,12 @@ var (
4147
debug = flag.Bool("debug", false, "Will set the logging level to DEBUG.")
4248
namespace = flag.String("n", "test", "Namespace")
4349

50+
certFile = flag.String("cert_file", "", "Certificate file name.")
51+
keyFile = flag.String("key_file", "", "Key file name.")
52+
keyFilePassphrase = flag.String("key_file_passphrase", "", "Key file's pass phrase.")
53+
nodeTLSName = flag.String("node_tls_name", "", "Node's TLS name.")
54+
rootCA = flag.String("root_ca", "", "Root certificate.")
55+
4456
clientPolicy *as.ClientPolicy
4557
client *as.Client
4658
)
@@ -70,7 +82,13 @@ func initTestVars() {
7082
clientPolicy.AuthMode = as.AuthModeExternal
7183
}
7284

73-
client, err = as.NewClientWithPolicy(clientPolicy, *host, *port)
85+
// setup TLS
86+
clientPolicy.TlsConfig = initTLS()
87+
88+
dbHost := as.NewHost(*host, *port)
89+
dbHost.TLSName = *nodeTLSName
90+
91+
client, err = as.NewClientWithPolicyAndHost(clientPolicy, dbHost)
7492
if err != nil {
7593
log.Fatal(err.Error())
7694
}
@@ -121,6 +139,11 @@ func securityEnabled() bool {
121139
return err == nil
122140
}
123141

142+
func xdrEnabled() bool {
143+
res := info(client, "get-config:context=xdr")
144+
return len(res) > 0 && !strings.HasPrefix(res, "ERROR")
145+
}
146+
124147
func nsInfo(ns string, feature string) string {
125148
node := client.GetNodes()[0]
126149
infoMap, err := node.RequestInfo(as.NewInfoPolicy(), "namespace/"+ns)
@@ -144,8 +167,110 @@ func info(client *as.Client, feature string) string {
144167
node := client.GetNodes()[0]
145168
infoMap, err := node.RequestInfo(as.NewInfoPolicy(), feature)
146169
if err != nil {
147-
log.Fatal("Failed to connect to aerospike: err:", err)
170+
if ae, ok := err.(ast.AerospikeError); ok {
171+
return ae.Error()
172+
} else {
173+
log.Fatal("Failed to connect to aerospike: err:", err)
174+
}
148175
}
149176

150177
return infoMap[feature]
151178
}
179+
180+
func initTLS() *tls.Config {
181+
if len(*rootCA) == 0 && len(*certFile) == 0 && len(*keyFile) == 0 {
182+
return nil
183+
}
184+
185+
// Try to load system CA certs, otherwise just make an empty pool
186+
serverPool, err := x509.SystemCertPool()
187+
if serverPool == nil || err != nil {
188+
log.Printf("Adding system certificates to the cert pool failed: %s", err)
189+
serverPool = x509.NewCertPool()
190+
}
191+
192+
if len(*rootCA) > 0 {
193+
// Try to load system CA certs and add them to the system cert pool
194+
caCert, err := readFromFile(*rootCA)
195+
if err != nil {
196+
log.Fatal(err)
197+
}
198+
199+
log.Printf("Adding CA certificate to the pool...")
200+
serverPool.AppendCertsFromPEM(caCert)
201+
}
202+
203+
var clientPool []tls.Certificate
204+
if len(*certFile) > 0 || len(*keyFile) > 0 {
205+
206+
// Read cert file
207+
certFileBytes, err := readFromFile(*certFile)
208+
if err != nil {
209+
log.Fatal(err)
210+
}
211+
212+
// Read key file
213+
keyFileBytes, err := readFromFile(*keyFile)
214+
if err != nil {
215+
log.Fatal(err)
216+
}
217+
218+
// Decode PEM data
219+
keyBlock, _ := pem.Decode(keyFileBytes)
220+
certBlock, _ := pem.Decode(certFileBytes)
221+
222+
if keyBlock == nil || certBlock == nil {
223+
log.Fatalf("Failed to decode PEM data for key or certificate")
224+
}
225+
226+
// Check and Decrypt the the Key Block using passphrase
227+
if x509.IsEncryptedPEMBlock(keyBlock) {
228+
decryptedDERBytes, err := x509.DecryptPEMBlock(keyBlock, []byte(*keyFilePassphrase))
229+
if err != nil {
230+
log.Fatalf("Failed to decrypt PEM Block: `%s`", err)
231+
}
232+
233+
keyBlock.Bytes = decryptedDERBytes
234+
keyBlock.Headers = nil
235+
}
236+
237+
// Encode PEM data
238+
keyPEM := pem.EncodeToMemory(keyBlock)
239+
certPEM := pem.EncodeToMemory(certBlock)
240+
241+
if keyPEM == nil || certPEM == nil {
242+
log.Fatalf("Failed to encode PEM data for key or certificate")
243+
}
244+
245+
cert, err := tls.X509KeyPair(certPEM, keyPEM)
246+
247+
if err != nil {
248+
log.Fatalf("Failed to add client certificate and key to the pool: `%s`", err)
249+
}
250+
251+
log.Printf("Adding client certificate and key to the pool...")
252+
clientPool = append(clientPool, cert)
253+
}
254+
255+
tlsConfig := &tls.Config{
256+
Certificates: clientPool,
257+
RootCAs: serverPool,
258+
InsecureSkipVerify: false,
259+
PreferServerCipherSuites: true,
260+
}
261+
tlsConfig.BuildNameToCertificate()
262+
263+
return tlsConfig
264+
}
265+
266+
// Read content from file
267+
func readFromFile(filePath string) ([]byte, error) {
268+
dataBytes, err := ioutil.ReadFile(filePath)
269+
if err != nil {
270+
return nil, fmt.Errorf("Failed to read from file `%s`: `%v`", filePath, err)
271+
}
272+
273+
data := bytes.TrimSuffix(dataBytes, []byte("\n"))
274+
275+
return data, nil
276+
}

anonymous_fields_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build !as_performance
22

3-
// Copyright 2013-2019 Aerospike, Inc.
3+
// Copyright 2014-2019 Aerospike, Inc.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

auth_mode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

batch_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

batch_command_exists.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -45,7 +45,6 @@ func newBatchCommandExists(
4545
keys: keys,
4646
existsArray: existsArray,
4747
}
48-
res.oneShot = false
4948
return res
5049
}
5150

batch_command_get.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -68,7 +68,6 @@ func newBatchCommandGet(
6868
records: records,
6969
readAttr: readAttr,
7070
}
71-
res.oneShot = false
7271
return res
7372
}
7473

batch_command_get_reflect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build !as_performance
22

3-
// Copyright 2013-2020 Aerospike, Inc.
3+
// Copyright 2014-2021 Aerospike, Inc.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

batch_command_reflect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build !as_performance
22

3-
// Copyright 2013-2020 Aerospike, Inc.
3+
// Copyright 2014-2021 Aerospike, Inc.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

batch_index_command_get.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -39,7 +39,6 @@ func newBatchIndexCommandGet(
3939
indexRecords: records,
4040
},
4141
}
42-
res.oneShot = false
4342
return res
4443
}
4544

batch_node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

batch_policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

batch_read.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2020 Aerospike, Inc.
1+
// Copyright 2014-2021 Aerospike, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)