You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/11/24 08:04:22 UTC

[GitHub] [skywalking] kezhenxu94 commented on a diff in pull request #10021: Enhance cache mechanism in the metric persistent process

kezhenxu94 commented on code in PR #10021:
URL: https://github.com/apache/skywalking/pull/10021#discussion_r1031161099


##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/SessionCacheCallback.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.skywalking.oap.server.core.storage;
+
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+
+/**
+ * SessionCacheCallback provides a bridge for storage implementations
+ */
+@RequiredArgsConstructor
+public class SessionCacheCallback {
+    private final Map<Metrics, Metrics> sessionCache;
+    private final Metrics metrics;
+    /**
+     * In some cases, this callback could be shared by multiple executions, such as SQLExecutor#additionalSQLs.
+     * This flag would make sure, once one of the generated executions is failure, the whole metric would be removed
+     * from the cache, and would not be added back. As those are executed in a batch mode. The sequence is uncertain.
+     */
+    private volatile boolean isFailed = false;
+
+    public void onInsertCompleted() {
+        if (isFailed) {
+            return;
+        }
+        sessionCache.put(metrics, metrics);
+    }
+
+    public void onUpdateFailure() {
+        sessionCache.remove(metrics);
+        isFailed = true;

Review Comment:
   I think you need to flip these two lines
   
   ```suggestion
           isFailed = true;
           sessionCache.remove(metrics);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org