-
Notifications
You must be signed in to change notification settings - Fork 77
Conversation
# Conflicts: # src/main/java/ru/vk/itmo/shemetovalexey/DiskStorage.java # src/main/java/ru/vk/itmo/shemetovalexey/InMemoryDao.java
try { | ||
Files.createFile(indexFile); | ||
} catch (FileAlreadyExistsException ignored) { | ||
// ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно логгер прикрутить (Как совет, это не обязательно делать)
|
||
Files.deleteIfExists(indexFile); | ||
|
||
Files.move(indexTmp, indexFile, StandardCopyOption.ATOMIC_MOVE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А здесь почему StandardCopyOption.REPLACE_EXISTING
не добавил? (Тут больше пояснение хочется)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну, да, согласен, удаление + перемещение = замене. Исправлю
src/main/java/ru/vk/itmo/shemetovalexey/sstable/SSTableUtils.java
Outdated
Show resolved
Hide resolved
|
||
public InMemoryDao(Config config) throws IOException { | ||
this.path = config.basePath().resolve("data"); | ||
maxSize = config.flushThresholdBytes() == 0 ? config.flushThresholdBytes() : Long.MAX_VALUE / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А this
зачем убрал?
public void flush() throws IOException { | ||
bgExecutor.execute(() -> { | ||
SSTableStates prevState = sstableState.get(); | ||
ConcurrentSkipListMap<MemorySegment, Entry<MemorySegment>> writeStorage = prevState.getWriteStorage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А что если 2 потока дойдут досюда и оба вызовут getWriteStorage()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Получается ты 2 раза сохранишь одну и ту же вещь? Или я где-то ошибаюсь?
|
||
upsertLock.writeLock().lock(); | ||
try { | ||
sstableState.set(nextState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так, а теперь ещё ситуация.
- Оба потока зашли во
flush
- Оба взяли
nextState
- Второй поток уснул, а первый закончил
flush
полностью и даже подабовлял ещё элементов
Почему когда второй поток проснётся, ничего не сломается?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пояснение. Он проснётся и начнёт со 175 строчки upsertLock.writeLock().lock();
long valueSize = entry.value() == null ? 0 : entry.value().byteSize(); | ||
if (size.addAndGet(keySize + valueSize) >= maxSize) { | ||
flush(); | ||
size.set(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это лучше делать во flush
. Представь, что у тебя какой-то поток зайдёт во flush
, bgExecutor
начнёт выполнять его таску и уснёт. Тогда таски от других потоков не будут выполняться, зато size
всё время будет проставляться в 0 и в какой-то момент writeStorage
может переполниться
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Окей 25/30 баллов
No description provided.