-
Notifications
You must be signed in to change notification settings - Fork 77
Ершов Вадим, Магистратура ИТМО "Распределенные веб-сервисы", hw 5 #291
Conversation
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.
Тут как таковой попытки неблокирующей реализации и не было, верно? Появился только ReadWriteLock
. Могу оценить в 1 балл за начала подхода к попытке.
public class ThreadSafeDaoImpl implements Dao<MemorySegment, Entry<MemorySegment>> { | ||
|
||
private final Comparator<MemorySegment> comparator = ThreadSafeDaoImpl::compare; | ||
private NavigableMap<MemorySegment, Entry<MemorySegment>> storage = new ConcurrentSkipListMap<>(comparator); |
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.
Поле storage
читается/пишется из разных потоков. Чтения не защищены.
public void flush() { | ||
w.lock(); | ||
try { | ||
DiskStorage.save(path, storage.values()); |
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.
Почему мы не очищаем storage
(MemTable) после flush
и не переоткрываем флашнутую таблицу?
} | ||
iterators.add(firstIterator); | ||
|
||
return new MergeIterator<>(iterators, Comparator.comparing(Entry::key, ThreadSafeDaoImpl::compare)); |
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.
Мы обращаемся к полю ThreadSafeDaoImpl
? Текут абстракции...
|
||
// private final ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||
|
||
private long currentBytes = 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.
Поле модифицируется из разных потоков под гонкой.
if (currentBytes > flushThresholdBytes) { | ||
flush(); | ||
} | ||
currentBytes += entry.key().byteSize(); |
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.
Операции инкремента currentBytes
в таком виде не атомарны.
DiskStorage.save(path, storage.values()); | ||
currentBytes = 0; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); |
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.
throw new RuntimeException(e); | |
throw new UncheckedIOException(e); |
} | ||
|
||
@Override | ||
public void 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.
Операция блокирующая и не соответствует спецификации, верно?
} | ||
|
||
@Override | ||
public void compact() throws IOException { |
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.
Операция блокирующая и не соответствует спецификации, верно?
try { | ||
Files.createDirectories(compactPath); | ||
DiskStorage.save(compactPath, this::all); | ||
DiskStorage.deleteFiles(path); |
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.
Почему мы не переключаемся на результат compaction, а продолжаем использовать удалённые файлы?
private final Path compactPath; | ||
private final long flushThresholdBytes; | ||
|
||
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); |
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.
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); | |
private final ReadWriteLock rwl = new ReentrantReadWriteLock(); |
No description provided.