Skip to content

Commit

Permalink
配置梳理
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Nov 14, 2023
1 parent 233908b commit 29d25e3
Show file tree
Hide file tree
Showing 37 changed files with 199 additions and 1,705 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ cd bin
- lua-protobuf

# 数据库支持
- etcd
- mongo
- mysql
- redis
- influx
- clickhouse

# 支持功能
Expand All @@ -98,7 +96,8 @@ cd bin
- 星型分布式服务器框架

# 辅助工具
- graylog日志系统
- GMWeb工具
- 协议测试Web工具
- redis服务发现系统
- zipkin/jager调用链系统
- nacos配置管理和服务发现系统
- dingding/wechat/lark等webhook通知
4 changes: 1 addition & 3 deletions bin/accord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ quanta启动环境配置
dofile("share.conf")

--mongo
set_env("QUANTA_MONGO_URLS", [[
mongodb://root:MTAE379673#@10.96.8.100:27017/tools?readPreference=secondaryPreferred;
]])
set_env("QUANTA_MONGO_URL", "mongodb://root:MTAE379673#@10.96.8.100:27017/tools")

--启动参数
---------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions bin/cache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ dofile("share.conf")
set_env("QUANTA_ENTRY", "cachesvr")
--定义服务名称
set_env("QUANTA_SERVICE", "cache")

--缓存组条目数量
set_env("QUANTA_DB_CACHE_MAX", "4096")
--每帧落地最大数量
set_env("QUANTA_DB_CACHE_FLUSH", "10")
12 changes: 3 additions & 9 deletions bin/database.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ quanta启动环境配置
--单个连接串格式: driver://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
--options格式: key1=value1&key2=value2
--mongo
set_env("QUANTA_MONGO_URLS", [[
mongodb://root:MTAE379673#@127.0.0.1:27017/quanta?readPreference=secondaryPreferred;
]])
set_env("QUANTA_MONGO_URL", "mongodb://root:MTAE379673#@127.0.0.1:27017/quanta")
--redis
set_env("QUANTA_REDIS_URLS", [[
redis://root:[email protected]:6379;
]])
set_env("QUANTA_REDIS_URL", "redis://root:[email protected]:6379")
--mysql
set_env("QUANTA_MYSQL_URLS", [[
mysql://root:[email protected]:3306/quanta;
]])
set_env("QUANTA_MYSQL_URL", "mysql://root:[email protected]:3306/quanta")
33 changes: 5 additions & 28 deletions bin/share.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ quanta启动环境配置
set_env("QUANTA_SERVICE", "quanta")
--服务索引
set_env("QUANTA_INDEX", "1")
--服务分组
set_env("QUANTA_GROUP", "1")
--服务分区
--服务大区
set_env("QUANTA_CLUSTER", "1")
--服务小区
set_env("QUANTA_REGION", "1")
--服务端口偏移
set_env("QUANTA_PORT", "1")
--部署集群
set_env("QUANTA_CLUSTER", "local")
--部署环境
set_env("QUANTA_ENVIRON", "develop")
--服务模式, 决定lua框架默认加载模块
--STANDLONE = 0 独立模式(不加载lua框架,此处仅列举,配置无效)
--SERVICE = 1 服务模式(加载全量)
Expand Down Expand Up @@ -102,20 +102,8 @@ set_env("QUANTA_OUT_ENCRYPT", "0")
-- 开启服务器出包压缩
set_env("QUANTA_OUT_PRESS", "0")


--第三方组件
-----------------------------------------------------
--influx配置
--set_env("QUANTA_INFLUX_ADDR", "10.96.8.100:8086")
--set_env("QUANTA_INFLUX_ORG", "xiyoo0812")
--set_env("QUANTA_INFLUX_BUCKET", "quanta")
--set_env("QUANTA_INFLUX_TOKEN", "d5SUTYyl4jou8BNN4Ee2kn1U0IhWuj3P7qR7JDU_59e7UAzW0yQq_oCyLcHbFt7nX_45yYfDCsmF7beZd6LiSQ==")
--opentrace配置
--set_env("QUANTA_OPENTRACE_ADDR", "10.96.8.100:9411")

--DB
-----------------------------------------------------
set_env("QUANTA_DB_MAIN_ID", "1")
set_env("QUANTA_DB_AUTOINCTB", "counters")
set_env("QUANTA_DB_BENCHMARK", "1001014135")
set_env("QUANTA_DB_AUTOINCKEY", "COUNTER:QUANTA:ROLE")
Expand All @@ -125,17 +113,10 @@ set_env("QUANTA_DB_POOL_COUNT", "10")

--消息队列驱动器/redis/mongo
set_env("QUANTA_MQ_DRIVER", "redis")
--命名空间,用于隔离环境
--使用redis则自定义,nacos使用nacos namespace
set_env("QUANTA_NAMESPACE", "quanta")

--CACHE
-----------------------------------------------------
set_env("QUANTA_DB_USE_CACHE", "1")
--缓存组条目数量
set_env("QUANTA_DB_CACHE_MAX", "4096")
--每帧落地最大数量
set_env("QUANTA_DB_CACHE_FLUSH", "10")

--webhook设置
-----------------------------------------------------
Expand All @@ -146,7 +127,3 @@ set_env("QUANTA_WEBHOOK_MODE", "log")
--set_env("QUANTA_LARK_URL", "https://open.feishu.cn/open-apis/bot/v2/hook/9a6565bf-51b4-48ab-80f0-64caf4d58ab8")
--set_env("QUANTA_DING_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a4c64781-adad-4ddc-a615-6bc232ce71ef")
set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d7cd918c-f608-4762-87af-bb8c7fc51074")

--graylog配置
-----------------------------------------------------
set_env("QUANTA_GRAYLOG_ADDR", "127.0.0.1:8087/udp")
50 changes: 24 additions & 26 deletions script/agent/mongo_agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,75 @@ local mrandom = qmath.random

local router_mgr = quanta.get("router_mgr")

local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID")

local MongoAgent = singleton()
function MongoAgent:__init()
end

--db_query: {coll_name, selector, fields}
function MongoAgent:find_one(db_query, hash_key, db_id)
function MongoAgent:find_one(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_find_one", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_find_one", key, tunpack(db_query))
end

--db_query: {coll_name, selector, fields, sortor, limit}
function MongoAgent:find(db_query, hash_key, db_id)
function MongoAgent:find(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_find", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_find", key, tunpack(db_query))
end

--db_query: {coll_name, selector, single}
function MongoAgent:delete(db_query, hash_key, db_id)
function MongoAgent:delete(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_delete", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_delete", key, tunpack(db_query))
end

--db_query: {coll_name, obj, selector, upsert, multi}
function MongoAgent:update(db_query, hash_key, db_id)
function MongoAgent:update(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_update", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_update", key, tunpack(db_query))
end

--db_query: {coll_name, obj}
function MongoAgent:insert(db_query, hash_key, db_id)
function MongoAgent:insert(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_insert", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_insert", key, tunpack(db_query))
end

--db_query: {coll_name, update, selector, upsert, fields, new}
function MongoAgent:find_and_modify(db_query, hash_key, db_id)
function MongoAgent:find_and_modify(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_find_and_modify", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_find_and_modify", key, tunpack(db_query))
end

--db_query: {pipeline, cursor, [xxkey, xxvalue] ...}
function MongoAgent:aggregate(db_query, hash_key, db_id)
function MongoAgent:aggregate(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_aggregate", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_aggregate", key, tunpack(db_query))
end

--db_query: {coll_name, selector}
function MongoAgent:count(db_query, hash_key, db_id)
return router_mgr:call_mongo_hash(hash_key or mrandom(), "rpc_mongo_count", db_id or MAIN_DBID, tunpack(db_query))
function MongoAgent:count(db_query, hash_key)
return router_mgr:call_mongo_hash(hash_key or mrandom(), "rpc_mongo_count", tunpack(db_query))
end

--db_query: {coll_name, indexes}
function MongoAgent:create_indexes(db_query, hash_key, db_id)
return router_mgr:call_mongo_hash(hash_key or mrandom(), "rpc_mongo_create_indexes", db_id or MAIN_DBID, tunpack(db_query))
function MongoAgent:create_indexes(db_query, hash_key)
return router_mgr:call_mongo_hash(hash_key or mrandom(), "rpc_mongo_create_indexes", tunpack(db_query))
end

--db_query: {coll_name, index_name}
function MongoAgent:drop_indexes(db_query, hash_key, db_id)
return router_mgr:call_mongo_hash(hash_key or mrandom(), "rpc_mongo_drop_indexes", db_id or MAIN_DBID, tunpack(db_query))
function MongoAgent:drop_indexes(db_query, hash_key)
return router_mgr:call_mongo_hash(hash_key or mrandom(), "rpc_mongo_drop_indexes", tunpack(db_query))
end

function MongoAgent:get_autoinc_id(id_key, db_id)
return router_mgr:call_mongo_hash(mrandom(), "rpc_mongo_get_autoinc_id", db_id or MAIN_DBID, id_key)
function MongoAgent:get_autoinc_id(id_key)
return router_mgr:call_mongo_hash(mrandom(), "rpc_mongo_get_autoinc_id", id_key)
end

--db_query: {cmd, ...}
function MongoAgent:execute(db_query, hash_key, db_id)
function MongoAgent:execute(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_mongo_hash(key, "rpc_mongo_execute", db_id or MAIN_DBID, key, tunpack(db_query))
return router_mgr:call_mongo_hash(key, "rpc_mongo_execute", key, tunpack(db_query))
end

------------------------------------------------------------------
Expand Down
36 changes: 17 additions & 19 deletions script/agent/mysql_agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ local router_mgr = quanta.get("router_mgr")

local PARAM_ERROR = quanta.enum("KernCode", "PARAM_ERROR")

local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID")

local MysqlAgent = singleton()
function MysqlAgent:__init()
end
Expand Down Expand Up @@ -50,76 +48,76 @@ function MysqlAgent:format_query_sql(fields)
end

-- 更新
function MysqlAgent:update(db_id, table_name, columns, conditions)
function MysqlAgent:update(table_name, columns, conditions)
if not next(columns) or not next(conditions) then
return false, PARAM_ERROR
end
local sql = sformat("update %s set %s where %s", table_name, self:format_update_sql(columns), self:format_condition_sql(conditions))
return self:excute(sql, db_id)
return self:excute(sql)
end

-- 插入
function MysqlAgent:insert(db_id, table_name, columns)
function MysqlAgent:insert(table_name, columns)
if not next(columns) then
return false, PARAM_ERROR
end
local sql = sformat("insert into %s %s", table_name, self:format_insert_sql(columns))
return self:excute(sql, db_id)
return self:excute(sql)
end

-- 重复插入(存在则更新,不存在则插入)
function MysqlAgent:insert_or_update(db_id, table_name, columns)
function MysqlAgent:insert_or_update(table_name, columns)
if not next(columns) then
return false, PARAM_ERROR
end
local sql = sformat("insert into %s %s on duplicate key update %s", table_name, self:format_insert_sql(columns), self:format_update_sql(columns))
return self:excute(sql, db_id)
return self:excute(sql)
end

-- 替换
function MysqlAgent:replace(db_id, table_name, columns)
function MysqlAgent:replace(table_name, columns)
if not next(columns) then
return false, PARAM_ERROR
end
local sql = sformat("replace into %s %s", table_name, self:format_insert_sql(columns))
return self:excute(sql, db_id)
return self:excute(sql)
end

-- 查询
function MysqlAgent:query(db_id, table_name, conditions, fields)
function MysqlAgent:query(table_name, conditions, fields)
local query_sql = "*"
if fields and #fields > 0 then
query_sql = self:format_query_sql(fields)
end
if conditions and next(conditions) then
-- 带条件查询
local sql = sformat("select %s from %s where %s", table_name, query_sql, self:format_condition_sql(conditions))
return self:excute(sql, db_id)
return self:excute(sql)
else
-- 不带条件查询
local sql = sformat("select %s from %s", table_name, query_sql)
return self:excute(sql, db_id)
return self:excute(sql)
end
end

-- 删除
function MysqlAgent:delete(db_id, table_name, conditions)
function MysqlAgent:delete(table_name, conditions)
if not next(conditions) then
return false, PARAM_ERROR
end
local sql = sformat("delete from %s where %s", table_name, self:format_condition_sql(conditions))
return self:excute(sql, db_id)
return self:excute(sql)
end

-- 清空整张表
function MysqlAgent:truncate(db_id, table_name)
function MysqlAgent:truncate(table_name)
local sql = sformat("truncate table %s", table_name)
return self:excute(sql, db_id)
return self:excute(sql)
end

--发送数据库请求
function MysqlAgent:execute(sql, db_id, hash_key)
return router_mgr:call_mysql_hash(hash_key or mrandom(), "rpc_mysql_execute", db_id or MAIN_DBID, sql)
function MysqlAgent:execute(sql, hash_key)
return router_mgr:call_mysql_hash(hash_key or mrandom(), "rpc_mysql_execute", sql)
end

------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions script/agent/redis_agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ local mrandom = qmath.random

local router_mgr = quanta.get("router_mgr")

local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID")

local RedisAgent = singleton()
function RedisAgent:__init()
end

--发送数据库请求
--db_query: { cmd, ...}
function RedisAgent:execute(db_query, hash_key, db_id)
function RedisAgent:execute(db_query, hash_key)
local key = hash_key or mrandom()
return router_mgr:call_redis_hash(key, "rpc_redis_execute", db_id or MAIN_DBID, tunpack(db_query))
return router_mgr:call_redis_hash(key, "rpc_redis_execute", tunpack(db_query))
end

------------------------------------------------------------------
Expand Down
13 changes: 4 additions & 9 deletions script/basic/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function service.make_node(port, domain)
id = quanta.id,
name = quanta.name,
index = quanta.index,
group = quanta.group,
region = quanta.region,
cluster = quanta.cluster,
service = quanta.service,
port = port or quanta.index,
host = domain or quanta.host,
Expand All @@ -46,28 +46,23 @@ function service.init()
end
--初始化服务信息
local index = environ.number("QUANTA_INDEX", 1)
local group = environ.number("QUANTA_GROUP", 1)
local cluster = environ.number("QUANTA_CLUSTER", 1)
local region = environ.number("QUANTA_REGION", 1)
local service_name = environ.get("QUANTA_SERVICE")
local service_id = SERVICES[service_name]
quanta.index = index
quanta.group = group
quanta.region = region
quanta.cluster = cluster
quanta.service = service_id
quanta.service_name = service_name
quanta.host = environ.get("QUANTA_HOST_IP")
quanta.order = environ.number("QUANTA_PORT", 1)
quanta.id = service.make_sid(service_id, index)
quanta.name = sformat("%s_%s", service_name, index)
quanta.cluster = environ.get("QUANTA_CLUSTER", "develop")
quanta.env = environ.get("QUANTA_ENVIRON", "develop")
service.make_node()
end

--生成节点id
function service.make_id(group, region, service, index)
return (group << 26) | (region << 16) | (service << 10) | index
end

--生成服务id
function service.make_sid(service, index)
return (service << 16) | index
Expand Down
Loading

0 comments on commit 29d25e3

Please sign in to comment.