Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
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
hujiebin
hilo-group
Commits
34116196
Commit
34116196
authored
Mar 07, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:一个事件一个事务减少锁粒度
parent
e8deba7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
20 deletions
+18
-20
send_gift.go
domain/service/event_s/send_gift.go
+18
-20
No files found.
domain/service/event_s/send_gift.go
View file @
34116196
...
@@ -30,12 +30,13 @@ func (s *GiftSendEventService) Consume() error {
...
@@ -30,12 +30,13 @@ func (s *GiftSendEventService) Consume() error {
}
}
}()
}()
var
model
=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
var
model
=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
events
,
offset
,
err
:=
event_m
.
FetchEventGiftSend
(
model
,
BatchCount
)
events
,
offset
,
err
:=
event_m
.
FetchEventGiftSend
(
model
,
BatchCount
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
k
:=
range
events
{
for
k
:=
range
events
{
// 一个事件一个事务
err
=
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
cpEvent
:=
&
event_m
.
EventGiftSend
{
cpEvent
:=
&
event_m
.
EventGiftSend
{
Entity
:
mysql
.
Entity
{
Entity
:
mysql
.
Entity
{
ID
:
events
[
k
]
.
ID
,
ID
:
events
[
k
]
.
ID
,
...
@@ -48,12 +49,12 @@ func (s *GiftSendEventService) Consume() error {
...
@@ -48,12 +49,12 @@ func (s *GiftSendEventService) Consume() error {
}
}
if
cpEvent
.
MarkHiloGroup
==
mysql
.
YES
{
if
cpEvent
.
MarkHiloGroup
==
mysql
.
YES
{
model
.
Log
.
Warnf
(
"already consume msg :%v"
,
cpEvent
)
model
.
Log
.
Warnf
(
"already consume msg :%v"
,
cpEvent
)
continue
return
nil
}
}
sendGiftEvent
:=
new
(
gift_ev
.
SendGiftEvent
)
sendGiftEvent
:=
new
(
gift_ev
.
SendGiftEvent
)
if
err
:=
json
.
Unmarshal
(
cpEvent
.
Payload
,
sendGiftEvent
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
cpEvent
.
Payload
,
sendGiftEvent
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"json msg fail,event:%v,err:%v"
,
cpEvent
,
err
)
model
.
Log
.
Errorf
(
"json msg fail,event:%v,err:%v"
,
cpEvent
,
err
)
continue
return
nil
}
}
if
err
:=
gift_ev
.
PublishSendGiftEvent
(
model
,
sendGiftEvent
);
err
!=
nil
{
if
err
:=
gift_ev
.
PublishSendGiftEvent
(
model
,
sendGiftEvent
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"PublishSendGiftEvent fail,event:%v,err:%v"
,
cpEvent
,
err
)
model
.
Log
.
Errorf
(
"PublishSendGiftEvent fail,event:%v,err:%v"
,
cpEvent
,
err
)
...
@@ -66,16 +67,13 @@ func (s *GiftSendEventService) Consume() error {
...
@@ -66,16 +67,13 @@ func (s *GiftSendEventService) Consume() error {
model
.
Log
.
Errorf
(
"consume msg fail,event:%v,err:%v"
,
cpEvent
,
err
)
model
.
Log
.
Errorf
(
"consume msg fail,event:%v,err:%v"
,
cpEvent
,
err
)
return
err
return
err
}
}
}
return
nil
if
err
!=
nil
{
})
model
.
Log
.
Errorf
(
"batch consume msg has fail,event,err:%v"
,
err
)
}
// 暂时先允许丢数据,继续mark offset
// 最后一次提交offset
}
if
len
(
events
)
>
0
{
// 最后一次提交offset
offset
.
MarkOffset
=
events
[
len
(
events
)
-
1
]
.
ID
if
len
(
events
)
>
0
{
return
offset
.
Persistence
()
offset
.
MarkOffset
=
events
[
len
(
events
)
-
1
]
.
ID
}
return
offset
.
Persistence
()
return
nil
}
return
nil
})
}
}
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