@@ -1571,6 +1571,9 @@ public String getServiceName() {
1571
1571
public void run () {
1572
1572
setState (AbstractStateService .START );
1573
1573
TimerMessageStore .LOGGER .info (this .getServiceName () + " service start" );
1574
+ //Mark different rounds
1575
+ boolean isRound = true ;
1576
+ Map <String ,MessageExt > avoidDeleteLose = new HashMap <>();
1574
1577
while (!this .isStopped ()) {
1575
1578
try {
1576
1579
setState (AbstractStateService .WAITING );
@@ -1587,9 +1590,18 @@ public void run() {
1587
1590
MessageExt msgExt = getMessageByCommitOffset (tr .getOffsetPy (), tr .getSizePy ());
1588
1591
if (null != msgExt ) {
1589
1592
if (needDelete (tr .getMagic ()) && !needRoll (tr .getMagic ())) {
1593
+ //Clearing is performed once in each round.
1594
+ //The deletion message is received first and the common message is received once
1595
+ if (!isRound ) {
1596
+ isRound = true ;
1597
+ for (MessageExt messageExt : avoidDeleteLose .values ()) {
1598
+ addMetric (messageExt , 1 );
1599
+ }
1600
+ avoidDeleteLose .clear ();
1601
+ }
1590
1602
if (msgExt .getProperty (MessageConst .PROPERTY_TIMER_DEL_UNIQKEY ) != null && tr .getDeleteList () != null ) {
1591
- //Execute metric plus one for messages that fail to be deleted
1592
- addMetric (msgExt , 1 );
1603
+
1604
+ avoidDeleteLose . put (msgExt . getProperty ( MessageConst . PROPERTY_TIMER_DEL_UNIQKEY ), msgExt );
1593
1605
tr .getDeleteList ().add (msgExt .getProperty (MessageConst .PROPERTY_TIMER_DEL_UNIQKEY ));
1594
1606
}
1595
1607
tr .idempotentRelease ();
@@ -1599,10 +1611,13 @@ public void run() {
1599
1611
if (null == uniqueKey ) {
1600
1612
LOGGER .warn ("No uniqueKey for msg:{}" , msgExt );
1601
1613
}
1614
+ //Mark ready for next round
1615
+ if (isRound ) {
1616
+ isRound = false ;
1617
+ }
1602
1618
if (null != uniqueKey && tr .getDeleteList () != null && tr .getDeleteList ().size () > 0
1603
1619
&& tr .getDeleteList ().contains (buildDeleteKey (getRealTopic (msgExt ), uniqueKey ))) {
1604
- //Normally, it cancels out with the +1 above
1605
- addMetric (msgExt , -1 );
1620
+ avoidDeleteLose .remove (uniqueKey );
1606
1621
doRes = true ;
1607
1622
tr .idempotentRelease ();
1608
1623
perfCounterTicks .getCounter ("dequeue_delete" ).flow (1 );
0 commit comments