Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW 5 Шишигин Степан DWS ИТМО #197

Merged
merged 91 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
294e3c7
dao init
Feb 19, 2024
e960631
service init
Feb 19, 2024
229b790
server init
Feb 19, 2024
4e01c45
lua random read write delete script
Feb 19, 2024
7dfdc2c
codestyle fixes
Feb 20, 2024
ba052d6
codestyle fixes
Feb 20, 2024
268619c
codestyle fixes
Feb 20, 2024
7203e78
codestyle fixes
Feb 20, 2024
8a5091b
codestyle fixes
Feb 20, 2024
4f67dbf
codestyle fixes
Feb 20, 2024
5655638
codestyle fixes
Feb 20, 2024
d6d663b
some dao fixes
Feb 21, 2024
04ace3c
lua script fixes
Feb 21, 2024
420a6da
lua script fixes
Feb 21, 2024
fff2d0d
report with artifacts
Feb 21, 2024
83ba322
Update README.md (#42)
incubos Feb 22, 2024
af06133
mem storage limit increased
Feb 26, 2024
e88204c
some script refactoring
Feb 26, 2024
7c15f5f
first straightforward solution (executor.execute in overriden handleR…
Feb 26, 2024
b1844f4
Merge branch 'main' into stage-2
sshishigin Feb 26, 2024
a2c72a1
small refactoring and thread numbers shuffle
Feb 26, 2024
8a4c926
Nonnul annotation missed
Feb 26, 2024
71e98e9
logging level in dao
Feb 26, 2024
9ecefb3
fix checkstyle?
Feb 26, 2024
475bdd2
fix checkstyle?
Feb 26, 2024
6b4ec74
Merge branch 'main' into stage-2
incubos Feb 27, 2024
ef6deb4
Merge remote-tracking branch 'origin/stage-2' into stage-2
Feb 27, 2024
adde554
checkstyle
Feb 27, 2024
4d8e176
checkstyle
Feb 27, 2024
ee7d646
two-level exception handling
Feb 27, 2024
d9afa40
code climate fix attempt
Feb 27, 2024
38f3d6e
code climate fix attempt 2
Feb 27, 2024
e9715d5
code climate победил
Feb 27, 2024
be989a8
code climate fix
Feb 27, 2024
714d648
code climate fix reverted
Mar 4, 2024
4154700
отчёт
Mar 4, 2024
849a914
фикс количества потоков в пуле
Mar 4, 2024
cc0b948
Merge branch 'main' into stage-2
sshishigin Mar 4, 2024
56e4ca3
SMALL fix, relative path in REPORT
Mar 10, 2024
1e1ca74
Merge remote-tracking branch 'origin/stage-2' into stage-2
Mar 10, 2024
ec44270
Merge remote-tracking branch 'upstream/main' into stage-3
Mar 12, 2024
2ee1d00
server correct resource management
Mar 12, 2024
b02a3d5
dao correct resource management
Mar 12, 2024
d8f73c5
remote dao connection impl
Mar 12, 2024
78eabf4
dao manager impl
Mar 12, 2024
690ca2f
dao manager substitute for server instead of just local dao
Mar 12, 2024
6ac65ce
Merge remote-tracking branch 'upstream/main' into stage-3
Mar 12, 2024
2dc2662
codestyle fix
Mar 12, 2024
b8d8197
codestyle fix
Mar 12, 2024
1d3e1a6
codestyle fix
Mar 12, 2024
ea219dd
codestyle fix
Mar 12, 2024
8785032
change hashing from java message digest to one nio murmur3 implementa…
Mar 17, 2024
4ea2f4e
v-node tuning and import cleanup + logical mistake
Mar 17, 2024
b183f4b
начала отчета, пока что без профилей
Mar 17, 2024
9660608
codestyle fix
Mar 17, 2024
a2aaeda
остатки отчета
Mar 19, 2024
289bb78
Merge remote-tracking branch 'upstream/main' into stage-4
Mar 23, 2024
a7a1c30
SOLUTION
Mar 27, 2024
007bf6c
Merge remote-tracking branch 'upstream/main' into stage-4
Mar 27, 2024
5391797
codestyle
Mar 27, 2024
de55298
codestyle
Mar 27, 2024
22ac2cb
codestyle
Mar 27, 2024
da03846
codestyle
Mar 27, 2024
f96cca8
отчет
Apr 3, 2024
05708e0
Merge remote-tracking branch 'upstream/main' into stage-4
Apr 7, 2024
cfa7b58
фиксы по комментам
Apr 9, 2024
e397a3d
фиксы по комментам
Apr 9, 2024
00171e8
broken totally
Apr 14, 2024
267064a
still broken
Apr 15, 2024
650ebfa
more broken than ever
Apr 15, 2024
b7c143b
probably fixed
Apr 16, 2024
1f84f54
Merge remote-tracking branch 'refs/remotes/upstream/main' into stage-5
Apr 16, 2024
6d64568
actually fixed!!!
Apr 16, 2024
8c117f6
codestyle
Apr 16, 2024
8008473
codestyle
Apr 16, 2024
69fb4ee
oopsie
Apr 16, 2024
ea0760e
code climate
Apr 16, 2024
89b57bf
code climate
Apr 16, 2024
f5026de
code climate
Apr 16, 2024
0295ac1
code climate
Apr 16, 2024
3e296ca
code climate
Apr 16, 2024
2358ca2
code climate
Apr 16, 2024
89d05fe
maybe fix
Apr 17, 2024
eae83fc
maybe fix
Apr 17, 2024
7d7e844
one more fix (code was running in selectors)
Apr 17, 2024
b59212b
code climate
Apr 17, 2024
01b4134
report
Apr 17, 2024
23256f2
Merge remote-tracking branch 'refs/remotes/upstream/main' into stage-5
Apr 24, 2024
1cb5b2d
Merge branch 'main' into stage-5
incubos Apr 28, 2024
279872e
Merge branch 'main' into stage-5
incubos May 1, 2024
e71dde0
Merge branch 'main' into stage-5
incubos May 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ru.vk.itmo.test.shishiginstepan.dao;

import ru.vk.itmo.dao.BaseEntry;
import ru.vk.itmo.dao.Entry;

import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
Expand All @@ -15,7 +12,7 @@
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicBoolean;

public class BinarySearchSSTable implements SSTable<MemorySegment, Entry<MemorySegment>> {
public class BinarySearchSSTable implements SSTable<MemorySegment, EntryWithTimestamp<MemorySegment>> {
private long tableSize;
private long indexSize;
private final MemorySegment tableSegment;
Expand Down Expand Up @@ -74,7 +71,8 @@ private long searchEntryPosition(MemorySegment key, boolean exact) {

long keyOffset = getKeyOffset(m);
long valOffset = normalize(getValOffset(m));
long mismatch = MemorySegment.mismatch(key, 0, key.byteSize(), tableSegment, keyOffset, valOffset);
long keyEnd = valOffset - ValueLayout.JAVA_LONG_UNALIGNED.byteSize();
long mismatch = MemorySegment.mismatch(key, 0, key.byteSize(), tableSegment, keyOffset, keyEnd);
if (mismatch == -1) {
return m;
}
Expand All @@ -99,18 +97,20 @@ private long searchEntryPosition(MemorySegment key, boolean exact) {
}

@Override
public Entry<MemorySegment> get(MemorySegment key) {
public EntryWithTimestamp<MemorySegment> get(MemorySegment key) {
MemorySegment val;
long m = this.searchEntryPosition(key, true);
if (m == -1) return null;
long valOffset = getValOffset(m);
long recordEnd = getRecordEnd(m);
long timestampOffset = getTimestampOffset(valOffset);
val = valOffset < 0 ? null : tableSegment.asSlice(valOffset, recordEnd - valOffset);
return new BaseEntry<>(key, val);
long timestamp = tableSegment.get(ValueLayout.JAVA_LONG_UNALIGNED, timestampOffset);
return new EntryWithTimestamp<>(key, val, timestamp);
}

@Override
public Iterator<Entry<MemorySegment>> scan(MemorySegment keyFrom, MemorySegment keyTo) {
public Iterator<EntryWithTimestamp<MemorySegment>> scan(MemorySegment keyFrom, MemorySegment keyTo) {
long startIndex;
long endIndex;
if (keyFrom == null) {
Expand All @@ -137,6 +137,10 @@ private long getKeyOffset(long recordIndex) {
return indexSegment.get(ValueLayout.JAVA_LONG_UNALIGNED, recordIndex * Long.BYTES * 2);
}

private long getTimestampOffset(long valOffset) { // таймстемп - лонг который лежит прямо перед значением record`а.
return normalize(valOffset) - ValueLayout.JAVA_LONG_UNALIGNED.byteSize();
}

private long getValOffset(long recordIndex) {
return indexSegment.get(ValueLayout.JAVA_LONG_UNALIGNED, recordIndex * Long.BYTES * 2 + Long.BYTES);
}
Expand All @@ -150,7 +154,7 @@ private long getRecordEnd(long recordIndex) {
}
}

private Iterator<Entry<MemorySegment>> iterator(long startEntryIndex, long endEntryIndex) {
private Iterator<EntryWithTimestamp<MemorySegment>> iterator(long startEntryIndex, long endEntryIndex) {
return new Iterator<>() {
long currentEntryIndex = startEntryIndex;

Expand All @@ -160,12 +164,13 @@ public boolean hasNext() {
}

@Override
public Entry<MemorySegment> next() {
public EntryWithTimestamp<MemorySegment> next() {
var keyOffset = getKeyOffset(currentEntryIndex);
var valOffset = getValOffset(currentEntryIndex);
var timeStampOffset = getTimestampOffset(valOffset);
long nextOffset = getRecordEnd(currentEntryIndex);
this.currentEntryIndex++;
return new BaseEntry<>(
return new EntryWithTimestamp<>(
tableSegment.asSlice(keyOffset, normalize(valOffset) - keyOffset),
valOffset < 0
?
Expand All @@ -174,7 +179,8 @@ public Entry<MemorySegment> next() {
tableSegment.asSlice(
normalize(valOffset),
nextOffset - normalize(valOffset)
)
),
tableSegment.get(ValueLayout.JAVA_LONG_UNALIGNED, timeStampOffset)
);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ru.vk.itmo.test.shishiginstepan.dao;

import ru.vk.itmo.dao.Entry;

import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
Expand Down Expand Up @@ -29,7 +27,7 @@ private BinarySearchSSTableWriter() {
}

public static BinarySearchSSTable writeSSTable(
Iterable<Entry<MemorySegment>> entries,
Iterable<EntryWithTimestamp<MemorySegment>> entries,
Path path,
int id,
Arena arena
Expand All @@ -52,7 +50,8 @@ public static BinarySearchSSTable writeSSTable(
if (entry.value() != null) {
dataSize += entry.value().byteSize();
}
indexSize += Long.BYTES * 2;
indexSize += Long.BYTES * 2; // размер лонгов которые оффсеты ключа, значения
dataSize += Long.BYTES; // размер лонга который будет таймстемпом в таблице
}
try (var fileChannel = FileChannel.open(
tempSSTPath.get(),
Expand Down Expand Up @@ -99,7 +98,7 @@ public static BinarySearchSSTable writeSSTable(
}

private static void writeEntries(
Iterable<Entry<MemorySegment>> entries,
Iterable<EntryWithTimestamp<MemorySegment>> entries,
MemorySegment tableSegment,
MemorySegment indexSegment
) {
Expand All @@ -111,6 +110,10 @@ private static void writeEntries(

MemorySegment.copy(entry.key(), 0, tableSegment, tableOffset, entry.key().byteSize());
tableOffset += entry.key().byteSize();

tableSegment.set(ValueLayout.JAVA_LONG_UNALIGNED, tableOffset, entry.timestamp());
tableOffset += ValueLayout.JAVA_LONG_UNALIGNED.byteSize();

if (entry.value() == null) {
indexSegment.set(ValueLayout.JAVA_LONG_UNALIGNED, indexOffset, tombstone(tableOffset));
indexOffset += ValueLayout.JAVA_LONG_UNALIGNED.byteSize();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.vk.itmo.test.shishiginstepan.dao;

import ru.vk.itmo.dao.Entry;

public record EntryWithTimestamp<D>(D key, D value, Long timestamp) implements Entry<D> {
@Override
public String toString() {
return "{" + key + ":" + value + "}" + " timestamp: " + timestamp;
}
}
36 changes: 18 additions & 18 deletions src/main/java/ru/vk/itmo/test/shishiginstepan/dao/InMemDaoImpl.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.vk.itmo.test.shishiginstepan.dao;

import ru.vk.itmo.dao.Dao;
import ru.vk.itmo.dao.Entry;

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
Expand All @@ -24,7 +23,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class InMemDaoImpl implements Dao<MemorySegment, Entry<MemorySegment>> {
public class InMemDaoImpl implements Dao<MemorySegment, EntryWithTimestamp<MemorySegment>> {
private final ExecutorService executor;
private final Lock flushLock = new ReentrantLock();

Expand Down Expand Up @@ -54,13 +53,13 @@ public class InMemDaoImpl implements Dao<MemorySegment, Entry<MemorySegment>> {

private final long memStorageLimit;

private final AtomicReference<ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>>> tempStorage =
new AtomicReference<>(
new ConcurrentSkipListMap<>(
keyComparator
)
);
private final AtomicReference<ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>>> memStorage =
private final AtomicReference<ConcurrentNavigableMap<MemorySegment, EntryWithTimestamp<MemorySegment>>>
tempStorage = new AtomicReference<>(
new ConcurrentSkipListMap<>(
keyComparator
)
);
private final AtomicReference<ConcurrentNavigableMap<MemorySegment, EntryWithTimestamp<MemorySegment>>> memStorage =
new AtomicReference<>(
new ConcurrentSkipListMap<>(
keyComparator
Expand Down Expand Up @@ -98,9 +97,9 @@ public InMemDaoImpl() {
}

@Override
public Iterator<Entry<MemorySegment>> get(MemorySegment from, MemorySegment to) {
Iterator<Entry<MemorySegment>> memIterator;
Iterator<Entry<MemorySegment>> tempIterator;
public Iterator<EntryWithTimestamp<MemorySegment>> get(MemorySegment from, MemorySegment to) {
Iterator<EntryWithTimestamp<MemorySegment>> memIterator;
Iterator<EntryWithTimestamp<MemorySegment>> tempIterator;
if (to == null && from == null) {
memIterator = this.memStorage.get().values().iterator();
tempIterator = this.tempStorage.get().values().iterator();
Expand All @@ -115,7 +114,7 @@ public Iterator<Entry<MemorySegment>> get(MemorySegment from, MemorySegment to)
tempIterator = this.tempStorage.get().subMap(from, to).values().iterator();
}

List<Iterator<Entry<MemorySegment>>> iterators = new ArrayList<>();
List<Iterator<EntryWithTimestamp<MemorySegment>>> iterators = new ArrayList<>();
iterators.add(memIterator);
iterators.add(tempIterator);
persistentStorage.enrichWithPersistentIterators(from, to, iterators);
Expand All @@ -124,23 +123,24 @@ public Iterator<Entry<MemorySegment>> get(MemorySegment from, MemorySegment to)
);
}

// если этот метод возвращает могилу, это валидный объект Ентри с таймстемпом смерти (RIP 😔)
@Override
public Entry<MemorySegment> get(MemorySegment key) {
Entry<MemorySegment> entry = this.memStorage.get().get(key);
public EntryWithTimestamp<MemorySegment> get(MemorySegment key) {
EntryWithTimestamp<MemorySegment> entry = this.memStorage.get().get(key);
if (entry == null) {
entry = this.tempStorage.get().get(key);
}
if (entry == null) {
entry = persistentStorage.get(key);
}
if (entry != null && entry.value() == null) {
return null;
if (entry == null) {
return new EntryWithTimestamp<>(key, null, 0L); // у пустых значений timestamp ноль
}
return entry;
}

@Override
public void upsert(Entry<MemorySegment> entry) {
public void upsert(EntryWithTimestamp<MemorySegment> entry) {
this.memStorage.get().put(entry.key(), entry);
this.memStorageSize.updateAndGet(
(size) -> size + (entry.key().byteSize() + (entry.value() == null ? 0 : entry.value().byteSize()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.List;
import java.util.PriorityQueue;

public class MergeIterator implements Iterator<Entry<MemorySegment>> {
public class MergeIterator implements Iterator<EntryWithTimestamp<MemorySegment>> {
private static final Comparator<MemorySegment> keyComparator = (o1, o2) -> {
long mismatch = o1.mismatch(o2);
if (mismatch == -1) {
Expand All @@ -33,12 +33,12 @@ public class MergeIterator implements Iterator<Entry<MemorySegment>> {
});

private static class PeekIteratorWrapper implements Iterator<Entry<MemorySegment>> {
private Entry<MemorySegment> prefetched;
private final Iterator<Entry<MemorySegment>> iterator;
private EntryWithTimestamp<MemorySegment> prefetched;
private final Iterator<EntryWithTimestamp<MemorySegment>> iterator;

private final int priority;

public PeekIteratorWrapper(Iterator<Entry<MemorySegment>> iterator, int priority) {
public PeekIteratorWrapper(Iterator<EntryWithTimestamp<MemorySegment>> iterator, int priority) {
this.iterator = iterator;
this.priority = priority;
}
Expand All @@ -49,11 +49,11 @@ public boolean hasNext() {
}

@Override
public Entry<MemorySegment> next() {
public EntryWithTimestamp<MemorySegment> next() {
if (this.prefetched == null) {
return this.iterator.next();
} else {
Entry<MemorySegment> toReturn = this.prefetched;
EntryWithTimestamp<MemorySegment> toReturn = this.prefetched;
this.prefetched = null;
return toReturn;
}
Expand All @@ -75,10 +75,10 @@ public void skip() {
}
}

public MergeIterator(List<Iterator<Entry<MemorySegment>>> iterators) {
public MergeIterator(List<Iterator<EntryWithTimestamp<MemorySegment>>> iterators) {
// приоритет мержа будет определен порядком итераторов
for (int i = 0; i < iterators.size(); i++) {
Iterator<Entry<MemorySegment>> iterator = iterators.get(i);
Iterator<EntryWithTimestamp<MemorySegment>> iterator = iterators.get(i);
if (iterator.hasNext()) {
this.iterators.add(new PeekIteratorWrapper(iterator, i));
}
Expand All @@ -92,9 +92,9 @@ public boolean hasNext() {
}

@Override
public Entry<MemorySegment> next() {
public EntryWithTimestamp<MemorySegment> next() {
PeekIteratorWrapper nextIterator = iterators.remove();
Entry<MemorySegment> nextEntry = nextIterator.next();
EntryWithTimestamp<MemorySegment> nextEntry = nextIterator.next();
if (nextIterator.hasNext()) {
this.iterators.add(nextIterator);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ru.vk.itmo.test.shishiginstepan.dao;

import ru.vk.itmo.dao.Entry;

import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
Expand Down Expand Up @@ -59,7 +57,7 @@ public void close() {
* Гарантирует что при успешном завершении записи на диск, SSTable с переданными в метод данными
* сразу будет доступен для чтения в PersistentStorage.
**/
public void store(Iterable<Entry<MemorySegment>> data, int id) {
public void store(Iterable<EntryWithTimestamp<MemorySegment>> data, int id) {
BinarySearchSSTable newSSTable = BinarySearchSSTableWriter.writeSSTable(
data,
basePath,
Expand All @@ -69,10 +67,10 @@ public void store(Iterable<Entry<MemorySegment>> data, int id) {
this.sstables.add(newSSTable);
}

public Entry<MemorySegment> get(MemorySegment key) {
public EntryWithTimestamp<MemorySegment> get(MemorySegment key) {
for (BinarySearchSSTable sstable : this.sstables) {
if (sstable.closed.get()) continue;
Entry<MemorySegment> ssTableResult = sstable.get(key);
EntryWithTimestamp<MemorySegment> ssTableResult = sstable.get(key);
if (ssTableResult != null) {
return ssTableResult;
}
Expand All @@ -83,25 +81,27 @@ public Entry<MemorySegment> get(MemorySegment key) {
public void enrichWithPersistentIterators(
MemorySegment from,
MemorySegment to,
List<Iterator<Entry<MemorySegment>>> iteratorsToEnrich
List<Iterator<EntryWithTimestamp<MemorySegment>>> iteratorsToEnrich
) {
iteratorsToEnrich.addAll(getPersistentIterators(from, to));
}

private List<Iterator<Entry<MemorySegment>>> getPersistentIterators(
private List<Iterator<EntryWithTimestamp<MemorySegment>>> getPersistentIterators(
MemorySegment from,
MemorySegment to
) {
List<Iterator<Entry<MemorySegment>>> iterators = new ArrayList<>(sstables.size() + 1);
List<Iterator<EntryWithTimestamp<MemorySegment>>> iterators = new ArrayList<>(sstables.size() + 1);
for (var sstable : sstables) {
if (sstable.closed.get()) continue;
iterators.add(sstable.scan(from, to));
}
return iterators;
}

private List<Iterator<Entry<MemorySegment>>> getCompactableIterators(List<BinarySearchSSTable> tablesToCompact) {
List<Iterator<Entry<MemorySegment>>> iteratorsToCompact = new ArrayList<>();
private List<Iterator<EntryWithTimestamp<MemorySegment>>> getCompactableIterators(
List<BinarySearchSSTable> tablesToCompact
) {
List<Iterator<EntryWithTimestamp<MemorySegment>>> iteratorsToCompact = new ArrayList<>();
for (var sstable : tablesToCompact) {
if (sstable.closed.get()) continue;
iteratorsToCompact.add(sstable.scan(null, null));
Expand Down
Loading
Loading