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

Commit

Permalink
Fix codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
persehoney committed Dec 6, 2023
1 parent 2fff4ba commit c7fd063
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/main/java/ru/vk/itmo/solnyshkoksenia/DaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void upsert(Entry<MemorySegment> entry, Long ttl) {
try {
autoFlush();
} catch (IOException e) {
throw new RuntimeException("Memory storage overflowed. Cannot flush: " + e.getMessage());
throw new DaoException("Memory storage overflowed. Cannot flush: " + e.getMessage());
}
}
}
Expand Down Expand Up @@ -119,12 +119,12 @@ private void tryFlush() {
this.curState = new State(state.config, state.storage, new ConcurrentSkipListMap<>(comparator),
new DiskStorage(DiskStorage.loadOrRecover(path, arena), path));
} catch (IOException e) {
throw new RuntimeException("Cannot recover storage on disk");
throw new DaoException("Cannot recover storage on disk", e);
} finally {
lock.writeLock().unlock();
}
} catch (IOException e) {
throw new RuntimeException("Flush failed: " + e.getMessage());
throw new DaoException("Flush failed", e);
}
}

Expand All @@ -133,9 +133,9 @@ public void compact() throws IOException {
try {
executor.submit(this::tryCompact).get();
} catch (InterruptedException e) {
throw new RuntimeException("Compaction failed. Thread interrupted: " + e.getMessage());
throw new DaoException("Compaction failed. Thread interrupted", e);
} catch (ExecutionException e) {
throw new RuntimeException("Compaction failed: " + e.getMessage());
throw new DaoException("Compaction failed", e);
}
}

Expand All @@ -144,15 +144,15 @@ private Object tryCompact() {
try {
state.diskStorage.compact();
} catch (IOException e) {
throw new RuntimeException("Cannot compact: " + e.getMessage());
throw new DaoException("Cannot compact", e);
}

lock.writeLock().lock();
try {
this.curState = new State(state.config, state.storage, state.flushingStorage,
new DiskStorage(DiskStorage.loadOrRecover(path, arena), path));
} catch (IOException e) {
throw new RuntimeException("Cannot recover storage on disk after compaction: " + e.getMessage());
throw new DaoException("Cannot recover storage on disk after compaction", e);
} finally {
lock.writeLock().unlock();
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/ru/vk/itmo/solnyshkoksenia/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ public State(Config config,
}

public void putInMemory(Entry<MemorySegment> entry, Long ttl) {
MemorySegment expiration;
MemorySegment expiration = null;
if (ttl != null) {
long[] ar = {System.currentTimeMillis() + ttl};
expiration = MemorySegment.ofArray(ar);
} else {
expiration = null;
}
Triple<MemorySegment> triple = new Triple<>(entry.key(), entry.value(), expiration);
Triple<MemorySegment> previousEntry = storage.put(triple.key(), triple);
Expand All @@ -75,7 +73,7 @@ private static long getSize(Triple<MemorySegment> entry) {

public State checkAndGet() {
if (isClosed.get()) {
throw new RuntimeException("Dao is already closed");
throw new DaoException("Dao is already closed");
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ protected boolean skip(Triple<MemorySegment> memorySegmentEntry) {
if (memorySegmentEntry.expiration() != null) {
long currentTime = System.currentTimeMillis();
long expiration = memorySegmentEntry.expiration().toArray(ValueLayout.JAVA_LONG_UNALIGNED)[0];
System.err.println(expiration + " || " + currentTime);
return memorySegmentEntry.value() == null || expiration <= currentTime;
}
return memorySegmentEntry.value() == null;
Expand Down Expand Up @@ -294,7 +293,7 @@ public Triple<MemorySegment> next() {
MemorySegment value =
startOfValue < 0
? null
: utils.slice(page, startOfValue, utils.endOfValue(page, index, recordsCount));
: utils.slice(page, startOfValue, utils.endOfValue(page, index));
long startOfExp = utils.startOfExpiration(page, index);
MemorySegment expiration =
startOfExp < 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected long startOfValue(MemorySegment segment, long recordIndex) {
return segment.get(ValueLayout.JAVA_LONG_UNALIGNED, recordIndex * 3 * Long.BYTES + Long.BYTES);
}

protected long endOfValue(MemorySegment segment, long recordIndex, long recordsCount) {
protected long endOfValue(MemorySegment segment, long recordIndex) {
return normalizedStartOfExpiration(segment, recordIndex);
}

Expand Down

0 comments on commit c7fd063

Please sign in to comment.