You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/06/01 16:07:54 UTC

[incubator-kvrocks] branch unstable updated: Fix crash when hitting the perflog command rule (#1481)

This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 58b99272 Fix crash when hitting the perflog command rule (#1481)
58b99272 is described below

commit 58b9927213778553821621852c5999d22f69ca8f
Author: hulk <hu...@gmail.com>
AuthorDate: Fri Jun 2 00:07:47 2023 +0800

    Fix crash when hitting the perflog command rule (#1481)
    
    The root cause is that we didn't allow the entry when creating
    the unique ptr. So it will be a null pointer when the command
    was hitting the perflog rule.
---
 src/server/redis_connection.cc            |  2 +-
 tests/gocase/unit/perflog/perflog_test.go | 48 +++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc
index c5310b82..819c8006 100644
--- a/src/server/redis_connection.cc
+++ b/src/server/redis_connection.cc
@@ -281,7 +281,7 @@ void Connection::RecordProfilingSampleIfNeed(const std::string &cmd, uint64_t du
   rocksdb::SetPerfLevel(rocksdb::PerfLevel::kDisable);
   if (perf_context.empty()) return;  // request without db operation
 
-  auto entry = std::unique_ptr<PerfEntry>();
+  auto entry = std::make_unique<PerfEntry>();
   entry->cmd_name = cmd;
   entry->duration = duration;
   entry->iostats_context = std::move(iostats_context);
diff --git a/tests/gocase/unit/perflog/perflog_test.go b/tests/gocase/unit/perflog/perflog_test.go
new file mode 100644
index 00000000..e42154e5
--- /dev/null
+++ b/tests/gocase/unit/perflog/perflog_test.go
@@ -0,0 +1,48 @@
+/*
+ * 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 ping
+
+import (
+	"context"
+	"fmt"
+	"testing"
+
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
+	"github.com/stretchr/testify/require"
+)
+
+func TestPerflog(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{})
+	defer srv.Close()
+
+	ctx := context.Background()
+	t.Run("PerfLog", func(t *testing.T) {
+		c := srv.NewClient()
+		defer func() { require.NoError(t, c.Close()) }()
+		require.NoError(t, c.ConfigSet(ctx, "profiling-sample-commands", "set").Err())
+		require.NoError(t, c.ConfigSet(ctx, "profiling-sample-ratio", "100").Err())
+		require.NoError(t, c.ConfigSet(ctx, "profiling-sample-record-threshold-ms", "0").Err())
+
+		for i := 0; i < 10; i++ {
+			require.NoError(t, c.Set(ctx, fmt.Sprintf("key-%d", i), "value", 0).Err())
+		}
+		require.EqualValues(t, 10, c.Do(ctx, "perflog", "len").Val())
+	})
+}