提交 83a8d90c authored 作者: Andrei Tokar's avatar Andrei Tokar 提交者: GitHub

Merge pull request #618 from h2database/small_opts

small optimizations, backward compatibility with 1.7 
...@@ -704,13 +704,12 @@ public final class MVStore { ...@@ -704,13 +704,12 @@ public final class MVStore {
} }
s = meta.get(s); s = meta.get(s);
Chunk c = Chunk.fromString(s); Chunk c = Chunk.fromString(s);
if (!chunks.containsKey(c.id)) { if (chunks.putIfAbsent(c.id, c) == null) {
if (c.block == Long.MAX_VALUE) { if (c.block == Long.MAX_VALUE) {
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
DataUtils.ERROR_FILE_CORRUPT, DataUtils.ERROR_FILE_CORRUPT,
"Chunk {0} is invalid", c.id); "Chunk {0} is invalid", c.id);
} }
chunks.put(c.id, c);
} }
} }
} }
...@@ -1268,16 +1267,13 @@ public final class MVStore { ...@@ -1268,16 +1267,13 @@ public final class MVStore {
return; return;
} }
Set<Integer> referenced = collectReferencedChunks(); Set<Integer> referenced = collectReferencedChunks();
ArrayList<Chunk> free = New.arrayList();
long time = getTimeSinceCreation(); long time = getTimeSinceCreation();
for (Chunk c : chunks.values()) {
for (Iterator<Chunk> it = chunks.values().iterator(); it.hasNext(); ) {
Chunk c = it.next();
if (!referenced.contains(c.id)) { if (!referenced.contains(c.id)) {
free.add(c);
}
}
for (Chunk c : free) {
if (canOverwriteChunk(c, time)) { if (canOverwriteChunk(c, time)) {
chunks.remove(c.id); it.remove();
markMetaChanged(); markMetaChanged();
meta.remove(Chunk.getMetaKey(c.id)); meta.remove(Chunk.getMetaKey(c.id));
long start = c.block * BLOCK_SIZE; long start = c.block * BLOCK_SIZE;
...@@ -1292,6 +1288,7 @@ public final class MVStore { ...@@ -1292,6 +1288,7 @@ public final class MVStore {
} }
} }
} }
}
private Set<Integer> collectReferencedChunks() { private Set<Integer> collectReferencedChunks() {
long testVersion = lastChunk.version; long testVersion = lastChunk.version;
...@@ -2358,14 +2355,14 @@ public final class MVStore { ...@@ -2358,14 +2355,14 @@ public final class MVStore {
} }
private void revertTemp(long storeVersion) { private void revertTemp(long storeVersion) {
for (Iterator<Long> it = freedPageSpace.keySet().iterator(); for (Iterator<Entry<Long, ConcurrentHashMap<Integer, Chunk>>> it =
it.hasNext();) { freedPageSpace.entrySet().iterator(); it.hasNext(); ) {
long v = it.next(); Entry<Long, ConcurrentHashMap<Integer, Chunk>> entry = it.next();
if (v > storeVersion) { Long v = entry.getKey();
continue; if (v <= storeVersion) {
}
it.remove(); it.remove();
} }
}
for (MVMap<?, ?> m : maps.values()) { for (MVMap<?, ?> m : maps.values()) {
m.removeUnusedOldVersions(); m.removeUnusedOldVersions();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论