Databases store data in tables, and different tables often represent different entities. As a domestic key-value NOSQL database, TcaplusDB supports two types of tables: Protocol Buffers table (Protobuf) and TDR table (Tencent Data Representation).
Protobuf is a descriptive language developed by Google that serializes structured data while emphasizing simplicity and performance. TDR is a cross-platform data representation language developed by Tencent, which combines the advantages of XML, binary and ORM (Object relational Mapping) and is widely used in the serialization scenarios of Tencent game data. This article briefly explains how to define these two types of tables.
Protobuf table
Here is an example of protobuf table game_players.proto. You can upload a file to Tencent Cloud console and create the table.
syntax = “proto3”; // Specify the protobuf language version, proto3.
/ / import TcaplusDB public define service import “tcaplusservice. Optionv1. Proto”;
Message game_players {// Define the TcaplusDB table with type message
Tcaplusservice. tcaplus_primary_key creates primary key fields based on the selection tCAplusservice. tcaplus_primary_key // TcaplusDB A maximum of four primary key fields option(tcaplusservice.tcaplus_primary_key) = can be specified for a single table “player_id, player_name, player_email”;
Tcaplusservice.tcaplus_index Option (tcaplusservice.tcaplus_index) = "index_1(player_id, player_name)"; option(tcaplusservice.tcaplus_index) = "index_2(player_id, player_email)"; // TcaplusDB supports the following numeric types: // int32, int64, uint32, uint64, sint32, sint64, bool, fixed64, sfixed64, double, fixed32, sfixed32, float, string, Bytes // Nested type: message // Primary key field int64 player_id = 1; string player_name = 2; string player_email = 3; // Plain (non-primary key) field int32 game_server_id = 4; repeated string login_timestamp = 5; repeated string logout_timestamp = 6; bool is_online = 7; payment pay = 8;Copy the code
}
message payment {
int64 pay_id = 1; uint64 amount = 2; int64 method = 3;
}
TDR table
TDR supports generic tables and list tables. Generic tables are tables that represent element attributes in the form of tables, such as student, employer, and gamer tables. A list is a list of records, such as a leaderboard of the game, and the emails in the game (usually the last 100 emails).
It is recommended to create two different types of tables in one XML file.
The element metalib is the root element of the XML file. Alternatively, you can use union to create nested types: a struct element that contains the attribute primarykey defines a table; Otherwise, it’s just a normal structure. Each time the table structure is modified, the version attribute value should be incremented by 1. The original version is always 1. The primarykey property specifies the primarykey field; You can specify up to eight primary key fields for generic tables and seven for list tables. The splitTableKey property is equivalent to a Shard key. The TcaplusDB table is split and stored on multiple storage nodes. Splittablekey must be one of the primary key fields. A good SplitTableKey should be highly distributed, which means a wide range of values. Strings are recommended. The desc attribute contains a description of the current element. The Entry element defines a field. The supported value types include int32, string, char, int64, double, short, and so on. The index element defines an index that must contain a splitTableKey. Because primary keys can be used to query tables, indexes should not be the same as primary key attributes. Sample: users_mails. XML
<entry name="level" type="int32" defaultvalue="1" desc="role's level"/>
<entry name="role_name" type="string" size="1024" desc="role's name"/>
<entry name="last_login_time" type="string" size="64" defaultvalue="" desc="user login timestamp"/>
<entry name="last_logout_time" type="string" size="64" defaultvalue="" desc="user logout timestamp"/>
<index name="index1" column="user_id"/>
Copy the code
<entry name="text" type="string" size="2048" desc="mail text"/>
<entry name="send_time" type="string" size="64" defaultvalue="" desc="timestamp of the mail sent"/>
<entry name="read_time" type="string" size="64" defaultvalue="" desc="timestamp of the mall read"/>
Copy the code
TcaplusDB is a distributed NoSQL database produced by Tencent. The storage and scheduling code is completely self-developed. It has features such as cache + ground fusion architecture, PB-level storage, millisecond delay, lossless horizontal expansion and complex data structure. At the same time, it has the characteristics of rich ecology, convenient migration, extremely low operation and maintenance cost and five nine high availability. Customers cover gaming, Internet, government, finance, manufacturing and Internet of Things and other fields.