Skip to content

Commit

Permalink
fix for h2database#3960
Browse files Browse the repository at this point in the history
  • Loading branch information
andreitokar committed Jan 22, 2024
1 parent c584a1e commit 1b2a2da
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions h2/src/main/org/h2/mvstore/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1903,28 +1903,31 @@ private int rewriteChunks(Set<Integer> set, boolean secondPass) {
int rewrittenPageCount = 0;
for (int chunkId : set) {
C chunk = chunks.get(chunkId);
long[] toc = getToC(chunk);
if (toc != null) {
for (int pageNo = 0; (pageNo = chunk.occupancy.nextClearBit(pageNo)) < chunk.pageCount; ++pageNo) {
long tocElement = toc[pageNo];
int mapId = DataUtils.getPageMapId(tocElement);
MVMap<String, String> metaMap = mvStore.getMetaMap();
MVMap<?, ?> map = mapId == layout.getId() ? layout
: mapId == metaMap.getId() ? metaMap : mvStore.getMap(mapId);
if (map != null && !map.isClosed()) {
assert !map.isSingleWriter();
if (secondPass || DataUtils.isLeafPosition(tocElement)) {
long pagePos = DataUtils.composePagePos(chunkId, tocElement);
serializationLock.unlock();
try {
if (map.rewritePage(pagePos)) {
++rewrittenPageCount;
if (mapId == metaMap.getId()) {
mvStore.markMetaChanged();
// there is a chance for a chunk to be dropped after set of chunks to be rewritten has been determined
if (chunk != null) {
long[] toc = getToC(chunk);
if (toc != null) {
for (int pageNo = 0; (pageNo = chunk.occupancy.nextClearBit(pageNo)) < chunk.pageCount; ++pageNo) {
long tocElement = toc[pageNo];
int mapId = DataUtils.getPageMapId(tocElement);
MVMap<String, String> metaMap = mvStore.getMetaMap();
MVMap<?, ?> map = mapId == layout.getId() ? layout
: mapId == metaMap.getId() ? metaMap : mvStore.getMap(mapId);
if (map != null && !map.isClosed()) {
assert !map.isSingleWriter();
if (secondPass || DataUtils.isLeafPosition(tocElement)) {
long pagePos = DataUtils.composePagePos(chunkId, tocElement);
serializationLock.unlock();
try {
if (map.rewritePage(pagePos)) {
++rewrittenPageCount;
if (mapId == metaMap.getId()) {
mvStore.markMetaChanged();
}
}
} finally {
serializationLock.lock();
}
} finally {
serializationLock.lock();
}
}
}
Expand Down

0 comments on commit 1b2a2da

Please sign in to comment.