You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.1 KiB

1 month ago
#!/usr/bin/sysbench
account_table_name = "tbaccount"
account_table_max = 100;
local account_id_mod = "%d_KKKKKKKKKKKKKKKKKKKKKKKKK"
function get_account_id(id_index)
return string.format(account_id_mod, id_index)
end
function random_accountToken()
return sysbench.rand.string("########################################")
end
function random_deviceid()
return sysbench.rand.string("#####################")
end
function random_nick()
return sysbench.rand.string("######################")
end
function random_icon()
return sysbench.rand.string("########################################")
end
function random_exdata()
return sysbench.rand.string("######################")
end
function random_time()
return sysbench.rand.default(1684756655,1784756655);
end
function random_gender()
return sysbench.rand.default(0, 3);
end
function random_ipaddr()
return sysbench.rand.default(1232235889, 2032235889)
end
function accountId_to_type(account_id)
return account_id % 6;
end
function insert_account_cmd(db_index, account_id)
return string.format(
"INSERT INTO `%s_%d` (`accountType`, `accountId`, `accountToken`, `createTime`, `createDeviceId`, `createIpAddr`, `nick`, `gender`, `icon`, `money`, `recharge`, `lastLoginRealm`, `grade`, `exData`) VALUES " ..
"(%d, '%s', '%s', %d, '%s', %d, %s, %d, %s, %d, %d,%d, %d, '%s')",
account_table_name, db_index,
accountId_to_type(account_id),
get_account_id(account_id),
random_accountToken(),
random_time(),
random_deviceid(),
random_ipaddr(),
random_nick(),
random_gender(),
random_icon(),
sysbench.rand.default(0, 1000000), -- money
sysbench.rand.default(0, 1000000), -- recharge
sysbench.rand.default(0, 1000000), -- lastLoginRealm
sysbench.rand.default(0, 6), -- grade
random_exdata()
)
end
function update_account_realm_cmd(db_index, account_id)
return string.format(
"update %s_%d set lastLoginRealm=%d where accountType=%d and accountId='%s'",
account_table_name, db_index,
sysbench.rand.default(0, 1000000),
accountId_to_type(account_id),
get_account_id(account_id)
)
end
function update_account_grade_cmd(db_index, account_id)
return string.format(
"update %s_%d set grade=%d where accountType=%d and accountId='%s'",
account_table_name, db_index,
sysbench.rand.default(0, 6),
accountId_to_type(account_id),
get_account_id(account_id)
)
end
function update_account_exdata_cmd(db_index, account_id)
return string.format(
"update %s_%d set exData=%s where accountType=%d and accountId='%s'",
account_table_name, db_index,
random_exdata(),
accountId_to_type(account_id),
get_account_id(account_id)
)
end
function select_account(db_index, account_id)
return string.format(
"select * from %s_%d where accountType=%d and accountId='%s'",
account_table_name, db_index,
accountId_to_type(account_id),
get_account_id(account_id)
)
end