Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
code review fix: fix bug with hasNext and one file
Browse files Browse the repository at this point in the history
  • Loading branch information
y0f0 committed Dec 21, 2023
1 parent 8756860 commit 2b75a4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ru/vk/itmo/pologovnikita/DaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Entry<MemorySegment> get(MemorySegment key) {
@Override
public void compact() throws IOException {
Iterable<Entry<MemorySegment>> allEntities = this::all;
DiskStorage.compact(allEntities, compactionalPath, path);
DiskStorage.compact(path, allEntities, compactionalPath, path);
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/ru/vk/itmo/pologovnikita/DiskStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,15 @@ public static void deleteFiles(Path path) throws IOException {
}
}

public static void compact(Iterable<Entry<MemorySegment>> entries, Path compactionalPath, Path path)
public static void compact(Path storagePath, Iterable<Entry<MemorySegment>> entries, Path compactionalPath, Path path)
throws IOException {
Path indexFile = storagePath.resolve("index.tmp");
List<String> existedFiles = Files.readAllLines(indexFile, StandardCharsets.UTF_8);

if (existedFiles.isEmpty() && !entries.iterator().hasNext()) {
return;
}

if (entries.iterator().hasNext()) {
DiskStorage.save(compactionalPath, entries); //save all in compact file
}
Expand Down

0 comments on commit 2b75a4d

Please sign in to comment.