GBase 8a数据库集群V95版本相对V8版本变动内容汇总

GBase 数据库集群V95版本,相对V8主要是支持了虚拟集群功能,以及一些自增列等功能的增强,如下是详细的介绍。

有重大变动的

这部分功能,与V8差距明显,使用者要注意区分。

运行期间不再需要root

安装数据库用的操作系统用户,一般是gbase,需要客户自行创建。
由于安装过程中不需要root密码,所以gbase用户也需要用户自己创建,设置密码,然后再安装。
安装目录,由于没有root权限,需要用户自行创建,并且确保gbase用户有完全的权限。
安装、升级等集群操作期间,需要用dbaUser进行远程登陆,需要系统允许。如有安全申请,请提前加入备案或过滤条件。

从V8升级时,仍然需要root密码。

设置环境要求部分SetSysEnv.py需要root权限(root用户,或者sudo用户)运行一次。
去除 service gcware start/stop/restart/status 命令以及相关配置或启劢文件,如
/etc/init.d/gcware
/etc/monit.d/gcware.conf
/etc/init.d/gclusterd
/etc/init.d/gbased
/etc/init.d/gcrecover
/etc/init.d/gcsync
/etc/init.d/gcware
/etc/init.d/corosync

服务启动命令变动

操作系统gbase用户运行
gcluster_service all start

开机自启动需要用户自行配置,因为需要root用户权限操作。

集群状态不再支持LOCK

即使一般管理节点OFFLINE/CLOSE,集群状态依然会NORMAL。 调用的SQL会卡住在获取集群状态(与gcware通讯),需要用户自行根据超时情况判定集群异常。
该变动影响较大,特别是gcadmin命令以及gccli等,当集群出现如上情况是,这些命令会卡住,直到集群恢复正常,而在V8里是报错返回的。

数据库日志的归档【默认】不再支持

在V8里,通过操作系统自带的logratate功能,对数据库的日志,比如express.log, system.log等,默认放在 /etc/logrotate.d/ 下面。如下几个红色的是安装时自动生成给的归档配置。

在V9里,需要在SetSysEnv.py时,增加--installPrefix参数,才能自动安装归档配置,例如

./SetSysEnv.py --dbaUser=gbase --installPrefix=/opt/gbase

如下时归档日志的配置文件样例

[root@rh6-1 ~]# ll /etc/logrotate.d/ -rt
total 92
-rw-r--r--. 1 root root 136 Mar  5  2010 ppp
-rw-r--r--  1 root root 188 Mar  2  2012 vsftpd
-rw-r--r--. 1 root root 329 Jul 10  2012 psacct
-rw-r--r--. 1 root root 100 Sep  7  2012 wpa_supplicant
-rw-r--r--. 1 root root 173 Oct 23  2012 iscsiuiolog
-rw-r--r--. 1 root root  71 Nov  6  2012 cups
-rw-r--r--. 1 root root  32 Nov  7  2012 up2date
-rw-r--r--. 1 root root 185 Dec  5  2012 httpd
-rw-r--r--. 1 root root 100 Jan  9  2013 yum
-rw-r--r--. 1 root root 103 Jan  9  2013 dracut
-rw-r--r--. 1 root root 210 Jan 10  2013 syslog
-rw-r--r--. 1 root root  71 Jan 21  2013 subscription-manager
-rw-r--r--. 1 root root 219 Jan 24  2013 sssd
-rw-r--r--. 1 root root 163 Jan 29  2013 libvirtd.qemu
-rw-r--r--. 1 root root 162 Jan 29  2013 libvirtd.lxc
-rw-r--r--. 1 root root 165 Jan 29  2013 libvirtd
-rw-r--r--  1 root root 119 Oct 27  2020 corosync
-rw-r--r--  1 root root 135 Oct 27  2020 gc_system
-rw-r--r--  1 root root 136 Oct 27  2020 gc_express
-rw-r--r--  1 root root 139 Oct 27  2020 gc_gc_recover
-rw-r--r--  1 root root 129 Oct 27  2020 gn_system
-rw-r--r--  1 root root 130 Oct 27  2020 gn_express
-rw-r--r--  1 root root 133 Oct 27  2020 gn_syncserver

注意,如果是从V8版本升级上来的,老的归档配置还在,会继续生效。但新节点(包括安装,扩容,节点替换)在SetSysEnv时必须设置参数,否则默认是不开启归档功能的。

元数据合并

在V8版本里,表的元数据(metadata目录下),每个列也是单独保存的,而在V9版本里,合并成了1个文件。

对于V8升级上来的表,如果发生了dml/ddl等操作,则该表的元数据会合并,否则会保持原有状态。这带来个问题,就是如果从V8生就到V9,且数据有了变动,将【无法回退】到V8了,因为数据格式不再兼容。

审计日志归档的event默认不可用

由于集群VC安装后【直接】创建distribution时,或者从V8升级时,系统默认创建了VC00001的虚拟集群编号。
而审计归档event是在安装包里内置的,默认是VC00000, 需要用户根据使用VC的情况(包括和V8兼容),更改event的数据。
update gbase.event set vc_id='vc00001' where name='import_audit_log';
其中的vc00001要根据你的vc情况决定。如有多个VC,需要自行创建各自的归档event。

tableid的长度变成64位

V8的早期版本是32位的,如果从其升级到64位版本,并创建了新表,那就无法再回退到老的不支持64位tableid的版本了。

查看tableid的方法,请参考 GBase 8a查看表的tableId 其中information_schema.tables表的tableid列,如果是bigint,那就是64位,如果是int,则是32位。

autocommit自动提交功能参数修改被屏蔽

在V8里,支持 set autocommit=0避免自动提交,在V95里增加了_t_gcluster_oldtransaction_support_set_autocommit参数,默认值为0,屏蔽了这个方式。 此改动将导致采用批量commit的insert values方法变成每行提交一次,性能会有几十倍的下降。

伪逻辑如下:

if _t_gcluster_oldtransaction_support_set_autocommit=0 then
  if set autocommit=0 then commit;
  if set autocommit=1 then commit;
else
  if set autocommit=0 then wait user commit or rollback;
  if set autocommit=1 then commit;
endif

检查方法

如果参数不存在,或者为1,代表无影响,如果为0, 则表示关闭。

gbase> show variables like '%_t_gcluster_oldtransaction_support_set_autocommit%';
+---------------------------------------------------+-------+
| Variable_name                                     | Value |
+---------------------------------------------------+-------+
| _t_gcluster_oldtransaction_support_set_autocommit | 0     |
+---------------------------------------------------+-------+
1 row in set (Elapsed: 00:00:00.00)

规避方式

1、改成insert values(),()方案,一个SQL里包含多个值,

2、修改参数。可以通过如下的方式,恢复该功能。

gbase> set global _t_gcluster_oldtransaction_support_set_autocommit=1;
Query OK, 0 rows affected (Elapsed: 00:00:00.01)

如果是长期使用,避免服务重启后失效,建议在【每个管理节点】的gcluster的配置文件gbase_8a_gcluster.cnf里,增加一行参数,如下红色部分

 [gbased]
。。。。。。。 其它参数
skip-name-resolve
query_cache_type = 0
query_cache_size = 0M
event_scheduler= 1

_t_gcluster_oldtransaction_support_set_autocommit=1

参数gbase_export_directory

默认值是1,会自动创建本地导出文件是,创建同名的目录。为了和86兼容,需要修改参数值为0。参考 https://www.gbase8.cn/1238

auto_increment=num写法不再支持

在86版本是SQL语法通过但无效,这带了理解歧义:语法能用为啥不生效?在V95版本里修正为报错:当前版本不支持。

解决方法是删掉无效的部分。

gbase> create table t1(id int primary key auto_increment)auto_increment=4;
ERROR 1235 (42000): This version of GBase doesn't yet support 'auto_increment=num'

功能使用方式变动

该部分对部分用户使用有影响。

在线节点替换

  • 管理节点,依然要复制全部元数据,和以前耗时相同。
  • 数据节点,由以前V8的复制元数据,通过event进行同步的方案,变成修改distrobution的主备策略,然后通过rebalance重分布的方式进行。可以更好的控制恢复期间的资源使用。
  • 管理和数据共机时,要分别做管理和数据替换,操作2次。

增加参数
gcluster_mode_wait
集群安装完毕,默认值为1,1—表示节点替换过程中出现写操作时无限等待,0—表示节点替换过程中出现写操作报错退出。
gcluster_mode_checkinterval
全在线节点替换参数。当gcluster_mode_wait为1时此参数生效,为检测时间间隔。单位分钟,默认5分钟。该参数的取值是最小值5,最大值30。

group_concat支持超过32K

gbase> show variables like '%concat%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| group_concat_max_len | 1024 |
+----------------------+-------+
1 row in set (Elapsed: 00:00:00.00)


gbase> set group_concat_max_len=102400;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)


gbase> set group_concat_max_len=1024000;
Query OK, 0 rows affected (Elapsed: 00:00:00.01)


gbase> show variables like '%concat%';
+----------------------+---------+
| Variable_name | Value |
+----------------------+---------+
| group_concat_max_len | 1024000 |
+----------------------+---------+
1 row in set (Elapsed: 00:00:00.00)

group_concat支持over 语法

gbase> select * from t2;
+------+------+
| id | name |
+------+------+
| 1 | 1234 |
| 2 | 2222 |
| 1 | 1333 |
| 2 | 2333 |
+------+------+
4 rows in set (Elapsed: 00:00:00.01)


标准的group_concat
gbase> select group_concat(name order by name) from t2 group by id;
+----------------------------------+
| group_concat(name order by name) |
+----------------------------------+
| 1234,1333 |
| 2222,2333 |
+----------------------------------+
2 rows in set (Elapsed: 00:00:00.07)
带OVER
gbase> select group_concat(name) over(partition by id order by name) from t2;
+--------------------------------------------------------+
| group_concat(name) over(partition by id order by name) |
+--------------------------------------------------------+
| 1234 |
| 1234,1333 |
| 2222 |
| 2222,2333 |
+--------------------------------------------------------+
4 rows in set (Elapsed: 00:00:00.32)


gbase> select id,name,
group_concat(name) over(partition by id order by name) a,
row_number()over(partition by id order by name) n
from t2
order by id,n;
+------+------+-----------+---+
| id | name | a | n |
+------+------+-----------+---+
| 1 | 1234 | 1234 | 1 |
| 1 | 1333 | 1234,1333 | 2 |
| 2 | 2222 | 2222 | 1 |
| 2 | 2333 | 2222,2333 | 2 |
+------+------+-----------+---+
4 rows in set (Elapsed: 00:00:00.33)

支持int数值直接like模糊匹配

gbase> create table t1(id int);
Query OK, 0 rows affected (Elapsed: 00:00:00.17)

gbase> insert into t1 values(1),(12344);
Query OK, 2 rows affected (Elapsed: 00:00:00.28)
Records: 2 Duplicates: 0 Warnings: 0

gbase> select * from t1 where id like '%3%';
+-------+
| id |
+-------+
| 12344 |
+-------+
1 row in set (Elapsed: 00:00:00.01)

日期相减不足一天的部分,从返回0改成返回小数(862B43开始)

gbase> create table td(a datetime);
Query OK, 0 rows affected (Elapsed: 00:00:00.09)

gbase> insert into td values('2020-03-04 08:00;00');
Query OK, 1 row affected (Elapsed: 00:00:00.32)

gbase> select now(),now()-a, datediff(now(),a) from td;
+---------------------+-------------+-------------------+
| now() | now()-a | datediff(now(),a) |
+---------------------+-------------+-------------------+
| 2020-03-04 08:14:15 | 0.009895833 | 0 |
+---------------------+-------------+-------------------+
1 row in set (Elapsed: 00:00:00.00)


如需要判断日期差距,请使用datediff函数,而不是直接想减。

表锁争抢改成排队

多个session对同一个表做锁操作,不再像86那样一起争抢,而是采用队列形式FIFO.避免了饿死的情况。

新增功能

新增清理某个节点的所有event

gcadmin rmfeventlog ip : remove all feventlog about ip

支持utf8mb4字符集(862B43开始)

用于处理生僻字,和GB18030字符集用途一样。


gbase> create table tmb4(id int,name varchar(100))charset=utf8mb4;
Query OK, 0 rows affected (Elapsed: 00:00:00.46)

gbase> show create table tmb4;
+-------+---------------------------+
| Table | Create Table |
+-------+---------------------------+
| tmb4 | CREATE TABLE "tmb4" (
"id" int(11) DEFAULT NULL,
"name" varchar(100) DEFAULT NULL
) ENGINE=EXPRESS DEFAULT CHARSET=utf8mb4 TABLESPACE='sys_tablespace' |
+-------+-----------------------------+
1 row in set (Elapsed: 00:00:00.00)

支持表空间

gbase> create tablespace aaa datadir '/opt/data' segsize 16M maxsize 1G;
Query OK, 0 rows affected (Elapsed: 00:00:00.06)

gbase> create table t1_data(id int) tablespace='aaa';
Query OK, 0 rows affected (Elapsed: 00:00:00.05)

支持分区(range,list,key,hash)

create tabble t1(id int)partition by range(id)(
partition p1 values less than 10,
partition p2 valeus less than 20,
partition pother values less than maxvalue
);
create table t2 (id int) partition by list(id)(
partition a values in (1,3,5,7),
partition b values in (2,4,6,8)
);

虚拟集群和镜像集群

请参考用户手册。 如继续使用V8方式兼容的集群,无需关心这部分。

多列Hash表

为了解决单列数据严重倾斜问题。但也要求参与group,join的列必须【全部】出现,否则失效。
理论上hash列可以支持2000个,和表相同,但由于元数据表table_distribution的Hash_column的定义是4096,所以不能超过这个最大值。

gbase> create table t3(id int, name varchar(20)) distributed by ('id','name');
Query OK, 0 rows affected (Elapsed: 00:00:00.07)


gbase> show create table t3;
+-------+------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------+
| t3 | CREATE TABLE "t3" (
"id" int(11) DEFAULT NULL,
"name" varchar(20) DEFAULT NULL
) ENGINE=EXPRESS DISTRIBUTED BY('id','name') DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |
+-------+------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)

自增列

只保证自增,但不保证连续。默认自增列不允许load,insert,update等操作。有参数可以打开自增列的可变动状态,但将由用户保证数据唯一。 参考 GBase 8a 在V95版本对表自增列auto_increment的支持样例

gbase> create table t4(id int primary key auto_increment not null, name varchar(100));
Query OK, 0 rows affected (Elapsed: 00:00:00.09)


gbase> show create table t4;
+-------+------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------+
| t4 | CREATE TABLE "t4" (
"id" int(11) NOT NULL AUTO_INCREMENT,
"name" varchar(100) DEFAULT NULL,
PRIMARY KEY ("id")
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |
+-------+------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)


gbase> insert into t4 values(1,'123');
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: auto-increment column should not be specified in insert(...)


gbase> insert into t4(name) values('111111'),(2222),(333),(44);
Query OK, 4 rows affected (Elapsed: 00:00:00.32)
Records: 4 Duplicates: 0 Warnings: 0


gbase> select * from t4;
+----+--------+
| id | name |
+----+--------+
| 1 | 111111 |
| 2 | 2222 |
| 3 | 333 |
| 4 | 44 |
+----+--------+
4 rows in set (Elapsed: 00:00:00.00)


gbase> update t4 set id=3 where id=2;
ERROR 1235 (42000): This version of GBase doesn't yet support 'update/merge on auto_increment column'
gbase> load data infile 'sftp://gbase:gbase1234@10.0.2.102/home/gbase/t4' into table t4;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: Task 1035 failed, [10.0.2.102:5050](GBA-02AD-0005)Failed to query in gnode:
DETAIL: Auto increment column 'id' should not be specified in loader.
SQL: LOAD /*+ TID('65635') */ DATA INFILE 'sftp://gbase:*********@10.0.2.102/home/gbase/t4#offset=0&length=51&firstblock&ffsize=51' INTO TABLE `testdb`.`t4_n1` DATA_FORMAT 3 FILE_FORMAT UNDEFINED HOST '10.0.2.102' CURRENT_TIMESTAMP 1583283005 SCN_NUMBER 1035 GCLUSTER_PORT 5258 INTO SERVER (HOST '10.0.2.102', PORT '5050', USER
gbase>

如下参数可以打开自增列的可变动状态,包括load,insert,update。

gbase> show variables like '%allow_insert%';
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| _gbase_auto_increment_allow_insert | OFF |
+------------------------------------+-------+
1 row in set (Elapsed: 00:00:00.01)


gbase> set _gbase_auto_increment_allow_insert=1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)


手工插入重复数据
gbase> insert into t4 values(1,'123');
Query OK, 1 row affected (Elapsed: 00:00:00.32)


gbase> select * from t4;
+----+--------+
| id | name |
+----+--------+
| 1 | 111111 |
| 2 | 2222 |
| 3 | 333 |
| 4 | 44 |
| 1 | 123 |
+----+--------+
5 rows in set (Elapsed: 00:00:00.01)


gbase> load data infile 'sftp://gbase:gbase1234@10.0.2.102/home/gbase/t4' into table t4 fields terminated by '\t';
Query OK, 5 rows affected (Elapsed: 00:00:01.22)
Task 1038 finished, Loaded 5 records, Skipped 0 records


gbase> select * from t4;
+----+-----------+
| id | name |
+----+-----------+
| 1 | 111111 |
| 2 | 2222 |
| 3 | 333 |
| 4 | 44 |
| 1 | 123 |
| 1 | 99999999 |
| 2 | 699999998 |
| 1 | 99999999 |
| 2 | 699999998 |
| 1 | 10 |
+----+-----------+
10 rows in set (Elapsed: 00:00:00.01)
gbase> update t4 set id=5 where name='10';
Query OK, 1 row affected (Elapsed: 00:00:00.32)
Rows matched: 1 Changed: 1 Warnings: 0


gbase> select * from t4;
+----+-----------+
| id | name |
+----+-----------+
| 1 | 111111 |
| 2 | 2222 |
| 3 | 333 |
| 4 | 44 |
| 1 | 123 |
| 1 | 99999999 |
| 2 | 699999998 |
| 1 | 99999999 |
| 2 | 699999998 |
| 5 | 10 |
+----+-----------+
10 rows in set (Elapsed: 00:00:00.00)

有限事务

详情看用户手册。
但从项目角度讲,依然不建议大量使用,毕竟这不是个【事务型】数据库。
已知对小文件加载,比如每次几行,几十行,数据几十K,但表很多时,开启事务会提升加载性能。

参考 GBase 8a针对宽表1000列的小文件加载不同版本配置性能测试
GBase 8a在V95版本支持session事务内内对一张表的多次更新变动DML操作

仍然不支持同一张表的并行事务写入(需要实现类似多版本功能),所以从严格角度讲,属于有限事务,不能当成事务数据库使用。

支持GB18030字符集(862B43开始)

可以解决一些生僻汉字的问题


gbase> create table t5(id int) charset='gb18030';
Query OK, 0 rows affected (Elapsed: 00:00:00.08)


gbase> show create table t5;
+-------+----------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------+
| t5 | CREATE TABLE "t5" (
"id" int(11) DEFAULT NULL
) ENGINE=EXPRESS DEFAULT CHARSET=gb18030 TABLESPACE='sys_tablespace' |
+-------+----------------------------------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)

支持sha256加密

包括数据库的用户密码,以及sftp传输的加密类型。详情参考

GBase 8a数据库支持sha256用户密码加密的功能gbase_caching_sha2_password
linux redhat 7 sshd 指定sha256密钥算法hmac-sha2-256

脱敏

敏感数据列显示时,按照定义的规则和用户权限做脱敏。

GBase 8a脱敏功能使用样例

KafKa交互

GBase 8a从Kafka的Topic加载数据使用样例