import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import com.google.common.collect.Sets;
private final SegmentedJournalWriter<E> writer;
private volatile long commitIndex;
- private final NavigableMap<Long, JournalSegment<E>> segments = new ConcurrentSkipListMap<>();
+ private final ConcurrentNavigableMap<Long, JournalSegment<E>> segments = new ConcurrentSkipListMap<>();
private final Collection<SegmentedJournalReader<E>> readers = Sets.newConcurrentHashSet();
private JournalSegment<E> currentSegment;
/**
* Opens the segments.
*/
- private void open() {
+ private synchronized void open() {
// Load existing log segments from disk.
for (JournalSegment<E> segment : loadSegments()) {
segments.put(segment.descriptor().index(), segment);