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级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。

目录
相关文章
|
安全 数据库 数据安全/隐私保护
|
12月前
|
数据挖掘 数据处理 开发者
Python3 自定义排序详解:方法与示例
Python的排序功能强大且灵活,主要通过`sorted()`函数和列表的`sort()`方法实现。两者均支持`key`参数自定义排序规则。本文详细介绍了基础排序、按字符串长度或元组元素排序、降序排序、多条件排序及使用`lambda`表达式和`functools.cmp_to_key`进行复杂排序。通过示例展示了如何对简单数据类型、字典、类对象及复杂数据结构(如列车信息)进行排序。掌握这些技巧可以显著提升数据处理能力,为编程提供更强大的支持。
651 10
|
Android开发 开发者
Android中弹框如何设计成全屏的
本文介绍在Android中实现全屏对话框的方法,包括使用`Dialog`和`DialogFragment`两种方式。通过设置对话框无标题、调整布局参数及使用透明背景实现全屏效果。适用于希望提升应用交互体验的开发者。
433 0
|
图形学 数据安全/隐私保护 iOS开发
Unity与IOS⭐Xcode打包,上架TestFlight的完整教程
Unity与IOS⭐Xcode打包,上架TestFlight的完整教程
|
安全 算法 网络协议
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
在数字时代,网络安全和信息安全已经成为了我们生活中不可或缺的一部分。本文将介绍网络安全漏洞、加密技术和安全意识等方面的内容,帮助读者更好地了解网络安全的重要性和应对措施。通过阅读本文,您将了解到网络安全的基本概念、常见的网络安全漏洞、加密技术的原理和应用以及如何提高个人和组织的网络安全意识。
|
网络协议 测试技术 网络安全
Python进行Socket接口测试的实现
在现代软件开发中,网络通信是不可或缺的一部分。无论是传输数据、获取信息还是实现实时通讯,都离不开可靠的网络连接和有效的数据交换机制。而在网络编程的基础中,Socket(套接字)技术扮演了重要角色。 Socket 允许计算机上的程序通过网络进行通信,它是网络通信的基础。Python 提供了强大且易于使用的 socket 模块,使开发者能够轻松地创建客户端和服务器应用,实现数据传输和交互。 本文将深入探讨如何利用 Python 编程语言来进行 Socket 接口测试。我们将从基础概念开始介绍,逐步引导大家掌握创建、测试和优化 socket 接口的关键技能。希望本文可以给大家的工作带来一些帮助~
Java-Thread多线程的使用
这篇文章介绍了Java中Thread类多线程的创建、使用、生命周期、状态以及线程同步和死锁的概念和处理方法。
Java-Thread多线程的使用
|
Unix C语言 C++
Python调用C/C++
Python调用C/C++
745 2
|
存储 Java API