This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
The following commit(s) were added to refs/heads/master by this push:
new 85b6a23 SCB-885 saga alpha event scanner delete duplicate events sql
optimization
85b6a23 is described below
commit 85b6a2371b29080a00fddc476edfd638b450c39b
Author: fcg <[email protected]>
AuthorDate: Mon Sep 3 20:30:19 2018 +0800
SCB-885 saga alpha event scanner delete duplicate events sql optimization
---
.../saga/alpha/server/SpringTxEventRepository.java | 3 ++-
.../saga/alpha/server/TxEventEnvelopeRepository.java | 19 ++++++++++++-------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SpringTxEventRepository.java
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SpringTxEventRepository.java
index 94ace76..0394f82 100644
---
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SpringTxEventRepository.java
+++
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SpringTxEventRepository.java
@@ -82,6 +82,7 @@ class SpringTxEventRepository implements TxEventRepository {
@Override
public void deleteDuplicateEvents(String type) {
- eventRepo.deleteByType(type);
+ eventRepo.findDuplicateEventsByType(type).forEach((txEvent) ->eventRepo.
+ deleteBySurrogateId(txEvent.id()));
}
}
diff --git
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
index fdf920f..89808c9 100644
---
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
+++
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
@@ -114,13 +114,18 @@ interface TxEventEnvelopeRepository extends
CrudRepository<TxEvent, Long> {
Optional<TxEvent> findFirstByTypeAndSurrogateIdGreaterThan(String type, long
surrogateId);
+ @Query("SELECT t FROM TxEvent t "
+ + "WHERE t.type = ?1 AND EXISTS ( "
+ + " SELECT t1.surrogateId"
+ + " FROM TxEvent t1 "
+ + " WHERE t1.globalTxId = t.globalTxId "
+ + " AND t1.localTxId = t.localTxId "
+ + " AND t1.type = t.type "
+ + " AND t1.surrogateId > t.surrogateId )")
+ List<TxEvent> findDuplicateEventsByType(String type);
+
@Transactional
@Modifying(clearAutomatically = true)
- @Query("DELETE FROM TxEvent t "
- + "WHERE t.type = ?1 AND t.surrogateId NOT IN ("
- + " SELECT MAX(t1.surrogateId) FROM TxEvent t1 "
- + " WHERE t1.type = ?1 "
- + " GROUP BY t1.globalTxId"
- + ")")
- void deleteByType(String type);
+ @Query("DELETE FROM TxEvent WHERE surrogateId = ?1 ")
+ void deleteBySurrogateId(Long surrogateId);
}