Tcaplus使用总结

简介: Tcaplus使用总结

一、Tcaplus是什么?

游戏数据库 TcaplusDB 是专为游戏设计的 NoSQL 分布式数据存储服务,支持 Protobuf 接口访问,Tcaplus 将 Cache 与硬盘结合,追求高性能的同时,也节省成本,很好地支持全区全服和分区分服,并针对游戏爆发增长和长尾运维特点提供不停机扩缩容、备份容灾、快速回档等全套解决方案,安全可信赖。目前应用于《王者荣耀》、《穿越火线》、《火影忍者》等数百款流行游戏。

二、使用步骤

特别要注意的是,在购买时,连接协议里选择TDR,这样就支持xml表定义了。

如何定义表

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<metalib name="demo_table" tagsetversion="1" version="1">
  <struct name="user" version="1" primarykey="user_id,server_id" splittablekey="user_id">
      <entry name="user_id" type="string" size="450" desc="用户ID"/>
      <entry name="server_id" type="uint64" desc="服务器ID" />
      <entry name="nick_name" type="string" size="50" desc="昵称"/>
      <entry name="desc" type="string" size="1024" desc="描述信息"/>
      <entry name="state" type="Tinyuint" defaultvalue="0" desc="用户状态 0 : AVALIABLE, 1 DELETED"/>
      <index name="index1" column="user_id"/>
    <index name="index2" column="user_id,server_id"/>
  </struct>
   <struct name="mail" version="1" primarykey="user_id,server_id,mail_id" splittablekey="user_id" >
    <entry name="user_id" type="string" size="50"  desc="用户ID"/>
    <entry name="server_id" type="uint64" desc="服务器ID" />
    <entry name="mail_id" type="uint64" desc="邮件ID" />
    <entry name="state" type="Tinyuint" defaultvalue="0" desc="邮件状态(0 未读/1 已读)"/>
    <entry name="from" type="string" size="50" desc="邮件发送方名字"/>
    <entry name="subject" type="string" size="100" desc="邮件标题"/>
    <entry name="content" type="string" size="1024" desc="邮件正文"/>
    <index name="index1" column="user_id"/>
    <index name="index2" column="user_id,server_id"/>
    <index name="index3" column="user_id,mail_id"/>
  </struct>
  <struct name="server" version="1" primarykey="server_id" splittablekey="server_id" >
    <entry name="server_id" type="uint64" desc="服务器ID" />
    <entry name="server_name" type="string" size="50" desc="服务器名称"/>
    <entry name="capacity" type="uint64"  desc="服务器最大承载容量"/>
      <entry name="desc" type="string" size="1024" desc="描述信息"/>
      <entry name="state" type="Tinyuint" defaultvalue="0" desc="server状态 0 : AVALIABLE, 1 DELETED"/>
      <index name="index1" column="server_id"/>
  </struct>
</metalib>

通过 client 工具访问 TcaplusDB 数据

1.tcaplus_client 是一个 TcaplusDB 表访问的客户端工具,可通过下表中的下载链接进行下载,Linux x86_64 平台的 TcaplusServiceAPI 发布包包含64位 Linux 版本的 tcaplus_client 工具:

版本 发布时间 操作系统 下载包名
3.46.0.199033 2020/12/28 Linux x86_64 下载

2.下载完成 TcaplusServiceApi 安装包后,将其 通过上传工具 上传至与 TcaplusDB 集群同一VPC,同一子网的云服务器中,然后解压。

tar -xf TcaplusPbApi3.46.0.199033.x86_64_release_20201210.tar.gz -C tcaplus

解压完成后,进入至 tcaplus 的 bin 目录中,并赋予可执行权限:

cd tcaplus/release/x86_64/bin
chmod +x tcaplus_client

直接执行./tcaplus_client命令,会提示连接数据库所需的参数信息,用户可以根据自己的集群信息进行填写

参数 说明 是否必填
-a 接入 ID 是
-z 表格组 ID 是
-s 集群密码 是
-d 集群 IP 地址及端口 是
-e 需要执行的 SQL 语句,需要双引号包含 否
./tcaplus_client -a 15 -z 1 -s "ooxx" -d 172.16.0.7:9999

返回结果

====== Welcome to use tcaplus_client, use "help" to show usage ======
tcaplus> help;
--------------------------------------------------------------------------------
    help: show usage of commands, example: "help select;".
    show: get server status related information. executing "help show;" for details.
    exit/quit: exit the client.
    count: print record number in the database.
    desc: print table field name and type.
    select: query records from database.
    insert: insert a new record into database.
   replace: replace a record into the database.
   update: update a record in the database.
   delete: delete record(s) from database.
   dump: dump records from database.
   load: load records into the database.
--------------------------------------------------------------------------------

查看数据库集群状态

tcaplus> show status;
------------------------------------------------------------------
Access_id(app_id) = 15
------------------------------------------------------------------
TableGroup_id(zone_id) = 1 
------------------------------------------------------------------
[dir_server_url]
    dir_server_url[0]: 172.16.0.7:9999
------------------------------------------------------------------
[Proxys]
    proxy[0]:tcp://172.16.0.7:10001 CONNECTED Authened 
    proxy[1]:tcp://172.16.0.7:10002 CONNECTED Authened 
------------------------------------------------------------------
[The connected dir server]
    tcp://172.16.0.7:9999
------------------------------------------------------------------

查看所有表

tcaplus> show tables;
----------------------------------------------------------
| Table Name                         Type      Protocol  |
----------------------------------------------------------
| server                             GENERIC   TDR       |
| user                               GENERIC   TDR       |
| mail                               GENERIC   TDR       |
----------------------------------------------------------

查看表结构

tcaplus> desc mail;
Table Structure From: Tcaplus System
TableName: mail
TableType: GENERIC, IdlType: TDRXML
SvrTdrCurrentVersion: 1
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|Field    |Type  |Key     |Index|Size|Version|DefaultValue|Count|Select|Desc                   |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|user_id  |string|PRI,SPLT|-    |50  |1      |-           |1    |-     |用户ID                 |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|server_id|uint64|PRI     |-    |8   |1      |-           |1    |-     |服务器ID               |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|mail_id  |uint64|PRI     |-    |8   |1      |-           |1    |-     |邮件ID                 |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|state    |uint8 |-       |-    |1   |1      |0           |1    |-     |邮件状态(0 未读/1 已读)|
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|from     |string|-       |-    |50  |1      |-           |1    |-     |邮件发送方名字         |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|subject  |string|-       |-    |100 |1      |-           |1    |-     |邮件标题               |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
|content  |string|-       |-    |1024|1      |-           |1    |-     |邮件正文               |
+---------+------+--------+-----+----+-------+------------+-----+------+-----------------------+
7 rows in set (113 us)

插入:

tcaplus> insert into mail (user_id, server_id, mail_id, state,from,subject,content) values ("10001",1,202106301221,0,"系统","新手邮件","欢迎你,来到我们的虚拟世界");
insert success
insert time: 6427 us

查询表格的记录总数

tcaplus> count mail;
--------------------------------------------------------------------------------
| TableName                                 Count                              |
--------------------------------------------------------------------------------
| mail                                      1                                  |
--------------------------------------------------------------------------------

查询:

tcaplus> select * from mail where user_id = "10001" and server_id = 1;
+-------+---------+------------+-----+------+----------+----------------------------+
|user_id|server_id|mail_id     |state|from  |subject   |content                     |
+-------+---------+------------+-----+------+----------+----------------------------+
|"10001"|1        |202106301221|0    |"系统"|"新手邮件"|"欢迎你,来到我们的虚拟世界"|
+-------+---------+------------+-----+------+----------+----------------------------+
1 records selected, select time: 41306 us

如果要列显示:

tcaplus> select * from mail where user_id = "10001" \G;
user_id: "10001"
server_id: 1
mail_id: 202106301221
state: 0
from: "系统"
subject: "新手邮件"
content: "欢迎你,来到我们的虚拟世界"
1 records selected, select time: 5450 us

更新:

tcaplus> update mail set state = 1, from = "系统2"  where user_id = "10001" and server_id = 1 and mail_id=202106301221;
update success
update time: 7497 us

删除:

tcaplus> delete from mail where user_id = "10001" and server_id = 1 and mail_id=202106301221;                                                                        
delete success
delete time: 5367 us

如果要通过部分key 删除符合条件的记录,如下使用:

tcaplus> delete from mail where user_id = "10001" and server_id = 1 by partkey;
delete success
delete time: 8567 us

导出

tcaplus> dump * into mail.txt from mail limit 10;

会导出到本目录下,打开后,内容如下:

[root@VM_0_13_centos bin]# cat mail.txt 
user_id,server_id,mail_id,state,from,subject,content
"10001",1,202106301221,0,"系统","新手邮件","欢迎你,来到我们的虚拟世界"

导入

tcaplus> load mail infile mail.txt;
loaded 1 records successful

索引查询

当开启全局索引功能后,TcaplusDB 将支持按照普通字段查询,查询条件中的字段必须是建立了全局索引的字段。

如果是聚合查询,那么聚合查询的字段也必须是建立了全局索引的字段。

一个索引查询请求,最多返回3000条记录。

支持的查询语句

条件查询

支持=, >, >=, <, <=, !=, between, in, not in, like, not like, and, or

聚合查询

当前支持的聚合查询包括:sum, count, max, min, avg,如:

以下两个指令要等到3.51.0才能支持

设置生命周期

毫秒级别

tcaplus> setttl  mail ttl=60000  where user_id = "10001" and server_id = 1 and mail_id="202106301221";

读取生命周期

tcaplus> getttl from mail where user_id = "10001" and server_id = 1 and mail_id="202106301221";

退出

tcaplus> exit

当你不知道某个指令如何使用时,可以用help 前缀看帮助内容:

help select

如何安装:

大概有7个G不到的大小

docker load -i tcaplusdb-local-3.53.1.tar.gz
[root@VM-0-15-centos download]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED      SIZE
tcaplusdb-local   3.53.1    34c03389c8d3   3 days ago   6.74GB

打tag

sudo docker tag 34c03389c8d3 ccr.ccs.tencentyun.com/jiangguilong/tcaplus:3.53.1

推送到远程镜像仓库

sudo docker push ccr.ccs.tencentyun.com/jiangguilong/tcaplus:3.53.1

创建工作负载 Deployment,特别要指出

运行命令为/bin/sh,运行参数

-c
sleep 36000
#TCAPLUS_CONTAINER_PROXY_PUBLIC_IP是指定proxy的ip, 获取方式:进CentOS7 环境,用ifconfig 获取eth0的ip,
docker run -itd --privileged -e TCAPLUS_CONTAINER_PROXY_PUBLIC_IP="x.x.x.x" -e TCAPLUS_CONTAINER_OMS_PASSWORD="***" -p 80:80 -p 13755-13765:13755-13765 
-p 9999:9999 --shm-size=3G --name test tcaplusdb-local:3.51.1

TCAPLUS_CONTAINER_PROXY_PUBLIC_IP说明:

场景1:Docker部署在远程机器环境,此时指定的IP为远程机器的IP(能被本机访问OK,telnet

9999,13755递增类端口ok)

场景2:Docker部署在本机windows10的wsl2环境,此时指定的ip为进wsl2的Centos7环境,ifconfig获取

的eth0的ip

场景3:Docker部署在腾讯云CVM环境,此时指定的IP为CVM机器的外网IP(安全组放通9999,13755-137xx

范围内的端口)

查看开通的

端口

[root@tcaplus-d57ffc6c8-n2tfq tcaplus]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      2205/httpd          
tcp        0      0 172.16.0.28:6000            0.0.0.0:*                   LISTEN      1451/./swiftd       
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1382/httpd          
tcp        0      0 172.16.0.28:9200            0.0.0.0:*                   LISTEN      966/java            
tcp        0      0 127.0.0.1:9010              0.0.0.0:*                   LISTEN      1351/tconnd         
tcp        0      0 172.16.0.28:4500            0.0.0.0:*                   LISTEN      2128/tcapdb         
tcp        0      0 172.16.0.28:9300            0.0.0.0:*                   LISTEN      966/java            
tcp        0      0 172.16.0.28:21              0.0.0.0:*                   LISTEN      825/vsftpd          
tcp        0      0 172.16.0.28:9017            0.0.0.0:*                   LISTEN      1478/base_agent_net 
tcp        0      0 172.16.0.28:13755           0.0.0.0:*                   LISTEN      2026/swiftd         
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      1382/httpd          
tcp        0      0 172.16.0.28:13756           0.0.0.0:*                   LISTEN      2029/swiftd         
tcp        0      0 172.16.0.28:9020            0.0.0.0:*                   LISTEN      1478/base_agent_net 
tcp        0      0 0.0.0.0:36000               0.0.0.0:*                   LISTEN      853/sshd            
tcp        0      0 172.16.0.28:8899            0.0.0.0:*                   LISTEN      1367/tcenterd       
tcp        0      0 172.16.0.28:9898            0.0.0.0:*                   LISTEN      2109/swiftd         
tcp        0      0 172.16.0.28:3306            0.0.0.0:*                   LISTEN      699/mysqld          
tcp        0      0 172.16.0.28:9999            0.0.0.0:*                   LISTEN      2109/swiftd

对pod的环境配置要求,如果内存不够用会导致启动部分service失败

CPU 内存 本地存储 实例数量(最低要求)
4 核 8 GB 50 GB 1

如何在TKE下设置pod配置:

工作负载类型:Deployment
镜像:ccr.ccs.tencentyun.com/yorha-kf-demo/tcaplus
镜像版本:3.53.1
环境变量:
TCAPLUS_CONTAINER_OMS_PASSWORD=Yorha888
TCAPLUS_CONTAINER_PROXY_PUBLIC_IP=42.192.666.252
工作目录:/data/tcaplus/
运行命令:/bin/sh
运行参数:
-c
sh tcaplus_run.sh  > run.log && sleep 36000
特权级容器:开启
容器开启特权级,将拥有宿主机的root权限

截图如下:

我们通过负载均衡来访问,服务和路由设置:

如果遇到license无效需要你上传时,只需要设置下,

系统管理–>系统配置->TOKEN绑定IP 设置否

游戏进程和Tcaplus之间的连接一般是一个进程一个连接,用异步

参考链接:游戏数据库TcaplusDB

总结

TcaplusDB是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。

目录
相关文章
|
6月前
|
监控 druid OLAP
别再盲选数据库了!ClickHouse、Druid、QuestDB 到底怎么选?一篇文章帮你避开 90% 的坑
别再盲选数据库了!ClickHouse、Druid、QuestDB 到底怎么选?一篇文章帮你避开 90% 的坑
521 0
|
缓存 前端开发 Java
使用http-server搭建静态文件服务器
本文介绍几种搭建静态文件服务器的方式,着重介绍基于node的http-server用法。
使用http-server搭建静态文件服务器
|
8月前
|
安全 API
敏感词过滤-文本审核-敏感词审核-违禁词审核-敏感词检测-违禁词检测
本服务提供智能文本审核,精准识别违禁词、色情低俗、恶意推广、辱骂攻击及低质灌水内容,并校验广告法合规性,适用于评论过滤、注册信息筛查、文章发布等场景,保障内容安全与平台合规。
1512 1
|
存储 人工智能 测试技术
HarmonyOS Next~HarmonyOS应用测试全流程解析:从一级类目上架到二级类目专项测试
本文深入解析HarmonyOS应用测试全流程,涵盖从一级类目通用测试到二级类目专项测试的技术方案。针对兼容性、性能、安全测试及分布式能力验证等关键环节,提供详细实践指导与代码示例。同时,结合典型案例分析常见问题及优化策略,帮助开发者满足华为严苛的质量标准,顺利上架应用。文章强调测试在开发中的核心地位,助力打造高品质HarmonyOS应用。
938 2
|
存储 NoSQL 安全
红包系统架构设计
红包系统架构设计
2878 0
红包系统架构设计
|
12月前
|
运维 监控 数据可视化
15-Portainer轻量级图形化监控 Portainer:Docker轻量级可视化工具
Portainer是一款轻量级Docker图形化管理工具,支持单机与集群环境,提供开源(CE)和商业版(BE/EE)。通过Docker部署,映射端口并挂载卷后即可运行,访问9000端口可进入界面。首次使用需创建管理员账号,可直观管理镜像、容器、网络、数据卷及Stack编排,简化运维操作。
|
SQL 关系型数据库 MySQL
MySQL如何排查和删除重复数据
该文章介绍了在MySQL中如何排查和删除重复数据的方法,包括通过组合字段生成唯一标识符以及使用子查询和聚合函数来定位并删除重复记录的具体步骤。
1636 2
|
数据采集 搜索推荐 API
速来!小红书电商 API 接口,解锁种草数据新玩法
在数字化电商时代,小红书电商 API 成为品牌与开发者挖掘“种草”数据价值的关键工具。本文详解 API 的使用方法、核心优势及实战案例,助你实现精准营销与创新应用,抢占市场先机。
1198 1
|
自然语言处理 Python
【Python自然语言处理】文本向量化的六种常见模型讲解(独热编码、词袋模型、词频-逆文档频率模型、N元模型、单词-向量模型、文档-向量模型)
【Python自然语言处理】文本向量化的六种常见模型讲解(独热编码、词袋模型、词频-逆文档频率模型、N元模型、单词-向量模型、文档-向量模型)
5147 0
|
人工智能 API
通过API调用通义千问时出现DataInspectionFailed的解决办法(玄学版)
在使用qwen-plus API进行长文本翻译时,遇到了DataInspectionFailed错误,提示输入数据可能包含不当内容。尽管确认文本无敏感内容,但误判依然发生。通过将每个分段的字符数从1000降低到700,问题得以解决。建议在处理长文本时,减少每次请求的字符数以避免误判。
8643 6