merged r1274:1322 from hyracks_dev_next
git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_lsm_tree@1342 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-tests/hyracks-storage-common-test/pom.xml b/hyracks-tests/hyracks-storage-common-test/pom.xml
index ea12f5b..6c25b9b 100644
--- a/hyracks-tests/hyracks-storage-common-test/pom.xml
+++ b/hyracks-tests/hyracks-storage-common-test/pom.xml
@@ -2,12 +2,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.uci.ics.hyracks</groupId>
<artifactId>hyracks-storage-common-test</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <version>0.2.1-SNAPSHOT</version>
<parent>
<groupId>edu.uci.ics.hyracks</groupId>
<artifactId>hyracks-tests</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <version>0.2.1-SNAPSHOT</version>
</parent>
<build>
@@ -23,11 +23,30 @@
</plugin>
</plugins>
</build>
- <dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>edu.uci.ics.hyracks</groupId>
+ <artifactId>hyracks-control-nc</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>edu.uci.ics.hyracks</groupId>
+ <artifactId>hyracks-storage-common</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>edu.uci.ics.hyracks</groupId>
<artifactId>hyracks-test-support</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <version>0.2.1-SNAPSHOT</version>
<type>jar</type>
<scope>test</scope>
</dependency>
diff --git a/hyracks-tests/hyracks-storage-common-test/src/test/java/edu/uci/ics/hyracks/storage/common/BufferCacheRegressionTests.java b/hyracks-tests/hyracks-storage-common-test/src/test/java/edu/uci/ics/hyracks/storage/common/BufferCacheRegressionTests.java
index fff9e31..a649aa7 100644
--- a/hyracks-tests/hyracks-storage-common-test/src/test/java/edu/uci/ics/hyracks/storage/common/BufferCacheRegressionTests.java
+++ b/hyracks-tests/hyracks-storage-common-test/src/test/java/edu/uci/ics/hyracks/storage/common/BufferCacheRegressionTests.java
@@ -10,8 +10,8 @@
import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.api.io.FileHandle;
import edu.uci.ics.hyracks.api.io.FileReference;
+import edu.uci.ics.hyracks.api.io.IFileHandle;
import edu.uci.ics.hyracks.api.io.IIOManager;
import edu.uci.ics.hyracks.api.io.IIOManager.FileReadWriteMode;
import edu.uci.ics.hyracks.api.io.IIOManager.FileSyncMode;
@@ -23,158 +23,149 @@
import edu.uci.ics.hyracks.test.support.TestUtils;
public class BufferCacheRegressionTests {
- protected static final String tmpDir = System.getProperty("java.io.tmpdir");
- protected static final String sep = System.getProperty("file.separator");
+ protected static final String tmpDir = System.getProperty("java.io.tmpdir");
+ protected static final String sep = System.getProperty("file.separator");
- protected String fileName = tmpDir + sep + "flushTestFile";
+ protected String fileName = tmpDir + sep + "flushTestFile";
- private static final int PAGE_SIZE = 256;
- private static final int HYRACKS_FRAME_SIZE = PAGE_SIZE;
- private IHyracksTaskContext ctx = TestUtils.create(HYRACKS_FRAME_SIZE);
+ private static final int PAGE_SIZE = 256;
+ private static final int HYRACKS_FRAME_SIZE = PAGE_SIZE;
+ private IHyracksTaskContext ctx = TestUtils.create(HYRACKS_FRAME_SIZE);
- // We want to test the following behavior when reclaiming a file slot in the
- // buffer cache:
- // 1. If the file being evicted was deleted, then its dirty pages should be
- // invalidated, but most not be flushed.
- // 2. If the file was not deleted, then we must flush its dirty pages.
- @Test
- public void testFlushBehaviorOnFileEviction() throws IOException {
- File f = new File(fileName);
- if (f.exists()) {
- f.delete();
- }
- flushBehaviorTest(true);
- flushBehaviorTest(false);
- }
+ // We want to test the following behavior when reclaiming a file slot in the
+ // buffer cache:
+ // 1. If the file being evicted was deleted, then its dirty pages should be
+ // invalidated, but most not be flushed.
+ // 2. If the file was not deleted, then we must flush its dirty pages.
+ @Test
+ public void testFlushBehaviorOnFileEviction() throws IOException {
+ File f = new File(fileName);
+ if (f.exists()) {
+ f.delete();
+ }
+ flushBehaviorTest(true);
+ flushBehaviorTest(false);
+ }
- private void flushBehaviorTest(boolean deleteFile) throws IOException {
- TestStorageManagerComponentHolder.init(PAGE_SIZE, 10, 1);
+ private void flushBehaviorTest(boolean deleteFile) throws IOException {
+ TestStorageManagerComponentHolder.init(PAGE_SIZE, 10, 1);
- IBufferCache bufferCache = TestStorageManagerComponentHolder
- .getBufferCache(ctx);
- IFileMapProvider fmp = TestStorageManagerComponentHolder
- .getFileMapProvider(ctx);
+ IBufferCache bufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx);
+ IFileMapProvider fmp = TestStorageManagerComponentHolder.getFileMapProvider(ctx);
- FileReference firstFileRef = new FileReference(new File(fileName));
- bufferCache.createFile(firstFileRef);
- int firstFileId = fmp.lookupFileId(firstFileRef);
- bufferCache.openFile(firstFileId);
+ FileReference firstFileRef = new FileReference(new File(fileName));
+ bufferCache.createFile(firstFileRef);
+ int firstFileId = fmp.lookupFileId(firstFileRef);
+ bufferCache.openFile(firstFileId);
- // Fill the first page with known data and make it dirty by write
- // latching it.
- ICachedPage writePage = bufferCache.pin(
- BufferedFileHandle.getDiskPageId(firstFileId, 0), true);
- writePage.acquireWriteLatch();
- try {
- ByteBuffer buf = writePage.getBuffer();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(Byte.MAX_VALUE);
- }
- } finally {
- writePage.releaseWriteLatch();
- bufferCache.unpin(writePage);
- }
- bufferCache.closeFile(firstFileId);
- if (deleteFile) {
- bufferCache.deleteFile(firstFileId, false);
- }
+ // Fill the first page with known data and make it dirty by write
+ // latching it.
+ ICachedPage writePage = bufferCache.pin(BufferedFileHandle.getDiskPageId(firstFileId, 0), true);
+ writePage.acquireWriteLatch();
+ try {
+ ByteBuffer buf = writePage.getBuffer();
+ for (int i = 0; i < buf.capacity(); i++) {
+ buf.put(Byte.MAX_VALUE);
+ }
+ } finally {
+ writePage.releaseWriteLatch();
+ bufferCache.unpin(writePage);
+ }
+ bufferCache.closeFile(firstFileId);
+ if (deleteFile) {
+ bufferCache.deleteFile(firstFileId, false);
+ }
- // Create a file with the same name.
- FileReference secondFileRef = new FileReference(new File(fileName));
- bufferCache.createFile(secondFileRef);
- int secondFileId = fmp.lookupFileId(secondFileRef);
+ // Create a file with the same name.
+ FileReference secondFileRef = new FileReference(new File(fileName));
+ bufferCache.createFile(secondFileRef);
+ int secondFileId = fmp.lookupFileId(secondFileRef);
- // This open will replace the firstFileRef's slot in the BufferCache,
- // causing it's pages to be cleaned up. We want to make sure that those
- // dirty pages are not flushed to the disk, because the file was
- // declared as deleted, and
- // somebody might be already using the same filename again (having been
- // assigned a different fileId).
- bufferCache.openFile(secondFileId);
+ // This open will replace the firstFileRef's slot in the BufferCache,
+ // causing it's pages to be cleaned up. We want to make sure that those
+ // dirty pages are not flushed to the disk, because the file was
+ // declared as deleted, and
+ // somebody might be already using the same filename again (having been
+ // assigned a different fileId).
+ bufferCache.openFile(secondFileId);
- // Manually open the file and inspect it's contents. We cannot simply
- // ask the BufferCache to pin the page, because it would return the same
- // physical memory again, and for performance reasons pages are never
- // reset with 0's.
- IIOManager ioManager = ctx.getIOManager();
- FileReference testFileRef = new FileReference(new File(fileName));
- FileHandle testFileHandle = new FileHandle(testFileRef);
- testFileHandle.open(FileReadWriteMode.READ_ONLY,
- FileSyncMode.METADATA_SYNC_DATA_SYNC);
- ByteBuffer testBuffer = ByteBuffer.allocate(PAGE_SIZE);
- ioManager.syncRead(testFileHandle, 0, testBuffer);
- for (int i = 0; i < testBuffer.capacity(); i++) {
- if (deleteFile) {
- // We deleted the file. We expect to see a clean buffer.
- if (testBuffer.get(i) == Byte.MAX_VALUE) {
- fail("Page 0 of deleted file was fazily flushed in openFile(), "
- + "corrupting the data of a newly created file with the same name.");
- }
- } else {
- // We didn't delete the file. We expect to see a buffer full of
- // Byte.MAX_VALUE.
- if (testBuffer.get(i) != Byte.MAX_VALUE) {
- fail("Page 0 of closed file was not flushed when properly, when reclaiming the file slot of fileId 0 in the BufferCache.");
- }
- }
- }
- testFileHandle.close();
- bufferCache.closeFile(secondFileId);
- if (deleteFile) {
- bufferCache.deleteFile(secondFileId, false);
- }
- bufferCache.close();
- }
+ // Manually open the file and inspect it's contents. We cannot simply
+ // ask the BufferCache to pin the page, because it would return the same
+ // physical memory again, and for performance reasons pages are never
+ // reset with 0's.
+ IIOManager ioManager = ctx.getIOManager();
+ FileReference testFileRef = new FileReference(new File(fileName));
+ IFileHandle testFileHandle = ioManager.open(testFileRef, FileReadWriteMode.READ_ONLY,
+ FileSyncMode.METADATA_SYNC_DATA_SYNC);
+ ByteBuffer testBuffer = ByteBuffer.allocate(PAGE_SIZE);
+ ioManager.syncRead(testFileHandle, 0, testBuffer);
+ for (int i = 0; i < testBuffer.capacity(); i++) {
+ if (deleteFile) {
+ // We deleted the file. We expect to see a clean buffer.
+ if (testBuffer.get(i) == Byte.MAX_VALUE) {
+ fail("Page 0 of deleted file was fazily flushed in openFile(), "
+ + "corrupting the data of a newly created file with the same name.");
+ }
+ } else {
+ // We didn't delete the file. We expect to see a buffer full of
+ // Byte.MAX_VALUE.
+ if (testBuffer.get(i) != Byte.MAX_VALUE) {
+ fail("Page 0 of closed file was not flushed when properly, when reclaiming the file slot of fileId 0 in the BufferCache.");
+ }
+ }
+ }
+ ioManager.close(testFileHandle);
+ bufferCache.closeFile(secondFileId);
+ if (deleteFile) {
+ bufferCache.deleteFile(secondFileId, false);
+ }
+ bufferCache.close();
+ }
- // Tests the behavior of the BufferCache when more than all pages are
- // pinned. We expect an exception.
- @Test
- public void testPinningAllPages() throws HyracksDataException {
- int numPages = 10;
- TestStorageManagerComponentHolder.init(PAGE_SIZE, numPages, 1);
+ // Tests the behavior of the BufferCache when more than all pages are
+ // pinned. We expect an exception.
+ @Test
+ public void testPinningAllPages() throws HyracksDataException {
+ int numPages = 10;
+ TestStorageManagerComponentHolder.init(PAGE_SIZE, numPages, 1);
- IBufferCache bufferCache = TestStorageManagerComponentHolder
- .getBufferCache(ctx);
- IFileMapProvider fmp = TestStorageManagerComponentHolder
- .getFileMapProvider(ctx);
+ IBufferCache bufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx);
+ IFileMapProvider fmp = TestStorageManagerComponentHolder.getFileMapProvider(ctx);
- FileReference firstFileRef = new FileReference(new File(fileName));
- bufferCache.createFile(firstFileRef);
- int fileId = fmp.lookupFileId(firstFileRef);
- bufferCache.openFile(fileId);
+ FileReference firstFileRef = new FileReference(new File(fileName));
+ bufferCache.createFile(firstFileRef);
+ int fileId = fmp.lookupFileId(firstFileRef);
+ bufferCache.openFile(fileId);
- // Pin all pages.
- ICachedPage[] pages = new ICachedPage[numPages];
- for (int i = 0; i < numPages; ++i) {
- pages[i] = bufferCache.pin(
- BufferedFileHandle.getDiskPageId(fileId, i), true);
- }
+ // Pin all pages.
+ ICachedPage[] pages = new ICachedPage[numPages];
+ for (int i = 0; i < numPages; ++i) {
+ pages[i] = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, i), true);
+ }
- // Try to pin another page. We expect a HyracksDataException.
- ICachedPage errorPage = null;
- try {
- errorPage = bufferCache.pin(
- BufferedFileHandle.getDiskPageId(fileId, numPages), true);
- } catch (HyracksDataException e) {
- // This is the expected outcome.
- // The BufferCache should still be able to function properly.
- // Try unpinning all pages.
- for (int i = 0; i < numPages; ++i) {
- bufferCache.unpin(pages[i]);
- }
- // Now try pinning the page that failed above again.
- errorPage = bufferCache.pin(
- BufferedFileHandle.getDiskPageId(fileId, numPages), true);
- // Unpin it.
- bufferCache.unpin(errorPage);
- // Cleanup.
- bufferCache.closeFile(fileId);
- bufferCache.close();
- return;
- } catch (Exception e) {
- fail("Expected a HyracksDataException when pinning more pages than available but got another exception: "
- + e.getMessage());
- }
- fail("Expected a HyracksDataException when pinning more pages than available.");
- }
+ // Try to pin another page. We expect a HyracksDataException.
+ ICachedPage errorPage = null;
+ try {
+ errorPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, numPages), true);
+ } catch (HyracksDataException e) {
+ // This is the expected outcome.
+ // The BufferCache should still be able to function properly.
+ // Try unpinning all pages.
+ for (int i = 0; i < numPages; ++i) {
+ bufferCache.unpin(pages[i]);
+ }
+ // Now try pinning the page that failed above again.
+ errorPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, numPages), true);
+ // Unpin it.
+ bufferCache.unpin(errorPage);
+ // Cleanup.
+ bufferCache.closeFile(fileId);
+ bufferCache.close();
+ return;
+ } catch (Exception e) {
+ fail("Expected a HyracksDataException when pinning more pages than available but got another exception: "
+ + e.getMessage());
+ }
+ fail("Expected a HyracksDataException when pinning more pages than available.");
+ }
}