From 35bc19f24a60c820543ad159dc5e44a346c565a9 Mon Sep 17 00:00:00 2001 From: Nikita Pologov Date: Fri, 22 Dec 2023 01:10:16 +0300 Subject: [PATCH] fix codeclimate --- src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java | 2 +- .../java/ru/vk/itmo/pologovnikita/DiskStorage.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java b/src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java index 21cdda827..363da7f4a 100644 --- a/src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java +++ b/src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java @@ -84,7 +84,7 @@ public Entry get(MemorySegment key) { @Override public void compact() throws IOException { Iterable> allEntities = this::all; - DiskStorage.compact(path, allEntities, compactionalPath, path); + DiskStorage.compact(allEntities, compactionalPath, path); } @Override diff --git a/src/main/java/ru/vk/itmo/pologovnikita/DiskStorage.java b/src/main/java/ru/vk/itmo/pologovnikita/DiskStorage.java index c794765d5..b869f4c05 100644 --- a/src/main/java/ru/vk/itmo/pologovnikita/DiskStorage.java +++ b/src/main/java/ru/vk/itmo/pologovnikita/DiskStorage.java @@ -58,7 +58,7 @@ protected boolean skip(Entry memorySegmentEntry) { public static void save(Path storagePath, Iterable> iterable) throws IOException { - final Path indexTmp = storagePath.resolve("index.tmp"); + final Path indexTmp = getIndexFile(storagePath); final Path indexFile = storagePath.resolve("index.idx"); try { @@ -151,7 +151,7 @@ public static void save(Path storagePath, Iterable> iterabl } public static List loadOrRecover(Path storagePath, Arena arena) throws IOException { - Path indexTmp = storagePath.resolve("index.tmp"); + Path indexTmp = getIndexFile(storagePath); Path indexFile = storagePath.resolve("index.idx"); if (Files.exists(indexTmp)) { @@ -191,9 +191,9 @@ public static void deleteFiles(Path path) throws IOException { } } - public static void compact(Path storagePath, Iterable> entries, Path compactionalPath, Path path) + public static void compact(Iterable> entries, Path compactionalPath, Path path) throws IOException { - Path indexFile = storagePath.resolve("index.tmp"); + Path indexFile = getIndexFile(path); List existedFiles = Files.readAllLines(indexFile, StandardCharsets.UTF_8); if (existedFiles.isEmpty() && !entries.iterator().hasNext()) { @@ -210,6 +210,10 @@ public static void compact(Path storagePath, Iterable> entr } } + private static Path getIndexFile(Path path) { + return path.resolve("index.tmp"); + } + private static long indexOf(MemorySegment segment, MemorySegment key) { long recordsCount = recordsCount(segment);