Fix logging for DiskLruCache and don't auto-delete
This commit is contained in:
parent
983f8fd472
commit
c5a29e07b5
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -17,7 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Security
|
||||
|
||||
## [1.0.0-RC20] - 2020-06-18
|
||||
## [1.0.0-RC21] - 2020-06-20
|
||||
### Changed
|
||||
- [2020-06-20] Fixed logging for DiskLruCache [@carbotaniuman]
|
||||
- [2020-06-20] Don't automatically delete on corruption [@carbotaniuman]
|
||||
|
||||
## [1.0.0-RC20] - 2020-06-19
|
||||
### Added
|
||||
- [2020-06-19] Errored out on invalid settings.json tokens [@carbotaniuman]
|
||||
|
||||
|
@ -123,7 +128,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
- [2020-06-11] Tweaked logging configuration to reduce log file sizes by [@carbotaniuman].
|
||||
|
||||
[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc20...HEAD
|
||||
[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc21...HEAD
|
||||
[1.0.0-rc20]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc20...1.0.0-rc21
|
||||
[1.0.0-rc20]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc19...1.0.0-rc20
|
||||
[1.0.0-rc19]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc18...1.0.0-rc19
|
||||
[1.0.0-rc18]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc17...1.0.0-rc18
|
||||
|
|
|
@ -6,6 +6,7 @@ import mdnet.base.server.ApplicationKt;
|
|||
import mdnet.base.server.WebUiKt;
|
||||
import mdnet.base.settings.ServerSettings;
|
||||
import mdnet.cache.DiskLruCache;
|
||||
import mdnet.cache.HeaderMismatchException;
|
||||
import org.http4k.server.Http4kServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -69,7 +70,11 @@ public class MangaDexClient {
|
|||
} else {
|
||||
statistics.set(new Statistics());
|
||||
}
|
||||
} catch (HeaderMismatchException e) {
|
||||
LOGGER.warn("Cache version may be outdated - remove if necessary");
|
||||
Main.dieWithError(e);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Cache version may be corrupt - remove if necessary");
|
||||
Main.dieWithError(e);
|
||||
}
|
||||
}
|
||||
|
|
13
src/main/java/mdnet/cache/DiskLruCache.java
vendored
13
src/main/java/mdnet/cache/DiskLruCache.java
vendored
|
@ -226,16 +226,9 @@ public final class DiskLruCache implements Closeable {
|
|||
// Prefer to pick up where we left off.
|
||||
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
|
||||
if (cache.journalFile.exists()) {
|
||||
try {
|
||||
cache.readJournal();
|
||||
cache.processJournal();
|
||||
return cache;
|
||||
} catch (IOException e) {
|
||||
if (LOGGER.isWarnEnabled()) {
|
||||
LOGGER.warn("DiskLruCache " + directory + " is corrupt/outdated - removing");
|
||||
}
|
||||
cache.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new empty cache.
|
||||
|
@ -255,8 +248,10 @@ public final class DiskLruCache implements Closeable {
|
|||
if (!MAGIC.equals(magic) || !VERSION_1.equals(version)
|
||||
|| !Integer.toString(appVersion).equals(appVersionString)
|
||||
|| !Integer.toString(valueCount).equals(valueCountString) || !"".equals(blank)) {
|
||||
throw new IOException("unexpected journal header: [" + magic + ", " + version + ", " + valueCountString
|
||||
+ ", " + blank + "]");
|
||||
throw new HeaderMismatchException(
|
||||
new String[]{magic, version, appVersionString, valueCountString, blank},
|
||||
new String[]{MAGIC, VERSION_1, Integer.toString(appVersion), Integer.toString(valueCount), ""}
|
||||
);
|
||||
}
|
||||
|
||||
int lineCount = 0;
|
||||
|
|
10
src/main/java/mdnet/cache/HeaderMismatchException.java
vendored
Normal file
10
src/main/java/mdnet/cache/HeaderMismatchException.java
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
package mdnet.cache;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class HeaderMismatchException extends IOException {
|
||||
public HeaderMismatchException(String[] actual, String[] expected) {
|
||||
super("expected header " + Arrays.toString(expected) + ", found " + Arrays.toString(actual));
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
|||
import java.time.Duration
|
||||
|
||||
object Constants {
|
||||
const val CLIENT_BUILD = 10
|
||||
const val CLIENT_BUILD = 11
|
||||
const val CLIENT_VERSION = "1.0"
|
||||
const val WEBUI_VERSION = "0.1.1"
|
||||
val MAX_AGE_CACHE: Duration = Duration.ofDays(14)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package mdnet.base
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException
|
||||
import ch.qos.logback.classic.LoggerContext
|
||||
import com.fasterxml.jackson.core.JsonProcessingException
|
||||
import com.fasterxml.jackson.databind.JsonMappingException
|
||||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import mdnet.base.Constants.JACKSON
|
||||
|
@ -61,6 +60,7 @@ object Main {
|
|||
if (LOGGER.isErrorEnabled) {
|
||||
LOGGER.error("Critical Error", e)
|
||||
}
|
||||
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,7 @@ object Main {
|
|||
if (LOGGER.isErrorEnabled) {
|
||||
LOGGER.error("Critical Error: {}", error)
|
||||
}
|
||||
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue