Skip to content

Commit

Permalink
IGNITE-18198 Implement snapshots of caches with disk page compression. (
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandasch authored Dec 23, 2022
1 parent a6e1d84 commit 8cfa8b0
Show file tree
Hide file tree
Showing 29 changed files with 960 additions and 182 deletions.
14 changes: 14 additions & 0 deletions modules/compress/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.ignite.internal.processors.compress;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Path;
Expand All @@ -29,12 +30,15 @@
import org.apache.ignite.configuration.DiskPageCompression;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.pagemem.PageUtils;
import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIO;
import org.apache.ignite.internal.processors.cache.persistence.tree.io.CompactablePageIO;
import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.xerial.snappy.Snappy;

import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.WRITE;
import static org.apache.ignite.configuration.DataStorageConfiguration.MAX_PAGE_SIZE;
import static org.apache.ignite.configuration.DiskPageCompression.SKIP_GARBAGE;
import static org.apache.ignite.internal.util.GridUnsafe.NATIVE_BYTE_ORDER;
Expand Down Expand Up @@ -90,6 +94,8 @@ static ByteBuffer allocateDirectBuffer(int cap) {
"must be at least 2 times larger than the underlying storage block size (detected to be " + fsBlockSize +
" bytes at '" + storagePath + "') for page compression.");
}

checkPunchHole(storagePath, fsBlockSize);
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -170,6 +176,34 @@ private ByteBuffer doCompactPage(ByteBuffer page, int pageSize) throws IgniteChe
return compactPage;
}

/** Check if filesystem actually supports punching holes. */
private void checkPunchHole(Path storagePath, int fsBlockSz) throws IgniteException {
ByteBuffer buffer = null;
File testFile = null;
try {
testFile = File.createTempFile("punch_hole_", null, storagePath.toFile());

buffer = GridUnsafe.allocateBuffer(fsBlockSz * 2);
GridUnsafe.zeroMemory(GridUnsafe.bufferAddress(buffer), buffer.capacity());

try (RandomAccessFileIO testFileIO = new RandomAccessFileIO(testFile, CREATE, WRITE)) {
testFileIO.writeFully(buffer);

testFileIO.punchHole(fsBlockSz, fsBlockSz);
}
}
catch (Exception e) {
throw new IgniteException("File system does not support punching holes on path " + storagePath, e);
}
finally {
if (buffer != null)
GridUnsafe.freeBuffer(buffer);

if (testFile != null)
testFile.delete();
}
}

/**
* @param page Page.
* @param compactSize Compacted page size.
Expand Down
Loading

0 comments on commit 8cfa8b0

Please sign in to comment.