[tcallusdb knowledge base] restfulapi2 0 for generic table - [Pb] Introduction to batchinsertrecords

Posted by gnawz on Mon, 21 Feb 2022 03:49:17 +0100

brief introduction

To add data in batch in PB table, you can specify the insertion method. Batch insertion interface is a non atomic interface, which allows partial success and partial failure. The user needs to judge the number of successful records or failed records according to the return value.

POST http://{Tcaplus_REST_URL}

Request syntax

Http request

#Tencent cloud console RESTful Endpoint, ip:80, port: 80 by default
http://172.17.0.22
#Tcallusdb local docker RESTful Endpoint, ip:31001, port default 31001
http://9.135.8.93:31001

Http head

x-tcaplus-target:Tcaplus.BatchInsertRecords
x-tcaplus-app-id:{string}
x-tcaplus-zone-id:{string}
x-tcaplus-protocol-version:{string}
x-tcaplus-table-name:{string}
x-tcaplus-pwd-md5:{string}
x-tcaplus-result-flag:result_flag
x-tcaplus-version:{string}
x-tcaplus-data-version-check:{string}
x-tcaplus-idl-type:protobuf

Parameter Description:

nameRequiredRestrictionsexplain
x-tcaplus-targetyesnothingTcaplus.BatchInsertRecords
x-tcaplus-versionyesnothingTcaplus3.50.0
x-tcaplus-app-idyesnothingCorresponding service id number (aka, cluster access id)
x-tcaplus-zone-idyesnothingCorresponding zone number (aka, table group id)
x-tcaplus-protocol-versionyesnothingThe corresponding protocol version number is 2.0 by default
x-tcaplus-table-nameyesnothingCorresponding table name
x-tcaplus-pwd-md5yesnothingBusiness password (aka, cluster access password), enter the calculated md5 value
x-tcaplus-idl-typeyesnothingprotobuf
x-tcaplus-result-flagnonothing0: no data will be returned after successful operation 1: data consistent with the request will be returned after successful operation 2: data after this update operation will be returned after successful operation 3: data before tcapsvr operation will be returned after successful operation
x-tcaplus-data-version-checkno1: Detect the record version number. The version number will increase automatically only when it is the same as the server version number. 2: do not detect the record version number, and force the record version number of the client to be written to the server. 3: do not detect the record version number, and increase the server version number automatically
x-tcaplus-data-versionnoSpecific version value

Example:

x-tcaplus-target:Tcaplus.BatchInsertRecords
x-tcaplus-app-id:3
x-tcaplus-zone-id:1
x-tcaplus-protocol-version:2.0
x-tcaplus-table-name:game_players
x-tcaplus-pwd-md5:4e81984efccfb4982333aeb1ff7968d5
x-tcaplus-result-flag:2
x-tcaplus-version:Tcaplus3.50.0
x-tcaplus-data-version-check: 3
x-tcaplus-idl-type:protobuf

Data

Record related information in json format. Parameter Description:

  • MultiRecords: recordsets
  • Record: required, sub record data
{
    "MultiRecords": [{
        "Record": {
            "player_id": 5,
            "player_name": "5",
            "player_email": "5",
            "game_server_id": 5,
            "login_timestamp": [],
            "logout_timestamp": [],
            "is_online": false,
            "pay": {
                "pay_id": 5,
                "amount": 5,
                "method": 5
            }
        }
    }, {

        "Record": {
            "player_id": 5,
            "player_name": "5",
            "player_email": "55",
            "game_server_id": 55,
            "login_timestamp": [],
            "logout_timestamp": [],
            "is_online": false,
            "pay": {
                "pay_id": 55,
                "amount": 55,
                "method": 55
            }
        }
    }, {

        "Record": {
            "player_id": 6,
            "player_name": "6",
            "player_email": "6",
            "game_server_id": 6,
            "login_timestamp": [],
            "logout_timestamp": [],
            "is_online": false,
            "pay": {
                "pay_id": 6,
                "amount": 6,
                "method": 6
            }
        }
    }]
}

Full request example

curl -i -XPOST -H 'x-tcaplus-target: Tcaplus.BatchInsertRecords' -H 'x-tcaplus-app-id: 70' -H 'x-tcaplus-zone-id: 1' -H 'x-tcaplus-protocol-version: 2.0' -H 'x-tcaplus-table-name: game_players' -H 'x-tcaplus-pwd-md5: 0972ad76decf4d11a69e2e0d9af335da' -H 'x-tcaplus-result-flag: 2' -H 'x-tcaplus-version: Tcaplus3.50.0' -H 'x-tcaplus-data-version-check: 3' -H 'x-tcaplus-idl-type: protobuf' http://172.17.32.17 -d '{
    "MultiRecords": [{

            "Record": {
                "player_id":5,
                "player_name":"5",
                "player_email":"5",
                "game_server_id":5,
                "login_timestamp":[],
                "logout_timestamp":[],
                "is_online":false,
                "pay": {
                    "pay_id": 5,
                    "amount": 5,
                    "method": 5
                }
            }
        }, {

            "Record": {
                "player_id":5,
                "player_name":"5",
                "player_email":"55",
                "game_server_id":55,
                "login_timestamp":[],
                "logout_timestamp":[],
                "is_online":false,
                "pay": {
                    "pay_id": 55,
                    "amount": 55,
                    "method": 55
                }
            }
        },{

            "Record": {
                "player_id":6,
                "player_name":"6",
                "player_email":"6",
                "game_server_id":6,
                "login_timestamp":[],
                "logout_timestamp":[],
                "is_online":false,
                "pay": {
                    "pay_id": 6,
                    "amount": 6,
                    "method": 6
                }
            }
        }]
}'

Return syntax

Return parameter description

Parameter nameexplain
ErrorCodeReturn code
ErrorMsgReturn information
ReturnValuesThe reserved data set by the user arrives at tcaplus with the request and is brought back by the reply as it is
SucceedRecordsjson format, the returned Data of successful records, see the Data section in the text for details
SucceedNumNumber of successful records
FailedRecordsjson format, return Data of failed records, see the Data section in the text for details
FailedNumNumber of failed records

Return example

Successful return example

{
    "ErrorCode": 0,
    "ErrorMsg": "Succeed",
    "SucceedRecords": [{
        "RecordVersion": 1,
        "Record": {
            "player_id": 5,
            "player_name": "5",
            "player_email": "5",
            "game_server_id": 5,
            "login_timestamp": [],
            "logout_timestamp": [],
            "is_online": false,
            "pay": {
                "pay_id": 5,
                "amount": 5,
                "method": 5
            }
        }
    }, {
        "RecordVersion": 1,
        "Record": {
            "player_id": 5,
            "player_name": "5",
            "player_email": "55",
            "game_server_id": 55,
            "login_timestamp": [],
            "logout_timestamp": [],
            "is_online": false,
            "pay": {
                "pay_id": 55,
                "amount": 55,
                "method": 55
            }
        }
    }, {
        "RecordVersion": 1,
        "Record": {
            "player_id": 6,
            "player_name": "6",
            "player_email": "6",
            "game_server_id": 6,
            "login_timestamp": [],
            "logout_timestamp": [],
            "is_online": false,
            "pay": {
                "pay_id": 6,
                "amount": 6,
                "method": 6
            }
        }
    }],
    "SucceedNum": 3
}

Failure return example

{
    "ErrorCode": -1293,
    "ErrorMsg": "tcapsvr_fail_record_exist",
    "SucceedRecords": [],
    "SucceedNum": 0,
    "FailedRecords": [{
        "Record": {
            "player_email": "5",
            "player_id": 5,
            "player_name": "5"
        }
    }, {
        "Record": {
            "player_email": "55",
            "player_id": 5,
            "player_name": "5"
        }
    }, {
        "Record": {
            "player_email": "6",
            "player_id": 6,
            "player_name": "6"
        }
    }],
    "FailedNum": 3
}

Tcallusdb is a distributed NoSQL database produced by Tencent. The storage and scheduling code is completely self-developed. It has the characteristics of cache + floor 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 games, Internet, government affairs, finance, manufacturing, Internet of things and other fields.

Topics: Database nosql TcaplusDB