You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/01/14 12:26:14 UTC

[GitHub] pavlukhin commented on a change in pull request #5805: IGNITE-10754

pavlukhin commented on a change in pull request #5805: IGNITE-10754
URL: https://github.com/apache/ignite/pull/5805#discussion_r247460678
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryHistoryTracker.java
 ##########
 @@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.jsr166.ConcurrentLinkedDeque8;
+
+/**
+ *
+ */
+class QueryHistoryTracker {
+    /** Query metrics. */
+    private final ConcurrentHashMap<QueryHistoryMetricsKey, QueryHistoryMetrics> qryMetrics;
+
+    /** Queue. */
+    private final ConcurrentLinkedDeque8<QueryHistoryMetrics> evictionQueue = new ConcurrentLinkedDeque8<>();
+
+    /** History size. */
+    private final int histSz;
+
+    /**
+     * @param histSz History size.
+     */
+    QueryHistoryTracker(int histSz) {
+        this.histSz = histSz;
+
+        qryMetrics = histSz > 0 ? new ConcurrentHashMap<>(histSz) : null;
+    }
+
+    /**
+     * @param failed {@code True} if query execution failed.
+     */
+    void collectMetrics(GridRunningQueryInfo runningQryInfo, boolean failed) {
+        if (histSz <= 0)
+            return;
+
+        String qry = runningQryInfo.query();
+        String schema = runningQryInfo.schemaName();
+        boolean loc = runningQryInfo.local();
+        long startTime = runningQryInfo.startTime();
+        long duration = System.currentTimeMillis() - startTime;
+
+        QueryHistoryMetrics m = new QueryHistoryMetrics(qry, schema, loc, startTime, duration, failed);
+
+        QueryHistoryMetrics mergedMetrics = qryMetrics.merge(m.key(), m, QueryHistoryMetrics::aggregateWithNew);
+
+        if (touch(mergedMetrics) && qryMetrics.size() > histSz)
 
 Review comment:
   Could not it be a problem that `size()` method of CHM is not constant-time? Perhaps, we should manually track an approximate size upon addition and removal from map.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services