Skip to content

Commit

Permalink
chore: bump glog to 0.7.1 (apache#2106)
Browse files Browse the repository at this point in the history
Co-authored-by: Yaroslav <torwigua@gmail.com>
Co-authored-by: Twice <twice.mliu@gmail.com>
Co-authored-by: Twice <twice@apache.org>
  • Loading branch information
4 people authored Nov 19, 2024
1 parent 7611d73 commit 88ac233
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmake/glog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ include_guard()
include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(glog
google/glog v0.6.0
MD5=1b246d4d0e8a011d33e0813b256198ef
google/glog v0.7.1
MD5=fa30180d4284c454bdd324ad3baf7f5f
)

FetchContent_MakeAvailableWithArgs(glog
Expand Down
5 changes: 3 additions & 2 deletions src/cli/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ostream>

#include "daemon_util.h"
#include "glog/log_severity.h"
#include "io_util.h"
#include "pid_util.h"
#include "scope_exit.h"
Expand Down Expand Up @@ -100,15 +101,15 @@ static void InitGoogleLog(const Config *config) {

if (util::EqualICase(config->log_dir, "stdout")) {
for (int level = google::INFO; level <= google::FATAL; level++) {
google::SetLogDestination(level, "");
google::SetLogDestination(static_cast<google::LogSeverity>(level), "");
}
FLAGS_stderrthreshold = google::ERROR;
FLAGS_logtostdout = true;
std::setbuf(stdout, nullptr);
} else {
FLAGS_log_dir = config->log_dir + "/";
if (config->log_retention_days != -1) {
google::EnableLogCleaner(config->log_retention_days);
google::EnableLogCleaner(std::chrono::hours(24) * config->log_retention_days);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::string TrimRocksDbPrefix(std::string s) {
}

Status SetRocksdbCompression(Server *srv, const rocksdb::CompressionType compression,
const int compression_start_level) {
const size_t compression_start_level) {
if (!srv) return Status::OK();
std::string compression_option;
for (auto &option : engine::CompressionOptions) {
Expand All @@ -128,7 +128,7 @@ Status SetRocksdbCompression(Server *srv, const rocksdb::CompressionType compres
for (int i = 0; i < compression_start_level; i++) {
compression_per_level_builder.emplace_back("kNoCompression");
}
for (int i = compression_start_level; i < KVROCKS_MAX_LSM_LEVEL; i++) {
for (size_t i = compression_start_level; i < KVROCKS_MAX_LSM_LEVEL; i++) {
compression_per_level_builder.emplace_back(compression_option);
}
const std::string compression_per_level = util::StringJoin(
Expand Down Expand Up @@ -600,7 +600,7 @@ void Config::initFieldCallback() {
}

if (log_retention_days != -1) {
google::EnableLogCleaner(log_retention_days);
google::EnableLogCleaner(std::chrono::hours(24) * log_retention_days);
} else {
google::DisableLogCleaner();
}
Expand Down
63 changes: 37 additions & 26 deletions tests/gocase/unit/log/logclean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,58 @@ package log

import (
"os"
"strings"
"testing"
"time"

"github.com/apache/kvrocks/tests/gocase/util"
"github.com/stretchr/testify/require"
)

func TestLogClean(t *testing.T) {
const infoLogFileNamePart = ".INFO."

func TestInfoLogClean(t *testing.T) {
logDir := "/tmp/kvrocks/logfile"
require.NoError(t, os.RemoveAll(logDir))
require.NoError(t, os.MkdirAll(logDir, os.ModePerm))

srv := util.StartServer(t, map[string]string{
"log-dir": logDir,
"log-retention-days": "0",
"log-retention-days": "-1",
})
srv.CloseWithoutCleanup()

logInfoFiles := getInfoLogFilesInDir(t, logDir)
require.NotEmpty(t, logInfoFiles)

srv = util.StartServer(t, map[string]string{
"log-dir": logDir,
"log-retention-days": "0", // all previous INFO level logs should be immediately removed
})
defer srv.Close()

files1, err := os.ReadDir(logDir)
logInfoFiles = getInfoLogFilesInDir(t, logDir)
require.Empty(t, logInfoFiles) // the log directory doesn't contain any INFO level log files
}

func getInfoLogFilesInDir(t *testing.T, dir string) []os.DirEntry {
t.Helper()

files, err := os.ReadDir(dir)
require.NoError(t, err)
if len(files1) == 0 {
return
}
require.Eventually(t, func() bool {
srv.Restart()

files2, err := os.ReadDir(logDir)
require.NoError(t, err)
for _, f1 := range files1 {
fileExists := false
for _, f2 := range files2 {
if f1.Name() == f2.Name() {
fileExists = true
break
}
}
// If the file does not exist, it means the file has been cleaned
if !fileExists {
return true
}

infoLogFiles := make([]os.DirEntry, 0, len(files))

for _, f := range files {
if !f.Type().IsRegular() {
continue
}

if !strings.Contains(f.Name(), infoLogFileNamePart) {
continue
}
return false
}, 10*time.Second, 200*time.Millisecond)

infoLogFiles = append(infoLogFiles, f)
}

return infoLogFiles
}
4 changes: 4 additions & 0 deletions tests/gocase/util/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (s *KvrocksServer) Close() {
s.close(false)
}

func (s *KvrocksServer) CloseWithoutCleanup() {
s.close(true)
}

func (s *KvrocksServer) close(keepDir bool) {
require.NoError(s.t, s.cmd.Process.Signal(syscall.SIGTERM))
f := func(err error) { require.NoError(s.t, err) }
Expand Down

0 comments on commit 88ac233

Please sign in to comment.