Skip to content

Commit d920126

Browse files
committed
Fix bugs after the third review
1 parent f32c280 commit d920126

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

src/pika_server.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ void PikaServer::DBSetSmallCompactionDurationThreshold(uint32_t small_compaction
507507
}
508508

509509
void PikaServer::UpdateDBBigKeysConfig() {
510-
std::shared_lock l(dbs_rw_);
510+
std::lock_guard l(dbs_rw_);
511511
for (const auto& db_item : dbs_) {
512512
db_item.second->DBLock();
513513
db_item.second->UpdateStorageBigKeysConfig(
@@ -2027,9 +2027,21 @@ void PikaServer::CleanExpiredBigKeys() {
20272027

20282028
bool all_expired = true;
20292029
for (const auto& ts : type_status) {
2030-
if (!ts.second.IsNotFound() && (ttls[ts.first] > 0 || ttls[ts.first] == -1)) {
2031-
all_expired = false;
2032-
break;
2030+
if (ts.second.ok()) { // A key with this name and type exists.
2031+
auto ttl_it = ttls.find(ts.first);
2032+
if (ttl_it != ttls.end()) {
2033+
// We found a TTL for it. Check if it's persistent or has time left.
2034+
const int64_t ttl = ttl_it->second;
2035+
if (ttl > 0 || ttl == -1) {
2036+
all_expired = false;
2037+
break;
2038+
}
2039+
} else {
2040+
// This is unexpected. The key exists but TTL was not returned.
2041+
// To be safe, we assume it is persistent and do not clean it.
2042+
all_expired = false;
2043+
break;
2044+
}
20332045
}
20342046
}
20352047

tools/pika_exporter/exporter/client.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ func (c *client) GetInfo() (string, error) {
8484
return info, nil
8585
}
8686

87-
info, err := c.Info()
88-
if err != nil {
89-
return "", err
90-
}
91-
if InfoConf.BigKeys {
92-
bigkeysInfo, err := c.InfoBigKeys()
93-
if err != nil {
94-
return "", err
95-
}
96-
info += "\n" + bigkeysInfo
97-
}
98-
9987
if InfoConf.Info {
10088
var rst []string
10189

@@ -132,10 +120,6 @@ func (c *client) InfoCommand(command string) (string, error) {
132120
return redis.String(c.conn.Do("INFO", command))
133121
}
134122

135-
func (c *client) InfoBigKeys() (string, error) {
136-
return redis.String(c.conn.Do("INFO", "BIGKEYS"))
137-
}
138-
139123
func (c *client) InfoNoneCommandList() (string, error) {
140124
var rst []string
141125

tools/pika_exporter/exporter/parser.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,15 @@ func parseInfo(info string) (*semver.Version, map[string]string, error) {
2828
return version, extracts, nil
2929
}
3030

31-
func parseInfoBigkey(s string) string {
32-
if strings.Contains(s, "# BigKeys statistics") {
33-
startIdx := strings.Index(s, "# BigKeys statistics")
34-
if startIdx != -1 {
35-
return s[startIdx:]
36-
}
37-
}
38-
return ""
39-
}
40-
4131
func extractInfo(s string) (map[string]string, error) {
4232
m := make(map[string]string)
43-
bigkeysOutput := parseInfoBigkey(s)
44-
if len(bigkeysOutput) > 0 {
45-
m["bigkeys_output"] = bigkeysOutput
33+
34+
kvPart, bigKeysOutput := extractBigKeys(s)
35+
if bigKeysOutput != "" {
36+
m["bigkeys_output"] = bigKeysOutput
4637
}
47-
scanner := bufio.NewScanner(strings.NewReader(s))
38+
39+
scanner := bufio.NewScanner(strings.NewReader(kvPart))
4840
for scanner.Scan() {
4941
line := scanner.Text()
5042

@@ -63,6 +55,15 @@ func extractInfo(s string) (map[string]string, error) {
6355
return m, scanner.Err()
6456
}
6557

58+
func extractBigKeys(s string) (kvPart, bigKeysOutput string) {
59+
if startIdx := strings.Index(s, "# BigKeys statistics"); startIdx != -1 {
60+
// Ensure we split at a line boundary
61+
lineStartIdx := strings.LastIndex(s[:startIdx], "\n") + 1
62+
return s[:lineStartIdx], s[lineStartIdx:]
63+
}
64+
return s, ""
65+
}
66+
6667
func trimSpace(s string) string {
6768
s = strings.TrimLeft(s, " ")
6869
s = strings.TrimRight(s, " ")

0 commit comments

Comments
 (0)