Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openresty
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tangku7
openresty
Commits
acf66189
Commit
acf66189
authored
Jul 28, 2018
by
周尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注释
parent
3be52cb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
+28
-8
nginx/lua/luabiz/tk_sdt.lua
nginx/lua/luabiz/tk_sdt.lua
+1
-2
nginx/lua/luabiz/tk_sync.lua
nginx/lua/luabiz/tk_sync.lua
+27
-6
No files found.
nginx/lua/luabiz/tk_sdt.lua
View file @
acf66189
...
...
@@ -9,7 +9,7 @@ local json = loadmod('cjson')
local
db_conf
=
"tk7_dbs.json"
-- 协
和
组
-- 协
程
组
local
tasks
=
{}
...
...
@@ -327,7 +327,6 @@ local function sdt_sql(db_st)
-- Convert type
shop
[
'op_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'op_map_id'
])
shop
[
'mer_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'mer_map_id'
])
shop
[
'shop_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'shop_map_id'
])
...
...
nginx/lua/luabiz/tk_sync.lua
View file @
acf66189
...
...
@@ -20,12 +20,15 @@ end
-- 表信息
-- @param table tk_biz 节点机数据库对象
-- table tk_control 总控机数据库对象
-- @param table tk_biz 节点机数据库对象
-- table tk_control 总控机数据库对象
-- table tk_database 数据同步数据库名
-- table tk_table 数据同步表名
-- @return nil
local
function
sync_sql
(
tk_biz
,
tk_control
,
tk_
table
,
tk_databas
e
)
local
function
sync_sql
(
tk_biz
,
tk_control
,
tk_
database
,
tk_tabl
e
)
zx_base
:
log
(
MODULE
,
"-----------------------> START[TK_SYNC]"
)
-- 新建mysql连接
local
db
,
err
=
mysql
:
new
()
if
not
db
then
...
...
@@ -55,7 +58,6 @@ local function sync_sql(tk_biz, tk_control, tk_table, tk_database)
tk_table
,
"20180716000000"
)
local
syncs
syncs
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql
)
if
not
syncs
then
...
...
@@ -99,7 +101,6 @@ local function sync_sql(tk_biz, tk_control, tk_table, tk_database)
for
i
=
1
,
#
syncs
do
local
sync
=
syncs
[
i
]
local
sql_result
=
zx_base
:
sql_concate
(
"duplicate"
,
tk_table
,
sync
)
ok
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_result
)
if
not
ok
then
zx_base
:
log
(
MODULE
,
"[TK_SYNC]"
,
sql_result
)
...
...
@@ -108,12 +109,20 @@ local function sync_sql(tk_biz, tk_control, tk_table, tk_database)
end
end
ngx
.
say
(
"SUCCESS"
)
EOF
()
end
local
function
async
(
tk_biz
,
tk_control
,
tk_database
,
tk_table
)
-- 异步运行
-- @param table tk_biz 节点机数据库对象
-- table tk_control 总控机数据库对象
-- table tk_database 数据同步数据库名
-- table tk_table 数据同步表名
-- @return nil
local
function
async
(
tk_biz
,
tk_control
,
tk_database
,
tk_table
)
local
co
=
coroutine.wrap
(
function
()
sync_sql
(
tk_biz
,
tk_control
,
tk_database
,
tk_table
)
...
...
@@ -122,6 +131,10 @@ local function async(tk_biz, tk_control, tk_database, tk_table)
table.insert
(
tasks
,
co
)
end
-- 协程调度
-- @param nil
-- @return nil
local
function
dispatch
()
local
i
=
1
while
true
do
...
...
@@ -141,6 +154,10 @@ local function dispatch()
end
end
-- 跑批业务处理
-- @param nil
-- @return nil
function
TK_SYNC
.
run
()
local
dbs_st
=
zx_base
:
db_read
(
db_conf
)
for
i
=
1
,
#
dbs_st
.
tk_biz
do
...
...
@@ -150,6 +167,10 @@ function TK_SYNC.run()
dispatch
()
end
-- 数据同步接口
-- @param nil
-- @return ngx.say
function
TK_SYNC
.
sync
()
local
dbs_st
=
zx_base
:
db_read
(
db_conf
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment