diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 04d4d7728d5..e223b4da442 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -234,6 +234,7 @@ Optimizations * SOLR-9506: cache IndexFingerprint for each segment (Pushkar Raste, yonik, noble) +* SOLR-7506: Roll over GC logs by default via bin/solr scripts (shalin, janhoy) Other Changes ---------------------- diff --git a/solr/bin/solr b/solr/bin/solr index d2936dee420..9d55e0a41f8 100755 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -1411,13 +1411,14 @@ if [ -z ${GC_LOG_OPTS+x} ]; then else GC_LOG_OPTS=($GC_LOG_OPTS) fi -# if verbose gc logging enabled, setup the location of the log file + +# if verbose gc logging enabled, setup the location of the log file and rotation if [ "$GC_LOG_OPTS" != "" ]; then gc_log_flag="-Xloggc" if [ "$JAVA_VENDOR" == "IBM J9" ]; then gc_log_flag="-Xverbosegclog" fi - GC_LOG_OPTS+=("$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log") + GC_LOG_OPTS+=("$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M) fi # If ZK_HOST is defined, the assume SolrCloud mode diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 317a7890933..4ab188fe704 100644 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -1013,23 +1013,23 @@ IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" ( ) IF "%JAVA_VENDOR%" == "IBM J9" ( - set "GCLOG_OPT=-Xverbosegclog" + set GCLOG_OPT="-Xverbosegclog:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M ) else ( - set "GCLOG_OPT=-Xloggc" + set GCLOG_OPT="-Xloggc:!SOLR_LOGS_DIR!\solr_gc.log" -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=9 -XX:GCLogFileSize=20M ) IF "%FG%"=="1" ( REM run solr in the foreground title "Solr-%SOLR_PORT%" echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port - "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!/solr_gc.log" ^ + "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT% ^ -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^ -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^ -Djetty.host=%SOLR_JETTY_HOST% -Djetty.port=%SOLR_PORT% -Djetty.home="%SOLR_SERVER_DIR%" ^ -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar "%SOLR_JETTY_CONFIG%" ) ELSE ( START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" ^ - "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!/solr_gc.log" ^ + "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT% ^ -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^ -Dsolr.log.muteconsole ^ -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^ diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java index 76e5ee94861..ebaeda808fa 100644 --- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java @@ -3444,13 +3444,13 @@ public class SolrCLI { Files.createDirectories(archivePath); } List archived = Files.find(archivePath, 1, (f, a) - -> a.isRegularFile() && String.valueOf(f.getFileName()).startsWith("solr_gc_")) + -> a.isRegularFile() && String.valueOf(f.getFileName()).matches("^solr_gc[_.].+")) .collect(Collectors.toList()); for (Path p : archived) { Files.delete(p); } List files = Files.find(logsPath, 1, (f, a) - -> a.isRegularFile() && String.valueOf(f.getFileName()).startsWith("solr_gc_")) + -> a.isRegularFile() && String.valueOf(f.getFileName()).matches("^solr_gc[_.].+")) .collect(Collectors.toList()); if (files.size() > 0) { out("Archiving " + files.size() + " old GC log files to " + archivePath); diff --git a/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java b/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java index 6b2d31cdeae..0ca65edf108 100644 --- a/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java +++ b/solr/core/src/test/org/apache/solr/util/UtilsToolTest.java @@ -55,6 +55,10 @@ public class UtilsToolTest extends SolrTestCaseJ4 { "solr_log_20160304", "solr-8983-console.log", "solr_gc_log_20160102", + "solr_gcnotremove", + "solr_gc.log", + "solr_gc.log.0", + "solr_gc.log.0.current", "solr_gc_log_2"); @Before @@ -136,7 +140,7 @@ public class UtilsToolTest extends SolrTestCaseJ4 { String[] args = {"utils", "-archive_gc_logs", "-l", dir.toString()}; assertEquals(files.size(), fileCount()); assertEquals(0, runTool(args)); - assertEquals(files.size()-2, fileCount()); + assertEquals(files.size()-5, fileCount()); assertFalse(listFiles().contains("solr_gc_log_2")); assertTrue(Files.exists(dir.resolve("archived").resolve("solr_gc_log_2"))); assertEquals(0, runTool(args));