h2/src/main/org/h2/mvstore/MVStore.java
/**
     * Apply the freed space to the chunk metadata. The metadata is updated, but
     * freed chunks are not removed yet.
     *
     * @param storeVersion apply up to the given version
     * @return the set of completely freed chunks (might be empty)
     */
Apply the freed space to the chunk metadata. The metadata is updated, but
freed chunks are not removed yet.

@param storeVersion apply up to the given version
@return the set of completely freed chunks (might be empty)
Apply the freed space to the chunk metadata . The metadata is updated but freed chunks are not removed yet . @param storeVersion apply up to the given version @return the set of completely freed chunks ( might be empty )
private Set<Chunk> applyFreedSpace(long storeVersion, long time) {
        Set<Chunk> removedChunks = New.hashSet();
        while (true) {
            ArrayList<Chunk> modified = New.arrayList();
            Iterator<Entry<Long, HashMap<Integer, Chunk>>> it;
            it = freedPageSpace.entrySet().iterator();
            while (it.hasNext()) {
                Entry<Long, HashMap<Integer, Chunk>> e = it.next();
                long v = e.getKey();
                if (v > storeVersion) {
                    continue;
                }
                HashMap<Integer, Chunk> freed = e.getValue();
                for (Chunk f : freed.values()) {
                    Chunk c = chunks.get(f.id);
                    if (c == null) {
                        continue;
                    }
                    c.maxLengthLive += f.maxLengthLive;
                    c.pageCountLive += f.pageCountLive;
                    if (c.pageCountLive < 0) {
                        throw DataUtils.newIllegalStateException(
                                DataUtils.ERROR_INTERNAL,
                                "Corrupt page count {0}", c.pageCountLive);
                    }
                    if (c.maxLengthLive < 0) {
                        throw DataUtils.newIllegalStateException(
                                DataUtils.ERROR_INTERNAL,
                                "Corrupt max length {0}", c.maxLengthLive);
                    }
                    if (c.pageCount == 0 && c.maxLengthLive > 0) {
                        throw DataUtils.newIllegalStateException(
                                DataUtils.ERROR_INTERNAL,
                                "Corrupt max length {0}", c.maxLengthLive);
                    }
                    modified.add(c);
                }
                it.remove();
            }
            for (Chunk c : modified) {
                if (c.maxLengthLive == 0) {
                    if (canOverwriteChunk(c, time)) {
                        removedChunks.add(c);
                        chunks.remove(c.id);
                        meta.remove("chunk." + c.id);
                    } else {
                        meta.put("chunk." + c.id, c.asString());
                        registerFreePage(storeVersion + 1, c.id, 0, 0);
                    }
                } else {
                    meta.put("chunk." + c.id, c.asString());
                }
            }
            if (modified.size() == 0) {
                break;
            }
        }
        return removedChunks;
    }
private Set < Chunk > applyFreedSpace ( long storeVersion , long time ) { Set < Chunk > removedChunks = New . hashSet ( ) ; while ( true ) { ArrayList < Chunk > modified = New . arrayList ( ) ; Iterator < Entry < Long , HashMap < Integer , Chunk > > > it ; it = freedPageSpace . entrySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { Entry < Long , HashMap < Integer , Chunk > > e = it . next ( ) ; long v = e . getKey ( ) ; if ( v > storeVersion ) { continue ; } HashMap < Integer , Chunk > freed = e . getValue ( ) ; for ( Chunk f : freed . values ( ) ) { Chunk c = chunks . get ( f . id ) ; if ( c == null ) { continue ; } c . maxLengthLive += f . maxLengthLive ; c . pageCountLive += f . pageCountLive ; if ( c . pageCountLive < 0 ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_INTERNAL , "Corrupt page count {0}" , c . pageCountLive ) ; } if ( c . maxLengthLive < 0 ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_INTERNAL , "Corrupt max length {0}" , c . maxLengthLive ) ; } if ( c . pageCount == 0 && c . maxLengthLive > 0 ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_INTERNAL , "Corrupt max length {0}" , c . maxLengthLive ) ; } modified . add ( c ) ; } it . remove ( ) ; } for ( Chunk c : modified ) { if ( c . maxLengthLive == 0 ) { if ( canOverwriteChunk ( c , time ) ) { removedChunks . add ( c ) ; chunks . remove ( c . id ) ; meta . remove ( "chunk." + c . id ) ; } else { meta . put ( "chunk." + c . id , c . asString ( ) ) ; registerFreePage ( storeVersion + 1 , c . id , 0 , 0 ) ; } } else { meta . put ( "chunk." + c . id , c . asString ( ) ) ; } } if ( modified . size ( ) == 0 ) { break ; } } return removedChunks ; }
Apply the freed space to the chunk metadata.
Apply the freed space to the chunk metadata .
// already removed // no need to synchronize, as old entries // are not concurrently modified // remove this chunk in the next save operation