1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00

Fix logging for DiskLruCache and don't auto-delete

This commit is contained in:
carbotaniuman 2020-06-20 11:32:15 -05:00
parent 983f8fd472
commit c5a29e07b5
6 changed files with 34 additions and 17 deletions

View file

@ -17,7 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security ### 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 ### Added
- [2020-06-19] Errored out on invalid settings.json tokens [@carbotaniuman] - [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 ### Fixed
- [2020-06-11] Tweaked logging configuration to reduce log file sizes by [@carbotaniuman]. - [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-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-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 [1.0.0-rc18]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc17...1.0.0-rc18

View file

@ -6,6 +6,7 @@ import mdnet.base.server.ApplicationKt;
import mdnet.base.server.WebUiKt; import mdnet.base.server.WebUiKt;
import mdnet.base.settings.ServerSettings; import mdnet.base.settings.ServerSettings;
import mdnet.cache.DiskLruCache; import mdnet.cache.DiskLruCache;
import mdnet.cache.HeaderMismatchException;
import org.http4k.server.Http4kServer; import org.http4k.server.Http4kServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -69,7 +70,11 @@ public class MangaDexClient {
} else { } else {
statistics.set(new Statistics()); statistics.set(new Statistics());
} }
} catch (HeaderMismatchException e) {
LOGGER.warn("Cache version may be outdated - remove if necessary");
Main.dieWithError(e);
} catch (IOException e) { } catch (IOException e) {
LOGGER.warn("Cache version may be corrupt - remove if necessary");
Main.dieWithError(e); Main.dieWithError(e);
} }
} }

View file

@ -226,16 +226,9 @@ public final class DiskLruCache implements Closeable {
// Prefer to pick up where we left off. // Prefer to pick up where we left off.
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize); DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
if (cache.journalFile.exists()) { if (cache.journalFile.exists()) {
try { cache.readJournal();
cache.readJournal(); cache.processJournal();
cache.processJournal(); return cache;
return cache;
} catch (IOException e) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("DiskLruCache " + directory + " is corrupt/outdated - removing");
}
cache.delete();
}
} }
// Create a new empty cache. // Create a new empty cache.
@ -255,8 +248,10 @@ public final class DiskLruCache implements Closeable {
if (!MAGIC.equals(magic) || !VERSION_1.equals(version) if (!MAGIC.equals(magic) || !VERSION_1.equals(version)
|| !Integer.toString(appVersion).equals(appVersionString) || !Integer.toString(appVersion).equals(appVersionString)
|| !Integer.toString(valueCount).equals(valueCountString) || !"".equals(blank)) { || !Integer.toString(valueCount).equals(valueCountString) || !"".equals(blank)) {
throw new IOException("unexpected journal header: [" + magic + ", " + version + ", " + valueCountString throw new HeaderMismatchException(
+ ", " + blank + "]"); new String[]{magic, version, appVersionString, valueCountString, blank},
new String[]{MAGIC, VERSION_1, Integer.toString(appVersion), Integer.toString(valueCount), ""}
);
} }
int lineCount = 0; int lineCount = 0;

View 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));
}
}

View file

@ -4,7 +4,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.time.Duration import java.time.Duration
object Constants { object Constants {
const val CLIENT_BUILD = 10 const val CLIENT_BUILD = 11
const val CLIENT_VERSION = "1.0" const val CLIENT_VERSION = "1.0"
const val WEBUI_VERSION = "0.1.1" const val WEBUI_VERSION = "0.1.1"
val MAX_AGE_CACHE: Duration = Duration.ofDays(14) val MAX_AGE_CACHE: Duration = Duration.ofDays(14)

View file

@ -1,8 +1,7 @@
package mdnet.base 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.core.JsonProcessingException
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import mdnet.base.Constants.JACKSON import mdnet.base.Constants.JACKSON
@ -61,6 +60,7 @@ object Main {
if (LOGGER.isErrorEnabled) { if (LOGGER.isErrorEnabled) {
LOGGER.error("Critical Error", e) LOGGER.error("Critical Error", e)
} }
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
exitProcess(1) exitProcess(1)
} }
@ -69,6 +69,7 @@ object Main {
if (LOGGER.isErrorEnabled) { if (LOGGER.isErrorEnabled) {
LOGGER.error("Critical Error: {}", error) LOGGER.error("Critical Error: {}", error)
} }
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
exitProcess(1) exitProcess(1)
} }