提交 a4a52a3e authored 作者: andrei's avatar andrei

rollback and versions

上级 5116b071
...@@ -1049,8 +1049,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1049,8 +1049,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
RootReference previous = rootReference.previous; RootReference previous = rootReference.previous;
return previous == null || previous.root != rootReference.root ? return previous == null || previous.root != rootReference.root ?
rootReference.version : rootReference.version : previous.version;
previous.version == INITIAL_VERSION ? store.getLastStoredVersion() : previous.version;
} }
final boolean hasChangesSince(long version) { final boolean hasChangesSince(long version) {
......
...@@ -740,6 +740,9 @@ public final class MVStore { ...@@ -740,6 +740,9 @@ public final class MVStore {
} while((newest = verifyLastChunks()) != null); } while((newest = verifyLastChunks()) != null);
setWriteVersion(currentVersion); setWriteVersion(currentVersion);
if (lastStoredVersion == INITIAL_VERSION) {
lastStoredVersion = currentVersion - 1;
}
} }
private void loadChunkMeta() { private void loadChunkMeta() {
...@@ -2330,6 +2333,7 @@ public final class MVStore { ...@@ -2330,6 +2333,7 @@ public final class MVStore {
currentVersion = version; currentVersion = version;
setWriteVersion(version); setWriteVersion(version);
metaChanged = false; metaChanged = false;
lastStoredVersion = INITIAL_VERSION;
return; return;
} }
DataUtils.checkArgument( DataUtils.checkArgument(
...@@ -2401,13 +2405,10 @@ public final class MVStore { ...@@ -2401,13 +2405,10 @@ public final class MVStore {
} }
} }
} }
// rollback might have rolled back the stored chunk metadata as well
if (lastChunk != null) {
for (Chunk c : chunks.values()) {
meta.put(Chunk.getMetaKey(c.id), c.asString());
}
}
currentVersion = version; currentVersion = version;
if (lastStoredVersion == INITIAL_VERSION) {
lastStoredVersion = currentVersion - 1;
}
} }
private static long getRootPos(MVMap<String, String> map, int mapId) { private static long getRootPos(MVMap<String, String> map, int mapId) {
......
...@@ -833,9 +833,6 @@ public class TestMVStore extends TestBase { ...@@ -833,9 +833,6 @@ public class TestMVStore extends TestBase {
} }
s.close(); s.close();
int[] expectedReadsForCacheSize = { int[] expectedReadsForCacheSize = {
// 3407, 2590, 1924, 1440, 1330, 956, 918
// 1880, 1789, 1578, 1374, 995, 711, 541
// 942, 1789, 1578, 1374, 995, 711, 541
1880, 1789, 1616, 1374, 970, 711, 541 // compressed 1880, 1789, 1616, 1374, 970, 711, 541 // compressed
// 1887, 1775, 1599, 1355, 1035, 732, 507 // uncompressed // 1887, 1775, 1599, 1355, 1035, 732, 507 // uncompressed
}; };
...@@ -1372,7 +1369,6 @@ public class TestMVStore extends TestBase { ...@@ -1372,7 +1369,6 @@ public class TestMVStore extends TestBase {
s.close(); s.close();
s = openStore(fileName); s = openStore(fileName);
s.setAutoCommitDelay(0);
m = s.openMap("data"); m = s.openMap("data");
assertEquals("Hi", m.get("1")); assertEquals("Hi", m.get("1"));
assertEquals(null, m.get("2")); assertEquals(null, m.get("2"));
...@@ -1381,7 +1377,7 @@ public class TestMVStore extends TestBase { ...@@ -1381,7 +1377,7 @@ public class TestMVStore extends TestBase {
// which is rather implementation artifact then intentional. // which is rather implementation artifact then intentional.
// Once store is closed, only one sinle version of the data // Once store is closed, only one sinle version of the data
// will exists upon re-opening - the latest. // will exists upon re-opening - the latest.
// I hope nobody relies on this. // I hope nobody relies on this "multi-versioning".
/* /*
mOld = m.openVersion(old3); mOld = m.openVersion(old3);
assertEquals("Hallo", mOld.get("1")); assertEquals("Hallo", mOld.get("1"));
...@@ -1423,6 +1419,7 @@ public class TestMVStore extends TestBase { ...@@ -1423,6 +1419,7 @@ public class TestMVStore extends TestBase {
} }
} }
assertTrue(s.compact(100, 50 * 1024)); assertTrue(s.compact(100, 50 * 1024));
// compaction alone will not guarantee file size reduction
s.compactMoveChunks(); s.compactMoveChunks();
s.close(); s.close();
long len2 = FileUtils.size(fileName); long len2 = FileUtils.size(fileName);
...@@ -1441,10 +1438,8 @@ public class TestMVStore extends TestBase { ...@@ -1441,10 +1438,8 @@ public class TestMVStore extends TestBase {
assertEquals(i + 1, m.size()); assertEquals(i + 1, m.size());
} }
assertEquals(1000, m.size()); assertEquals(1000, m.size());
// previously (131896) we fail to account for initial root page for every map // memory calculations were adjusted, so as this out-of-the-thin-air number
// there are two of them here (meta and "data"), hence lack of 256 bytes assertEquals(84730, s.getUnsavedMemory());
// assertEquals(132152, s.getUnsavedMemory());
assertEquals(84940, s.getUnsavedMemory());
s.commit(); s.commit();
assertEquals(2, s.getFileStore().getWriteCount()); assertEquals(2, s.getFileStore().getWriteCount());
s.close(); s.close();
...@@ -1524,12 +1519,13 @@ public class TestMVStore extends TestBase { ...@@ -1524,12 +1519,13 @@ public class TestMVStore extends TestBase {
assertNull(meta.get("name.data1")); assertNull(meta.get("name.data1"));
assertNull(m0.get("1")); assertNull(m0.get("1"));
assertEquals("Hello", m.get("1")); assertEquals("Hello", m.get("1"));
assertEquals(3, s.commit()); // no changes - no real commit here
assertEquals(2, s.commit());
s.close(); s.close();
s = openStore(fileName); s = openStore(fileName);
s.setRetentionTime(45000); s.setRetentionTime(45000);
assertEquals(3, s.getCurrentVersion()); assertEquals(2, s.getCurrentVersion());
meta = s.getMetaMap(); meta = s.getMetaMap();
assertNotNull(meta.get("name.data")); assertNotNull(meta.get("name.data"));
assertNotNull(meta.get("name.data0")); assertNotNull(meta.get("name.data0"));
...@@ -1542,12 +1538,12 @@ public class TestMVStore extends TestBase { ...@@ -1542,12 +1538,12 @@ public class TestMVStore extends TestBase {
m.put("1", "Hallo"); m.put("1", "Hallo");
s.commit(); s.commit();
long v3 = s.getCurrentVersion(); long v3 = s.getCurrentVersion();
assertEquals(4, v3); assertEquals(3, v3);
s.close(); s.close();
s = openStore(fileName); s = openStore(fileName);
s.setRetentionTime(45000); s.setRetentionTime(45000);
assertEquals(4, s.getCurrentVersion()); assertEquals(3, s.getCurrentVersion());
m = s.openMap("data"); m = s.openMap("data");
m.put("1", "Hi"); m.put("1", "Hi");
s.close(); s.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论