You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/09/15 11:58:51 UTC
[skywalking] branch master updated: Fix H2EventQueryDAO doesn't
sort data by Event.START_TIME and uses a wrong pagination query (#7720)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 08990c9 Fix H2EventQueryDAO doesn't sort data by Event.START_TIME and uses a wrong pagination query (#7720)
08990c9 is described below
commit 08990c90694d440c43e7846f995cfb89ec476045
Author: 刘威 <51...@users.noreply.github.com>
AuthorDate: Wed Sep 15 19:58:41 2021 +0800
Fix H2EventQueryDAO doesn't sort data by Event.START_TIME and uses a wrong pagination query (#7720)
* Fix H2EventQueryDAO doesn't sort data by Event.START_TIME.
* Fix H2EventQueryDAO uses a wrong pagination query.
---
CHANGES.md | 1 +
.../plugin/jdbc/h2/dao/H2EventQueryDAO.java | 33 ++++++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 991e9c9..c80f0a0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -64,6 +64,7 @@ Release Notes.
* Support apollo grouped dynamic configurations.
* Fix `ProfileThreadSnapshotQuery.queryProfiledSegments` adopts a wrong sort function
* Support gRPC sync grouped dynamic configurations.
+* Fix `H2EventQueryDAO` doesn't sort data by Event.START_TIME and uses a wrong pagination query.
#### UI
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2EventQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2EventQueryDAO.java
index 3444268..e6b5c10 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2EventQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2EventQueryDAO.java
@@ -29,16 +29,18 @@ import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.server.core.query.PaginationUtils;
-import org.apache.skywalking.oap.server.core.query.type.Pagination;
-import org.apache.skywalking.oap.server.core.source.Event;
+import org.apache.skywalking.oap.server.core.query.enumeration.Order;
import org.apache.skywalking.oap.server.core.query.input.Duration;
import org.apache.skywalking.oap.server.core.query.type.event.EventQueryCondition;
import org.apache.skywalking.oap.server.core.query.type.event.EventType;
import org.apache.skywalking.oap.server.core.query.type.event.Events;
import org.apache.skywalking.oap.server.core.query.type.event.Source;
+import org.apache.skywalking.oap.server.core.source.Event;
import org.apache.skywalking.oap.server.core.storage.query.IEventQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
+import static java.util.Objects.isNull;
+
import static com.google.common.base.Strings.isNullOrEmpty;
@Slf4j
@@ -67,10 +69,15 @@ public class H2EventQueryDAO implements IEventQueryDAO {
result.setTotal(resultSet.getInt("total"));
}
- PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(condition.getPaging());
-
- sql = "select * from " + Event.INDEX_NAME + whereClause
- + " limit " + page.getLimit() + " offset " + page.getFrom();
+ final Order queryOrder = isNull(condition.getOrder()) ? Order.DES : condition.getOrder();
+ final PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(condition.getPaging());
+ sql = "select * from " + Event.INDEX_NAME + whereClause;
+ if (Order.DES.equals(queryOrder)) {
+ sql += " order by " + Event.START_TIME + " desc";
+ } else {
+ sql += " order by " + Event.START_TIME + " asc";
+ }
+ sql += " limit " + page.getLimit() + " offset " + page.getFrom();
if (log.isDebugEnabled()) {
log.debug("Query SQL: {}, parameters: {}", sql, parameters);
}
@@ -97,8 +104,6 @@ public class H2EventQueryDAO implements IEventQueryDAO {
.map(Tuple2::_1)
.map(it -> it.collect(Collectors.joining(" and ")))
.collect(Collectors.joining(" or ", " where ", ""));
- final int size = conditions.stream().map(EventQueryCondition::getPaging)
- .mapToInt(Pagination::getPageSize).sum();
final Events result = new Events();
try (final Connection connection = client.getConnection()) {
@@ -112,7 +117,17 @@ public class H2EventQueryDAO implements IEventQueryDAO {
}
result.setTotal(resultSet.getInt("total"));
}
- sql = "select * from " + Event.INDEX_NAME + whereClause + " limit " + size;
+
+ EventQueryCondition condition = conditions.get(0);
+ final Order queryOrder = isNull(condition.getOrder()) ? Order.DES : condition.getOrder();
+ final PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(condition.getPaging());
+ sql = "select * from " + Event.INDEX_NAME + whereClause;
+ if (Order.DES.equals(queryOrder)) {
+ sql += " order by " + Event.START_TIME + " desc";
+ } else {
+ sql += " order by " + Event.START_TIME + " asc";
+ }
+ sql += " limit " + page.getLimit() + " offset " + page.getFrom();
if (log.isDebugEnabled()) {
log.debug("Query SQL: {}, parameters: {}", sql, parameters);
}