提交 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,26 +1267,24 @@ public final class MVStore { ...@@ -1268,26 +1267,24 @@ 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); if (canOverwriteChunk(c, time)) {
} it.remove();
}
for (Chunk c : free) {
if (canOverwriteChunk(c, time)) {
chunks.remove(c.id);
markMetaChanged();
meta.remove(Chunk.getMetaKey(c.id));
long start = c.block * BLOCK_SIZE;
int length = c.len * BLOCK_SIZE;
fileStore.free(start, length);
} else {
if (c.unused == 0) {
c.unused = time;
meta.put(Chunk.getMetaKey(c.id), c.asString());
markMetaChanged(); markMetaChanged();
meta.remove(Chunk.getMetaKey(c.id));
long start = c.block * BLOCK_SIZE;
int length = c.len * BLOCK_SIZE;
fileStore.free(start, length);
} else {
if (c.unused == 0) {
c.unused = time;
meta.put(Chunk.getMetaKey(c.id), c.asString());
markMetaChanged();
}
} }
} }
} }
...@@ -2358,13 +2355,13 @@ public final class MVStore { ...@@ -2358,13 +2355,13 @@ 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论