初识 Aerospike

简介

  Aerospike 是一个高性能高可扩展高可用高复杂性分布式Key-ValueNoSQL 数据库(注意不是缓存哦,其定位就是数据库),可基于行进行随机存取,支持多种部署模式(纯内存、内存 + SSD、纯 SSD)。

  Aerospike 的体系结构主要具有三个目标:

  • 为 Web 规模的应用程序创建一个灵活的可扩展平台
  • 提供传统数据库期望的鲁棒性和可靠性(如 ACID)
  • 以最少的人工参与提供运营效率

为什么使用 Aerospike?

  Aerospike 的优点很多,下面列举了一部分:

  • 多线程的处理能力,能够提高单节点对于服务端聚合能力计算的吞吐量
  • 较少的节点数量,便于实施部署与运维
  • 保持较高水平的性能指标前提下,具备完整的数据备份恢复能力,便于故障恢复
  • 支持方便、完备的扩容缩容机制,数据重平衡时不影响集群吞吐量
  • 服务端 UDF 扩展能力,便于扩展服务端局和的自定义算法
  • 自带比较完全的 Web 监控控制台,便于监控集群状态

体系结构

  Aerospike 体系结构包括了以下三层:

  • 客户端层:此集群感知层包括开源客户端库(如 Java、C#、Python 等),这些库实现了 Aerospike API,可以跟踪节点并知道数据在集群中的位置
  • 集群数据分发层:此层管理集群通信并自动执行故障转移,复制,跨数据中心复制(XDR)以及智能重新平衡和数据迁移工作
  • 数据存储层:此层可靠地将数据存储在 DRAM 和 Flash 中,以便快速检索

数据模型

  NoSQL 数据库一般称为 schemaless(无模式的),即数据的存储没有固定的模式
  虽然 Aerospike 采用的是无模式存储,但某种程度上其数据模型类似 RDBMS:

Aerospike RDBMS
Namespace Database
Set Table
Record Row
Bin Colum

  从上表可知,在 Aerospike 中:

  • 可以包含多个 Namespace(数据库)
  • 每一个 Namespace 可以包含多个 Set(数据表)
  • 每一个 Set 可以包含多个 Bin(列)和 Record(行)
  • 不同 Record(行)中可以有不同的 Bin(列)

  Aerospike 中这些概念,下面将详细介绍。

Namespace

  命名空间(namespace)类似于关系型数据库里的“数据库”(database),即存储和索引关联数据的地方。
  在 Aerospike 中,每个节点最多可设置 32 个 namespace。
  namespace 包括:

  • records:记录
  • indexes:索引的存储方式
  • policies:规定了数据的行为,包括:
    • 数据的存储位置,是内存还是闪存呀
    • 数据存储占有的容量大小
    • 副本的数量
    • 过期时间(TTL)

Set

  Set 类似于关系型数据库里的“表”(Table),每个 Namespace 最多 1023 个 Set。

Record

  Record 类似于关系型数据库里的“行”(Row)。
  Record 中包含:

  • Key:全局唯一,Aerospike 作为 K-V 数据库一般也是通过 key 定位以进行查询
  • Bins:相当于列,存储具体的数据,即 Value
  • Metadata:元数据,存储一些基本信息,例如 Record 版本、设置的 TTL(过期时间)等

注意哦:对 Record 而言,一条 Record 可以有多个 Bins,不同 Record 的 Bins 也可以不同。

Bin

  Bin 类似于数据库列,可以分别容纳不同的数据类型。

  每个 Bin 包括一个 name 和 object ,object 里面定义了具体的类型。
  若是 key-value 存储的话,最后我们取出的数据将返回一个 bin 数据结构。

  从数据结构层面来说:Aerospike 数据存储模式为 Key-Value 结构,只是对于 Value 并没有特定的格式要求。

注意哦:对于无模式的 Aerospike 而言,不必预先定义 set 或 bin,因为在应用程序对 Aerospike 执行写操作时,它会实时创建 set 或 bin

Bin 的数据类型

  Aerospike 的bin中可以容纳不同的数据类型,比如:

  • 基本数据类型:Bytes、Integer、String、Double
  • 复杂数据类型:List、Map、嵌套的 List 与 Map、
  • 特殊数据类型:GeoJSON
  • 特定语言序列化的 Blob:如 Java 序列化的对象

复杂数据类型

List

  

Map

  

嵌套 List 与 Map

  

概念理解

  对于 AS 中的以上概念,可以将 Set 理解为一个 Map<K,V>结构,通过 K可以找到一个 Record(V),Record (V)又可以理解为一个 Map<K,V>,通过其 K可以找到 Bins(V)。
  因此,可以将 Set 理解为一个Map<K,Map<K,V>>结构。

下载与安装

  AeroSpike 官网提供了两个版本供下载:

  • Community edition:社区版,功能包括查询,地理空间索引和存储,用户自定义函数(UDF),备份和重启,还有用于基本监视的 Aerospike 管理控制台(AMC)
  • Enterprise edition:企业版,添加了跨数据中心复制,强一致性,压缩,全闪存,机架感知,安全性等功能

  企业版需要收费,我们使用社区版就行了(虽然存在很多限制,但还是很强大呀)。

压缩包方式

下载

  我们需要下载以下压缩包到 Linux 中:

解压

  解压server压缩包,得到aerospike-serveraerospike-tool

1
2
3
4
5
6
7
8
[root@centos-linux--2- ~]# tar zxvf aerospike-server-community-4.3.1.5-el7.tgz 
aerospike-server-community-4.3.1.5-el7/
aerospike-server-community-4.3.1.5-el7/SHA256SUMS
aerospike-server-community-4.3.1.5-el7/aerospike-tools-3.15.3.18-1.el7.x86_64.rpm
aerospike-server-community-4.3.1.5-el7/aerospike-server-community-4.3.1.5-1.el7.x86_64.rpm
aerospike-server-community-4.3.1.5-el7/LICENSE
aerospike-server-community-4.3.1.5-el7/asinstall
aerospike-server-community-4.3.1.5-el7/dep-check

安装

  安装aerospike-serveraerospike-tool的 rpm 包:

1
2
3
cd aerospike-server-community-4.3.1.5-el7
rpm -Uvh aerospike-server-community-4.3.1.5-1.el7.x86_64.rpm
rpm -Uvh aerospike-tools-3.15.3.18-1.el7.x86_64.rpm

  其实也可以通过 Aerospike 提供的安装脚本一键执行上面的两个命令(需要 root 权限):

1
sudo ./asinstall

启动相关命令

  Aerospike 服务相关命令:

命令 说明
service aerospike start 启动 AS 服务
service aerospike restart 重启 AS 服务
service aerospike stop 停止 AS 服务
service aerospike status 查看 AS 状态

注意哦:启动 Aerospike 后,是启动的默认 3000 端口,程序中只用 3000 端口,这里不能改成其他。

测试

  测试 Aerospike 是否启动成功:

1
aql

  若出现以下命令行,则代表安装成功:

1
2
3
4
5
6
7
8
Seed:         127.0.0.1
User: None
Config File: /etc/aerospike/astools.conf /root/.aerospike/astools.conf
Aerospike Query Client
Version 3.15.3.18
C Client Version 4.3.17
Copyright 2012-2017 Aerospike. All rights reserved.
aql>

配置与详解

  进入配置目录,可以进行配置文件的修改:

1
2
cd /etc/aerospike/
vi aerospike.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Aerospike database configuration file for use with systemd.

service {
paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1.
proto-fd-max 15000
}

logging {
console {
context any info
}
}

network {
service {
address any
port 3000
}

heartbeat {
mode multicast
multicast-group 239.1.99.222
port 9918

# To use unicast-mesh heartbeats, remove the 3 lines above, and see
# aerospike_mesh.conf for alternative.

interval 150
timeout 10
}

fabric {
port 3001
}

info {
port 3003
}
}

namespace test {
replication-factor 2
memory-size 4G
default-ttl 30d # 30 days, use 0 to never expire/evict.

storage-engine memory
}

namespace bar {
replication-factor 2
memory-size 4G
default-ttl 30d # 30 days, use 0 to never expire/evict.

storage-engine memory

# To use file storage backing, comment out the line above and use the
# following lines instead.
# storage-engine device {
# file /opt/aerospike/data/bar.dat
# filesize 16G
# data-in-memory true # Store data in memory in addition to file.
# }
}
参数 参数值 说明
network.heartbeat.mode mesh 集群心跳模式
replication-factor 2 副本数,配置为 2 代表总共 2 份数据
memory-size 50G 最大占用内存
default-ttl 30d 默认存活时间,默认为 0;
一定要设置,否则数据无法被逐出
storage-engine memory 存储引擎: memory 代表纯内存模式
device 代表持久化模式
data-in-memory true 默认 false , 代表数据不在内存
设置为 true 可提升性能
high-water-memory-pct 60 内存占用超过 60%,触发逐出
stop-writes-pct 90 内存占用超过 90%,停止写入
high-water-disk-pct 60 持久化存储 60%,触发逐出
evict-tenths-pct 100 每一轮清理周期中需要清理的对象千分比 设置过小,可能来不及逐出,
导致内存超过 stop-writes-pct 的配置,从而触发写入停止
transaction-pending-limit 0 设置成 0,解决 hot key 的问题 需要版本 >= 4.3.1.5
evict-hist-buckets 100000 驱逐桶个数,最大 1000 万,桶越多,粒度越细,可以更好的控制逐出行为

Web 控制台

解压

  解压下载的AMC压缩包:

1
tar zxvf aerospike-amc-community-4.0.19-linux.tar.gz

注意哦:解压后会在当前解压目录生成几个文件夹(包含 AMC相关信息),请根据需要放在合适位置哦!

配置

  主要是修改配置的端口信息:

1
2
3
4
5
cd /etc/amc/
vi amc.conf

# 默认端口 8081
bind = "0.0.0.0:8081"

启动

1
2
cd /etc/init.d/
./amc start

注意哦:要把外网端口打开才能访问哦:

1
2
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload

  浏览器访问主机的8081端口出现以下界面则代表启动成功:

善用 AMC

  通过 AMC 可以观察 Aerospike 的允许情况,比如:

  • 集群的健康度
  • 磁盘和内存占用情况,内存空间/磁盘空间比例
  • 服务器 I/O 负载,CPU 负载,磁盘碎片化程度等信息
  • 集群吞吐量,读写 TPS

集群

  对 AeroSpike 而言,无需重新启动集群中的现有节点即可添加新节点。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
network {
...

heartbeat {
mode mesh
address 10.0.0.100
port 3002 # 该节点的心跳端口

# 一个或更多节点的集合,共同构成集群
mesh-seed-address-port 10.0.0.100 3002
mesh-seed-address-port 10.0.0.101 3002
mesh-seed-address-port 10.0.0.103 3002

...
}
...
}

  对 IP 为10.0.0.101的 AeroSpike 服务器来说,只有以下心跳配置:

1
2
mesh-seed-address-port 10.0.0.101  3002
mesh-seed-address-port 10.0.0.103 3002

  但是,当 IP 为10.0.0.100的 AS 加入集群后,会被以上配置的节点发现。

注意哦:防火墙的相应端口需要打开,否则集群无法相互通信!

Docker 方式

  下面使用 Docker 安装与部署:

1
2
3
4
# 拉取 aerospike 镜像
docker pull aerospike:4.9.0.3
# 创建并启动 aerospike 容器
docker run -d --name=myaerospike -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike:4.9.0.3

  若需要操作 aerospike,可以借助 aql:

1
2
3
4
# 进入容器
docker exec -it 96 /bin/bash
root@9698e0f5af68:/# cd usr/bin/
root@9698e0f5af68:/usr/bin# aql

基本语法

  在aql中输入help可以查看帮助手册,以下为整理后的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
COMMANDS
DDL
CREATE INDEX <index> ON <ns>[.<set>] (<bin>) NUMERIC|STRING|GEO2DSPHERE
CREATE LIST/MAPKEYS/MAPVALUES INDEX <index> ON <ns>[.<set>] (<bin>) NUMERIC|STRING|GEO2DSPHERE
DROP INDEX <ns>[.<set>] <index>
Examples:

CREATE INDEX idx_foo ON test.demo (foo) NUMERIC
DROP INDEX test.demo idx_foo

MANAGE UDFS
REGISTER MODULE '<filepath>'
REMOVE MODULE <filename>

<filepath> is file path to the UDF module(in single quotes).
<filename> is file name of the UDF module.

Examples:

REGISTER MODULE '~/test.lua'
REMOVE MODULE test.lua

USER ADMINISTRATION
CREATE USER <user> PASSWORD <password> ROLE[S] <role1>,<role2>...
pre-defined roles: read|read-write|read-write-udf|sys-admin|user-admin
DROP USER <user>
SET PASSWORD <password> [FOR <user>]
GRANT ROLE[S] <role1>,<role2>... TO <user>
REVOKE ROLE[S] <role1>,<role2>... FROM <user>
CREATE ROLE <role> PRIVILEGE[S] <priv1[.ns1[.set1]]>,<priv2[.ns2[.set2]]>...
priv: read|read-write|read-write-udf|sys-admin|user-admin|data-admin
ns: namespace. Applies to all namespaces if not set.
set: set name. Applie to all sets within namespace if not set.
sys-admin, user-admin and data-admin can't be qualified with namespace or set.
DROP ROLE <role>
GRANT PRIVILEGE[S] <priv1[.ns1[.set1]]>,<priv2[.ns2[.set2]]>... TO <role>
REVOKE PRIVILEGE[S] <priv1[.ns1[.set1]]>,<priv2[.ns2[.set2]]>... FROM <role>


DML
INSERT INTO <ns>[.<set>] (PK, <bins>) VALUES (<key>, <values>)
DELETE FROM <ns>[.<set>] WHERE PK = <key>
TRUNCATE <ns>[.<set>] [upto <LUT>]

<ns> is the namespace for the record.
<set> is the set name for the record.
<key> is the record's primary key.
<bins> is a comma-separated list of bin names.
<values> is comma-separated list of bin values, which may include type cast expressions. Set to NULL (case insensitive & w/o quotes) to delete the bin.
<LUT> is last update time upto which set or namespace needs to be truncated. LUT is either nanosecond since Unix epoch like 1513687224599000000 or in date string in format like "Dec 19 2017 12:40:00".

Type Cast Expression Formats:

CAST(<Value> AS <TypeName>)
<TypeName>(<Value>)

Supported AQL Types:

Bin Value Type Equivalent Type Name(s)
===============================================================
Integer DECIMAL, INT, NUMERIC
Floating Point FLOAT, REAL
Aerospike CDT (List, Map, etc.) JSON
Aerospike List LIST
Aerospike Map MAP
GeoJSON GEOJSON
String CHAR, STRING, TEXT, VARCHAR
===============================================================

[Note: Type names and keywords are case insensitive.]

Examples:

INSERT INTO test.demo (PK, foo, bar) VALUES ('key1', 123, 'abc')
INSERT INTO test.demo (PK, foo, bar) VALUES ('key1', CAST('123' AS INT), JSON('{"a": 1.2, "b": [1, 2, 3]}'))
INSERT INTO test.demo (PK, foo, bar) VALUES ('key1', LIST('[1, 2, 3]'), MAP('{"a": 1, "b": 2}'))
INSERT INTO test.demo (PK, gj) VALUES ('key1', GEOJSON('{"type": "Point", "coordinates": [123.4, -456.7]}'))
DELETE FROM test.demo WHERE PK = 'key1'

INVOKING UDFS
EXECUTE <module>.<function>(<args>) ON <ns>[.<set>]
EXECUTE <module>.<function>(<args>) ON <ns>[.<set>] WHERE PK = <key>
EXECUTE <module>.<function>(<args>) ON <ns>[.<set>] WHERE <bin> = <value>
EXECUTE <module>.<function>(<args>) ON <ns>[.<set>] WHERE <bin> BETWEEN <lower> AND <upper>

<module> is UDF module containing the function to invoke.
<function> is UDF to invoke.
<args> is a comma-separated list of argument values for the UDF.
<ns> is the namespace for the records to be queried.
<set> is the set name for the record to be queried.
<key> is the record's primary key.
<bin> is the name of a bin.
<value> is the value of a bin.
<lower> is the lower bound for a numeric range query.
<upper> is the lower bound for a numeric range query.

Examples:

EXECUTE myudfs.udf1(2) ON test.demo
EXECUTE myudfs.udf1(2) ON test.demo WHERE PK = 'key1'

OPERATE
OPERATE <op(<bin>, params...)>[with_policy(<map policy>),] [<op(<bin>, params...)> with_policy (<map policy>) ...] ON <ns>[.<set>] where PK=<key>

<op> name of operation to perform.
<bin> is the name of a bin.
<params> parameters for operation.
<map policy> map operation policy.
<ns> is the namespace for the records to be queried.
<set> is the set name for the record to be queried.
<key> is the record's primary key.

OP
LIST_APPEND (<bin>, <val>)
LIST_INSERT (<bin>, <index>, <val>)
LIST_SET (<bin>, <index>, <val>)
LIST_GET (<bin>, <index>)
LIST_POP (<bin>, <index>)
LIST_REMOVE (<bin>, <index>)
LIST_APPEND_ITEMS (<bin>, <list of vals>)
LIST_INSERT_ITEMS (<bin>, <index>, <list of vals>)
LIST_GET_RANGE (<bin>, <startindex>[, <count>])
LIST_POP_RANGE (<bin>, <startindex>[, <count>])
LIST_REMOVE_RANGE (<bin>, <startindex>[, <count>])
LIST_TRIM (<bin>, <startindex>[, <count>])
LIST_INCREMENT (<bin>, <index>, <numeric val>)
LIST_CLEAR (<bin>)
LIST_SIZE (<bin>)
MAP_PUT (<bin>, <key>, <val>) [with_policy (<map policy>)]
MAP_PUT_ITEMS (<bin>, <map>) [with_policy (<map policy>)]
MAP_INCREMENT (<bin>, <key>, <numeric val>) [with_policy (<map policy>)]
MAP_DECREMENT (<bin>, <key>, <numeric val>) [with_policy (<map policy>)]
MAP_GET_BY_KEY (<bin>, <key>)
MAP_REMOVE_BY_KEY (<bin>, <key>)
MAP_GET_BY_VALUE (<bin>, <value>)
MAP_REMOVE_BY_VALUE (<bin>, <value>)
MAP_GET_BY_INDEX (<bin>, <index>)
MAP_REMOVE_BY_INDEX (<bin>, <index>)
MAP_GET_BY_RANK (<bin>, <rank>)
MAP_REMOVE_BY_RANK (<bin>, <rank>)
MAP_REMOVE_BY_KEY_LIST (<bin>, <list of keys>)
MAP_REMOVE_BY_VALUE_LIST (<bin>, <list of vals>)
MAP_GET_BY_KEY_RANGE (<bin>, <startkey>, <endkey>)
MAP_REMOVEBY_RANGE (<bin>, <startkey>, <endkey>)
MAP_GET_BY_VALUE_RANGE (<bin>, <startval>, <endval>)
MAP_REMOVE_BY_VALUE_RANGE (<bin>, <startval>, <endval>)
MAP_GET_BY_INDEX_RANGE (<bin>, <startindex>[, <count>])
MAP_REMOVE_BY_INDEX_RANGE (<bin>, <startindex>[, <count>])
MAP_GET_BY_RANK_RANGE (<bin>, <startrank> [, <count>])
MAP_REMOVE_BY_RANK_RANGE (<bin>, <startrank> [, <count>])
MAP_CLEAR (<bin>)
MAP_SET_TYPE (<bin>, <map type>)
MAP_SIZE (<bin>)
TOUCH ()
READ (<bin>)
WRITE (<bin>, <val>)
PREPEND (<bin>, <val>)
APPEND (<bin>, <val>)
INCR (<bin>, <numeric val>)

Examples:

OPERATE LIST_APPEND(listbin, 1), LIST_APPEND(listbin2, 10) ON test.demo where PK = 'key1'
OPERATE LIST_POP_RANGE(listbin, 1, 10) ON test.demo where PK = 'key1'


QUERY
SELECT <bins> FROM <ns>[.<set>]
SELECT <bins> FROM <ns>[.<set>] WHERE <bin> = <value>
SELECT <bins> FROM <ns>[.<set>] WHERE <bin> BETWEEN <lower> AND <upper>
SELECT <bins> FROM <ns>[.<set>] WHERE PK = <key>
SELECT <bins> FROM <ns>[.<set>] IN <indextype> WHERE <bin> = <value>
SELECT <bins> FROM <ns>[.<set>] IN <indextype> WHERE <bin> BETWEEN <lower> AND <upper>
SELECT <bins> FROM <ns>[.<set>] IN <indextype> WHERE <bin> CONTAINS <GeoJSONPoint>
SELECT <bins> FROM <ns>[.<set>] IN <indextype> WHERE <bin> WITHIN <GeoJSONPolygon>

<ns> is the namespace for the records to be queried.
<set> is the set name for the record to be queried.
<key> is the record's primary key.
<bin> is the name of a bin.
<value> is the value of a bin.
<indextype> is the type of a index user wants to query. (LIST/MAPKEYS/MAPVALUES)
<bins> can be either a wildcard (*) or a comma-separated list of bin names.
<lower> is the lower bound for a numeric range query.
<upper> is the lower bound for a numeric range query.

Examples:

SELECT * FROM test.demo
SELECT * FROM test.demo WHERE PK = 'key1'
SELECT foo, bar FROM test.demo WHERE PK = 'key1'
SELECT foo, bar FROM test.demo WHERE foo = 123
SELECT foo, bar FROM test.demo WHERE foo BETWEEN 0 AND 999
SELECT * FROM test.demo WHERE gj CONTAINS CAST('{"type": "Point", "coordinates": [0.0, 0.0]}' AS GEOJSON)

AGGREGATION
AGGREGATE <module>.<function>(<args>) ON <ns>[.<set>]
AGGREGATE <module>.<function>(<args>) ON <ns>[.<set>] WHERE <bin> = <value>
AGGREGATE <module>.<function>(<args>) ON <ns>[.<set>] WHERE <bin> BETWEEN <lower> AND <upper>

<module> is UDF module containing the function to invoke.
<function> is UDF to invoke.
<args> is a comma-separated list of argument values for the UDF.
<ns> is the namespace for the records to be queried.
<set> is the set name for the record to be queried.
<key> is the record's primary key.
<bin> is the name of a bin.
<value> is the value of a bin.
<lower> is the lower bound for a numeric range query.
<upper> is the lower bound for a numeric range query.

Examples:

AGGREGATE myudfs.udf2(2) ON test.demo WHERE foo = 123
AGGREGATE myudfs.udf2(2) ON test.demo WHERE foo BETWEEN 0 AND 999

EXPLAIN
EXPLAIN SELECT * FROM <ns>[.<set>] WHERE PK = <key>

<ns> is the namespace for the records to be queried.
<set> is the set name for the record to be queried.
<key> is the record's primary key.

Examples:

EXPLAIN SELECT * FROM test.demo WHERE PK = 'key1'


INFO
SHOW NAMESPACES | SETS | BINS | INDEXES
SHOW SCANS | QUERIES
STAT NAMESPACE <ns> | INDEX <ns> <indexname>
STAT SYSTEM
ASINFO <ASInfoCommand>

JOB MANAGEMENT
KILL_QUERY <transaction_id>
KILL_SCAN <scan_id>

USER ADMINISTRATION
SHOW USER [<user>]
SHOW USERS
SHOW ROLE <role>
SHOW ROLES

MANAGE UDFS
SHOW MODULES
DESC MODULE <filename>

<filepath> is file path to the UDF module(in single quotes).
<filename> is file name of the UDF module.

Examples:

SHOW MODULES
DESC MODULE test.lua

RUN <filepath>

SYSTEM <bash command>


SETTINGS
ECHO (true | false, default false)
VERBOSE (true | false, default false)
OUTPUT (TABLE | JSON | MUTE | RAW, default TABLE)
OUTPUT_TYPES (true | false, default true)
TIMEOUT (time in ms, default: 1000)
LUA_USERPATH <path>, default : /opt/aerospike/usr/udf/lua
USE_SMD (true | false, default false)
RECORD_TTL (time in sec, default: 0)
RECORD_PRINT_METADATA (true | false, default false, prints record metadata)
REPLICA_ANY (true | false, default false)
KEY_SEND (true | false, default false)
DURABLE_DELETE (true | false, default false)
FAIL_ON_CLUSTER_CHANGE (true | false, default true, policy applies to scans)
SCAN_PRIORITY priority of scan (LOW, MEDIUM, HIGH, AUTO), default : AUTO
NO_BINS (true | false, default false, No bins as part of scan and query result)
LINEARIZE_READ (true | false, default false, Make read linearizable, applicable only for namespace with strong_consistency enabled.)


To get the value of a setting, run:

aql> GET <setting>

To set the value of a setting, run:

aql> SET <setting> <value>

To reset the value of a setting back to default, run:

aql> RESET <setting>

  删除指定set

1
aql -c "TRUNCATE <namespace_name>.<set_name>"

缺点

版本限制

  由于使用的 Aerospike 是社区版,所以存在一些限制,比如:

  • 社区版对于 4.0 之前的版本,最大节点数限制为 31,对于 4.0 及更高版本,最大节点数限制为 8
  • 社区版 Namespace 被限制为 2 个
  • 社区版每个 Namespace 限制 Set 为 1023
  • 社区版每个 Namespace 最多有 32,727 个 Bin
  • 只支持 Batch Read,不支持 Batch Write
  • Record 大小存在限制(小于 1M)
  • Bin 限制为 14 个字符,单子段一般不会超过,但嵌套类型就很容易超过了
  • 没有内建的聚合函数(如 Count、Max、Min、Group By 等),通过 UDF 可以支持(但使用方式不友好,效率也不高)
  • Namespace 限制 Set 为 1023,二级索引限制为 256,唯一 Binname 限制 32 K
  • 一个 Namespace 最多 40 亿 Record

操作限制

  Aerospike 与 MySQL 相比,存在如下限制:

  • 范围查询只支持整数类型,不支持浮点数
  • 范围查询只支持 BETWEEN 语句,没有小于或大于查询
  • Query 不支持分页
  • Query 不支持排序
  • 不支持动态创建 NameSpace,只能通过修改配置文件,重启服务
  • 只有清空 Set 数据接口,却并没有真正 Drop 掉 Sets,因此会留下 Empty Set

参考

0%