提交 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 {
}
s = meta.get(s);
Chunk c = Chunk.fromString(s);
if (!chunks.containsKey(c.id)) {
if (chunks.putIfAbsent(c.id, c) == null) {
if (c.block == Long.MAX_VALUE) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_FILE_CORRUPT,
"Chunk {0} is invalid", c.id);
}
chunks.put(c.id, c);
}
}
}
......@@ -1268,26 +1267,24 @@ public final class MVStore {
return;
}
Set<Integer> referenced = collectReferencedChunks();
ArrayList<Chunk> free = New.arrayList();
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)) {
free.add(c);
}
}
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());
if (canOverwriteChunk(c, time)) {
it.remove();
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 {
}
private void revertTemp(long storeVersion) {
for (Iterator<Long> it = freedPageSpace.keySet().iterator();
it.hasNext();) {
long v = it.next();
if (v > storeVersion) {
continue;
for (Iterator<Entry<Long, ConcurrentHashMap<Integer, Chunk>>> it =
freedPageSpace.entrySet().iterator(); it.hasNext(); ) {
Entry<Long, ConcurrentHashMap<Integer, Chunk>> entry = it.next();
Long v = entry.getKey();
if (v <= storeVersion) {
it.remove();
}
it.remove();
}
for (MVMap<?, ?> m : maps.values()) {
m.removeUnusedOldVersions();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论