joafip-svn Mailing List for java data object persistence in file (Page 13)
Brought to you by:
luc_peuvrier
You can subscribe to this list here.
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
(102) |
Nov
(52) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2012 |
Jan
(4) |
Feb
|
Mar
(14) |
Apr
(116) |
May
(100) |
Jun
(14) |
Jul
|
Aug
|
Sep
(30) |
Oct
|
Nov
(108) |
Dec
(2) |
|
From: <luc...@us...> - 2012-04-24 04:44:20
|
Revision: 3029
http://joafip.svn.sourceforge.net/joafip/?rev=3029&view=rev
Author: luc_peuvrier
Date: 2012-04-24 04:44:11 +0000 (Tue, 24 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. LeafPage tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-testsuite/pom.xml
trunk/joafip-testsuite/src/main/java/net/sf/joafip/PersistanceTestsNoLongTests.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/
trunk/joafip-btreeplus/src/test/java/net/sf/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -32,15 +33,14 @@
*/
public abstract class AbstractElement implements IPageRecordable {
- private final PageRecord pageRecord;
+ private IPageRecord pageRecord;
- public AbstractElement(final PageRecord pageRecord) {
- super();
+ public void setPageRecord(IPageRecord pageRecord) {
this.pageRecord = pageRecord;
}
@Override
- public PageRecord getPageRecord() {
+ public IPageRecord getPageRecord() {
return pageRecord;
}
@@ -53,4 +53,17 @@
public void setValueIsNotChanged() {
pageRecord.setValueIsNotChanged();
}
+
+ public long getPositionInFile() {
+ return pageRecord.getPositionInFile();
+ }
+
+ protected int entrySize(final DataRecordIdentifier key) {
+ int entryByteSize = 8/* long size for pointer */+ 8/* long size for value */;
+ final int dataSize = key.getKeyDataSize();
+ if (dataSize != 0) {
+ entryByteSize += 4/* int size for data size */+ dataSize;
+ }
+ return entryByteSize;
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity;
+import java.util.Arrays;
+
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -30,27 +32,77 @@
* @author luc peuvrier
*
*/
-public class DataBlock implements IStateStored {
+public class DataBlock implements IDataBlock {
private final DataBlockPage dataBlockPage;
private final byte[] data;
- public DataBlock(final DataBlockPage dataBlockPage, final int size) {
+ private final int indexInDataBlockPage;
+
+ private final byte bits;
+
+ private final int minSize;
+
+ private final int maxSize;
+
+ private int size;
+
+ private long position = -1;
+
+ public DataBlock(final DataBlockPage dataBlockPage,
+ final int indexInDataBlockPage, final byte bits, final int minSize,
+ final int maxSize) {
super();
this.dataBlockPage = dataBlockPage;
- data = new byte[size];
+ this.indexInDataBlockPage = indexInDataBlockPage;
+ this.bits = bits;
+ this.minSize = minSize;
+ this.maxSize = maxSize;
+ data = new byte[maxSize];
}
- public byte[] getData() {
+ @Override
+ public int getMinSize() {
+ return minSize;
+ }
+
+ @Override
+ public int getMaxSize() {
+ return maxSize;
+ }
+
+ @Override
+ public byte getBits() {
+ return bits;
+ }
+
+ public DataBlockPage getDataBlockPage() {
+ return dataBlockPage;
+ }
+
+ @Override
+ public int getIndexInDataBlockPage() {
+ return indexInDataBlockPage;
+ }
+
+ @Override
+ public byte[] getDataHolder() {
return data;
}
- public int getSize() {
- return data.length;
+ @Override
+ public void setData(final byte[] data) throws HeapException {
+ System.arraycopy(data, 0, this.data, 0, size = data.length);
+ setValueIsChangedValueToSave();
}
@Override
+ public byte[] getData() {
+ return Arrays.copyOf(data, size);
+ }
+
+ @Override
public void setValueIsChangedValueToSave() throws HeapException {
dataBlockPage.setValueIsChangedValueToSave();
}
@@ -59,4 +111,39 @@
public void setValueIsNotChanged() {
dataBlockPage.setValueIsNotChanged();
}
+
+ @Override
+ public void setNextFreeDataBlockPosition(
+ final long nextFreeDataBlockPosition) throws HeapException {
+ data[0] = (byte) (nextFreeDataBlockPosition >> 56);
+ data[1] = (byte) (nextFreeDataBlockPosition >> 48);
+ data[2] = (byte) (nextFreeDataBlockPosition >> 40);
+ data[3] = (byte) (nextFreeDataBlockPosition >> 32);
+ data[4] = (byte) (nextFreeDataBlockPosition >> 24);
+ data[5] = (byte) (nextFreeDataBlockPosition >> 16);
+ data[6] = (byte) (nextFreeDataBlockPosition >> 8);
+ data[7] = (byte) (nextFreeDataBlockPosition);
+ setValueIsChangedValueToSave();
+ }
+
+ @Override
+ public long getNextFreeDataBlockPosition() {
+ return
+ /**/((((long) data[0]) & 0xff) << 56) |
+ /**/((((long) data[1]) & 0xff) << 48) |
+ /**/((((long) data[2]) & 0xff) << 40) |
+ /**/((((long) data[3]) & 0xff) << 32) |
+ /**/((((long) data[4]) & 0xff) << 24) |
+ /**/((((long) data[5]) & 0xff) << 16) |
+ /**/((((long) data[6]) & 0xff) << 8) |
+ /**/(((long) data[0]) & 0xff);
+ }
+
+ @Override
+ public long getPosition() {
+ if (position == -1) {
+ position = dataBlockPage.position(indexInDataBlockPage);
+ }
+ return position;
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.kvstore.service.HeapException;
+
/**
*
* @author luc peuvrier
@@ -41,10 +43,10 @@
private final int dataBlockDataSize;
- private final DataBlock[] dataBlocks;
+ private final IDataBlock[] dataBlocks;
- public DataBlockPage(final PageRecord pageRecord, final byte bits) {
- super(pageRecord);
+ public DataBlockPage(final byte bits) {
+ super();
this.bits = bits;
dataBlockDataSize = 1 << bits;
// the less numberOfPageValue which for
@@ -59,7 +61,7 @@
final int totalSize = FIX_VALUE_SIZE
+ /* numberOfBlock* */dataBlockDataSize;
final int n = totalSize >> PageConstant.PAGE_BITS;
- if ((totalSize & PageConstant.PAGE_MASK) == 0) {
+ if ((totalSize & PageConstant.IN_PAGE_POSITION_MASK) == 0) {
numberOfPage = n;
} else {
numberOfPage = n + 1;
@@ -67,12 +69,17 @@
} else {
// more than one block in one page
numberOfPage = 1;
- numberOfBlock = (PageConstant.PAGE_SIZE - FIX_VALUE_SIZE)
- / dataBlockDataSize;
+ // numberOfBlock = ((int)PageConstant.PAGE_SIZE - FIX_VALUE_SIZE)
+ // / dataBlockDataSize;
+ numberOfBlock = ((int) PageConstant.PAGE_SIZE - FIX_VALUE_SIZE) >> bits;
}
+ final int minSize = bits == PageConstant.MIN_DATA_BLOCK_BITS ? 0
+ : ((1 << (bits - 1)) + 1);
dataBlocks = new DataBlock[numberOfBlock];
- for (int index = 0; index < numberOfBlock; index++) {
- dataBlocks[index] = new DataBlock(this, dataBlockDataSize);
+ for (int dataBlockIndex = 0; dataBlockIndex < numberOfBlock; dataBlockIndex++) {
+ dataBlocks[dataBlockIndex] = new DataBlock(this, dataBlockIndex,
+ bits, minSize, dataBlockDataSize);
+
}
}
@@ -97,10 +104,46 @@
@Override
public int getByteSize() {
- return numberOfPage * PageConstant.PAGE_SIZE;
+ return numberOfPage * (int) PageConstant.PAGE_SIZE;
}
- public DataBlock[] getDataBlocks() {
+ public IDataBlock[] getDataBlocks() {
return dataBlocks;
}
+
+ public IDataBlock getDataBlock(final long dataBlockPosition) {
+ // >> bits as divide by data block size
+ final int index = ((int) (dataBlockPosition - getPositionInFile()) - FIX_VALUE_SIZE) >> bits;
+ return dataBlocks[index];
+ }
+
+ public long position(final int index) {
+ return getPositionInFile() + FIX_VALUE_SIZE + (index << bits);
+ }
+
+ public void setAllFree() throws HeapException {
+ long nextPosition = getPositionInFile() + FIX_VALUE_SIZE
+ + dataBlockDataSize;
+ for (int index = 0; index < dataBlocks.length - 1; index++) {
+ dataBlocks[index].setNextFreeDataBlockPosition(nextPosition);
+ nextPosition += dataBlockDataSize;
+ }
+ dataBlocks[dataBlocks.length - 1].setNextFreeDataBlockPosition(-1L);
+ }
+
+ @Override
+ public void setParentPage(final IPageRecordable parentPage,
+ final int inParentIndex) throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public IPageRecordable getParentPage() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ throw new HeapException("unsupported");
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.kvstore.service.HeapException;
+
/**
*
* @author luc peuvrier
@@ -32,8 +34,8 @@
private final long nextFreePage;
- public FreePage(final PageRecord pageRecord, final long nextFreePage) {
- super(pageRecord);
+ public FreePage(final long nextFreePage) {
+ super();
this.nextFreePage = nextFreePage;
}
@@ -63,4 +65,20 @@
public long getNextFreePage() {
return nextFreePage;
}
+
+ @Override
+ public void setParentPage(final IPageRecordable parentPage,
+ final int inParentIndex) throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public IPageRecordable getParentPage() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ throw new HeapException("unsupported");
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -40,9 +40,9 @@
/** page number of first free page. -1 means no free page */
private long pageNumberOfFirstFreePage = -1L;
- private long pageNumberOfRootPage = -1L;
+ private long rootPagePosition = -1L;
- private long[] freeDataBlock;
+ private long[] freeDataBlocks;
private long nextDataRecordIdentifier;
@@ -70,34 +70,35 @@
this.pageNumberOfFirstFreePage = pageNumberOfFirstFreePage;
}
- public long getPageNumberOfRootPage() {
- return pageNumberOfRootPage;
+ public long getRootPagePosition() {
+ return rootPagePosition;
}
- public void setPageNumberOfRootPage(final long pageNumberOfRootPage)
+ public void setRootPagePosition(final long rootPagePosition)
throws HeapException {
setValueIsChangedValueToSave();
- this.pageNumberOfRootPage = pageNumberOfRootPage;
+ this.rootPagePosition = rootPagePosition;
}
public void setFirstFreeBlock(final long firstFreeBlockPosition,
final int blockBits) throws HeapException {
setValueIsChangedValueToSave();
initializeFreeDataBlock();
- freeDataBlock[blockBits - PageConstant.MIN_DATA_BLOCK_BITS] = firstFreeBlockPosition;
+ freeDataBlocks[blockBits - PageConstant.MIN_DATA_BLOCK_BITS] = firstFreeBlockPosition;
}
public long getFirstFreeBlock(final int blockBits) {
initializeFreeDataBlock();
- return freeDataBlock[blockBits - PageConstant.MIN_DATA_BLOCK_BITS];
+ return freeDataBlocks[blockBits - PageConstant.MIN_DATA_BLOCK_BITS];
}
public void clear() {
super.clear();
fileSizeAsNumberOfPage = -1L;
pageNumberOfFirstFreePage = -1L;
- pageNumberOfRootPage = -1L;
- freeDataBlock = null;
+ rootPagePosition = -1L;
+ freeDataBlocks = null;
+ nextDataRecordIdentifier = 0;
}
@Override
@@ -117,12 +118,12 @@
@Override
public int getRecordSize() throws HeapException {
- return PageConstant.PAGE_SIZE;
+ return (int) PageConstant.PAGE_SIZE;
}
@Override
protected int toMarshallSize() throws HeapException {
- return PageConstant.PAGE_SIZE;
+ return (int) PageConstant.PAGE_SIZE;
}
@Override
@@ -130,18 +131,18 @@
writeByteRecordType(EnumRecordType.HEADER_PAGE);
writeLong(fileSizeAsNumberOfPage);
writeLong(pageNumberOfFirstFreePage);
- writeLong(pageNumberOfRootPage);
+ writeLong(rootPagePosition);
writeLong(nextDataRecordIdentifier);
initializeFreeDataBlock();
for (int index = 0; index < PageConstant.NUMBER_OF_BLOCK_TYPE; index++) {
- writeLong(freeDataBlock[index]);
+ writeLong(freeDataBlocks[index]);
}
writeCrc32();
}
@Override
protected void unmarshallImpl() throws HeapException {
- readFileToIoBuffer(PageConstant.PAGE_SIZE);
+ readFileToIoBuffer((int) PageConstant.PAGE_SIZE);
final EnumRecordType recordType = readRecordType();
if (!EnumRecordType.HEADER_PAGE.equals(recordType)) {
throw new HeapException(EnumRecordType.HEADER_PAGE
@@ -149,19 +150,19 @@
}
fileSizeAsNumberOfPage = readLong();
pageNumberOfFirstFreePage = readLong();
- pageNumberOfRootPage = readLong();
+ rootPagePosition = readLong();
nextDataRecordIdentifier = readLong();
initializeFreeDataBlock();
for (int index = 0; index < PageConstant.NUMBER_OF_BLOCK_TYPE; index++) {
- freeDataBlock[index] = readLong();
+ freeDataBlocks[index] = readLong();
}
readAndCheckCrc32();
}
private void initializeFreeDataBlock() {
- if (freeDataBlock == null) {
- freeDataBlock = new long[PageConstant.NUMBER_OF_BLOCK_TYPE];
- Arrays.fill(freeDataBlock, -1L);
+ if (freeDataBlocks == null) {
+ freeDataBlocks = new long[PageConstant.NUMBER_OF_BLOCK_TYPE];
+ Arrays.fill(freeDataBlocks, -1L);
}
}
@@ -172,10 +173,15 @@
@Override
public int getByteSize() {
- return PageConstant.PAGE_SIZE;
+ return (int) PageConstant.PAGE_SIZE;
}
@Override
+ public void setPageRecord(IPageRecord pageRecord) throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
public PageRecord getPageRecord() throws HeapException {
throw new HeapException("unsupported");
}
@@ -196,4 +202,32 @@
setValueIsChangedValueToSave();
return value;
}
+
+ public long getFreeDataBlockPosition(final int bits) {
+ initializeFreeDataBlock();
+ return freeDataBlocks[bits - PageConstant.MIN_DATA_BLOCK_BITS];
+ }
+
+ public void setFreeDataBlockPosition(final int bits,
+ long freeDataBlockPosition) throws HeapException {
+ initializeFreeDataBlock();
+ freeDataBlocks[bits - PageConstant.MIN_DATA_BLOCK_BITS] = freeDataBlockPosition;
+ setValueIsChangedValueToSave();
+ }
+
+ @Override
+ public void setParentPage(final IPageRecordable parentPage,
+ final int inParentIndex) throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public IPageRecordable getParentPage() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ throw new HeapException("unsupported");
+ }
}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface IDataBlock extends IStateStored {
+
+ long getPosition();
+
+ void setData(byte[] data) throws HeapException;
+
+ byte[] getData();
+
+ void setNextFreeDataBlockPosition(long nextFreeDataBlockPosition)
+ throws HeapException;
+
+ long getNextFreeDataBlockPosition();
+
+ byte[] getDataHolder();
+
+ int getMinSize();
+
+ int getMaxSize();
+
+ byte getBits();
+
+ int getIndexInDataBlockPage();
+
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface IPageRecord extends IFileStorable {
+
+ /**
+ * @see IFileStorable#getPositionInFile
+ */
+ @Override
+ long getPositionInFile();
+
+ /**
+ * @see IFileStorable#setValueIsChangedValueToSave
+ */
+ @Override
+ void setValueIsChangedValueToSave() throws HeapException;
+
+ /**
+ * @see IFileStorable#setValueIsNotChanged
+ */
+ @Override
+ void setValueIsNotChanged();
+
+ /**
+ * @see IFileStorable#isValueChangedToSave
+ */
+ @Override
+ boolean isValueChangedToSave();
+
+}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -49,6 +49,14 @@
void updateByteSize();
- PageRecord getPageRecord() throws HeapException;
+ IPageRecord getPageRecord() throws HeapException;
+ void setPageRecord(IPageRecord pageRecord) throws HeapException;
+
+ void setParentPage(IPageRecordable parentPage, int inParentIndex)
+ throws HeapException;
+
+ IPageRecordable getParentPage() throws HeapException;
+
+ int getInParentIndex() throws HeapException;
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -23,7 +23,10 @@
*/
package net.sf.joafip.btreeplus.entity;
+import java.util.Arrays;
+
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
/**
*
@@ -32,7 +35,7 @@
*/
public class LeafPage extends AbstractElement {
- private long[] pagePointers;
+ private long[] dataBlockPosition;
private DataRecordIdentifier[] keys;
@@ -42,14 +45,32 @@
private long next;
- public LeafPage(final PageRecord pageRecord, final int numberOfKeyEntries) {
- super(pageRecord);
+ private IPageRecordable parentPage;
+
+ private int inParentIndex;
+
+ public LeafPage() {
+ this(0);
+ updateByteSize();
+ }
+
+ public LeafPage(final int numberOfKeyEntries) {
+ super();
this.numberOfKeyEntries = numberOfKeyEntries;
keys = new DataRecordIdentifier[numberOfKeyEntries];
- pagePointers = new long[numberOfKeyEntries];
+ dataBlockPosition = new long[numberOfKeyEntries];
byteSize = 0;
}
+ public LeafPage(final int numberOfKeyEntries,
+ final long[] dataBlockPosition, final DataRecordIdentifier[] keys) {
+ super();
+ this.numberOfKeyEntries = numberOfKeyEntries;
+ this.dataBlockPosition = dataBlockPosition;
+ this.keys = keys;
+ updateByteSize();
+ }
+
@Override
public EnumRecordType getRecordType() {
return EnumRecordType.LEAF_PAGE;
@@ -60,6 +81,23 @@
return 1;
}
+ @Override
+ public void setParentPage(final IPageRecordable parentPage,
+ final int inParentIndex) {
+ this.parentPage = parentPage;
+ this.inParentIndex = inParentIndex;
+ }
+
+ @Override
+ public IPageRecordable getParentPage() {
+ return parentPage;
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ return inParentIndex;
+ }
+
public int getNumberOfKeyEntries() {
return numberOfKeyEntries;
}
@@ -69,7 +107,7 @@
}
public long getBlockPointer(final int index) {
- return pagePointers[index];
+ return dataBlockPosition[index];
}
public long getNext() {
@@ -82,29 +120,145 @@
public void setEntry(final int index, final long pagePointer,
final DataRecordIdentifier key) {
- pagePointers[index] = pagePointer;
+ dataBlockPosition[index] = pagePointer;
keys[index] = key;
}
@Override
public int getByteSize() {
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
return byteSize;
}
@Override
public void updateByteSize() {
- byteSize = 1/* byte size for record type */+
+ byteSize = computeByteSize();
+ }
+
+ private int computeByteSize() {
+ int xbyteSize = 1/* byte size for record type */+
/**/4/* int size for number of entries */+
/**/4/* int size for crc32 */+
- /**/(numberOfKeyEntries + 1/* for next */) * 8/*
- * long size for pointer
- */;
+ /**/8/* for next */;
for (int index = 0; index < numberOfKeyEntries; index++) {
- byteSize += 8/* long size for value */;
- final int dataSize = keys[index].getKeyDataSize();
- if (dataSize != 0) {
- byteSize += 4/* int size for data size */+ dataSize;
+ xbyteSize += entrySize(keys[index]);
+ }
+ return xbyteSize;
+ }
+
+ /**
+ *
+ * @param dataRecordIdentifier
+ * @return data block pointer on data associated to data record identifier,
+ * -1 if not found
+ */
+ public long getDataBlockPosition(
+ final DataRecordIdentifier dataRecordIdentifier) {
+ // FIXMELUC _______dichotomic search
+ long position = -1;
+ for (int index = 0; position == -1L && index < numberOfKeyEntries; index++) {
+ if (keys[index].compareTo(dataRecordIdentifier) == 0) {
+ position = dataBlockPosition[index];
}
}
+ return position;
}
+
+ public void setDataBlock(final int index, final IDataBlock dataBlock)
+ throws HeapException {
+ dataBlockPosition[index] = dataBlock.getPosition();
+ }
+
+ /**
+ *
+ * @param dataRecordIdentifier
+ * @param dataBlock
+ * @return true if added
+ * @throws HeapException
+ */
+ public boolean add(final DataRecordIdentifier dataRecordIdentifier,
+ final IDataBlock dataBlock) throws HeapException {
+ final int entrySize = entrySize(dataRecordIdentifier);
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ final boolean canAdd = entrySize + byteSize <= PageConstant.PAGE_SIZE;
+ if (canAdd) {
+ // can add
+ final int insertBeforeIndex = computeInsertBeforeIndex(dataRecordIdentifier);
+ final int afterLength = numberOfKeyEntries - insertBeforeIndex;
+ numberOfKeyEntries++;
+ final long[] newDataBlockPosition = new long[numberOfKeyEntries];
+ final DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
+ if (insertBeforeIndex != 0) {
+ System.arraycopy(dataBlockPosition, 0, newDataBlockPosition, 0,
+ insertBeforeIndex);
+ System.arraycopy(keys, 0, newKeys, 0, insertBeforeIndex);
+ }
+ newDataBlockPosition[insertBeforeIndex] = dataBlock.getPosition();
+ newKeys[insertBeforeIndex] = dataRecordIdentifier;
+ if (afterLength != 0) {
+ System.arraycopy(dataBlockPosition, insertBeforeIndex,
+ newDataBlockPosition, insertBeforeIndex + 1,
+ afterLength);
+ System.arraycopy(keys, insertBeforeIndex, newKeys,
+ insertBeforeIndex + 1, afterLength);
+ }
+ dataBlockPosition = newDataBlockPosition;
+ keys = newKeys;
+ byteSize += entrySize;
+ // ASSERTX
+ assert byteSize == computeByteSize() : byteSize + " for "
+ + computeByteSize() + " computed";
+ }
+ return canAdd;
+ }
+
+ public LeafPage split(final DataRecordIdentifier dataRecordIdentifier,
+ final IDataBlock dataBlock) throws HeapException {
+ final int insertBeforeIndex = computeInsertBeforeIndex(dataRecordIdentifier);
+ final int newNumberOfKeyEntries = numberOfKeyEntries / 2;
+ final int newLeafPageNumberOfKeyEntries = numberOfKeyEntries
+ - newNumberOfKeyEntries;
+
+ final long[] newDataBlockPosition = Arrays.copyOf(dataBlockPosition,
+ newNumberOfKeyEntries);
+ final DataRecordIdentifier[] newKeys = Arrays.copyOf(keys,
+ newNumberOfKeyEntries);
+ final long[] newLeafPageDataBlockPosition = Arrays.copyOfRange(
+ dataBlockPosition, newNumberOfKeyEntries, numberOfKeyEntries);
+ final DataRecordIdentifier[] newLeafPageKeys = Arrays.copyOfRange(keys,
+ newNumberOfKeyEntries, numberOfKeyEntries);
+
+ final LeafPage newLeafPage = new LeafPage(
+ newLeafPageNumberOfKeyEntries, newLeafPageDataBlockPosition,
+ newLeafPageKeys);
+ dataBlockPosition = newDataBlockPosition;
+ keys = newKeys;
+ numberOfKeyEntries = newNumberOfKeyEntries;
+ updateByteSize();
+ if (insertBeforeIndex >= newNumberOfKeyEntries) {
+ if (!newLeafPage.add(dataRecordIdentifier, dataBlock)) {
+ throw new HeapException("failed add in new leaf page");
+ }
+ } else {
+ if (!add(dataRecordIdentifier, dataBlock)) {
+ throw new HeapException("failed add in splitted leaf page");
+ }
+ }
+ return newLeafPage;
+ }
+
+ private int computeInsertBeforeIndex(
+ final DataRecordIdentifier dataRecordIdentifier) {
+ int index;
+ for (index = 0; index < numberOfKeyEntries
+ && dataRecordIdentifier.compareTo(keys[index]) > 0; index++)
+ ;
+ return index;
+ }
+
+ public DataRecordIdentifier lastKey() {
+ return keys[numberOfKeyEntries - 1];
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -23,7 +23,10 @@
*/
package net.sf.joafip.btreeplus.entity;
+import java.util.Arrays;
+
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
/**
*
@@ -32,7 +35,7 @@
*/
public class NonTerminalPage extends AbstractElement {
- private long[] pagePointers;
+ private long[] pagePositions;
private DataRecordIdentifier[] keys;
@@ -40,15 +43,34 @@
private int byteSize;
- public NonTerminalPage(final PageRecord pageRecord,
- final int numberOfKeyEntries) {
- super(pageRecord);
+ private IPageRecordable parentPage;
+
+ private int inParentIndex;
+
+ private DataRecordIdentifier middleKey;
+
+ public NonTerminalPage() {
+ this(0);
+ updateByteSize();
+ }
+
+ public NonTerminalPage(final int numberOfKeyEntries) {
+ super();
this.numberOfKeyEntries = numberOfKeyEntries;
keys = new DataRecordIdentifier[numberOfKeyEntries];
- pagePointers = new long[numberOfKeyEntries + 1];
+ pagePositions = new long[numberOfKeyEntries + 1];
byteSize = 0;
}
+ public NonTerminalPage(final int numberOfKeyEntries,
+ final DataRecordIdentifier[] keys, final long[] pagePosition) {
+ super();
+ this.numberOfKeyEntries = numberOfKeyEntries;
+ this.keys = keys;
+ this.pagePositions = pagePosition;
+ updateByteSize();
+ }
+
@Override
public EnumRecordType getRecordType() {
return EnumRecordType.NON_TERMINAL_PAGE;
@@ -59,9 +81,26 @@
return 1;
}
+ @Override
+ public void setParentPage(final IPageRecordable parentPage,
+ final int inParentIndex) {
+ this.parentPage = parentPage;
+ this.inParentIndex = inParentIndex;
+ }
+
+ @Override
+ public IPageRecordable getParentPage() {
+ return parentPage;
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ return inParentIndex;
+ }
+
public void setEntry(final int index, final long pagePointer,
final DataRecordIdentifier key) {
- pagePointers[index] = pagePointer;
+ pagePositions[index] = pagePointer;
if (key != null) {
keys[index] = key;
}
@@ -69,23 +108,25 @@
@Override
public int getByteSize() {
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
return byteSize;
}
@Override
public void updateByteSize() {
- byteSize = 1/* byte size for record type */+
+ byteSize = computeByteSize();
+ }
+
+ private int computeByteSize() {
+ int xbyteSize = 1/* byte size for record type */+
/**/4/* int size for number of entries */+
/**/4/* int size for crc32 */+
- /**/(numberOfKeyEntries + 1) * 8;// pointer long size
+ /**/8/* last pointer long size */;
for (int index = 0; index < numberOfKeyEntries; index++) {
- byteSize += 8;// long size for value
- final int dataSize = keys[index].getKeyDataSize();
- if (dataSize != 0) {
- // 4 for length store in integer
- byteSize += 4 + dataSize;
- }
+ xbyteSize += entrySize(keys[index]);
}
+ return xbyteSize;
}
public int getNumberOfKeyEntries() {
@@ -93,10 +134,116 @@
}
public long getPagePointer(final int index) {
- return pagePointers[index];
+ return pagePositions[index];
}
public DataRecordIdentifier getKey(final int index) {
return keys[index];
}
+
+ /**
+ *
+ * @param dataRecordIdentifier
+ * @return sub page index for data record identifier
+ */
+ public int getIndex(final DataRecordIdentifier dataRecordIdentifier) {
+ // FIXMELUC _______dichotomic search
+ int index;
+ boolean found = false;
+ for (index = 0; !found && index < numberOfKeyEntries; index++) {
+ found = keys[index].compareTo(dataRecordIdentifier) <= 0;
+ }
+ return index;
+ }
+
+ /**
+ *
+ * @param existingLeftLeafPage
+ * @param newRightLeafPage
+ * @return true if add not need split
+ * @throws HeapException
+ */
+ public boolean add(final LeafPage existingLeftLeafPage,
+ final LeafPage newRightLeafPage) throws HeapException {
+ final int index = existingLeftLeafPage.getInParentIndex();
+ final DataRecordIdentifier key = existingLeftLeafPage.lastKey();
+ final int entrySize = entrySize(key);
+ final int afterLength = numberOfKeyEntries - (index + 1);
+ numberOfKeyEntries++;
+ DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
+ long[] newPagePosition = new long[numberOfKeyEntries + 1];
+ if (index != 0) {
+ System.arraycopy(keys, 0, newKeys, 0, index);
+ System.arraycopy(pagePositions, 0, newPagePosition, 0, index);
+ }
+ newKeys[index] = key;
+ newPagePosition[index + 1] = newRightLeafPage.getPositionInFile();
+ newKeys[index + 1] = newRightLeafPage.lastKey();
+ System.arraycopy(pagePositions, index + 1, newPagePosition, index + 2,
+ afterLength + 1);
+ System.arraycopy(keys, index + 1, newKeys, index + 2, afterLength);
+ keys = newKeys;
+ pagePositions = newPagePosition;
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ byteSize += entrySize;
+ // ASSERTX
+ assert byteSize == computeByteSize();
+ return byteSize < PageConstant.PAGE_SIZE;
+ }
+
+ public boolean add(final NonTerminalPage leftSonNonTerminalPage,
+ final DataRecordIdentifier middleKey,
+ final NonTerminalPage rightSonNonTerminalPage) throws HeapException {
+ final int index = leftSonNonTerminalPage.getInParentIndex();
+ final int entrySize = entrySize(middleKey);
+ final int afterLength = numberOfKeyEntries - (index + 1);
+ numberOfKeyEntries++;
+ DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
+ long[] newPagePosition = new long[numberOfKeyEntries + 1];
+ System.arraycopy(pagePositions, 0, newPagePosition, 0, index + 1);
+ if (index != 0) {
+ System.arraycopy(keys, 0, newKeys, 0, index);
+ }
+ DataRecordIdentifier k = keys[index];
+ newKeys[index] = middleKey;
+ newKeys[index + 1] = k;
+ System.arraycopy(pagePositions, index + 1, newPagePosition, index + 2,
+ afterLength + 1);
+ System.arraycopy(keys, index + 2, newKeys, index + 2, afterLength);
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ byteSize += entrySize + 8;
+ // ASSERTX
+ assert byteSize == computeByteSize();
+ return byteSize < PageConstant.PAGE_SIZE;
+ }
+
+ public NonTerminalPage split() {
+ final int splitIndex = numberOfKeyEntries / 2;
+ middleKey = keys[splitIndex];
+ final int newNumberOfKeyEntries = splitIndex;
+ final int newNonTerminalPageNumberOfKeyEntries = numberOfKeyEntries
+ - (splitIndex + 1);
+ final DataRecordIdentifier[] newKeys = Arrays.copyOf(keys,
+ newNumberOfKeyEntries);
+ final long[] newPagePosition = Arrays.copyOf(pagePositions,
+ newNumberOfKeyEntries + 1);
+ final DataRecordIdentifier[] newNonTerminalKeys = Arrays.copyOfRange(
+ keys, splitIndex + 1, numberOfKeyEntries);
+ final long[] newNonTerminalPagePosition = Arrays.copyOfRange(
+ pagePositions, splitIndex + 1, numberOfKeyEntries + 1);
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(
+ newNonTerminalPageNumberOfKeyEntries, newNonTerminalKeys,
+ newNonTerminalPagePosition);
+ keys = newKeys;
+ pagePositions = newPagePosition;
+ numberOfKeyEntries = newNumberOfKeyEntries;
+ updateByteSize();
+ return nonTerminalPage;
+ }
+
+ public DataRecordIdentifier getMiddleKey() {
+ return middleKey;
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -32,10 +32,12 @@
public final static int PAGE_BITS = 12;
- public final static int PAGE_SIZE = 1 << PAGE_BITS;
+ public final static long PAGE_SIZE = 1 << PAGE_BITS;
- public final static int PAGE_MASK = PAGE_SIZE - 1;
+ public final static long IN_PAGE_POSITION_MASK = PAGE_SIZE - 1;
+ public final static long START_PAGE_POSITION_MASK = ~(IN_PAGE_POSITION_MASK);
+
public final static int MIN_DATA_BLOCK_BITS = 4;
public final static int MAX_DATA_BLOCK_BITS = 24;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -32,7 +32,7 @@
* @author luc peuvrier
*
*/
-public class PageRecord extends AbstractPageRecord {
+public class PageRecord extends AbstractPageRecord implements IPageRecord {
private EnumRecordType recordType;
@@ -45,13 +45,13 @@
* @param pageNumber
*/
public PageRecord(final IFileForStorable fileForStorable,
- final int pageNumber) {
- super(fileForStorable, ((long) pageNumber) << PageConstant.PAGE_BITS);
+ final long pageNumber) {
+ super(fileForStorable, pageNumber << PageConstant.PAGE_BITS);
}
public PageRecord(final IFileForStorable fileForStorable,
- final IPageRecordable pageRecordable, final int pageNumber) {
- super(fileForStorable, ((long) pageNumber) << PageConstant.PAGE_BITS);
+ final IPageRecordable pageRecordable, final long pageNumber) {
+ super(fileForStorable, pageNumber << PageConstant.PAGE_BITS);
this.pageRecordable = pageRecordable;
this.recordType = pageRecordable.getRecordType();
}
@@ -73,14 +73,14 @@
public int getRecordSize() throws HeapException {
// ASSERTX
assert pageRecordable != null;
- return pageRecordable.getNumberOfPage() * PageConstant.PAGE_SIZE;
+ return pageRecordable.getNumberOfPage() * (int) PageConstant.PAGE_SIZE;
}
@Override
protected int toMarshallSize() throws HeapException {
// ASSERTX
assert recordType != null && pageRecordable != null;
- return pageRecordable.getNumberOfPage() * PageConstant.PAGE_SIZE;
+ return pageRecordable.getNumberOfPage() * (int) PageConstant.PAGE_SIZE;
}
@Override
@@ -114,7 +114,7 @@
@Override
protected void unmarshallImpl() throws HeapException {
// one page is minimum size
- readFileToIoBuffer(PageConstant.PAGE_SIZE);
+ readFileToIoBuffer((int) PageConstant.PAGE_SIZE);
recordType = readRecordType();
switch (recordType) {
case NON_TERMINAL_PAGE:
@@ -152,8 +152,9 @@
private void unmarshallNonTerminalPage() throws HeapException {
final int numberOfKeyEntries = readInteger();
- final NonTerminalPage nonTerminalPage = new NonTerminalPage(this,
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(
numberOfKeyEntries);
+ nonTerminalPage.setPageRecord(this);
for (int index = 0; index < numberOfKeyEntries; index++) {
final long pagePointer = readLong();
final DataRecordIdentifier key = readKey();
@@ -181,7 +182,8 @@
private void unmarshallLeafPage() throws HeapException {
final int numberOfKeyEntries = readInteger();
- final LeafPage leafPage = new LeafPage(this, numberOfKeyEntries);
+ final LeafPage leafPage = new LeafPage(numberOfKeyEntries);
+ leafPage.setPageRecord(this);
for (int index = 0; index < numberOfKeyEntries; index++) {
final DataRecordIdentifier key = readKey();
final long pagePointer = readLong();
@@ -201,7 +203,8 @@
private void unmarshallFreePage() throws HeapException {
final long nextFreePage = readLong();
- final FreePage freePage = new FreePage(this, nextFreePage);
+ final FreePage freePage = new FreePage(nextFreePage);
+ freePage.setPageRecord(this);
readAndCheckCrc32();
pageRecordable = freePage;
}
@@ -214,21 +217,22 @@
// ASSERTX
assert pageRecordable.getByteSize() <= numberOfPage
* PageConstant.PAGE_SIZE;
- final DataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
- for (DataBlock dataBlock : dataBlocks) {
- writeBytes(dataBlock.getData());
+ final IDataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
+ for (IDataBlock dataBlock : dataBlocks) {
+ writeBytes(dataBlock.getDataHolder());
}
writeCrc32();
}
private void unmarshallDataBlock() throws HeapException {
final byte bits = readByte();
- final DataBlockPage dataBlockPage = new DataBlockPage(this, bits);
+ final DataBlockPage dataBlockPage = new DataBlockPage(bits);
+ dataBlockPage.setPageRecord(this);
final int numberOfPage = dataBlockPage.getNumberOfPage();
- readFileAppendToIoBuffer(numberOfPage * PageConstant.PAGE_SIZE);
- final DataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
- for (DataBlock dataBlock : dataBlocks) {
- readBytes(dataBlock.getData());
+ readFileAppendToIoBuffer(numberOfPage * (int) PageConstant.PAGE_SIZE);
+ final IDataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
+ for (IDataBlock dataBlock : dataBlocks) {
+ readBytes(dataBlock.getDataHolder());
}
readAndCheckCrc32();
pageRecordable = dataBlockPage;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -28,6 +28,11 @@
import java.util.Set;
import net.sf.joafip.Fortest;
+import net.sf.joafip.btreeplus.entity.EnumRecordType;
+import net.sf.joafip.btreeplus.entity.IDataBlock;
+import net.sf.joafip.btreeplus.entity.IPageRecordable;
+import net.sf.joafip.btreeplus.entity.LeafPage;
+import net.sf.joafip.btreeplus.entity.NonTerminalPage;
import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.HeapElementManagerFactory;
@@ -44,6 +49,11 @@
*/
public class BtreePlusDataManager extends AbstractHeapDataManager {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7339154239959364861L;
+
private final BtreePlusElementMgr btreePlusElementMgr;
public BtreePlusDataManager(final HeapFileSetup setup) throws HeapException {
@@ -154,66 +164,190 @@
btreePlusElementMgr.getNewDataRecordIdentifier());
}
+ // ------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------
+
@Override
- protected boolean deleteDataRecordImpl(
+ protected byte[] readDataRecordImpl(
DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- // TODO Auto-generated method stub
- return false;
+ final IPageRecordable root = btreePlusElementMgr.getRoot();
+ final long dataBlockPosition = dataBlockPosition(root,
+ dataRecordIdentifier);
+ final byte[] data;
+ if (dataBlockPosition == -1) {
+ data = null;
+ } else {
+ data = btreePlusElementMgr.getData(dataBlockPosition);
+ }
+ return data;
}
@Override
- protected byte[] readDataRecordImpl(
- DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- // TODO Auto-generated method stub
- return null;
+ protected boolean hasDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final IPageRecordable root = btreePlusElementMgr.getRoot();
+ final long dataBlockPosition = dataBlockPosition(root,
+ dataRecordIdentifier);
+ return dataBlockPosition != -1L;
}
+ private long dataBlockPosition(final IPageRecordable root,
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final long dataBlockPosition;
+ final LeafPage leafPage = leafPage(root, dataRecordIdentifier);
+ if (leafPage == null) {
+ dataBlockPosition = -1L;
+ } else {
+ dataBlockPosition = leafPage
+ .getDataBlockPosition(dataRecordIdentifier);
+ }
+ return dataBlockPosition;
+ }
+
+ private LeafPage leafPage(final IPageRecordable root,
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ IPageRecordable page;
+ if (root == null) {
+ page = null;
+ } else {
+ page = root;
+ while (!EnumRecordType.LEAF_PAGE.equals(page)) {
+ final NonTerminalPage nonTerminalPage = (NonTerminalPage) page;
+ final int index = nonTerminalPage
+ .getIndex(dataRecordIdentifier);
+ final long pagePosition = nonTerminalPage.getPagePointer(index);
+ page = btreePlusElementMgr.getPage(pagePosition, page, index);
+ }
+ }
+ return (LeafPage) page;
+ }
+
@Override
protected boolean writeDataRecordImpl(
- DataRecordIdentifier dataRecordIdentifier, byte[] data)
+ final DataRecordIdentifier dataRecordIdentifier, final byte[] data)
throws HeapException {
- // TODO Auto-generated method stub
- return false;
+ final IPageRecordable root = btreePlusElementMgr.getRoot();
+ LeafPage leafPage = leafPage(root, dataRecordIdentifier);
+ final boolean created;
+ if (leafPage == null) {
+ // no existing data
+ created = true;
+ final IDataBlock dataBlock = btreePlusElementMgr
+ .createDataBlock(data);
+ btreePlusElementMgr
+ .newRootLeafPage(dataRecordIdentifier, dataBlock);
+ } else {
+ long dataBlockPosition = leafPage
+ .getDataBlockPosition(dataRecordIdentifier);
+ if (dataBlockPosition == -1) {
+ // data record not found
+ created = true;
+ final IDataBlock dataBlock = btreePlusElementMgr
+ .createDataBlock(data);
+ if (!leafPage.add(dataRecordIdentifier, dataBlock)) {
+ LeafPage newLeafPage = leafPage.split(dataRecordIdentifier,
+ dataBlock);
+ btreePlusElementMgr.appendPageRecordable(newLeafPage);
+ leafPage.setNext(newLeafPage.getPositionInFile());
+
+ NonTerminalPage nonTerminalPage = (NonTerminalPage) leafPage
+ .getParentPage();
+ if (nonTerminalPage == null) {
+ btreePlusElementMgr.newRootNonTerminalPage(leafPage,
+ newLeafPage);
+ } else {
+ if (!nonTerminalPage.add(leafPage, newLeafPage)) {
+ NonTerminalPage newNonTerminalPage = nonTerminalPage
+ .split();
+ do {
+ btreePlusElementMgr
+ .appendPageRecordable(newNonTerminalPage);
+ DataRecordIdentifier middleKey = nonTerminalPage
+ .getMiddleKey();
+ NonTerminalPage parent = (NonTerminalPage) nonTerminalPage
+ .getParentPage();
+ if (parent == null) {
+ btreePlusElementMgr.newRootNonTerminalPage(
+ nonTerminalPage, middleKey,
+ newNonTerminalPage);
+ } else {
+ if (parent.add(nonTerminalPage, middleKey,
+ newNonTerminalPage)) {
+ newNonTerminalPage = null;
+ } else {
+ newNonTerminalPage = nonTerminalPage
+ .split();
+ }
+ }
+ } while (newNonTerminalPage != null);
+ }
+ }
+ }
+ } else {
+ // data record found
+ created = false;
+ IDataBlock dataBlock = btreePlusElementMgr
+ .getDataBlock(dataBlockPosition);
+ if (data.length >= dataBlock.getMinSize()
+ && data.length <= dataBlock.getMaxSize()) {
+ dataBlock.setData(data);
+ } else {
+ final int index = dataBlock.getIndexInDataBlockPage();
+ btreePlusElementMgr.remove(dataBlock);
+ final IDataBlock newDataBlock = btreePlusElementMgr
+ .createDataBlock(data);
+ leafPage.setDataBlock(index, newDataBlock);
+ }
+ }
+ }
+ return created;
}
@Override
- protected boolean hasDataRecordImpl(
- DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- // TODO Auto-generated method stub
- return false;
+ protected boolean deleteDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
@Override
protected DataRecordIdentifier removeFirstDataRecordImpl()
throws HeapException {
- // TODO Auto-generated method stub
- return null;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
@Override
protected int getNumberOfDataRecordImpl() throws HeapException {
- // TODO Auto-generated method stub
- return 0;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
@Override
protected int getNumberOfFreeRecordImpl() throws HeapException {
- // TODO Auto-generated method stub
- return 0;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
@Override
protected Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
throws HeapException {
- // TODO Auto-generated method stub
- return null;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
@Override
protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
throws HeapException {
- // TODO Auto-generated method stub
- return null;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
@Override
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-23 01:47:15 UTC (rev 3028)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -24,7 +24,13 @@
package net.sf.joafip.btreeplus.service;
import net.sf.joafip.Fortest;
+import net.sf.joafip.btreeplus.entity.DataBlockPage;
import net.sf.joafip.btreeplus.entity.HeaderPage;
+import net.sf.joafip.btreeplus.entity.IDataBlock;
+import net.sf.joafip.btreeplus.entity.IPageRecord;
+import net.sf.joafip.btreeplus.entity.IPageRecordable;
+import net.sf.joafip.btreeplus.entity.LeafPage;
+import net.sf.joafip.btreeplus.entity.NonTerminalPage;
import net.sf.joafip.btreeplus.entity.PageConstant;
import net.sf.joafip.btreeplus.entity.PageRecord;
import net.sf.joafip.kvstore.entity.IFileStorable;
@@ -111,7 +117,7 @@
public IFileStorable createHeapRecord(
final HeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
- assert (positionInFile & PageConstant.PAGE_MASK) == 0;
+ assert (positionInFile & PageConstant.IN_PAGE_POSITION_MASK) == 0;
return new PageRecord(fileForStorable,
(int) (positionInFile >> PageConstant.PAGE_BITS));
}
@@ -129,13 +135,13 @@
}
public long freeSize() throws HeapException {
- // TODO Auto-generated method stub
- return 0;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
public long usedSize() throws HeapException {
- // TODO Auto-generated method stub
- return 0;
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
}
public String backup(final long identifier, final int maxBackup)
@@ -165,4 +171,141 @@
public long getNewDataRecordIdentifier() throws HeapException {
return header.getNewDataRecordIdentifier();
}
+
+ /**
+ *
+ * @return root page or null if none (no data)
+ * @throws HeapException
+ */
+ public IPageRecordable getRoot() throws HeapException {
+ final long position = header.getRootPagePosition();
+ final IPageRecordable page;
+ if (position == -1L) {
+ page = null;
+ } else {
+ page = getPage(position, null, -1);
+ }
+ return page;
+ }
+
+ public IPageRecordable getPage(final long position,
+ final IPageRecordable parentPage, final int index)
+ throws HeapException {
+ final IPageRecordable readHeapFileDataRecord = (IPageRecordable) heapElementManager
+ .readHeapFileDataRecord(position);
+ readHeapFileDataRecord.setParentPage(parentPage, index);
+ return readHeapFileDataRecord;
+ }
+
+ /**
+ *
+ * @param dataBlockPosition
+ * @return data of data block at position
+ * @throws HeapException
+ */
+ public byte[] getData(final long dataBlockPosition) throws HeapException {
+ final IDataBlock datablock = getDataBlock(dataBlockPosition);
+ return datablock.getData();
+ }
+
+ /**
+ *
+ * @param dataBlockPosition
+ * @return data block at position
+ * @throws HeapException
+ */
+ public IDataBlock getDataBlock(final long dataBlockPosition)
+ throws HeapException {
+ DataBlockPage dataBlockPage = (DataBlockPage) heapElementManager
+ .readHeapFileDataRecord(dataBlockPosition
+ & PageConstant.START_PAGE_POSITION_MASK);
+ final IDataBlock datablock = dataBlockPage
+ .getDataBlock(dataBlockPosition);
+ return datablock;
+ }
+
+ public void newRootLeafPage(
+ final DataRecordIdentifier dataRecordIdentifier,
+ final IDataBlock dataBlock) throws HeapException {
+ final LeafPage leafPage = new LeafPage(1);
+ appendPageRecordable(leafPage);
+ leafPage.setDataBlock(0, dataBlock);
+ leafPage.setNext(-1L);
+ leafPage.updateByteSize();
+ header.setRootPagePosition(leafPage.getPositionInFile());
+ }
+
+ public void newRootNonTerminalPage(final LeafPage leftLeafPage,
+ final LeafPage rightLeafPage) throws HeapException {
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
+ nonTerminalPage.setEntry(0, leftLeafPage.getPositionInFile(),
+ leftLeafPage.lastKey());
+ nonTerminalPage.setEntry(1, rightLeafPage.getPositionInFile(), null);
+ appendPageRecordable(nonTerminalPage);
+ nonTerminalPage.updateByteSize();
+ header.setRootPagePosition(nonTerminalPage.getPositionInFile());
+ }
+
+ public void newRootNonTerminalPage(
+ final NonTerminalPage leftNonTerminalPage,
+ final DataRecordIdentifier middleKey,
+ final NonTerminalPage rightNonTerminalPage) throws HeapException {
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
+ nonTerminalPage.setEntry(0, leftNonTerminalPage.getPositionInFile(),
+ middleKey);
+ nonTerminalPage.setEntry(1, rightNonTerminalPage.getPositionInFile(),
+ null);
+ appendPageRecordable(nonTerminalPage);
+ nonTerminalPage.updateByteSize();
+ header.setRootPagePosition(nonTerminalPage.getPositionInFile());
+ }
+
+ public IDataBlock createDataBlock(final byte[] data) throws HeapException {
+ final byte bits = bitsForLength(data.length);
+ final long freeDataBlockPosition = header
+ .getFreeDataBlockPosition(bits);
+ final IDataBlock dataBlock;
+ if (freeDataBlockPosition == -1L) {
+ DataBlockPage dataBlockPage = new DataBlockPage(bits);
+ appendPageRecordable(dataBlockPage);
+ dataBlockPage.setAllFree();
+ dataBlock = dataBlockPage.getDataBlocks()[0];
+ } else {
+ dataBlock = getDataBlock(freeDataBlockPosition);
+ }
+ final long nextFreeDataBlockPosition = dataBlock
+ .getNextFreeDataBlockPosition();
+ header.setFreeDataBlockPosition(bits, nextFreeDataBlockPosition);
+ dataBlock.setData(data);
+ return dataBlock;
+ }
+
+ public void remove(final IDataBlock dataBlock) throws HeapException {
+ final byte bits = dataBlock.getBits();
+ final long freeDataBlockPosition = header
+ .getFreeDataBlockPosition(bits);
+ dataBlock.setNextFreeDataBlockPosition(freeDataBlockPosition);
+ final long position = dataBlock.getPosition();
+ header.setFreeDataBlockPosition(bits, position);
+ }
+
+ private byte bitsForLength(final int length) throws HeapException {
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits <= PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ if (length < (1 << bits)) {
+ return bits;
+ }
+ }
+ throw new HeapException("length " + length + " to big for "
+ + PageConstant.MAX_DATA_BLOCK_BITS + " bits storage");
+ }
+
+ public void appendPageRecordable(IPageRecordable pageRecordable)
+ throws HeapException {
+ long pageNumber = header.getFileSizeAsNumberOfPage() + 1;
+ header.setFileSizeAsNumberOfPage(pageNumber);
+ final IPageRecord pageRecord = new PageRecord(fileForStorable,
+ pageRecordable, pageNumber);
+ pageRecordable.setPageRecord(pageRecord);
+ heapElementManager.appendHeapFileRecord(pageRecord);
+ }
}
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-24 04:44:11 UTC (rev 3029)
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governin...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-24 04:44:18
|
Revision: 3029
http://joafip.svn.sourceforge.net/joafip/?rev=3029&view=rev
Author: luc_peuvrier
Date: 2012-04-24 04:44:11 +0000 (Tue, 24 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. LeafPage tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-testsuite/pom.xml
trunk/joafip-testsuite/src/main/java/net/sf/joafip/PersistanceTestsNoLongTests.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/
trunk/joafip-btreeplus/src/test/java/net/sf/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-23 01:47:21
|
Revision: 3028
http://joafip.svn.sourceforge.net/joafip/?rev=3028&view=rev
Author: luc_peuvrier
Date: 2012-04-23 01:47:15 +0000 (Mon, 23 Apr 2012)
Log Message:
-----------
optimization
Modified Paths:
--------------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordIdentifier.java
Removed Paths:
-------------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/NullDataRecordKey.java
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordIdentifier.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordIdentifier.java 2012-04-22 06:55:31 UTC (rev 3027)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordIdentifier.java 2012-04-23 01:47:15 UTC (rev 3028)
@@ -54,7 +54,7 @@
public DataRecordIdentifier() {
super();
this.value = 0;
- this.dataRecordKey = NullDataRecordKey.getInstance();
+ this.dataRecordKey = null;
}
/**
@@ -67,7 +67,7 @@
public DataRecordIdentifier(final int value) {
super();
this.value = value;
- this.dataRecordKey = NullDataRecordKey.getInstance();
+ this.dataRecordKey = null;
}
/**
@@ -79,7 +79,7 @@
public DataRecordIdentifier(final long long1) {
super();
this.value = long1;
- this.dataRecordKey = NullDataRecordKey.getInstance();
+ this.dataRecordKey = null;
}
/**
@@ -91,7 +91,7 @@
public DataRecordIdentifier(final DataRecordIdentifier dataRecordIdentifier) {
super();
this.value = dataRecordIdentifier.value + 1;
- this.dataRecordKey = NullDataRecordKey.getInstance();
+ this.dataRecordKey = null;
}
// public long getValue() {
@@ -104,20 +104,16 @@
this.dataRecordKey = dataRecordKey;
}
- public IDataRecordKey getDataRecordKey() {
- return dataRecordKey;
- }
-
public int getKeyDataSize() {
- return dataRecordKey.getKeyDataSize();
+ return value == -1 ? dataRecordKey.getKeyDataSize() : 0;
}
public byte[] getKeyData() {
- return dataRecordKey.getKeyData();
+ return value == -1 ? dataRecordKey.getKeyData() : null;
}
public Object getKey() throws HeapException {
- return dataRecordKey.getKey();
+ return value == -1 ? dataRecordKey.getKey() : null;
}
public int getIndex() {
@@ -135,20 +131,23 @@
compareTo = -1;
} else if (value > otherLong1) {
compareTo = 1;
- } else {
+ } else if (value == -1) {
try {
compareTo = dataRecordKey
.compareTo(dataRecordIdentifier.dataRecordKey);
} catch (HeapException exception) {
throw new HeapRuntimeException(exception);
}
+ } else {
+ compareTo = 0;
}
return compareTo;
}
@Override
public int hashCode() {
- return (int) (value ^ (value >>> 32)) + dataRecordKey.getKeyHashcode();
+ return (int) (value ^ (value >>> 32))
+ + (value == -1 ? dataRecordKey.getKeyHashcode() : 0);
}
@Override
@@ -164,7 +163,8 @@
final DataRecordIdentifier other = (DataRecordIdentifier) obj;
try {
return value == other.value
- && dataRecordKey.compareTo(other.dataRecordKey) == 0;
+ && (value != -1 || dataRecordKey
+ .compareTo(other.dataRecordKey) == 0);
} catch (HeapException exception) {
throw new HeapRuntimeException(exception);
}
Deleted: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/NullDataRecordKey.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/NullDataRecordKey.java 2012-04-22 06:55:31 UTC (rev 3027)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/NullDataRecordKey.java 2012-04-23 01:47:15 UTC (rev 3028)
@@ -1,82 +0,0 @@
-/*
- * Copyright 2012 Luc Peuvrier
- *
- * This file is a part of JOAFIP.
- *
- * JOAFIP is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * JOAFIP is distributed in the hope that it will be useful, but
- * unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.kvstore.record.entity;
-
-import java.io.Serializable;
-
-import net.sf.joafip.NotStorableClass;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public final class NullDataRecordKey implements IDataRecordKey, Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = -6437312314493430699L;
-
- private final static NullDataRecordKey INSTANCE = new NullDataRecordKey();
-
- public static NullDataRecordKey getInstance() {
- return INSTANCE;
- }
-
- private NullDataRecordKey() {
- super();
- }
-
- @Override
- public int getKeyHashcode() {
- return 0;
- }
-
- @Override
- public int compareTo(final IDataRecordKey dataRecordKey) {
- return 0;
- }
-
- @Override
- public int getKeyDataSize() {
- return 0;
- }
-
- @Override
- public byte[] getKeyData() { // NOPMD
- return null;
- }
-
- @Override
- public Object getKey() {
- // no implementation
- return null;
- }
-
- // @Override
- // public void setKey(final Object key) {
- // // no implementation
- // }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-23 01:47:21
|
Revision: 3028
http://joafip.svn.sourceforge.net/joafip/?rev=3028&view=rev
Author: luc_peuvrier
Date: 2012-04-23 01:47:15 +0000 (Mon, 23 Apr 2012)
Log Message:
-----------
optimization
Modified Paths:
--------------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordIdentifier.java
Removed Paths:
-------------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/NullDataRecordKey.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-22 06:55:37
|
Revision: 3027
http://joafip.svn.sourceforge.net/joafip/?rev=3027&view=rev
Author: luc_peuvrier
Date: 2012-04-22 06:55:31 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
WIP BtreeePlusDataManager data record identifier management added
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-22 06:42:59 UTC (rev 3026)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-22 06:55:31 UTC (rev 3027)
@@ -44,6 +44,8 @@
private long[] freeDataBlock;
+ private long nextDataRecordIdentifier;
+
public HeaderPage(final IFileForStorable fileForStorable) {
super(fileForStorable, 0L);
}
@@ -129,6 +131,7 @@
writeLong(fileSizeAsNumberOfPage);
writeLong(pageNumberOfFirstFreePage);
writeLong(pageNumberOfRootPage);
+ writeLong(nextDataRecordIdentifier);
initializeFreeDataBlock();
for (int index = 0; index < PageConstant.NUMBER_OF_BLOCK_TYPE; index++) {
writeLong(freeDataBlock[index]);
@@ -147,6 +150,7 @@
fileSizeAsNumberOfPage = readLong();
pageNumberOfFirstFreePage = readLong();
pageNumberOfRootPage = readLong();
+ nextDataRecordIdentifier = readLong();
initializeFreeDataBlock();
for (int index = 0; index < PageConstant.NUMBER_OF_BLOCK_TYPE; index++) {
freeDataBlock[index] = readLong();
@@ -175,4 +179,21 @@
public PageRecord getPageRecord() throws HeapException {
throw new HeapException("unsupported");
}
+
+ public long getNextFreeDataRecordIdentifier() {
+ return nextDataRecordIdentifier;
+ }
+
+ public void setNextFreeDataRecordIdentifier(final long value)
+ throws HeapException {
+ this.nextDataRecordIdentifier = value;
+ setValueIsChangedValueToSave();
+ }
+
+ public long getNewDataRecordIdentifier() throws HeapException {
+ final long value = nextDataRecordIdentifier;
+ nextDataRecordIdentifier++;
+ setValueIsChangedValueToSave();
+ return value;
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-22 06:55:31 UTC (rev 3027)
@@ -136,22 +136,22 @@
@Override
protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
throws HeapException {
- // TODO Auto-generated method stub
- return null;
+ return new DataRecordIdentifier(
+ btreePlusElementMgr.getNextFreeDataRecordIdentifier());
}
@Override
protected void setNextFreeDataRecordIdentifierImpl(
DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- // TODO Auto-generated method stub
-
+ btreePlusElementMgr
+ .setNextFreeDataRecordIdentifier(dataRecordIdentifier.value);
}
@Override
protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
throws HeapException {
- // TODO Auto-generated method stub
- return null;
+ return new DataRecordIdentifier(
+ btreePlusElementMgr.getNewDataRecordIdentifier());
}
@Override
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 06:42:59 UTC (rev 3026)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 06:55:31 UTC (rev 3027)
@@ -152,4 +152,17 @@
public long getLastRecordPositionInFile() throws HeapException {
throw new UnsupportedOperationException("not implemented");
}
+
+ public long getNextFreeDataRecordIdentifier() {
+ return header.getNextFreeDataRecordIdentifier();
+ }
+
+ public void setNextFreeDataRecordIdentifier(final long value)
+ throws HeapException {
+ header.setNextFreeDataRecordIdentifier(value);
+ }
+
+ public long getNewDataRecordIdentifier() throws HeapException {
+ return header.getNewDataRecordIdentifier();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-22 06:55:37
|
Revision: 3027
http://joafip.svn.sourceforge.net/joafip/?rev=3027&view=rev
Author: luc_peuvrier
Date: 2012-04-22 06:55:31 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
WIP BtreeePlusDataManager data record identifier management added
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-22 06:43:06
|
Revision: 3026
http://joafip.svn.sourceforge.net/joafip/?rev=3026&view=rev
Author: luc_peuvrier
Date: 2012-04-22 06:42:59 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
WIP BtreeePlusDataManager created
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java
trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java
trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -1010,15 +1010,6 @@
}
@Override
- public String getChangeFileName() throws FilePersistenceException {
- try {
- return store.getChangeFileName();
- } catch (final StoreException exception) {
- throw new FilePersistenceException(exception);
- }
- }
-
- @Override
@Deprecated
public Object copy(final Object sourceObject)
throws FilePersistenceException {
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -906,13 +906,6 @@
String getStorageFileName() throws FilePersistenceException;
/**
- *
- * @return file name for change logging
- * @throws FilePersistenceException
- */
- String getChangeFileName() throws FilePersistenceException;
-
- /**
* set save event listener
*
* @param saveEventListener
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -229,13 +229,4 @@
throw new StoreException(exception);
}
}
-
- @Override
- public String getChangeFileName() throws StoreException {
- try {
- return dataManager.getChangeFileName();
- } catch (HeapException exception) {
- throw new StoreException(exception);
- }
- }
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -573,13 +573,6 @@
*/
String getStorageFileName() throws StoreException;
- /**
- *
- * @return file name for change logging
- * @throws StoreException
- */
- String getChangeFileName() throws StoreException;
-
StoreSynchro getStoreSynchro();
HelperBinaryConversion getHelperBinaryConversion();
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -243,14 +243,15 @@
}
boolean localChangeLogEnabled;
if (changeLogEnabled) {
- try {
- final String changeFileName = dataManager.getChangeFileName();
- objectIOManager.openChangeLog(changeFileName);
- localChangeLogEnabled = true;
- } catch (final Exception exception) {
- LOGGER.warn("change log disabled", exception);
- localChangeLogEnabled = false;
- }
+ // FIXMELUC ____change log no more usable
+ // try {
+ // final String changeFileName = dataManager.getChangeFileName();
+ // objectIOManager.openChangeLog(changeFileName);
+ // localChangeLogEnabled = true;
+ // } catch (final Exception exception) {
+ // LOGGER.warn("change log disabled", exception);
+ localChangeLogEnabled = false;
+ // }
} else {
localChangeLogEnabled = false;
}
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -332,10 +332,6 @@
return store.getCandidate();
}
- public String getChangeFileName() throws StoreException {
- return store.getChangeFileName();
- }
-
public int getClassIdentifier(final Class<?> clazz) throws StoreException,
StoreClassNotFoundException {
return store.getClassIdentifier(clazz);
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -90,7 +90,7 @@
bob1.setBob3(bob3);
session.close(EnumFilePersistenceCloseAction.SAVE);
- changeFileName = filePersistence.getChangeFileName();
+ // changeFileName = filePersistence.getChangeFileName();
storageFileName = filePersistence.getStorageFileName();
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.service;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Set;
+
+import net.sf.joafip.Fortest;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.HeapElementManagerFactory;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class BtreePlusDataManager extends AbstractHeapDataManager {
+
+ private final BtreePlusElementMgr btreePlusElementMgr;
+
+ public BtreePlusDataManager(final HeapFileSetup setup) throws HeapException {
+ super();
+ final IHeapElementManager heapElementManager = HeapElementManagerFactory
+ .create(setup);
+ btreePlusElementMgr = new BtreePlusElementMgr(heapElementManager);
+ }
+
+ @Override
+ public boolean isDataLost() {
+ return btreePlusElementMgr.isDataLost();
+ }
+
+ @Override
+ public String backup(long identifier, int maxBackup) throws HeapException {
+ return btreePlusElementMgr.backup(identifier, maxBackup);
+ }
+
+ @Override
+ public String getStorageFileName() throws HeapException {
+ final IFileForStorable fileForStorable = btreePlusElementMgr
+ .getFileForStorable();
+ final File file = fileForStorable.getFile();
+ return file.getAbsolutePath();
+ }
+
+ @Override
+ public void setDataRecordKeyComparator(
+ IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ btreePlusElementMgr.setDataRecordKeyComparator(dataRecordKeyComparator);
+ }
+
+ @Override
+ protected void removeFiles() throws HeapException {
+ btreePlusElementMgr.removeFiles();
+ }
+
+ @Override
+ protected void startServiceImpl(boolean removeFiles) throws HeapException {
+ if (removeFiles) {
+ btreePlusElementMgr.removeFiles();
+ }
+ btreePlusElementMgr.startService();
+ btreePlusElementMgr.openTransaction();
+ }
+
+ @Override
+ protected void stopServiceImpl() throws HeapException {
+ if (btreePlusElementMgr.isTransactionOpened()) {
+ btreePlusElementMgr.closeTransactionDiscardChange();
+ }
+ btreePlusElementMgr.stopService();
+ }
+
+ @Override
+ protected void clearImpl() throws HeapException {
+ btreePlusElementMgr.clear();
+ }
+
+ @Override
+ protected void flushImp() throws HeapException {
+ btreePlusElementMgr.closeTransaction();
+ btreePlusElementMgr.openTransaction();
+ }
+
+ @Override
+ protected void clearStandbyModificationImpl() throws HeapException {
+ btreePlusElementMgr.closeTransactionDiscardChange();
+ btreePlusElementMgr.openTransaction();
+ }
+
+ @Override
+ protected void closeHeapManagerAfterException() {
+ try {
+ if (btreePlusElementMgr.isTransactionOpened()) {
+ btreePlusElementMgr.closeTransactionDiscardChange();
+ }
+ } catch (Exception exception) {
+ logger.warn("closing after exception", exception);
+ }
+
+ try {
+ btreePlusElementMgr.stopService();
+ } catch (Exception exception) {
+ logger.warn("closing after exception", exception);
+ }
+ }
+
+ @Override
+ protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
+ throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected void setNextFreeDataRecordIdentifierImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
+ throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected boolean deleteDataRecordImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ protected byte[] readDataRecordImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected boolean writeDataRecordImpl(
+ DataRecordIdentifier dataRecordIdentifier, byte[] data)
+ throws HeapException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ protected boolean hasDataRecordImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ protected DataRecordIdentifier removeFirstDataRecordImpl()
+ throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected int getNumberOfDataRecordImpl() throws HeapException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ protected int getNumberOfFreeRecordImpl() throws HeapException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ protected Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
+ throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected long heapSizeImpl() throws HeapException {
+ return btreePlusElementMgr.heapSize();
+ }
+
+ @Override
+ protected long freeSizeImpl() throws HeapException {
+ return btreePlusElementMgr.freeSize();
+ }
+
+ @Override
+ protected long usedSizeImpl() throws HeapException {
+ return btreePlusElementMgr.usedSize();
+ }
+
+ @Fortest
+ @Override
+ public long getRecordPositionInfile(final DataRecordIdentifier identifier)
+ throws HeapException {
+ return btreePlusElementMgr.getRecordPositionInfile(identifier);
+ }
+
+ @Fortest
+ @Override
+ public long getLastRecordPositionInFile() throws HeapException {
+ return btreePlusElementMgr.getLastRecordPositionInFile();
+ }
+}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -23,15 +23,19 @@
*/
package net.sf.joafip.btreeplus.service;
+import net.sf.joafip.Fortest;
import net.sf.joafip.btreeplus.entity.HeaderPage;
import net.sf.joafip.btreeplus.entity.PageConstant;
import net.sf.joafip.btreeplus.entity.PageRecord;
import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IFileForStorable;
+import net.sf.joafip.logger.JoafipLogger;
/**
*
@@ -40,6 +44,9 @@
*/
public class BtreePlusElementMgr implements IHeapRecordFactory {
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(BtreePlusElementMgr.class);
+
private final IHeapElementManager heapElementManager;
private final HeaderPage header;
@@ -54,8 +61,20 @@
heapElementManager.setHeapRecordFactory(this);
heapElementManager.setHeapHeader(header);
fileForStorable = heapElementManager.getFileForStorable();
+ if (fileForStorable.isUseCache()
+ && fileForStorable.getCachePageSize() != PageConstant.PAGE_SIZE) {
+ LOGGER.warn("btree+ page size is " + PageConstant.PAGE_SIZE
+ + " and file cache page size is "
+ + fileForStorable.getCachePageSize());
+ }
}
+ public void setDataRecordKeyComparator(
+ final IDataRecordKeyManager dataRecordKeyComparator)
+ throws HeapException {
+ heapElementManager.setDataRecordKeyManager(dataRecordKeyComparator);
+ }
+
public void startService() throws HeapException {
heapElementManager.startService();
}
@@ -72,6 +91,10 @@
heapElementManager.closeTransaction();
}
+ public boolean isTransactionOpened() {
+ return heapElementManager.isTransactionOpened();
+ }
+
public void closeTransactionDiscardChange() throws HeapException {
heapElementManager.closeTransactionDiscardChange();
}
@@ -92,4 +115,41 @@
return new PageRecord(fileForStorable,
(int) (positionInFile >> PageConstant.PAGE_BITS));
}
+
+ public boolean isDataLost() {
+ return heapElementManager.isDataLost();
+ }
+
+ public IFileForStorable getFileForStorable() {
+ return fileForStorable;
+ }
+
+ public long heapSize() throws HeapException {
+ return header.getFileSizeAsNumberOfPage() * PageConstant.PAGE_SIZE;
+ }
+
+ public long freeSize() throws HeapException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long usedSize() throws HeapException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String backup(final long identifier, final int maxBackup)
+ throws HeapException {
+ return heapElementManager.backup(identifier, maxBackup);
+ }
+
+ @Fortest
+ public long getRecordPositionInfile(final DataRecordIdentifier identifier) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Fortest
+ public long getLastRecordPositionInFile() throws HeapException {
+ throw new UnsupportedOperationException("not implemented");
+ }
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -17,16 +17,13 @@
package net.sf.joafip.heapfile.service;
import java.io.File;
-import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import java.util.TreeSet;
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
import net.sf.joafip.heapfile.record.entity.HeapFreeNode;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
@@ -102,7 +99,7 @@
private static final long MAX_INT = (long) Integer.MAX_VALUE;
/** the heap element manager, data record are accessible by position in file */
- protected IHeapElementManager heapElementManager;
+ protected final IHeapElementManager heapElementManager;
/** free node tree to manage free area in heap file */
private final RedBlackTree<Integer> freeNodeTree;
@@ -110,9 +107,6 @@
/** to map data record identifier to file position */
private final RedBlackTree<DataRecordIdentifier> idNodeTree;
- /** file name for change logging */
- private String changeFileName;
-
// /** file name for backup logging */
// private String backupFileName;
@@ -1049,76 +1043,12 @@
return heapHeader.getUsedSize();
}
- @NotStorableClass
- private class BackupFileFilter implements FilenameFilter {
-
- final private String nameBody;
-
- public BackupFileFilter(final String nameBody) {
- super();
- this.nameBody = nameBody;
- }
-
- @Override
- public boolean accept(final File dir, final String name) {
- return !nameBody.equals(name) && name.startsWith(nameBody);
- }
-
- }
-
@Override
public String backup(final long identifier, final int maxBackup)
throws HeapException {
- /*
- * no more than maxBackup file(s)
- */
- final IFileForStorable fileForStorable = heapElementManager
- .getFileForStorable();
- final File file = fileForStorable.getFile();
- final File parent = file.getParentFile();
- String fileNameForFilter = file.getName() + ".old";
- cleanFile(maxBackup, parent, fileNameForFilter);
- fileNameForFilter = file.getName() + ".change";
- cleanFile(maxBackup, parent, fileNameForFilter);
- /*
- * do the backup
- */
- String format = file.getAbsolutePath() + ".old.%020d";
- final Object[] args = new Object[] { identifier };
- String backupFileName = String.format(format, args);
- try {
- fileForStorable.copy(backupFileName);
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- /*
- * create file name for change
- */
- format = file.getAbsolutePath() + ".change.%020d";
- changeFileName = String.format(format, args);
- return backupFileName;
+ return heapElementManager.backup(identifier, maxBackup);
}
- private void cleanFile(final int maxBackup, final File parent,
- final String fileNameForFilter) throws HeapException {
- final FilenameFilter filter = new BackupFileFilter(fileNameForFilter);
- final File[] files = parent.listFiles(filter);
- if (files.length >= maxBackup) {
- final Set<File> set = new TreeSet<File>();
- for (File fileListed : files) {
- set.add(fileListed);
- }
- final Iterator<File> iterator = set.iterator();
- for (int count = files.length; iterator.hasNext()
- && count >= maxBackup; count--) {
- final File toDelete = iterator.next();
- if (!toDelete.delete()) {
- throw new HeapException("failed delete " + toDelete);
- }
- }
- }
- }
-
@Override
public String getStorageFileName() throws HeapException {
final IFileForStorable fileForStorable = heapElementManager
@@ -1127,11 +1057,6 @@
return file.getAbsolutePath();
}
- @Override
- public String getChangeFileName() {
- return changeFileName;
- }
-
@NotStorableClass
private class DataRecordIterator implements Iterator<DataRecordIdentifier> {
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -352,4 +352,9 @@
public IDataRecordKeyManager getDataRecordKeyManager() {
throw new UnsupportedOperationException("not implemented");
}
+
+ @Override
+ public String backup(long identifier, int maxBackup) throws HeapException {
+ throw new UnsupportedOperationException("not implemented");
+ }
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -428,11 +428,6 @@
throw new HeapException("not implemented");
}
- @Override
- public String getChangeFileName() throws HeapException {
- return null;
- }
-
private int read(final long position, final int offset, final byte[] data,
final boolean addToCache) throws FileIOException {
DataBlock dataBlock = cacheMap.get(position);
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -336,12 +336,6 @@
}
@Override
- public String getChangeFileName() throws HeapException {
- // no implementation
- return null;
- }
-
- @Override
public Set<DataRecordIdentifier> getDataRecordIdentifierSet()
throws HeapException {
// no implementation
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -93,4 +93,14 @@
public void copy(String fileName) throws FileIOException {
delegate.copy(fileName);
}
+
+ @Override
+ public boolean isUseCache() {
+ return delegate.isUseCache();
+ }
+
+ @Override
+ public int getCachePageSize() {
+ return delegate.getCachePageSize();
+ }
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -320,11 +320,6 @@
}
@Override
- public String getChangeFileName() {
- return heapFileDataManager.getChangeFileName();
- }
-
- @Override
public Iterator<DataRecordIdentifier> dataRecordIterator()
throws HeapException {
return heapFileDataManager.dataRecordIterator();
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -281,11 +281,6 @@
}
@Override
- public String getChangeFileName() throws HeapException {
- throw new HeapException(UNSUPPORTED);
- }
-
- @Override
public Iterator<DataRecordIdentifier> dataRecordIteratorImpl() {
return getDataRecordIdentifierSetImpl().iterator();
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -452,11 +452,6 @@
}
@Override
- public String getChangeFileName() throws HeapException {
- throw new HeapException(UNSUPPORTED);
- }
-
- @Override
public Iterator<DataRecordIdentifier> dataRecordIteratorImpl() {
throw new UnsupportedOperationException();
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -17,7 +17,9 @@
package net.sf.joafip.kvstore.record.service;
import java.io.File;
+import java.io.FilenameFilter;
import java.io.PrintStream;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -1145,4 +1147,71 @@
public IFileStorable getHeapFileRecordInWriteCache(final long positionInFile) {
return heapRecordToWriteMap.get(positionInFile);
}
+
+ @Override
+ public String backup(long identifier, int maxBackup) throws HeapException {
+ /*
+ * no more than maxBackup file(s)
+ */
+ final File file = fileForStorable.getFile();
+ final File parent = file.getParentFile();
+ String fileNameForFilter = file.getName() + ".old";
+ cleanFile(maxBackup, parent, fileNameForFilter);
+ fileNameForFilter = file.getName() + ".change";
+ cleanFile(maxBackup, parent, fileNameForFilter);
+ /*
+ * do the backup
+ */
+ final String format = file.getAbsolutePath() + ".old.%020d";
+ final Object[] args = new Object[] { identifier };
+ String backupFileName = String.format(format, args);
+ try {
+ fileForStorable.copy(backupFileName);
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ /*
+ * create file name for change
+ */
+ // format = file.getAbsolutePath() + ".change.%020d";
+ // changeFileName = String.format(format, args);
+ return backupFileName;
+ }
+
+ private void cleanFile(final int maxBackup, final File parent,
+ final String fileNameForFilter) throws HeapException {
+ final FilenameFilter filter = new BackupFileFilter(fileNameForFilter);
+ final File[] files = parent.listFiles(filter);
+ if (files.length >= maxBackup) {
+ final Set<File> set = new TreeSet<File>();
+ for (File fileListed : files) {
+ set.add(fileListed);
+ }
+ final Iterator<File> iterator = set.iterator();
+ for (int count = files.length; iterator.hasNext()
+ && count >= maxBackup; count--) {
+ final File toDelete = iterator.next();
+ if (!toDelete.delete()) {
+ throw new HeapException("failed delete " + toDelete);
+ }
+ }
+ }
+ }
+
+ @NotStorableClass
+ private class BackupFileFilter implements FilenameFilter {
+
+ final private String nameBody;
+
+ public BackupFileFilter(final String nameBody) {
+ super();
+ this.nameBody = nameBody;
+ }
+
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return !nameBody.equals(name) && name.startsWith(nameBody);
+ }
+
+ }
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -188,4 +188,6 @@
void setDataRecordKeyManager(IDataRecordKeyManager dataRecordKeyComparator);
IDataRecordKeyManager getDataRecordKeyManager();
+
+ String backup(long identifier, int maxBackup) throws HeapException;
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -63,6 +63,10 @@
private Exception closerTrace = new Exception("closer trace");
+ private final boolean useCache;
+
+ private final int cachePageSize;
+
/**
* create a file to read from and write to {@link IFileStorable} object.<br>
* no cache used for file management<br>
@@ -93,6 +97,8 @@
*/
public FileForStorable(final File file, final int maxRetry,
final int retryMsDelay) throws HeapException {
+ this.useCache = false;
+ this.cachePageSize = 0;
this.file = file;
randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
retryMsDelay);
@@ -137,6 +143,8 @@
public FileForStorable(final File file, final int pageSize,
final int maxPage, final int maxRetry, final int retryMsDelay)
throws HeapException {
+ this.useCache = true;
+ this.cachePageSize = pageSize;
this.file = file;
final RandomAccessFileDirectNio randomAccessFileDirect =
/**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
@@ -165,6 +173,8 @@
public FileForStorable(final File file, final int pageSize,
final int maxPage, final boolean haveReadCache, final int maxRetry,
final int retryMsDelay) {
+ this.useCache = true;
+ this.cachePageSize = pageSize;
this.file = file;
final RandomAccessFileDirectNio randomAccessFileDirect =
/**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
@@ -173,6 +183,16 @@
}
@Override
+ public boolean isUseCache() {
+ return useCache;
+ }
+
+ @Override
+ public int getCachePageSize() {
+ return cachePageSize;
+ }
+
+ @Override
public void open() throws HeapException {
if (opened) {
throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -148,4 +148,8 @@
* @throws FileIOException
*/
void copy(String fileName) throws FileIOException;
+
+ boolean isUseCache();
+
+ int getCachePageSize();
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java 2012-04-22 06:42:59 UTC (rev 3026)
@@ -259,6 +259,9 @@
*/
void clearStandbyModification() throws HeapException;
+ void setDataRecordKeyComparator(
+ IDataRecordKeyManager dataRecordKeyComparator) throws HeapException;
+
/**
* get number of data record in heap file.<br>
* service must be started.
@@ -314,13 +317,6 @@
String getStorageFileName() throws HeapException;
/**
- *
- * @return file name for change logging
- * @throws HeapException
- */
- String getChangeFileName() throws HeapException;
-
- /**
* for test purpose<br>
*
* @return all data record identifier
@@ -344,7 +340,4 @@
@Fortest
long getLastRecordPositionInFile() throws HeapException;
-
- void setDataRecordKeyComparator(
- IDataRecordKeyManager dataRecordKeyComparator) throws HeapException;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-22 06:43:06
|
Revision: 3026
http://joafip.svn.sourceforge.net/joafip/?rev=3026&view=rev
Author: luc_peuvrier
Date: 2012-04-22 06:42:59 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
WIP BtreeePlusDataManager created
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java
trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java
trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-22 05:38:29
|
Revision: 3025
http://joafip.svn.sourceforge.net/joafip/?rev=3025&view=rev
Author: luc_peuvrier
Date: 2012-04-22 05:38:20 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
added HeapElementManagerFactory
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java
trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/ExportStoreQue.java
trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerCheckerFile.java
trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerHeapFile.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractDataManagerTestCase.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java
trunk/joafip-4test/pom.xml
trunk/joafip-4test/src/main/java/net/sf/joafip/bugtree/MainTreeDual.java
trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CheckSaved.java
trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java
trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AutoSaveHeapFileDataManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
trunk/joafip-pmap/src/main/java/net/sf/joafip/pmap/FileTreeMap.java
trunk/joafip-pmap/src/test/java/net/sf/joafip/pmap/TestFileTreeMap.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/HeapFileSetup.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManagerFactory.java
Removed Paths:
-------------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/HeapFileSetup.java
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -1010,15 +1010,6 @@
}
@Override
- public String getBackupFileName() throws FilePersistenceException {
- try {
- return store.getBackupFileName();
- } catch (final StoreException exception) {
- throw new FilePersistenceException(exception);
- }
- }
-
- @Override
public String getChangeFileName() throws FilePersistenceException {
try {
return store.getChangeFileName();
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -907,13 +907,6 @@
/**
*
- * @return file name for backup logging
- * @throws FilePersistenceException
- */
- String getBackupFileName() throws FilePersistenceException;
-
- /**
- *
* @return file name for change logging
* @throws FilePersistenceException
*/
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -19,8 +19,8 @@
import java.io.File;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.HeapFileDataManager;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IHeapDataManager;
@@ -138,6 +138,7 @@
}
}
+ @Override
public IHeapDataManager getDataManager() throws StoreException {
return dataManager;
}
@@ -220,6 +221,7 @@
}
}
+ @Override
public String getStorageFileName() throws StoreException {
try {
return dataManager.getStorageFileName();
@@ -228,14 +230,7 @@
}
}
- public String getBackupFileName() throws StoreException {
- try {
- return dataManager.getBackupFileName();
- } catch (HeapException exception) {
- throw new StoreException(exception);
- }
- }
-
+ @Override
public String getChangeFileName() throws StoreException {
try {
return dataManager.getChangeFileName();
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -575,13 +575,6 @@
/**
*
- * @return file name for backup logging
- * @throws StoreException
- */
- String getBackupFileName() throws StoreException;
-
- /**
- *
* @return file name for change logging
* @throws StoreException
*/
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/ExportStoreQue.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/ExportStoreQue.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/ExportStoreQue.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -25,8 +25,8 @@
import java.io.File;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.AutoSaveHeapFileDataManager;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IHeapDataManager;
Modified: trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerCheckerFile.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerCheckerFile.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerCheckerFile.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -22,8 +22,8 @@
import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.HeapFileCheckerDataManager;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
/**
*
Modified: trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerHeapFile.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerHeapFile.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerHeapFile.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -22,8 +22,8 @@
import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.HeapFileDataManager;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
/**
*
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractDataManagerTestCase.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractDataManagerTestCase.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractDataManagerTestCase.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -23,10 +23,10 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.HeapFileDataManager;
import net.sf.joafip.heapfile.service.HeapFileState;
import net.sf.joafip.kvstore.entity.EnumFileState;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IHeapDataManager;
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -327,10 +327,6 @@
return store.getAllReferenceLink();
}
- public String getBackupFileName() throws StoreException {
- return store.getBackupFileName();
- }
-
public List<DataRecordIdentifierRBTNode> getCandidate()
throws StoreException {
return store.getCandidate();
Modified: trunk/joafip-4test/pom.xml
===================================================================
--- trunk/joafip-4test/pom.xml 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/pom.xml 2012-04-22 05:38:20 UTC (rev 3025)
@@ -51,18 +51,6 @@
<dependency>
<groupId>net.sf.joafip</groupId>
- <artifactId>joafip-jdbm</artifactId>
- <version>4.0.0b8</version>
- </dependency>
-
- <dependency>
- <groupId>net.sf.joafip</groupId>
- <artifactId>joafip-babudb</artifactId>
- <version>4.0.0b8</version>
- </dependency>
-
- <dependency>
- <groupId>net.sf.joafip</groupId>
<artifactId>joafip-rbtree</artifactId>
<version>4.0.0b8</version>
</dependency>
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/bugtree/MainTreeDual.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/bugtree/MainTreeDual.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/bugtree/MainTreeDual.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -5,10 +5,10 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.BlockDataManager;
import net.sf.joafip.heapfile.service.DualWrapDataManager;
import net.sf.joafip.heapfile.service.HeapFileDataManager;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IHeapDataManager;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -26,7 +26,8 @@
public class MainTestLogger {
public static void main(final String[] args) {
- final JoafipLogger logger=JoafipLogger.getLogger(MainTestLogger.class);
+ final JoafipLogger logger = JoafipLogger
+ .getLogger(MainTestLogger.class);
logger.fatal("fatal error message");
}
}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -229,39 +229,42 @@
}
byItemIndex = 0;
}
-
- protected static void initializeDirectory(final String rootDir) throws FilePersistenceException {
+
+ protected static void initializeDirectory(final String rootDir)
+ throws FilePersistenceException {
initializeDirectory(new File(rootDir));
}
-
- protected static void initializeDirectory(final File rootDir) throws FilePersistenceException {
- if( rootDir.exists()) {
- if( rootDir.isDirectory()) {
+
+ protected static void initializeDirectory(final File rootDir)
+ throws FilePersistenceException {
+ if (rootDir.exists()) {
+ if (rootDir.isDirectory()) {
deleteDir(rootDir);
} else {
- if( !rootDir.delete() ) {
- throw new FilePersistenceException(FAILED_DELETE+rootDir);
+ if (!rootDir.delete()) {
+ throw new FilePersistenceException(FAILED_DELETE + rootDir);
}
}
}
- if( !rootDir.mkdirs()) {
- throw new FilePersistenceException("failed create "+rootDir);
+ if (!rootDir.mkdirs()) {
+ throw new FilePersistenceException("failed create " + rootDir);
}
}
-
- private static void deleteDir(final File dir) throws FilePersistenceException {
+
+ private static void deleteDir(final File dir)
+ throws FilePersistenceException {
final File[] files = dir.listFiles();
- for(File file:files) {
- if( file.isDirectory()) {
+ for (File file : files) {
+ if (file.isDirectory()) {
deleteDir(file);
} else {
- if( !file.delete() ) {
- throw new FilePersistenceException(FAILED_DELETE+file);
+ if (!file.delete()) {
+ throw new FilePersistenceException(FAILED_DELETE + file);
}
}
}
- if( !dir.delete() ) {
- throw new FilePersistenceException(FAILED_DELETE+dir);
+ if (!dir.delete()) {
+ throw new FilePersistenceException(FAILED_DELETE + dir);
}
}
}
Deleted: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -1,67 +0,0 @@
-/*
- * Copyright 2011 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.performance.items.service;//NOPMD
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.StorableAccess;
-import net.sf.joafip.babudb.service.BabudbDataManager;
-import net.sf.joafip.kvstore.service.IHeapDataManager;
-import net.sf.joafip.logger.JoafipLogger;
-import net.sf.joafip.service.FilePersistenceClassNotFoundException;
-import net.sf.joafip.service.FilePersistenceDataCorruptedException;
-import net.sf.joafip.service.FilePersistenceException;
-import net.sf.joafip.service.FilePersistenceInvalidClassException;
-import net.sf.joafip.service.FilePersistenceNotSerializableException;
-import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
-import net.sf.joafip.store.service.StoreClassNotFoundException;
-
-@SuppressWarnings("PMD")
-@NotStorableClass
-@StorableAccess
-public class InserterBabuDB extends AbstractInserter {
-
- private static final JoafipLogger LOGGER = JoafipLogger
- .getLogger(InserterBabuDB.class);
-
- public InserterBabuDB(final IHeapDataManager dataManager)
- throws FilePersistenceException,
- FilePersistenceInvalidClassException,
- FilePersistenceNotSerializableException,
- FilePersistenceClassNotFoundException,
- FilePersistenceDataCorruptedException, StoreClassNotFoundException,
- FilePersistenceTooBigForSerializationException {
- super(dataManager);
- }
-
- public static void main(final String[] args) {
- try {
- /* remove existing data */
- initializeDirectory(RUNTIME_DIR);
- final File dataDirectory = new File(RUNTIME_DIR);
- InserterBabuDB inserter;
- final BabudbDataManager babudbDataManager = new BabudbDataManager(
- (new File(dataDirectory, "banana.data")).getAbsolutePath());
- inserter = new InserterBabuDB(babudbDataManager);
- inserter.run(NUMBER_OF_ITEM);
- inserter.close();
- } catch (final Throwable throwable) {// NOPMD catch all
- LOGGER.fatal("error", throwable);
- }
- }
-}
Deleted: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -1,68 +0,0 @@
-/*
- * Copyright 2011 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.performance.items.service;//NOPMD
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.StorableAccess;
-import net.sf.joafip.jdbm.service.JdbmDataManager;
-import net.sf.joafip.kvstore.service.IHeapDataManager;
-import net.sf.joafip.logger.JoafipLogger;
-import net.sf.joafip.service.FilePersistenceClassNotFoundException;
-import net.sf.joafip.service.FilePersistenceDataCorruptedException;
-import net.sf.joafip.service.FilePersistenceException;
-import net.sf.joafip.service.FilePersistenceInvalidClassException;
-import net.sf.joafip.service.FilePersistenceNotSerializableException;
-import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
-import net.sf.joafip.store.service.StoreClassNotFoundException;
-
-@SuppressWarnings("PMD")
-@NotStorableClass
-@StorableAccess
-public class InserterJdbm extends AbstractInserter {
-
- private static final JoafipLogger LOGGER = JoafipLogger
- .getLogger(InserterJdbm.class);
-
- public InserterJdbm(final IHeapDataManager dataManager)
- throws FilePersistenceException,
- FilePersistenceInvalidClassException,
- FilePersistenceNotSerializableException,
- FilePersistenceClassNotFoundException,
- FilePersistenceDataCorruptedException, StoreClassNotFoundException,
- FilePersistenceTooBigForSerializationException {
- super(dataManager);
- }
-
- public static void main(final String[] args) {
- try {
- final File dataDirectory = new File(RUNTIME_DIR);
- /* remove existing data */
- initializeDirectory(RUNTIME_DIR);
- dataDirectory.mkdirs();
- InserterJdbm inserter;
- final JdbmDataManager jdbmDataManager = new JdbmDataManager(
- (new File(dataDirectory, "banana.data")).getAbsolutePath());
- inserter = new InserterJdbm(jdbmDataManager);
- inserter.run(NUMBER_OF_ITEM);
- inserter.close();
- } catch (final Throwable throwable) {// NOPMD catch all
- LOGGER.fatal("error", throwable);
- }
- }
-}
Deleted: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -1,63 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.performance.items.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.StorableAccess;
-import net.sf.joafip.jdbm.service.JdbmDataManager;
-import net.sf.joafip.kvstore.service.IHeapDataManager;
-import net.sf.joafip.logger.JoafipLogger;
-import net.sf.joafip.service.FilePersistenceClassNotFoundException;
-import net.sf.joafip.service.FilePersistenceDataCorruptedException;
-import net.sf.joafip.service.FilePersistenceException;
-import net.sf.joafip.service.FilePersistenceInvalidClassException;
-import net.sf.joafip.service.FilePersistenceNotSerializableException;
-import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
-
-@NotStorableClass
-@StorableAccess
-public class SearcherJdbm extends AbstractSearcher {
-
- private static final JoafipLogger LOGGER = JoafipLogger
- .getLogger(SearcherJdbm.class);
-
-
- public SearcherJdbm(final IHeapDataManager dataManager)
- throws FilePersistenceInvalidClassException,
- FilePersistenceNotSerializableException,
- FilePersistenceClassNotFoundException,
- FilePersistenceDataCorruptedException, FilePersistenceException,
- FilePersistenceTooBigForSerializationException {
- super(dataManager);
- }
-
-
- public static void main(final String[] args) {
- SearcherJdbm searcher;
- try {
- final File dataDirectory = new File(RUNTIME_DIR);
- final JdbmDataManager jdbmDataManager = new JdbmDataManager(
- (new File(dataDirectory, "banana.data")).getAbsolutePath());
- searcher = new SearcherJdbm(jdbmDataManager);
- searcher.run();
- } catch (final Throwable throwable) {// NOPMD catch all
- LOGGER.fatal("error", throwable);
- }
- }
-}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CheckSaved.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CheckSaved.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CheckSaved.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -20,8 +20,8 @@
import java.util.Arrays;
import java.util.Map;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.service.HeapFileDataManager;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IHeapDataManager;
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -45,8 +45,6 @@
return INSTANCE;
}
- private String backupFileName;
-
private String changeFileName;
private String storageFileName;
@@ -92,8 +90,6 @@
bob1.setBob3(bob3);
session.close(EnumFilePersistenceCloseAction.SAVE);
- backupFileName = filePersistence.getBackupFileName();
-
changeFileName = filePersistence.getChangeFileName();
storageFileName = filePersistence.getStorageFileName();
@@ -105,10 +101,6 @@
return storageFileName;
}
- public String getBackupFileName() {
- return backupFileName;
- }
-
public String getChangeFileName() {
return changeFileName;
}
Modified: trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
===================================================================
--- trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -28,13 +28,14 @@
/**
*
* @author luc peuvrier
- *
+ *
*/
public class TestCreateLogger extends TestCase {
public void test() {
- final JoafipLogger logger=JoafipLogger.getLogger(TestCreateLogger.class);
+ final JoafipLogger logger = JoafipLogger
+ .getLogger(TestCreateLogger.class);
logger.fatal("fatal error message");
- assertTrue("logger must be set",logger.loggerIsSet());
+ assertTrue("logger must be set", logger.loggerIsSet());
}
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -24,26 +24,36 @@
package net.sf.joafip.btreeplus.service;
import net.sf.joafip.btreeplus.entity.HeaderPage;
+import net.sf.joafip.btreeplus.entity.PageConstant;
+import net.sf.joafip.btreeplus.entity.PageRecord;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.service.HeapElementManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
/**
*
* @author luc peuvrier
*
*/
-public class BtreePlusElementMgr {
+public class BtreePlusElementMgr implements IHeapRecordFactory {
private final IHeapElementManager heapElementManager;
private final HeaderPage header;
+ private final IFileForStorable fileForStorable;
+
public BtreePlusElementMgr(final IHeapElementManager heapElementManager)
throws HeapException {
super();
this.heapElementManager = heapElementManager;
header = new HeaderPage(heapElementManager.getFileForStorable());
+ heapElementManager.setHeapRecordFactory(this);
heapElementManager.setHeapHeader(header);
+ fileForStorable = heapElementManager.getFileForStorable();
}
public void startService() throws HeapException {
@@ -73,4 +83,13 @@
public void removeFiles() throws HeapException {
heapElementManager.removeFiles();
}
+
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ assert (positionInFile & PageConstant.PAGE_MASK) == 0;
+ return new PageRecord(fileForStorable,
+ (int) (positionInFile >> PageConstant.PAGE_BITS));
+ }
}
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/HeapFileSetup.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/HeapFileSetup.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/HeapFileSetup.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -1,286 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.entity;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- * heap file setup<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class HeapFileSetup {
-
- /** true if crash safe mode enabled */
- private final boolean crashSafeMode;
-
- /** the file for the heap */
- private final File dataFile;
-
- /** the backup file for the heap, set only if crash safe mode enabled */
- private File backupDataFile = null;
-
- /**
- * file used has flag for data file on stable state, set only if crash safe
- * mode enabled
- */
- private File stateOkFlagFile;
-
- /**
- * file used has flag for backup data file on stable state, set only if
- * crash safe mode enabled
- */
- private File stateBackupOkFlagFile;
-
- /**
- * file indicating backup and data file stable state, set only if crash safe
- * mode enabled
- */
- private File globalStateFlagFile;
-
- private final File openFileTraceFile;
-
- /** true if use cache */
- private final boolean useCacheMode;
-
- /**
- * page size ( number of byte ), must be greater or equals to 1024, set only
- * if use cache enabled
- */
- private int pageSize = -1;
-
- /**
- * maximum number of page for read cache, set only if use cache enabled
- */
- private int maxPage = -1;
-
- private final boolean deleteRenaming;
-
- private final boolean clearResizeFile;
-
- private final int maxFileOperationRetry;
-
- private final int fileOperationRetryMsDelay;
-
- /**
- *
- * @param dataFile
- * the file for the heap
- * @param crashSafeMode
- * true if crash safe mode enabled
- * @param useCacheMode
- * true if use cache
- * @param deleteRenaming
- * @param clearResizeFile
- * @param maxFileOperationRetry
- * @param fileOperationRetryMsDelay
- * @throws HeapException
- */
- public HeapFileSetup(final File dataFile, final boolean crashSafeMode,
- final boolean useCacheMode, final boolean deleteRenaming,
- final boolean clearResizeFile, final int maxFileOperationRetry,
- final int fileOperationRetryMsDelay, final File openFileTraceFile)
- throws HeapException {
- super();
- if (dataFile == null) {
- throw new HeapException("file must be defined");
- }
- this.dataFile = dataFile;
- this.crashSafeMode = crashSafeMode;
- this.useCacheMode = useCacheMode;
- this.deleteRenaming = deleteRenaming;
- this.clearResizeFile = clearResizeFile;
- this.maxFileOperationRetry = maxFileOperationRetry;
- this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- this.openFileTraceFile = openFileTraceFile;
- }
-
- /**
- * setup of cache parameters<br>
- *
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024, set only if use cache enabled
- * @param maxPage
- * maximum number of page for read cache, set only if use cache
- * enabled
- * @throws HeapException
- * use cache mode not enabled
- */
- public void cacheSetup(final int pageSize, final int maxPage)
- throws HeapException {
- if (useCacheMode) {
- if (pageSize < 256) {
- throw new HeapException(
- "page size must be greater or equal 1024 bytes");
- }
- if (maxPage <= 0) {
- throw new HeapException(
- "max number of page must be greater than 0");
- }
- this.pageSize = pageSize;
- this.maxPage = maxPage;
- } else {
- throw new HeapException(
- "can not setup cache if use cache mode not enabled");
- }
- }
-
- /**
- * setup of crash safe mode parameters<br>
- *
- * @param backupDataFile
- * the backup file for the heap
- * @param stateOkFlagFile
- * file used has flag for data file on stable state
- * @param stateBackupOkFlagFile
- * file used has flag for backup data file on stable state
- * @param globalStateFlagFile
- * file indicating backup and data file stable state
- * @throws HeapException
- * crash safe mode not enable
- */
- public void crashSafeSetup(final File backupDataFile,
- final File stateOkFlagFile, final File stateBackupOkFlagFile,
- final File globalStateFlagFile) throws HeapException {
- if (crashSafeMode) {
- if (backupDataFile == null || stateOkFlagFile == null
- || stateBackupOkFlagFile == null
- || globalStateFlagFile == null) {
- throw new HeapException("files must be defined");
- }
- this.backupDataFile = backupDataFile;
- this.stateOkFlagFile = stateOkFlagFile;
- this.stateBackupOkFlagFile = stateBackupOkFlagFile;
- this.globalStateFlagFile = globalStateFlagFile;
- } else {
- throw new HeapException(
- "can not setup crash safe if crash safe mode not enabled");
- }
- }
-
- public File getBackupDataFile() throws HeapException {
- if (crashSafeMode) {
- if (backupDataFile == null) {
- throw new HeapException(
- "crash safe mode set but backup file not defined");
- }
- } else {
- throw new HeapException(
- "do not use backup file is crash safe mode not set");
- }
- return backupDataFile;
- }
-
- public boolean isCrashSafeMode() {
- return crashSafeMode;
- }
-
- public File getDataFile() {
- return dataFile;
- }
-
- public File getGlobalStateFlagFile() throws HeapException {
- if (crashSafeMode) {
- if (backupDataFile == null) {
- throw new HeapException(
- "crash safe mode set but global state file not defined");
- }
- } else {
- throw new HeapException(
- "do not use global state file is crash safe mode not set");
- }
- return globalStateFlagFile;
- }
-
- public int getMaxPage() throws HeapException {
- if (useCacheMode) {
- if (maxPage == -1) {
- throw new HeapException("maxPage not set");
- }
- } else {
- throw new HeapException("not cache used");
- }
- return maxPage;
- }
-
- public int getPageSize() throws HeapException {
- if (useCacheMode) {
- if (pageSize == -1) {
- throw new HeapException("pageSize not set");
- }
- } else {
- throw new HeapException("not cache used");
- }
- return pageSize;
- }
-
- public File getStateBackupOkFlagFile() throws HeapException {
- if (crashSafeMode) {
- if (backupDataFile == null) {
- throw new HeapException(
- "crash safe mode set but backup state file not defined");
- }
- } else {
- throw new HeapException(
- "do not use backup state file is crash safe mode not set");
- }
- return stateBackupOkFlagFile;
- }
-
- public File getStateOkFlagFile() throws HeapException {
- if (crashSafeMode) {
- if (backupDataFile == null) {
- throw new HeapException(
- "crash safe mode set but state ok for data file not defined");
- }
- } else {
- throw new HeapException(
- "do not use state ok for data file is crash safe mode not set");
- }
- return stateOkFlagFile;
- }
-
- public boolean isUseCacheMode() {
- return useCacheMode;
- }
-
- public boolean isDeleteRenaming() {
- return deleteRenaming;
- }
-
- public boolean isClearResizeFile() {
- return clearResizeFile;
- }
-
- public int getMaxFileOperationRetry() {
- return maxFileOperationRetry;
- }
-
- public int getFileOperationRetryMsDelay() {
- return fileOperationRetryMsDelay;
- }
-
- public File getOpenFileTraceFile() {
- return openFileTraceFile;
- }
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AutoSaveHeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AutoSaveHeapFileDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AutoSaveHeapFileDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -23,7 +23,7 @@
package net.sf.joafip.heapfile.service;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -27,23 +27,23 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
import net.sf.joafip.heapfile.record.entity.HeapFreeNode;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.heapfile.record.service.HeapFreeNodeManager;
import net.sf.joafip.heapfile.record.service.HeapIdNodeManager;
-import net.sf.joafip.kvstore.entity.EnumFileState;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.HeapElementManagerFactory;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
-import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.IRBTVisitor;
import net.sf.joafip.redblacktree.service.RBTException;
@@ -77,9 +77,6 @@
private static final String ONLY_FREE_RECORD_CAN_BE_IN_FREE_NODE_FREE =
/**/"only free record can be in free node free";
- private static final String RESTART_FROM_STABLE_BACKUP =
- /**/"restart from stable backup: ";
-
private static final String DELETE_FREE_NODE_FAILED =
/**/"delete free node failed";
@@ -104,24 +101,6 @@
/** integer max value in long */
private static final long MAX_INT = (long) Integer.MAX_VALUE;
- /** true if crash safe mode enabled */
- private final boolean crashSafeMode;
-
- /** to access data on file, used by heap element manager */
- private final FileForStorable fileForStorable;
-
- /** backup data file, used by heap element manager */
- private final FileForStorable fileForStorableBackup;
-
- /** flag file state stable for data file */
- private final File stateOkFlagFile;
-
- /** flag file state stable for backup data file */
- private final File stateBackupOkFlagFile;
-
- /** flag file indicating backup and data file stable state */
- private final File globalStateFlagFile;
-
/** the heap element manager, data record are accessible by position in file */
protected IHeapElementManager heapElementManager;
@@ -134,67 +113,13 @@
/** file name for change logging */
private String changeFileName;
- /** file name for backup logging */
- private String backupFileName;
+ // /** file name for backup logging */
+ // private String backupFileName;
public HeapFileDataManager(final HeapFileSetup setup,
final boolean manageNodeIndex) throws HeapException {
super();
- final boolean deleteRenaming = setup.isDeleteRenaming();
- final boolean clearResizeFile = setup.isClearResizeFile();
- final int maxFileOperationRetry = setup.getMaxFileOperationRetry();
- final int fileOperationRetryMsDelay = setup
- .getFileOperationRetryMsDelay();
- if (setup.isCrashSafeMode()) {
- crashSafeMode = true;
- if (setup.isUseCacheMode()) {
- fileForStorable = new FileForStorable(setup.getDataFile(),
- setup.getPageSize(), setup.getMaxPage(),
- maxFileOperationRetry, fileOperationRetryMsDelay);
- /* no read cache on backup copy, not used for read */
- fileForStorableBackup = new FileForStorable(
- setup.getBackupDataFile(), setup.getPageSize(),
- setup.getMaxPage(), false, maxFileOperationRetry,
- fileOperationRetryMsDelay);
- stateOkFlagFile = setup.getStateOkFlagFile();
- } else {
- fileForStorable = new FileForStorable(setup.getDataFile(),
- maxFileOperationRetry, fileOperationRetryMsDelay);
- fileForStorableBackup = new FileForStorable(
- setup.getBackupDataFile(), maxFileOperationRetry,
- fileOperationRetryMsDelay);
- stateOkFlagFile = setup.getStateOkFlagFile();
- }
- this.stateBackupOkFlagFile = setup.getStateBackupOkFlagFile();
- this.globalStateFlagFile = setup.getGlobalStateFlagFile();
- } else {
- crashSafeMode = false;
- if (setup.isUseCacheMode()) {
- fileForStorable = new FileForStorable(setup.getDataFile(),
- setup.getPageSize(), setup.getMaxPage(),
- maxFileOperationRetry, fileOperationRetryMsDelay);
-
- } else {
- fileForStorable = new FileForStorable(setup.getDataFile(),
- maxFileOperationRetry, fileOperationRetryMsDelay);
- }
- fileForStorableBackup = null;// NOPMD no file defined
- stateOkFlagFile = null;// NOPMD no file defined
- stateBackupOkFlagFile = null;// NOPMD no file defined
- globalStateFlagFile = null;// NOPMD no file defined
- }
- final File openFileTraceFile = setup.getOpenFileTraceFile();
- if (crashSafeMode) {
- heapElementManager = new HeapElementManager(fileForStorable,
- stateOkFlagFile, fileForStorableBackup,
- stateBackupOkFlagFile, globalStateFlagFile, deleteRenaming,
- clearResizeFile, maxFileOperationRetry,
- fileOperationRetryMsDelay, openFileTraceFile);
- } else {
- heapElementManager = new HeapElementManager(fileForStorable,
- deleteRenaming, clearResizeFile, maxFileOperationRetry,
- fileOperationRetryMsDelay, openFileTraceFile);
- }
+ heapElementManager = HeapElementManagerFactory.create(setup);
heapElementManager.setHeapRecordFactory(this);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
final HeapFreeNodeManager heapFreeNodeManager = new HeapFreeNodeManager(
@@ -205,15 +130,7 @@
heapElementManager);
idNodeTree = new RedBlackTree<DataRecordIdentifier>(heapIdNodeManager,
manageNodeIndex, true);
- if (crashSafeMode && heapElementManager.wasBadFileStableState()) {
- logger.warn(RESTART_FROM_STABLE_BACKUP);
- /* validate the stable state */
- final boolean dataLost = heapElementManager.isDataLost();
- final EnumFileState fileState = dataLost ? EnumFileState.STATE_RESTORED_DATA_LOST
- : EnumFileState.STATE_RESTORED_NO_DATA_LOST;
- throw new HeapException(RESTART_FROM_STABLE_BACKUP
- + fileState.toString(), fileState);
- }
+
}
@Override
@@ -1150,11 +1067,13 @@
}
@Override
- public void backup(final long identifier, final int maxBackup)
+ public String backup(final long identifier, final int maxBackup)
throws HeapException {
/*
* no more than maxBackup file(s)
*/
+ final IFileForStorable fileForStorable = heapElementManager
+ .getFileForStorable();
final File file = fileForStorable.getFile();
final File parent = file.getParentFile();
String fileNameForFilter = file.getName() + ".old";
@@ -1166,7 +1085,7 @@
*/
String format = file.getAbsolutePath() + ".old.%020d";
final Object[] args = new Object[] { identifier };
- backupFileName = String.format(format, args);
+ String backupFileName = String.format(format, args);
try {
fileForStorable.copy(backupFileName);
} catch (FileIOException exception) {
@@ -1177,6 +1096,7 @@
*/
format = file.getAbsolutePath() + ".change.%020d";
changeFileName = String.format(format, args);
+ return backupFileName;
}
private void cleanFile(final int maxBackup, final File parent,
@@ -1201,6 +1121,8 @@
@Override
public String getStorageFileName() throws HeapException {
+ final IFileForStorable fileForStorable = heapElementManager
+ .getFileForStorable();
final File file = fileForStorable.getFile();
return file.getAbsolutePath();
}
@@ -1210,11 +1132,6 @@
return changeFileName;
}
- @Override
- public String getBackupFileName() {
- return backupFileName;
- }
-
@NotStorableClass
private class DataRecordIterator implements Iterator<DataRecordIdentifier> {
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -323,6 +323,11 @@
}
@Override
+ public boolean isCrashSafeMode() {
+ return false;
+ }
+
+ @Override
public int getNumberOfHeaprecordInMemory() {
throw new UnsupportedOperationException("not implemented");
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -23,7 +23,7 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IHeapDataManager;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -423,18 +423,12 @@
}
@Override
- public void backup(final long identifier, final int maxBackup)
+ public String backup(final long identifier, final int maxBackup)
throws HeapException {
throw new HeapException("not implemented");
}
@Override
- public String getBackupFileName() throws HeapException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
public String getChangeFileName() throws HeapException {
return null;
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -323,9 +323,10 @@
}
@Override
- public void backup(final long identifier, final int maxBackup)
+ public String backup(final long identifier, final int maxBackup)
throws HeapException {
// no implementation
+ return null;
}
@Override
@@ -335,12 +336,6 @@
}
@Override
- public String getBackupFileName() throws HeapException {
- // no implementation
- return null;
- }
-
- @Override
public String getChangeFileName() throws HeapException {
// no implementation
return null;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -2,7 +2,9 @@
import java.io.File;
+import net.sf.joafip.file.service.FileIOException;
import net.sf.joafip.kvstore.entity.ToBackupRecord;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IFileForStorable;
@@ -80,4 +82,15 @@
public void write(final ToBackupRecord toBackupRecord) throws HeapException {
delegate.write(toBackupRecord);
}
+
+ @Override
+ public void copy(final FileForStorable fileForStorable)
+ throws HeapException {
+ delegate.copy(fileForStorable);
+ }
+
+ @Override
+ public void copy(String fileName) throws FileIOException {
+ delegate.copy(fileName);
+ }
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -21,7 +21,7 @@
import java.util.Iterator;
import java.util.Set;
-import net.sf.joafip.heapfile.entity.HeapFileSetup;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.HeapException;
@@ -309,9 +309,9 @@
}
@Override
- public void backup(final long identifier, final int maxBackup)
+ public String backup(final long identifier, final int maxBackup)
throws HeapException {
- heapFileDataManager.backup(identifier, maxBackup);
+ return heapFileDataManager.backup(identifier, maxBackup);
}
@Override
@@ -325,11 +325,6 @@
}
@Override
- public String getBackupFileName() throws HeapException {
- return heapFileDataManager.getBackupFileName();
- }
-
- @Override
public Iterator<DataRecordIdentifier> dataRecordIterator()
throws HeapException {
return heapFileDataManager.dataRecordIterator();
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -270,7 +270,7 @@
}
@Override
- public void backup(final long identifier, final int maxBackup)
+ public String backup(final long identifier, final int maxBackup)
throws HeapException {
throw new HeapException(UNSUPPORTED);
}
@@ -286,11 +286,6 @@
}
@Override
- public String getBackupFileName() throws HeapException {
- throw new HeapException(UNSUPPORTED);
- }
-
- @Override
public Iterator<DataRecordIdentifier> dataRecordIteratorImpl() {
return getDataRecordIdentifierSetImpl().iterator();
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -441,7 +441,7 @@
}
@Override
- public void backup(final long identifier, final int maxBackup)
+ public String backup(final long identifier, final int maxBackup)
throws HeapException {
throw new HeapException(UNSUPPORTED);
}
@@ -457,11 +457,6 @@
}
@Override
- public String getBackupFileName() throws HeapException {
- throw new HeapException(UNSUPPORTED);
- }
-
- @Override
public Iterator<DataRecordIdentifier> dataRecordIteratorImpl() {
throw new UnsupportedOperationException();
}
Copied: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/HeapFileSetup.java (from rev 3024, trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/HeapFileSetup.java)
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/HeapFileSetup.java (rev 0)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/HeapFileSetup.java 2012-04-22 05:38:20 UTC (rev 3025)
@@ -0,0 +1,286 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.entity;
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ * heap file setup<br>
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class HeapFileSetup {
+
+ /** true if crash safe mode enabled */
+ private final boolean crashSafeMode;
+
+ /** the file for the heap */
+ private final File dataFile;
+
+ /** the backup file for the heap, set only if crash safe mode enabled */
+ private File backupDataFile = null;
+
+ /**
+ * file used has flag for data file on stable state, set only if crash safe
+ * mode enabled
+ */
+ private File stateOkFlagFile;
+
+ /**
+ * file used has flag for backup data file on stable state, set only if
+ * crash safe mode enabled
+ */
+ private File stateBackupOkFlagFile;
+
+ /**
+ * file indicating backup and data file stable state, set only if crash safe
+ * mode enabled
+ */
+ private File globalStateFlagFile;
+
+ private final File openFileTraceFile;
+
+ /** true if use cache */
+ private final boolean useCacheMode;
+
+ /**
+ * page size ( number of byte ), must be greater or equals to 1024, set only
+ * if use cache enabled
+ */
+ private int pageSize = -1;
+
+ /**
+ * maximum number of page for read cache, set only if use cache enabled
+ */
+ private int maxPage = -1;
+
+ private final boolean deleteRenaming;
+
+ private final boolean clearResizeFile;
+
+ private final int maxFileOperationRetry;
+
+ private final int fileOperationRetryMsDelay;
+
+ /**
+ *
+ * @param dataFile
+ * the file for the heap
+ * @param crashSafeMode
+ * true if crash safe mode enabled
+ * @param useCacheMode
+ * true if use cache
+ * @param deleteRenaming
+ * @param clearResizeFile
+ * @param maxFileOperationRetry
+ * @param fileOperationRetryMsDelay
+ * @throws HeapException
+ */
+ public HeapFileSetup(final File dataFile, final boolean crashSafeMode,
+ final boolean useCacheMode, final boolean deleteRenaming,
+ final boolean clearResizeFile, final int maxFileOperationRetry,
+ final int fileOperationRetryMsDelay, final File openFileTraceFile)
+ throws HeapException {
+ super();
+ if (dataFile == null) {
+ throw new HeapException("file must be defined");
+ }
+ this.dataFile = dataFile;
+ this.crashSafeMode = crashSafeMode;
+ this.useCacheMode = useCacheMode;
+ this.deleteRenaming = deleteRenaming;
+ this.clearResizeFile = clearResizeFile;
+ this.maxFileOperationRetry = maxFileOperationRetry;
+ this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
+ this.openFileTraceFile = openFileTraceFile;
+ }
+
+ /**
+ * setup of cache parameters<br>
+ *
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024, set only if use cache enabled
+ * @param maxPage
+ * maximum number of page for read cache, set only if use cache
+ * enabled
+ * @throws HeapException
+ * use cache mode not enabled
+ */
+ public void cacheSetup(final int pageSize, final int maxPage)
+ throws HeapException {
+ if (useCacheMode) {
+ if (pageSize < 1024) {
+ throw new HeapException(
+ "page size must be greater or equal 1024 bytes");
+ }
+ if (maxPage <= 0) {
+ throw new HeapException(
+ "max number of page must be greater than 0");
+ }
+ this.pageSize = pageSize;
+ this.maxPage = maxPage;
+ } else {
+ throw new HeapException(
+ "can not setup cache if use cache mode not enabled");
+ }
+ }
+
+ /**
+ * setup of crash safe mode parameters<br>
+ *
+ * @param backupDataFile
+ * the backup file for the heap
+ * @param stateOkFlagFile
+ * file used has flag for data file on stable state
+ * @param stateBackupOkFlagFile
+ * file used has flag for backup data file on stable state
+ * @param globalStateFlagFile
+ * file indicating backup and data file stable state
+ * @throws HeapException
+ * crash safe mode not enable
+ */
+ public void crashSafeSetup(final File ...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-22 05:38:28
|
Revision: 3025
http://joafip.svn.sourceforge.net/joafip/?rev=3025&view=rev
Author: luc_peuvrier
Date: 2012-04-22 05:38:20 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
added HeapElementManagerFactory
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/AbstractFilePersistenceDelegatingToStore.java
trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/AbstractStoreDelegatingToDataManager.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/IStore.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/ExportStoreQue.java
trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerCheckerFile.java
trunk/joafip/src/test/java/net/sf/joafip/service/TestDataManagerHeapFile.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractDataManagerTestCase.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/StoreForTest.java
trunk/joafip-4test/pom.xml
trunk/joafip-4test/src/main/java/net/sf/joafip/bugtree/MainTreeDual.java
trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CheckSaved.java
trunk/joafip-4test/src/main/java/net/sf/joafip/service/changelog/CreateChangeLog.java
trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AutoSaveHeapFileDataManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
trunk/joafip-pmap/src/main/java/net/sf/joafip/pmap/FileTreeMap.java
trunk/joafip-pmap/src/test/java/net/sf/joafip/pmap/TestFileTreeMap.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/HeapFileSetup.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManagerFactory.java
Removed Paths:
-------------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/HeapFileSetup.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-22 04:19:30
|
Revision: 3024
http://joafip.svn.sourceforge.net/joafip/?rev=3024&view=rev
Author: luc_peuvrier
Date: 2012-04-22 04:19:21 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
btree+ entity added
Modified Paths:
--------------
trunk/joafip-btreeplus/pom.xml
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/ParallelRandomAccessFileForTest.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/RandomAccessFileProbeForTest.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/
trunk/joafip-btreeplus/src/main/java/net/sf/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IStateStored.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
Modified: trunk/joafip-btreeplus/pom.xml
===================================================================
--- trunk/joafip-btreeplus/pom.xml 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-btreeplus/pom.xml 2012-04-22 04:19:21 UTC (rev 3024)
@@ -41,6 +41,14 @@
<dependency>
<groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-kvstore</artifactId>
+ <version>4.0.0b8</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
<artifactId>joafip-log4j</artifactId>
<version>4.0.0b8</version>
<scope>test</scope>
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public abstract class AbstractElement implements IPageRecordable {
+
+ private final PageRecord pageRecord;
+
+ public AbstractElement(final PageRecord pageRecord) {
+ super();
+ this.pageRecord = pageRecord;
+ }
+
+ @Override
+ public PageRecord getPageRecord() {
+ return pageRecord;
+ }
+
+ @Override
+ public void setValueIsChangedValueToSave() throws HeapException {
+ pageRecord.setValueIsChangedValueToSave();
+ }
+
+ @Override
+ public void setValueIsNotChanged() {
+ pageRecord.setValueIsNotChanged();
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordKey;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public abstract class AbstractPageRecord extends AbstractFileStorable {
+
+ public AbstractPageRecord(final IFileForStorable fileForStorable,
+ final long positionInFile) {
+ super(fileForStorable, positionInFile);
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ protected EnumRecordType readRecordType() throws HeapException {
+ final int typeIdentifier = readByte() & 0xff;
+ return EnumRecordType.get(typeIdentifier);
+ }
+
+ protected void writeByteRecordType(final EnumRecordType recordType)
+ throws HeapException {
+ writeByte((byte) recordType.getTypeIdentifier());
+ }
+
+ private IDataRecordKeyManager dataRecordKeyManager;
+
+ protected DataRecordIdentifier readKey() throws HeapException {
+ final long value = readLong();
+ final DataRecordIdentifier dataRecordIdentifier;
+ if (value == -1) {
+ final int keySize = readInteger();
+ final byte[] keyData = readBytes(keySize);
+ final IDataRecordKey dataRecordKey = new DataRecordKey(
+ dataRecordKeyManager, keyData);
+ dataRecordIdentifier = new DataRecordIdentifier(dataRecordKey);
+ } else {
+ dataRecordIdentifier = new DataRecordIdentifier(value);
+ }
+ return dataRecordIdentifier;
+ }
+
+ protected void writeKey(final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ writeLong(dataRecordIdentifier.value);
+ final int keyDataSize = dataRecordIdentifier.getKeyDataSize();
+ if (keyDataSize != 0) {
+ writeInteger(keyDataSize);
+ writeBytes(dataRecordIdentifier.getKeyData());
+ }
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class DataBlock implements IStateStored {
+
+ private final DataBlockPage dataBlockPage;
+
+ private final byte[] data;
+
+ public DataBlock(final DataBlockPage dataBlockPage, final int size) {
+ super();
+ this.dataBlockPage = dataBlockPage;
+ data = new byte[size];
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public int getSize() {
+ return data.length;
+ }
+
+ @Override
+ public void setValueIsChangedValueToSave() throws HeapException {
+ dataBlockPage.setValueIsChangedValueToSave();
+ }
+
+ @Override
+ public void setValueIsNotChanged() {
+ dataBlockPage.setValueIsNotChanged();
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class DataBlockPage extends AbstractElement {
+
+ private static final int FIX_VALUE_SIZE =
+ /**/1/* byte size for record type */+
+ /**/1/* byte size for bits */+
+ /**/4/* int size for crc32 */;
+
+ private byte bits;
+
+ private final int numberOfPage;
+
+ private final int dataBlockDataSize;
+
+ private final DataBlock[] dataBlocks;
+
+ public DataBlockPage(final PageRecord pageRecord, final byte bits) {
+ super(pageRecord);
+ this.bits = bits;
+ dataBlockDataSize = 1 << bits;
+ // the less numberOfPageValue which for
+ // numberOfPage * PAGE_SIZE >= FIX_VALUE_SIZE + numberOfBlock *
+ // dataBlockDataSize
+ // numberOfBlock=1 if dataBlockDataSize > PAGE_SIZE - FIX_VALUE_SIZE
+ //
+ final int numberOfBlock;
+ if (dataBlockDataSize > PageConstant.PAGE_SIZE - FIX_VALUE_SIZE) {
+ // one data block on one or more pages
+ numberOfBlock = 1;
+ final int totalSize = FIX_VALUE_SIZE
+ + /* numberOfBlock* */dataBlockDataSize;
+ final int n = totalSize >> PageConstant.PAGE_BITS;
+ if ((totalSize & PageConstant.PAGE_MASK) == 0) {
+ numberOfPage = n;
+ } else {
+ numberOfPage = n + 1;
+ }
+ } else {
+ // more than one block in one page
+ numberOfPage = 1;
+ numberOfBlock = (PageConstant.PAGE_SIZE - FIX_VALUE_SIZE)
+ / dataBlockDataSize;
+ }
+ dataBlocks = new DataBlock[numberOfBlock];
+ for (int index = 0; index < numberOfBlock; index++) {
+ dataBlocks[index] = new DataBlock(this, dataBlockDataSize);
+ }
+ }
+
+ @Override
+ public EnumRecordType getRecordType() {
+ return EnumRecordType.DATA_BLOCK;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ return numberOfPage;
+ }
+
+ public byte getBits() {
+ return bits;
+ }
+
+ @Override
+ public void updateByteSize() {
+ // no implementation
+ }
+
+ @Override
+ public int getByteSize() {
+ return numberOfPage * PageConstant.PAGE_SIZE;
+ }
+
+ public DataBlock[] getDataBlocks() {
+ return dataBlocks;
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public enum EnumRecordType {
+ /**
+ *
+ */
+ HEADER_PAGE,
+ /**
+ *
+ */
+ NON_TERMINAL_PAGE,
+ /**
+ *
+ */
+ LEAF_PAGE,
+ /**
+ *
+ */
+ FREE_PAGE,
+ /**
+ *
+ */
+ DATA_BLOCK;
+
+ public int getTypeIdentifier() {
+ return ordinal();
+ }
+
+ public static EnumRecordType get(final int typeIdentifier) {
+ return values()[typeIdentifier];
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class FreePage extends AbstractElement {
+
+ private final long nextFreePage;
+
+ public FreePage(final PageRecord pageRecord, final long nextFreePage) {
+ super(pageRecord);
+ this.nextFreePage = nextFreePage;
+ }
+
+ @Override
+ public EnumRecordType getRecordType() {
+ return EnumRecordType.FREE_PAGE;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ return 1;
+ }
+
+ @Override
+ public void updateByteSize() {
+ // no implementation
+ }
+
+ @Override
+ public int getByteSize() {
+ // return PageConstant.PAGE_SIZE;
+ return 1/* byte size for record type */+
+ /**/8/* long size for next free page */+
+ /**/4/* int size for crc32 */;
+ }
+
+ public long getNextFreePage() {
+ return nextFreePage;
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import java.util.Arrays;
+
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class HeaderPage extends AbstractPageRecord implements IPageRecordable {
+
+ private long fileSizeAsNumberOfPage = -1L;
+
+ /** page number of first free page. -1 means no free page */
+ private long pageNumberOfFirstFreePage = -1L;
+
+ private long pageNumberOfRootPage = -1L;
+
+ private long[] freeDataBlock;
+
+ public HeaderPage(final IFileForStorable fileForStorable) {
+ super(fileForStorable, 0L);
+ }
+
+ public long getFileSizeAsNumberOfPage() {
+ return fileSizeAsNumberOfPage;
+ }
+
+ public void setFileSizeAsNumberOfPage(final long fileSizeAsNumberOfPage)
+ throws HeapException {
+ setValueIsChangedValueToSave();
+ this.fileSizeAsNumberOfPage = fileSizeAsNumberOfPage;
+ }
+
+ public long getPageNumberOfFirstFreePage() {
+ return pageNumberOfFirstFreePage;
+ }
+
+ public void setPageNumberOfFirstFreePage(
+ final long pageNumberOfFirstFreePage) throws HeapException {
+ setValueIsChangedValueToSave();
+ this.pageNumberOfFirstFreePage = pageNumberOfFirstFreePage;
+ }
+
+ public long getPageNumberOfRootPage() {
+ return pageNumberOfRootPage;
+ }
+
+ public void setPageNumberOfRootPage(final long pageNumberOfRootPage)
+ throws HeapException {
+ setValueIsChangedValueToSave();
+ this.pageNumberOfRootPage = pageNumberOfRootPage;
+ }
+
+ public void setFirstFreeBlock(final long firstFreeBlockPosition,
+ final int blockBits) throws HeapException {
+ setValueIsChangedValueToSave();
+ initializeFreeDataBlock();
+ freeDataBlock[blockBits - PageConstant.MIN_DATA_BLOCK_BITS] = firstFreeBlockPosition;
+ }
+
+ public long getFirstFreeBlock(final int blockBits) {
+ initializeFreeDataBlock();
+ return freeDataBlock[blockBits - PageConstant.MIN_DATA_BLOCK_BITS];
+ }
+
+ public void clear() {
+ super.clear();
+ fileSizeAsNumberOfPage = -1L;
+ pageNumberOfFirstFreePage = -1L;
+ pageNumberOfRootPage = -1L;
+ freeDataBlock = null;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ return 1;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ return -1L;
+ }
+
+ @Override
+ public EnumRecordType getRecordType() {
+ return EnumRecordType.HEADER_PAGE;
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return PageConstant.PAGE_SIZE;
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return PageConstant.PAGE_SIZE;
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeByteRecordType(EnumRecordType.HEADER_PAGE);
+ writeLong(fileSizeAsNumberOfPage);
+ writeLong(pageNumberOfFirstFreePage);
+ writeLong(pageNumberOfRootPage);
+ initializeFreeDataBlock();
+ for (int index = 0; index < PageConstant.NUMBER_OF_BLOCK_TYPE; index++) {
+ writeLong(freeDataBlock[index]);
+ }
+ writeCrc32();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(PageConstant.PAGE_SIZE);
+ final EnumRecordType recordType = readRecordType();
+ if (!EnumRecordType.HEADER_PAGE.equals(recordType)) {
+ throw new HeapException(EnumRecordType.HEADER_PAGE
+ + " expected record type and is " + recordType);
+ }
+ fileSizeAsNumberOfPage = readLong();
+ pageNumberOfFirstFreePage = readLong();
+ pageNumberOfRootPage = readLong();
+ initializeFreeDataBlock();
+ for (int index = 0; index < PageConstant.NUMBER_OF_BLOCK_TYPE; index++) {
+ freeDataBlock[index] = readLong();
+ }
+ readAndCheckCrc32();
+ }
+
+ private void initializeFreeDataBlock() {
+ if (freeDataBlock == null) {
+ freeDataBlock = new long[PageConstant.NUMBER_OF_BLOCK_TYPE];
+ Arrays.fill(freeDataBlock, -1L);
+ }
+ }
+
+ @Override
+ public void updateByteSize() {
+ // no implementation
+ }
+
+ @Override
+ public int getByteSize() {
+ return PageConstant.PAGE_SIZE;
+ }
+
+ @Override
+ public PageRecord getPageRecord() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface IPageRecordable extends IStateStored {
+
+ EnumRecordType getRecordType();
+
+ /**
+ * the number of pages take is fix
+ *
+ * @return number of page take by the record
+ */
+ int getNumberOfPage();
+
+ /**
+ *
+ * @return byte size of the element
+ */
+ int getByteSize();
+
+ void updateByteSize();
+
+ PageRecord getPageRecord() throws HeapException;
+
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IStateStored.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IStateStored.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IStateStored.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface IStateStored {
+
+ void setValueIsChangedValueToSave() throws HeapException;
+
+ void setValueIsNotChanged();
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class LeafPage extends AbstractElement {
+
+ private long[] pagePointers;
+
+ private DataRecordIdentifier[] keys;
+
+ private int numberOfKeyEntries;
+
+ private int byteSize;
+
+ private long next;
+
+ public LeafPage(final PageRecord pageRecord, final int numberOfKeyEntries) {
+ super(pageRecord);
+ this.numberOfKeyEntries = numberOfKeyEntries;
+ keys = new DataRecordIdentifier[numberOfKeyEntries];
+ pagePointers = new long[numberOfKeyEntries];
+ byteSize = 0;
+ }
+
+ @Override
+ public EnumRecordType getRecordType() {
+ return EnumRecordType.LEAF_PAGE;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ return 1;
+ }
+
+ public int getNumberOfKeyEntries() {
+ return numberOfKeyEntries;
+ }
+
+ public DataRecordIdentifier getKey(final int index) {
+ return keys[index];
+ }
+
+ public long getBlockPointer(final int index) {
+ return pagePointers[index];
+ }
+
+ public long getNext() {
+ return next;
+ }
+
+ public void setNext(final long next) {
+ this.next = next;
+ }
+
+ public void setEntry(final int index, final long pagePointer,
+ final DataRecordIdentifier key) {
+ pagePointers[index] = pagePointer;
+ keys[index] = key;
+ }
+
+ @Override
+ public int getByteSize() {
+ return byteSize;
+ }
+
+ @Override
+ public void updateByteSize() {
+ byteSize = 1/* byte size for record type */+
+ /**/4/* int size for number of entries */+
+ /**/4/* int size for crc32 */+
+ /**/(numberOfKeyEntries + 1/* for next */) * 8/*
+ * long size for pointer
+ */;
+ for (int index = 0; index < numberOfKeyEntries; index++) {
+ byteSize += 8/* long size for value */;
+ final int dataSize = keys[index].getKeyDataSize();
+ if (dataSize != 0) {
+ byteSize += 4/* int size for data size */+ dataSize;
+ }
+ }
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class NonTerminalPage extends AbstractElement {
+
+ private long[] pagePointers;
+
+ private DataRecordIdentifier[] keys;
+
+ private int numberOfKeyEntries;
+
+ private int byteSize;
+
+ public NonTerminalPage(final PageRecord pageRecord,
+ final int numberOfKeyEntries) {
+ super(pageRecord);
+ this.numberOfKeyEntries = numberOfKeyEntries;
+ keys = new DataRecordIdentifier[numberOfKeyEntries];
+ pagePointers = new long[numberOfKeyEntries + 1];
+ byteSize = 0;
+ }
+
+ @Override
+ public EnumRecordType getRecordType() {
+ return EnumRecordType.NON_TERMINAL_PAGE;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ return 1;
+ }
+
+ public void setEntry(final int index, final long pagePointer,
+ final DataRecordIdentifier key) {
+ pagePointers[index] = pagePointer;
+ if (key != null) {
+ keys[index] = key;
+ }
+ }
+
+ @Override
+ public int getByteSize() {
+ return byteSize;
+ }
+
+ @Override
+ public void updateByteSize() {
+ byteSize = 1/* byte size for record type */+
+ /**/4/* int size for number of entries */+
+ /**/4/* int size for crc32 */+
+ /**/(numberOfKeyEntries + 1) * 8;// pointer long size
+ for (int index = 0; index < numberOfKeyEntries; index++) {
+ byteSize += 8;// long size for value
+ final int dataSize = keys[index].getKeyDataSize();
+ if (dataSize != 0) {
+ // 4 for length store in integer
+ byteSize += 4 + dataSize;
+ }
+ }
+ }
+
+ public int getNumberOfKeyEntries() {
+ return numberOfKeyEntries;
+ }
+
+ public long getPagePointer(final int index) {
+ return pagePointers[index];
+ }
+
+ public DataRecordIdentifier getKey(final int index) {
+ return keys[index];
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public final class PageConstant {
+
+ public final static int PAGE_BITS = 12;
+
+ public final static int PAGE_SIZE = 1 << PAGE_BITS;
+
+ public final static int PAGE_MASK = PAGE_SIZE - 1;
+
+ public final static int MIN_DATA_BLOCK_BITS = 4;
+
+ public final static int MAX_DATA_BLOCK_BITS = 24;
+
+ public final static int NUMBER_OF_BLOCK_TYPE = MAX_DATA_BLOCK_BITS
+ - MIN_DATA_BLOCK_BITS + 1;
+
+ private PageConstant() {
+ super();
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,236 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class PageRecord extends AbstractPageRecord {
+
+ private EnumRecordType recordType;
+
+ private IPageRecordable pageRecordable;
+
+ /**
+ * creation for reading
+ *
+ * @param fileForStorable
+ * @param pageNumber
+ */
+ public PageRecord(final IFileForStorable fileForStorable,
+ final int pageNumber) {
+ super(fileForStorable, ((long) pageNumber) << PageConstant.PAGE_BITS);
+ }
+
+ public PageRecord(final IFileForStorable fileForStorable,
+ final IPageRecordable pageRecordable, final int pageNumber) {
+ super(fileForStorable, ((long) pageNumber) << PageConstant.PAGE_BITS);
+ this.pageRecordable = pageRecordable;
+ this.recordType = pageRecordable.getRecordType();
+ }
+
+ public EnumRecordType getRecordType() {
+ return recordType;
+ }
+
+ public IPageRecordable getPageRecordable() {
+ return pageRecordable;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ return -1L;
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ // ASSERTX
+ assert pageRecordable != null;
+ return pageRecordable.getNumberOfPage() * PageConstant.PAGE_SIZE;
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ // ASSERTX
+ assert recordType != null && pageRecordable != null;
+ return pageRecordable.getNumberOfPage() * PageConstant.PAGE_SIZE;
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ // ASSERTX
+ assert recordType != null && pageRecordable != null;
+ // ASSERTX
+ assert pageRecordable.getPageRecord() == this;
+ // ASSERTX
+ assert recordType.equals(pageRecordable.getRecordType());
+ writeByteRecordType(recordType);
+ switch (recordType) {
+ case NON_TERMINAL_PAGE:
+ marshallNonTerminalPage();
+ break;
+ case LEAF_PAGE:
+ marshallLeafPage();
+ break;
+ case FREE_PAGE:
+ marshallFreePage();
+ break;
+ case DATA_BLOCK:
+ marshallDataBlock();
+ break;
+ case HEADER_PAGE:
+ default:
+ throw new HeapException("bad record type " + recordType);
+ }
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ // one page is minimum size
+ readFileToIoBuffer(PageConstant.PAGE_SIZE);
+ recordType = readRecordType();
+ switch (recordType) {
+ case NON_TERMINAL_PAGE:
+ unmarshallNonTerminalPage();
+ break;
+ case LEAF_PAGE:
+ unmarshallLeafPage();
+ break;
+ case FREE_PAGE:
+ unmarshallFreePage();
+ break;
+ case DATA_BLOCK:
+ unmarshallDataBlock();
+ break;
+ case HEADER_PAGE:
+ default:
+ throw new HeapException("bad record type " + recordType);
+ }
+ pageRecordable.updateByteSize();
+ }
+
+ private void marshallNonTerminalPage() throws HeapException {
+ // ASSERTX
+ assert pageRecordable.getByteSize() <= PageConstant.PAGE_SIZE;
+ final NonTerminalPage nonTerminalPage = (NonTerminalPage) pageRecordable;
+ final int numberOfKeyEntries = nonTerminalPage.getNumberOfKeyEntries();
+ writeInteger(numberOfKeyEntries);
+ for (int index = 0; index < numberOfKeyEntries; index++) {
+ writeLong(nonTerminalPage.getPagePointer(index));
+ writeKey(nonTerminalPage.getKey(index));
+ }
+ writeLong(nonTerminalPage.getPagePointer(numberOfKeyEntries));
+ writeCrc32();
+ }
+
+ private void unmarshallNonTerminalPage() throws HeapException {
+ final int numberOfKeyEntries = readInteger();
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(this,
+ numberOfKeyEntries);
+ for (int index = 0; index < numberOfKeyEntries; index++) {
+ final long pagePointer = readLong();
+ final DataRecordIdentifier key = readKey();
+ nonTerminalPage.setEntry(index, pagePointer, key);
+ }
+ final long pagePointer = readLong();
+ nonTerminalPage.setEntry(numberOfKeyEntries, pagePointer, null);
+ readAndCheckCrc32();
+ pageRecordable = nonTerminalPage;
+ }
+
+ private void marshallLeafPage() throws HeapException {
+ // ASSERTX
+ assert pageRecordable.getByteSize() <= PageConstant.PAGE_SIZE;
+ final LeafPage leafPage = (LeafPage) pageRecordable;
+ final int numberOfKeyEntries = leafPage.getNumberOfKeyEntries();
+ writeInteger(numberOfKeyEntries);
+ for (int index = 0; index < numberOfKeyEntries; index++) {
+ writeKey(leafPage.getKey(index));
+ writeLong(leafPage.getBlockPointer(index));
+ }
+ writeLong(leafPage.getNext());
+ writeCrc32();
+ }
+
+ private void unmarshallLeafPage() throws HeapException {
+ final int numberOfKeyEntries = readInteger();
+ final LeafPage leafPage = new LeafPage(this, numberOfKeyEntries);
+ for (int index = 0; index < numberOfKeyEntries; index++) {
+ final DataRecordIdentifier key = readKey();
+ final long pagePointer = readLong();
+ leafPage.setEntry(index, pagePointer, key);
+ }
+ leafPage.setNext(readLong());
+ readAndCheckCrc32();
+ pageRecordable = leafPage;
+ }
+
+ private void marshallFreePage() throws HeapException {
+ // ASSERTX
+ assert pageRecordable.getByteSize() <= PageConstant.PAGE_SIZE;
+ final FreePage freePage = (FreePage) pageRecordable;
+ writeLong(freePage.getNextFreePage());
+ }
+
+ private void unmarshallFreePage() throws HeapException {
+ final long nextFreePage = readLong();
+ final FreePage freePage = new FreePage(this, nextFreePage);
+ readAndCheckCrc32();
+ pageRecordable = freePage;
+ }
+
+ private void marshallDataBlock() throws HeapException {
+ final DataBlockPage dataBlockPage = (DataBlockPage) pageRecordable;
+ final byte bits = dataBlockPage.getBits();
+ writeByte(bits);
+ final int numberOfPage = dataBlockPage.getNumberOfPage();
+ // ASSERTX
+ assert pageRecordable.getByteSize() <= numberOfPage
+ * PageConstant.PAGE_SIZE;
+ final DataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
+ for (DataBlock dataBlock : dataBlocks) {
+ writeBytes(dataBlock.getData());
+ }
+ writeCrc32();
+ }
+
+ private void unmarshallDataBlock() throws HeapException {
+ final byte bits = readByte();
+ final DataBlockPage dataBlockPage = new DataBlockPage(this, bits);
+ final int numberOfPage = dataBlockPage.getNumberOfPage();
+ readFileAppendToIoBuffer(numberOfPage * PageConstant.PAGE_SIZE);
+ final DataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
+ for (DataBlock dataBlock : dataBlocks) {
+ readBytes(dataBlock.getData());
+ }
+ readAndCheckCrc32();
+ pageRecordable = dataBlockPage;
+ }
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.service;
+
+import net.sf.joafip.btreeplus.entity.HeaderPage;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class BtreePlusElementMgr {
+
+ private final IHeapElementManager heapElementManager;
+
+ private final HeaderPage header;
+
+ public BtreePlusElementMgr(final IHeapElementManager heapElementManager)
+ throws HeapException {
+ super();
+ this.heapElementManager = heapElementManager;
+ header = new HeaderPage(heapElementManager.getFileForStorable());
+ heapElementManager.setHeapHeader(header);
+ }
+
+ public void startService() throws HeapException {
+ heapElementManager.startService();
+ }
+
+ public void stopService() throws HeapException {
+ heapElementManager.stopService();
+ }
+
+ public void openTransaction() throws HeapException {
+ heapElementManager.openTransaction();
+ }
+
+ public void closeTransaction() throws HeapException {
+ heapElementManager.closeTransaction();
+ }
+
+ public void closeTransactionDiscardChange() throws HeapException {
+ heapElementManager.closeTransactionDiscardChange();
+ }
+
+ public void clear() throws HeapException {
+ heapElementManager.clear();
+ }
+
+ public void removeFiles() throws HeapException {
+ heapElementManager.removeFiles();
+ }
+}
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -127,6 +127,16 @@
protected abstract int readImpl(byte[] data) throws FileIOException;
@Override
+ public int read(final byte[] data, final int offset, final int length)
+ throws FileIOException {
+ checkOpened();
+ return readImpl(data, offset, length);
+ }
+
+ protected abstract int readImpl(byte[] data, int offset, int length)
+ throws FileIOException;
+
+ @Override
public void write(final byte[] data) throws FileIOException {
checkOpened();
writeImpl(data);
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -71,6 +71,8 @@
int read(byte[] data) throws FileIOException;
+ int read(byte[] data, int offset, int length) throws FileIOException;
+
void write(byte[] data) throws FileIOException;
void write(byte[] data, int length) throws FileIOException;
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -190,6 +190,22 @@
}
@Override
+ protected int readImpl(byte[] data, int offset, int length)
+ throws FileIOException {
+ int read;
+ try {
+ read = randomAccessFile.read(data, offset, length);
+ } catch (IOException exception) {
+ throw HELPER_FILE_UTIL.fileIOException("failed read " + file, file,
+ exception);
+ }
+ if (read > 0) {
+ currentPositionInFile += read;
+ }
+ return read;
+ }
+
+ @Override
public void seekImpl(final long positionInFile) throws FileIOException {
if (currentPositionInFile != positionInFile) {
try {
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -231,6 +231,22 @@
}
@Override
+ protected int readImpl(byte[] data, int offset, int length)
+ throws FileIOException {
+ try {
+ final ByteBuffer byteBuffer = ByteBuffer.wrap(data, offset, length);
+ final int read = fileChannel.read(byteBuffer);
+ if (read > 0) {
+ currentPositionInFile += read;
+ }
+ return read;
+ } catch (IOException exception) {
+ throw HELPER_FILE_UTIL.fileIOException("failed read in " + file,
+ file, exception);
+ }
+ }
+
+ @Override
public void seekImpl(final long positionInFile) throws FileIOException {
try {
if (currentPositionInFile != positionInFile) {
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -268,6 +268,13 @@
}
@Override
+ protected int readImpl(final byte[] data, final int offset, final int length)
+ throws FileIOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
public void writeImpl(final byte[] data) throws FileIOException {
writeImpl(data, 0, data.length);
}
Modified: trunk/joafip-file/src/test/java/net/sf/joafip/file/service/ParallelRandomAccessFileForTest.java
===================================================================
--- trunk/joafip-file/src/test/java/net/sf/joafip/file/service/ParallelRandomAccessFileForTest.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/test/java/net/sf/joafip/file/service/ParallelRandomAccessFileForTest.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -139,6 +139,38 @@
}
@Override
+ public int read(final byte[] data, final int offset, final int length)
+ throws FileIOException {
+ final byte[] data1 = Arrays.copyOf(data, data.length);
+ final int readLength1 = randomFileDirect.read(data1, offset, length);
+ final byte[] data2 = Arrays.copyOf(data, data.length);
+ final int readLength2 = randomFileDirectNio.read(data2, offset, length);
+ final byte[] data3 = Arrays.copyOf(data, data.length);
+ final int readLength3 = randomFileReadWriteCache.read(data3, offset,
+ length);
+ if (readLength1 != readLength2 || readLength1 != readLength3
+ || readLength2 != readLength3) {
+ throw HelperFileUtil.getInstance().fileIOException(
+ "read error " + readLength1 + "," + readLength2 + ","
+ + readLength3, null, null);
+ }
+ if (!Arrays.equals(data1, data2)) {
+ throw HelperFileUtil.getInstance().fileIOException(
+ "difference between data1 and data2", null, null);
+ }
+ if (!Arrays.equals(data1, data3)) {
+ throw HelperFileUtil.getInstance().fileIOException(
+ "difference between data1 and data3", null, null);
+ }
+ if (!Arrays.equals(data2, data3)) {
+ throw HelperFileUtil.getInstance().fileIOException(
+ "difference between data2 and data3", null, null);
+ }
+ System.arraycopy(data1, offset, data, offset, readLength1);
+ return readLength1;
+ }
+
+ @Override
public void seek(final long positionInFile) throws FileIOException {
randomFileDirect.seek(positionInFile);
randomFileDirectNio.seek(positionInFile);
Modified: trunk/joafip-file/src/test/java/net/sf/joafip/file/service/RandomAccessFileProbeForTest.java
===================================================================
--- trunk/joafip-file/src/test/java/net/sf/joafip/file/service/RandomAccessFileProbeForTest.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-file/src/test/java/net/sf/joafip/file/service/RandomAccessFileProbeForTest.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -66,6 +66,19 @@
}
@Override
+ public int read(final byte[] data, final int offset, final int length)
+ throws FileIOException {
+ final long positionInFile = delegate.currentPositionInFile();
+ final int read = delegate.read(data, offset, length);
+ if (read > 0) {
+ final FileAccessRecord fileAccessRecord = new FileAccessRecord(
+ positionInFile, data, offset, length);
+ readLog.add(fileAccessRecord);
+ }
+ return read;
+ }
+
+ @Override
public void write(final byte[] data) throws FileIOException {
final long positionInFile = delegate.currentPositionInFile();
final FileAccessRecord fileAccessRecord = new FileAccessRecord(
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -185,16 +185,17 @@
}
final File openFileTraceFile = setup.getOpenFileTraceFile();
if (crashSafeMode) {
- heapElementManager = new HeapElementManager(this, fileForStorable,
+ heapElementManager = new HeapElementManager(fileForStorable,
stateOkFlagFile, fileForStorableBackup,
stateBackupOkFlagFile, globalStateFlagFile, deleteRenaming,
clearResizeFile, maxFileOperationRetry,
fileOperationRetryMsDelay, openFileTraceFile);
} else {
- heapElementManager = new HeapElementManager(this, fileForStorable,
+ heapElementManager = new HeapElementManager(fileForStorable,
deleteRenaming, clearResizeFile, maxFileOperationRetry,
fileOperationRetryMsDelay, openFileTraceFile);
}
+ heapElementManager.setHeapRecordFactory(this);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
final HeapFreeNodeManager heapFreeNodeManager = new HeapFreeNodeManager(
heapElementManager);
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -82,9 +82,10 @@
fileForStorable = new FileForStorable(dataFile, 1, 0);
backupFileForStorable = new FileForStorable(backupFile, 1, 0);
- heapElementManager = new HeapElementManager(this, fileForStorable,
+ heapElementManager = new HeapElementManager(fileForStorable,
stateDataFile, backupFileForStorable, stateDataBackupFile,
globalStateFlag, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapRecordFactory(this);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
heapElementManager.startService();
heapElementManager.openTransaction();
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -85,9 +85,10 @@
fileForStorable = new FileForStorable(dataFile, 1, 0);
final FileForStorable backupFileForStorage;
backupFileForStorage = new FileForStorable(backupFile, 1, 0);
- heapElementManager = new HeapElementManager(this, fileForStorable,
+ heapElementManager = new HeapElementManager(fileForStorable,
stateDataFile, backupFileForStorage, stateDataBackupFile,
globalStateFile, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapRecordFactory(this);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
final HeapIdNodeManager heapIdNodeManager = new HeapIdNodeManager(
heapElementManager);
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -31,6 +31,7 @@
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.service.RBTException;
@@ -327,6 +328,16 @@
}
@Override
+ public void setHeapRecordFactory(final IHeapRecordFactory heapRecordFactory) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public IHeapRecordFactory getHeapRecordFactory() {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
public void setDataRecordKeyManager(
final IDataRecordKeyManager dataRecordKeyComparator) {
throw new UnsupportedOperationException("not implemented");
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-21 13:56:59 UTC (rev 3023)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-22 04:19:21 UTC (rev 3024)
@@ -61,6 +61,12 @@
}
@Override
+ public int read(final byte[] data, final int offset, final int length)
+ throws HeapException {
+ return delegate.read(data, offset, length);
+ }
+
+ @Override
public void seek(final long positionInFile) throws HeapException {
delegate.seek(positionInFile);
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
=================================...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-22 04:19:28
|
Revision: 3024
http://joafip.svn.sourceforge.net/joafip/?rev=3024&view=rev
Author: luc_peuvrier
Date: 2012-04-22 04:19:21 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
btree+ entity added
Modified Paths:
--------------
trunk/joafip-btreeplus/pom.xml
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/ParallelRandomAccessFileForTest.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/RandomAccessFileProbeForTest.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/
trunk/joafip-btreeplus/src/main/java/net/sf/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecordable.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IStateStored.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-21 13:57:05
|
Revision: 3023
http://joafip.svn.sourceforge.net/joafip/?rev=3023&view=rev
Author: luc_peuvrier
Date: 2012-04-21 13:56:59 +0000 (Sat, 21 Apr 2012)
Log Message:
-----------
todo update
Modified Paths:
--------------
trunk/joafip/doc/_todo.txt
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-21 13:57:05
|
Revision: 3023
http://joafip.svn.sourceforge.net/joafip/?rev=3023&view=rev
Author: luc_peuvrier
Date: 2012-04-21 13:56:59 +0000 (Sat, 21 Apr 2012)
Log Message:
-----------
todo update
Modified Paths:
--------------
trunk/joafip/doc/_todo.txt
Modified: trunk/joafip/doc/_todo.txt
===================================================================
--- trunk/joafip/doc/_todo.txt 2012-04-21 13:55:43 UTC (rev 3022)
+++ trunk/joafip/doc/_todo.txt 2012-04-21 13:56:59 UTC (rev 3023)
@@ -89,6 +89,10 @@
currently:
-------------------------------------------------------------------------------------
+storage in btree+
+- performance tests when use as main store, then add usage option in file persistence builder
+- replace HeapDataFileManager direct use and option for main joafip storage
+
changes for garbage management because of autosave
- tests to add
- test for state machine
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-21 13:55:49
|
Revision: 3022
http://joafip.svn.sourceforge.net/joafip/?rev=3022&view=rev
Author: luc_peuvrier
Date: 2012-04-21 13:55:43 +0000 (Sat, 21 Apr 2012)
Log Message:
-----------
fixme update
Modified Paths:
--------------
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PTreeSubSet.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-21 13:55:49
|
Revision: 3022
http://joafip.svn.sourceforge.net/joafip/?rev=3022&view=rev
Author: luc_peuvrier
Date: 2012-04-21 13:55:43 +0000 (Sat, 21 Apr 2012)
Log Message:
-----------
fixme update
Modified Paths:
--------------
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PTreeSubSet.java
Modified: trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PTreeSubSet.java
===================================================================
--- trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PTreeSubSet.java 2012-04-20 01:43:56 UTC (rev 3021)
+++ trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PTreeSubSet.java 2012-04-21 13:55:43 UTC (rev 3022)
@@ -139,13 +139,13 @@
return super.add(element);
}
- // FIXMELUC ____________must be override
+ // FIXMELUC ____must be override
@Override
public boolean contains(final Object object) {// NOPMD
return super.contains(object);
}
- // FIXMELUC ____________must be override
+ // FIXMELUC ____must be override
@Override
public boolean remove(final Object object) {// NOPMD
return super.remove(object);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-20 01:44:03
|
Revision: 3021
http://joafip.svn.sourceforge.net/joafip/?rev=3021&view=rev
Author: luc_peuvrier
Date: 2012-04-20 01:43:56 +0000 (Fri, 20 Apr 2012)
Log Message:
-----------
data record key moved to joafip-kvstore because of common usage
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/DataRecordKeyManager.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordKey.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java 2012-04-19 02:51:34 UTC (rev 3020)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java 2012-04-20 01:43:56 UTC (rev 3021)
@@ -1,83 +0,0 @@
-/*
- * Copyright 2012 Luc Peuvrier
- *
- * This file is a part of JOAFIP.
- *
- * JOAFIP is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * JOAFIP is distributed in the hope that it will be useful, but
- * unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.record.entity;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
-import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class DataRecordKey implements IDataRecordKey {
-
- private final IDataRecordKeyManager dataRecordKeyManager;
-
- private final byte[] data;
-
- private transient Object key;
-
- public DataRecordKey(final IDataRecordKeyManager dataRecordKeyManager,
- final byte[] data) {// NOPMD
- super();
- this.dataRecordKeyManager = dataRecordKeyManager;
- this.data = data;
- }
-
- @Override
- public int getKeyHashcode() {
- return 0;
- }
-
- @Override
- public int compareTo(final IDataRecordKey dataRecordKey)
- throws HeapException {
- return dataRecordKeyManager.compareDataRecordKey(this, dataRecordKey);
- }
-
- @Override
- public int getKeyDataSize() {
- return data.length;
- }
-
- @Override
- public byte[] getKeyData() {
- return data; // NOPMD
- }
-
- @Override
- public Object getKey() throws HeapException {
- if (key == null) {
- key = dataRecordKeyManager.unmarshall(data);
- }
- return key;
- }
-
- public void setKey(final Object key) {
- this.key = key;
- }
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-19 02:51:34 UTC (rev 3020)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-20 01:43:56 UTC (rev 3021)
@@ -22,6 +22,7 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.entity.DataRecordKey;
import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
import net.sf.joafip.kvstore.record.service.HeapElementManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/DataRecordKeyManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/DataRecordKeyManager.java 2012-04-19 02:51:34 UTC (rev 3020)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/DataRecordKeyManager.java 2012-04-20 01:43:56 UTC (rev 3021)
@@ -29,8 +29,8 @@
import java.util.Comparator;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.entity.DataRecordKey;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.entity.DataRecordKey;
import net.sf.joafip.kvstore.service.HeapException;
/**
Copied: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordKey.java (from rev 3020, trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java)
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordKey.java (rev 0)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordKey.java 2012-04-20 01:43:56 UTC (rev 3021)
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.entity;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class DataRecordKey implements IDataRecordKey {
+
+ private final IDataRecordKeyManager dataRecordKeyManager;
+
+ private final byte[] data;
+
+ private transient Object key;
+
+ public DataRecordKey(final IDataRecordKeyManager dataRecordKeyManager,
+ final byte[] data) {// NOPMD
+ super();
+ this.dataRecordKeyManager = dataRecordKeyManager;
+ this.data = data;
+ }
+
+ @Override
+ public int getKeyHashcode() {
+ return 0;
+ }
+
+ @Override
+ public int compareTo(final IDataRecordKey dataRecordKey)
+ throws HeapException {
+ return dataRecordKeyManager.compareDataRecordKey(this, dataRecordKey);
+ }
+
+ @Override
+ public int getKeyDataSize() {
+ return data.length;
+ }
+
+ @Override
+ public byte[] getKeyData() {
+ return data; // NOPMD
+ }
+
+ @Override
+ public Object getKey() throws HeapException {
+ if (key == null) {
+ key = dataRecordKeyManager.unmarshall(data);
+ }
+ return key;
+ }
+
+ public void setKey(final Object key) {
+ this.key = key;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-20 01:44:03
|
Revision: 3021
http://joafip.svn.sourceforge.net/joafip/?rev=3021&view=rev
Author: luc_peuvrier
Date: 2012-04-20 01:43:56 +0000 (Fri, 20 Apr 2012)
Log Message:
-----------
data record key moved to joafip-kvstore because of common usage
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/DataRecordKeyManager.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordKey.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 02:51:44
|
Revision: 3020
http://joafip.svn.sourceforge.net/joafip/?rev=3020&view=rev
Author: luc_peuvrier
Date: 2012-04-19 02:51:34 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
test added for HeapElementManager
Modified Paths:
--------------
trunk/joafip-heapfile/pom.xml
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
Modified: trunk/joafip-heapfile/pom.xml
===================================================================
--- trunk/joafip-heapfile/pom.xml 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-heapfile/pom.xml 2012-04-19 02:51:34 UTC (rev 3020)
@@ -41,6 +41,14 @@
<dependency>
<groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-kvstore</artifactId>
+ <version>4.0.0b8</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
<artifactId>joafip-collection</artifactId>
<version>4.0.0b8</version>
<type>test-jar</type>
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -16,20 +16,15 @@
*/
package net.sf.joafip.heapfile.record.service;
-import java.io.File;
-
-import net.sf.joafip.AbstractCommonDeleteFileTestCase;
import net.sf.joafip.DoNotTransform;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.AbstractTestHeapElementManager;
import net.sf.joafip.kvstore.record.service.HeapElementManager;
-import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
-import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
@@ -37,14 +32,8 @@
@NotStorableClass
@DoNotTransform
public class TestHeapElementManagerWithHeapRecord extends
- AbstractCommonDeleteFileTestCase implements IHeapRecordFactory {// NOPMD
+ AbstractTestHeapElementManager {
- private FileForStorable fileForStorable; // NOPMD
-
- private FileForStorable backupFileForStorable; // NOPMD
-
- private HeapElementManager heapElementManager; // NOPMD
-
/** first record position */
private long record1pos; // NOPMD
@@ -67,51 +56,13 @@
}
@Override
- protected void setUp() throws Exception {// NOPMD override test case
+ protected void setUp() throws Exception {
super.setUp();
- final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
-
- final File dataFile = new File(runtimePath + File.separator
- + "test.dat");
-
- final File backupFile = new File(runtimePath + File.separator
- + "backup.dat");
-
- final File stateDataBackupFile;
- stateDataBackupFile = new File(runtimePath + File.separator
- + "backup.flag");
-
- final File stateDataFile;
- stateDataFile = new File(runtimePath + File.separator + "data.flag");
- fileForStorable = new FileForStorable(dataFile, 1, 0);
- backupFileForStorable = new FileForStorable(backupFile, 1, 0);
- final File globalStateFile;
- globalStateFile = new File(runtimePath + File.separator + "global.flag");
- final File openFileTraceFile = new File(runtimePath + File.separator
- + "trace.txt");
- heapElementManager = new HeapElementManager(this, fileForStorable,
- stateDataFile, backupFileForStorable, stateDataBackupFile,
- globalStateFile, false, false, 1, 0, openFileTraceFile);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
}
@Override
- protected void tearDown() throws Exception {// NOPMD override test case
- try {
- if (fileForStorable.isOpened()) {
- fileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- try {
- if (backupFileForStorable.isOpened()) {
- backupFileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- fileForStorable = null;// NOPMD
- backupFileForStorable = null;// NOPMD
- heapElementManager = null;// NOPMD
+ protected void tearDown() throws Exception {
heapRecordAppened1 = null;// NOPMD
heapRecordAppened2 = null;// NOPMD
super.tearDown();
@@ -152,7 +103,7 @@
heapElementManager.startService();
heapElementManager.openTransaction();
final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
- /* add heap record */
+ /* create heap record */
final HeapRecord heapRecord = new HeapRecord(heapElementManager,
/**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
// heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
@@ -381,8 +332,6 @@
heapHeader1.getFreeRootNodeFilePosition());
assertEquals("IdRootNodeFilePosition must be -1", -1,
heapHeader1.getIdRootNodeFilePosition());
- // assertTrue("created header must be to save", heapHeader1
- // .isValueChangedToSave());
assertFalse("created header must be saved",
heapHeader1.isValueChangedToSave());
heapElementManager.closeTransaction();
Modified: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -37,17 +37,21 @@
private final int recordSize;
+ private final long previousRecordPositionInFile;
+
private int value;
public RecordForTest(final IHeapElementManager heapElementManager,
- final long positionInFile, final int recordSize) {
+ final long positionInFile, final int recordSize,
+ final long previousRecordPositionInFile) {
super(heapElementManager.getFileForStorable(), positionInFile);
this.recordSize = recordSize;
+ this.previousRecordPositionInFile = previousRecordPositionInFile;
}
@Override
public long getPreviousRecordPositionInFile() throws HeapException {
- throw new HeapException("unsupported");
+ return previousRecordPositionInFile;
}
@Override
Added: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.service;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.service.FileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@DoNotTransform
+public abstract class AbstractTestHeapElementManager extends
+ AbstractCommonDeleteFileTestCase implements IHeapRecordFactory {
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ private FileForStorable backupFileForStorable; // NOPMD
+
+ protected HeapElementManager heapElementManager; // NOPMD
+
+ public AbstractTestHeapElementManager() throws TestException {
+ super();
+ }
+
+ public AbstractTestHeapElementManager(final String name)
+ throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {// NOPMD override test case
+ super.setUp();
+ final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
+
+ final File dataFile = new File(runtimePath + File.separator
+ + "test.dat");
+
+ final File backupFile = new File(runtimePath + File.separator
+ + "backup.dat");
+
+ final File stateDataBackupFile;
+ stateDataBackupFile = new File(runtimePath + File.separator
+ + "backup.flag");
+
+ final File stateDataFile;
+ stateDataFile = new File(runtimePath + File.separator + "data.flag");
+ fileForStorable = new FileForStorable(dataFile, 1, 0);
+ backupFileForStorable = new FileForStorable(backupFile, 1, 0);
+ final File globalStateFile;
+ globalStateFile = new File(runtimePath + File.separator + "global.flag");
+ final File openFileTraceFile = new File(runtimePath + File.separator
+ + "trace.txt");
+ heapElementManager = new HeapElementManager(this, fileForStorable,
+ stateDataFile, backupFileForStorable, stateDataBackupFile,
+ globalStateFile, false, false, 1, 0, openFileTraceFile);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ try {
+ if (backupFileForStorable.isOpened()) {
+ backupFileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileForStorable = null;// NOPMD
+ backupFileForStorable = null;// NOPMD
+ heapElementManager = null;// NOPMD
+ super.tearDown();
+ }
+
+}
Added: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.service;
+
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.entity.RecordForTest;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.redblacktree.service.RBTException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@DoNotTransform
+public class TestHeapElementManager extends AbstractTestHeapElementManager {
+
+ private static final int RECORD_SIZE = 100;
+
+ private static final int HEAP_HEADER_VALUE = Integer.MAX_VALUE;
+
+ public TestHeapElementManager() throws TestException {
+ super();
+ }
+
+ public TestHeapElementManager(final String name) throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final RecordForTest heapHeader = new RecordForTest(heapElementManager,
+ 0L, RECORD_SIZE, -1);
+ heapHeader.setValue(HEAP_HEADER_VALUE);
+ heapElementManager.setHeapHeader(heapHeader);
+ }
+
+ /**
+ * test creation of the heap header in empty heap file
+ *
+ * @throws HeapException
+ *
+ */
+ public void testEmptyHeap() throws HeapException {// NOPMD assertion in
+ // method called
+
+ /* new heap header creation and write with check */
+ final RecordForTest heapHeader = appendHeaderInEmptyFile();
+
+ /* check the wrote header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ getHeapHeaderAndCheckPosition(heapHeader);
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * test header modification saved in heap file
+ *
+ * @throws HeapException
+ * @throws RBTException
+ *
+ */
+ public void testChangeHeader() throws HeapException, RBTException {
+ /* new heap header creation and write with check */
+ final RecordForTest heapHeader1 = appendHeaderInEmptyFile();
+
+ /* then read header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final RecordForTest heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
+ heapHeader2.setValue(HEAP_HEADER_VALUE - 1);
+ /* write modifications */
+ heapElementManager.closeTransaction();
+
+ /* read the last modification */
+ heapElementManager.openTransaction();
+ final RecordForTest heapHeader3 = getHeapHeaderAndCheckPosition(heapHeader2);
+ /* check modifications */
+ assertEquals("bad value", HEAP_HEADER_VALUE - 1, heapHeader3.getValue());
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testAppendRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // check
+ heapElementManager.openTransaction();
+ for (int recordNumber = 0; recordNumber < 100; recordNumber++) {
+ final RecordForTest heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", recordNumber, heapRecord.getValue());
+ }
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testUpdateRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // update
+ heapElementManager.openTransaction();
+ final int recordNumber = 50;
+ RecordForTest heapRecord = new RecordForTest(heapElementManager,
+ RECORD_SIZE * (recordNumber + 1), RECORD_SIZE, RECORD_SIZE
+ * recordNumber);
+ heapRecord.setValue(-recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ heapElementManager.closeTransaction();
+ // check update
+ heapElementManager.openTransaction();
+ heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", -recordNumber, heapRecord.getValue());
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testDeleteRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // update
+ heapElementManager.openTransaction();
+ final int recordNumber = 50;
+ RecordForTest heapRecord = new RecordForTest(heapElementManager,
+ RECORD_SIZE * (recordNumber + 1), RECORD_SIZE, RECORD_SIZE
+ * recordNumber);
+ heapRecord.setValue(-recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ heapElementManager.delete(RECORD_SIZE * (recordNumber + 1));
+ heapElementManager.closeTransaction();
+ // check update
+ heapElementManager.openTransaction();
+ heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", recordNumber, heapRecord.getValue());
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testDiscard() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // update
+ heapElementManager.openTransaction();
+ int recordNumber = 50;
+ RecordForTest heapRecord = new RecordForTest(heapElementManager,
+ RECORD_SIZE * (recordNumber + 1), RECORD_SIZE, RECORD_SIZE
+ * recordNumber);
+ heapRecord.setValue(-recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ heapElementManager.closeTransactionDiscardChange();
+ // check
+ heapElementManager.openTransaction();
+ for (recordNumber = 0; recordNumber < 100; recordNumber++) {
+ heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", recordNumber, heapRecord.getValue());
+ }
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * append heap header in heap empty file
+ *
+ * @return appened heap header
+ * @throws HeapException
+ *
+ */
+ private RecordForTest appendHeaderInEmptyFile() throws HeapException {
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final RecordForTest heapHeader1 = getHeapHeaderAndCheckPosition(null);
+ assertEquals("bad value", HEAP_HEADER_VALUE, heapHeader1.getValue());
+ assertFalse("created header must be saved",
+ heapHeader1.isValueChangedToSave());
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ assertFalse("saving implies no more value changed",
+ heapHeader1.isValueChangedToSave());
+ assertFalse("just created must be false", heapHeader1.isJustCreated());
+ return heapHeader1;
+ }
+
+ /**
+ * get heap header and check its position
+ *
+ * @param heapHeaderReference
+ *
+ * @return heap header
+ * @throws HeapException
+ */
+ private RecordForTest getHeapHeaderAndCheckPosition(
+ final RecordForTest heapHeaderReference) throws HeapException {
+ final RecordForTest heapHeader = (RecordForTest) heapElementManager
+ .getHeapHeader();
+ assertEquals("header must be at file beginning", 0,
+ heapHeader.getPositionInFile());
+ if (heapHeaderReference != null) {
+ assertEquals("wrote and read must be equals", heapHeaderReference,
+ heapHeader);
+ }
+ return heapHeader;
+ }
+
+ private void appendRecords() throws HeapException {
+ heapElementManager.openTransaction();
+ for (int recordNumber = 0; recordNumber < 100; recordNumber++) {
+ final RecordForTest heapRecord = new RecordForTest(
+ heapElementManager, RECORD_SIZE * (recordNumber + 1),
+ RECORD_SIZE, RECORD_SIZE * recordNumber);
+ heapRecord.setValue(recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ }
+ heapElementManager.closeTransaction();
+ }
+
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ return new RecordForTest(heapElementManager, positionInFile,
+ RECORD_SIZE, positionInFile - RECORD_SIZE);
+ }
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -26,10 +26,7 @@
public static Test suite() {
final TestSuite suite = new TestSuite("Test for kvstore.record.service");
// $JUnit-BEGIN$
- // suite.addTestSuite(TestRandomAccessFileCache.class);
- // suite.addTestSuite(TestHeapElementManager.class);
- // suite.addTestSuite(TestHeapRecordManage.class);
- // suite.addTestSuite(TestStoreRestore.class);
+ suite.addTestSuite(TestHeapElementManager.class);
// $JUnit-END$
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 02:51:41
|
Revision: 3020
http://joafip.svn.sourceforge.net/joafip/?rev=3020&view=rev
Author: luc_peuvrier
Date: 2012-04-19 02:51:34 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
test added for HeapElementManager
Modified Paths:
--------------
trunk/joafip-heapfile/pom.xml
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 01:10:34
|
Revision: 3019
http://joafip.svn.sourceforge.net/joafip/?rev=3019&view=rev
Author: luc_peuvrier
Date: 2012-04-19 01:10:23 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
bad package changed
Modified Paths:
--------------
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/
Removed Paths:
-------------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,114 @@
+package net.sf.joafip.kvstore.record.entity;
+
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class RecordForTest extends AbstractFileStorable {
+
+ private final int recordSize;
+
+ private int value;
+
+ public RecordForTest(final IHeapElementManager heapElementManager,
+ final long positionInFile, final int recordSize) {
+ super(heapElementManager.getFileForStorable(), positionInFile);
+ this.recordSize = recordSize;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return recordSize;
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return 8;// integer vale and integer crc32
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(final int value) throws HeapException {
+ this.value = value;
+ setValueIsChangedValueToSave();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(8);
+ value = readInteger();
+ readAndCheckCrc32();
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeInteger(value);
+ writeCrc32();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + recordSize;
+ result = prime * result + value;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RecordForTest other = (RecordForTest) obj;
+ if (recordSize != other.recordSize)
+ return false;
+ if (value != other.value)
+ return false;
+ return true;
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,215 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.entity;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestAbstractFileStorable extends AbstractCommonDeleteFileTestCase {// NOPMD
+
+ private String fileName;
+
+ private static final String DATA1 = "abcdefghijkl";
+
+ private static final String DATA2 = "0123456789abcdefghijkl";
+
+ @NotStorableClass
+ private class Storable extends AbstractFileStorable {
+
+ public byte data[]; // NOPMD
+
+ public int dataSize; // NOPMD
+
+ public Storable(final FileForStorable fileForStorable,
+ final long positionInFile) {
+ super(fileForStorable, positionInFile);
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return dataSize + 4;
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(dataSize + 4);// +4 for crc32
+ data = readBytes(dataSize);
+ readAndCheckCrc32();
+ logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeBytes(data);
+ writeCrc32();
+ logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {// NOPMD hascode not needed
+ boolean equals;
+ if (obj == null) {
+ equals = false;
+ } else if (obj instanceof Storable) {
+ final Storable storable = (Storable) obj;
+ equals = positionInFile == storable.positionInFile;
+ if (equals) {
+ equals = data.length == storable.data.length;
+ }
+ for (int index = 0; equals && index < data.length; index++) {
+ equals = data[index] == storable.data[index];
+ }
+ } else {
+ equals = false;
+ }
+ return equals;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+ };
+
+ private Storable storableIn1; // NOPMD
+
+ private Storable storableOut1; // NOPMD
+
+ private Storable storableIn2; // NOPMD
+
+ private Storable storableOut2; // NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ public TestAbstractFileStorable() throws TestException {
+ super();
+ }
+
+ public TestAbstractFileStorable(final String name) throws TestException {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {// NOPMD inherit test case
+ super.setUp();
+ fileName = TestConstant.getWinRamDiskRuntimeDir() + File.separator
+ + "test.dat";
+ fileForStorable = new FileForStorable(fileName, 1, 0);
+ /* length = DATA1.length() + 4 */
+ storableIn1 = new Storable(fileForStorable, 0);
+ /* length= DATA1.length() + 4 */
+ storableOut1 = new Storable(fileForStorable, 0);
+ storableOut1.setValueIsChangedValueToSave();
+ /* length= DATA2.length() + 4 : +4 for crc32 */
+ storableIn2 = new Storable(fileForStorable, DATA1.length() + 4);
+ /* length= DATA2.length() + 4 : +4 for crc32 */
+ storableOut2 = new Storable(fileForStorable, DATA1.length() + 4);
+ storableOut2.setValueIsChangedValueToSave();
+ }
+
+ protected void tearDown() throws Exception {// NOPMD
+ try {
+ fileForStorable.close();
+ } catch (Throwable throwable) {// NOPMD
+ // ignore error
+ }
+ fileForStorable = null;// NOPMD
+ storableIn1 = null;// NOPMD
+ storableOut1 = null;// NOPMD
+ storableIn2 = null;// NOPMD
+ storableOut2 = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testInOut1() throws HeapException {// NOPMD assertion in outIn
+ new File(fileName).delete();
+ outIn();
+ }
+
+ public void testInOut2() throws HeapException {// NOPMD assertion in out in
+ new File(fileName).delete();
+ output();
+ input();
+ }
+
+ private void outIn() throws HeapException {
+ output();
+ input();
+ assertEquals("in1 must be equals to out1", storableIn1, storableOut1);
+ assertEquals("in2 must be equals to out2", storableIn2, storableOut2);
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ */
+ private void input() throws HeapException {
+ storableIn1.dataSize = DATA1.length();
+ storableIn2.dataSize = DATA2.length();
+
+ fileForStorable.open();
+ // fileForStorable.readStorable(storableIn2);
+ storableIn2.readFromFile();
+ // fileForStorable.readStorable(storableIn1);
+ storableIn1.readFromFile();
+ fileForStorable.close();
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ */
+ private void output() throws HeapException {
+ storableOut1.data = DATA1.getBytes();
+ storableOut1.dataSize = DATA1.length();
+
+ fileForStorable.open();
+ // fileForStorable.writeStorable(storableOut1);
+ storableOut1.writeToFile();
+ fileForStorable.close();
+
+ storableOut2.data = DATA2.getBytes();
+ storableOut2.dataSize = DATA2.length();
+
+ fileForStorable.open();
+ // fileForStorable.writeStorable(storableOut2);
+ storableOut2.writeToFile();
+ // long fileSize = fileForStorable.getFileSize();
+ fileForStorable.close();
+ // because of cache can not test that
+ // assertEquals(DATA1.length() + DATA2.length(), fileSize);
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2008 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.entity;
+
+import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+
+@NotStorableClass
+@DoNotTransform
+public class TestDataRecordIdentifier extends AbstractJoafipCommonTestCase {
+
+ public TestDataRecordIdentifier() throws TestException {
+ super();
+ }
+
+ public TestDataRecordIdentifier(final String name) throws TestException {
+ super(name);
+ }
+
+ public void testSmall() {
+ final DataRecordIdentifier identifier0 = new DataRecordIdentifier(0);
+
+ assertEquals("id0 long1 must be 0", 0, identifier0.value);
+
+ final DataRecordIdentifier identifier1 = new DataRecordIdentifier(1);
+
+ assertEquals("id1 long1 must be 1", 1, identifier1.value);
+
+ final DataRecordIdentifier identifier0Bis = new DataRecordIdentifier(0);
+
+ assertEquals("id0 must be equals to itself", identifier0, identifier0);
+ assertEquals("id0 and id0bis must be equals", identifier0,
+ identifier0Bis);
+ assertEquals("id0 must be equals to itself thru compareTo", 0,
+ identifier0.compareTo(identifier0));
+ assertEquals("id0 and id0bis must be equals compareTo", 0,
+ identifier0.compareTo(identifier0Bis));
+ assertEquals("id0 and id0bis must be equals compareTo", 0,
+ identifier0Bis.compareTo(identifier0));
+ assertTrue("id0 must be less than id1",
+ identifier0.compareTo(identifier1) < 0);
+ assertTrue("id1 must be greater than id0",
+ identifier1.compareTo(identifier0) > 0);
+ }
+
+ public void testIncremente() {
+ final DataRecordIdentifier identifier = new DataRecordIdentifier(0);
+ final DataRecordIdentifier nextIdentifier = new DataRecordIdentifier(
+ identifier);
+ assertCompareWithNext(identifier, nextIdentifier);
+ final DataRecordIdentifier expectedNext = new DataRecordIdentifier(1);
+ assertEquals("not expected", expectedNext, nextIdentifier);
+ }
+
+ private void assertCompareWithNext(final DataRecordIdentifier identifier,
+ final DataRecordIdentifier nextIdentifier) {
+ assertTrue("id must be less than next",
+ identifier.compareTo(nextIdentifier) < 0);
+ assertTrue("next must be greater than id",
+ nextIdentifier.compareTo(identifier) > 0);
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.entity;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestMarshall extends AbstractCommonDeleteFileTestCase {// NOPMD
+
+ @NotStorableClass
+ private class Marshallizable extends AbstractFileStorable {
+
+ public Marshallizable(final FileForStorable fileForStorable) {
+ /* length=8 + 4 + 1 + 4 : 1 long + 1 integer + 1 boolean + 1 integer */
+ super(fileForStorable, 0/* , 8 + 4 + 1 + 4 *//*
+ * 1 long + 1 integer +
+ * 1 boolean + 1 integer
+ */);
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ public long longValue;
+
+ public int intValue; // NOPMD
+
+ public boolean booleanValue; // NOPMD
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return 8 + 4 + 1 + 4;
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeLong(longValue);
+ writeInteger(intValue);
+ writeBoolean(booleanValue);
+ writeCrc32();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(8 + 4 + 1 + 4);
+ longValue = readLong();
+ intValue = readInteger();
+ booleanValue = readBoolean();
+ readAndCheckCrc32();
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+ };
+
+ private Marshallizable fileStorableForWrite; // NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ public TestMarshall() throws TestException {
+ super();
+ }
+
+ public TestMarshall(final String name) throws TestException {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {// NOPMD inherit test case
+ super.setUp();
+ fileForStorable = new FileForStorable(
+ TestConstant.getWinRamDiskRuntimeDir() + File.separator
+ + "test.dat", 1, 0);
+ }
+
+ protected void tearDown() throws Exception {// NOPMD inherit test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ /* ignore error */
+ }
+ fileStorableForWrite = null;// NOPMD
+ fileForStorable = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testInOut() throws HeapException {
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ assertTrue("must be in state just created",
+ fileStorableForWrite.isJustCreated());
+ assertFalse("must be in state value not changed",
+ fileStorableForWrite.isValueChangedToSave());
+ fileStorableForWrite.longValue = 0;
+ fileStorableForWrite.intValue = 0;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ assertFalse("must not be in state just created",
+ fileStorableForWrite.isJustCreated());
+ assertTrue("must be in state value changed",
+ fileStorableForWrite.isValueChangedToSave());
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff;
+ fileStorableForWrite.intValue = 0xff;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff00;
+ fileStorableForWrite.intValue = 0xff00;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff0000;
+ fileStorableForWrite.intValue = 0xff0000;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff000000;
+ fileStorableForWrite.intValue = 0xff000000;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff00000000L;
+ fileStorableForWrite.intValue = 0xff00ff00;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff0000000000L;
+ fileStorableForWrite.intValue = 0x00ff00ff;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff000000000000L;
+ fileStorableForWrite.intValue = 0xf0f0f0f0;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff00000000000000L;
+ fileStorableForWrite.intValue = 0x0f0f0f0f;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff00ff00ff00ff00L;
+ fileStorableForWrite.intValue = 0xffffffff;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ *
+ */
+ private void check() throws HeapException {
+ final Marshallizable fileStorableForRead;
+ fileForStorable.open();
+ fileStorableForWrite.writeToFile(/* fileForStorable */);
+ assertFalse("must not be in state value changed since just wrote",
+ fileStorableForWrite.isValueChangedToSave());
+ fileStorableForRead = new Marshallizable(fileForStorable);
+ fileStorableForRead.readFromFile(/* fileForStorable */);
+ assertFalse("must be in state just created",
+ fileStorableForRead.isJustCreated());
+ assertFalse("must not be in state value changed",
+ fileStorableForRead.isValueChangedToSave());
+ fileForStorable.close();
+ assertEquals("wrote and read long value must be equals",
+ fileStorableForWrite.longValue, fileStorableForRead.longValue);
+ assertEquals("wrote and read int value must be equals",
+ fileStorableForWrite.intValue, fileStorableForRead.intValue);
+ assertEquals("wrote and read boolean value must be equals",
+ fileStorableForWrite.booleanValue,
+ fileStorableForRead.booleanValue);
+ }
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java 2012-04-18 08:49:04 UTC (rev 3018)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -19,9 +19,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.entity.TestAbstractFileStorable;
-import net.sf.joafip.heapfile.record.entity.TestDataRecordIdentifier;
-import net.sf.joafip.heapfile.record.entity.TestMarshall;
@NotStorableClass
public class KVRecordEntityTests {// NOPMD
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 01:10:30
|
Revision: 3019
http://joafip.svn.sourceforge.net/joafip/?rev=3019&view=rev
Author: luc_peuvrier
Date: 2012-04-19 01:10:23 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
bad package changed
Modified Paths:
--------------
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/
Removed Paths:
-------------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 08:49:16
|
Revision: 3018
http://joafip.svn.sourceforge.net/joafip/?rev=3018&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:49:04 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
indempendant HeapElementManager move in joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 08:49:15
|
Revision: 3018
http://joafip.svn.sourceforge.net/joafip/?rev=3018&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:49:04 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
indempendant HeapElementManager move in joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -18,7 +18,7 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.heapfile.record.service.AbstractHeapNodeManager;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.entity.RBTSentinel;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -17,7 +17,7 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTComparableNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -17,9 +17,9 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
/**
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -17,8 +17,8 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTComparableNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -20,11 +20,11 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.HeapElementManager;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
+import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -18,6 +18,7 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.logger.JoafipLogger;
import net.sf.joafip.redblacktree.entity.IRBTNode;
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -1,1140 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.record.service;
-
-import java.io.File;
-import java.io.PrintStream;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import net.sf.joafip.Fortest;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.HelperFileUtil;
-import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.kvstore.entity.EnumFileState;
-import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.kvstore.service.IFileForStorable;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * Heap elements manager in heap file.<br>
- * elements are one heap header and the heap records<br>
- * see {@link IHeapElementManager} for role description<br>
- * implement a cache for elements read and to write<br>
- * data in the cache that was modified will be saved when closing transaction<br>
- * <br>
- * cache mechanism:<br>
- * record cache is in {@link #heapRecordToWriteMap} and in
- * {@link #readHeapRecordMap}<br>
- * <br>
- * {@link #readHeapFileDataRecord(long, boolean)} check if record already in
- * cache, if not read it from file and put it in cache ( the record is marked
- * not modified )<br>
- * <br>
- * {@link #newHeapFileRecord(long, long, long, boolean, boolean, int, int)},
- * create a new record and put it in the cache<br>
- * <br>
- * {@link #delete(long)} delete record from the cache<br>
- * <br>
- * {@link #closeTransaction()} write record marked changed from the cache to the
- * files ( see crash safe mechanisms )<br>
- * <br>
- * crash safe mechanism can be turned off<br>
- * <br>
- * crash safe mechanism:<br>
- * <br>
- * to be crash safe file is maintained open for reading, write are not done as
- * soon they are ask but put in the read/write cache. records on the read/write
- * cache marked changed are write to file when {@link #closeTransaction()} is
- * call, that close the file to be sure all is on disk before reopen file for
- * reading<br>
- * <br>
- * {@link #wasBadFileStableState()} must be call before use files to restore
- * stable file state if needed<br>
- * <br>
- * FlagData : flag file indicating data file state stable<br>
- * FlagBackup: flag file indicating backup data file state stable<br>
- * FlagGlobal: flag file indicating backup and data file stable state<br>
- * <br>
- * <span style="font-family: monospace;"><br>
- * FlagGlobal present .===#...................#===<br>
- * .......... absent .....#===================#...<br>
- * .......................|...................|...<br>
- * FlagData present ...=======#...#===============<br>
- * .......... absent .....|...#===#...........|...<br>
- * .......................|...|...|...........|...<br>
- * FlagBackup present .===============#...#=======<br>
- * .......... absent .....|...|...|...#===#...|...<br>
- * .......................|...|...|...|...|...|...<br>
- * ..................... (1) (2) (3) (4) (5) (6) .<br>
- * </span> <br>
- * (1) starting of files access for write<br>
- * (2) starting of data file modification (write)<br>
- * (3) ending of data file modification<br>
- * (4) starting of backup data file modification (write)<br>
- * (5) ending of backup data file modification<br>
- * (6)end of files access for write<br>
- * <br>
- * if all flag file are present then all files are in stable state<br>
- * if 'FlagGlobal' is absent there was a modification crash<br>
- * <ul>
- * <li>if both 'FlagData' and 'FlagBackup' are present then the files are not
- * deteriorated, but backup data may not be up to date</li>
- * <li>if 'FlagData' is absent then data file may be deteriorated, backup file
- * is in stable state ( previous data before last interrupted modification)</li>
- * <li>if 'FlagBackup' is absent then backup data file is deteriorated, data
- * file is in stable state ( contains last modification )</li>
- * </ul>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class HeapElementManager implements IHeapElementManager {// NOPMD
-
- private static final JoafipLogger LOGGER = JoafipLogger
- .getLogger(HeapElementManager.class);
-
- private static final String NO_FILES =
- /**/"no files";
-
- private static final String OPEN_FAILED =
- /**/"open failed";
-
- private static final String DATA_FILE_NOT_IN_STABLE_STATE_RESTORED =
- /**/"data file not in stable state, restored";
-
- private static final String BACKUP_FILE_NOT_IN_STABLE_STATE_RESTORED =
- /**/"backup file not in stable state, restored";
-
- private static final String FILES_IN_STABLE_STATE =
- /**/"files in stable state";
-
- private static final String NO_FILES_IN_STABLE_STATE =
- /**/"no files in stable state";
-
- private static final String READ_HEAP_FILE_NODE_FAILED =
- /**/"read heap file node failed";
-
- private static final String WRITE_FILE_HEADER_FAILED =
- /**/"close failed, write file header failed";
-
- private static final String READ_FILE_HEADER_FAILED =
- /**/"open failed, read file header failed";
-
- private static final String RECORD_MANAGER_IS_STARTED =
- /**/"record manager is started";
-
- private static final String RECORD_MANAGER_TRANSACTION_ALREADY_OPENED =
- /**/"record manager transaction already opened";
-
- private static final String RECORD_MANAGER_IS_STOPPED =
- /**/"record manager is stopped";
-
- private static final String RECORD_MANAGER_TRANSACTION_IS_CLOSED =
- /**/"record manager transaction is closed";
-
- private static final HelperFileUtil HELPER_FILE_UTIL = HelperFileUtil
- .getInstance();
-
- /** true if crash safe mode enabled */
- private final boolean crashSafeMode;
-
- /** file for {@link IFileStorable} object: header and nodes */
- private final IFileForStorable fileForStorable;
-
- /** backup file for {@link IFileStorable} object: header and nodes */
- private final IFileForStorable fileForStorableBackup;
-
- /** flag file indicating data file state stable */
- private final File stateOkFlagFile;
-
- /** flag file indicating backup data file state stable */
- private final File stateBackupOkFlagFile;
-
- /** flag file indicating backup and data file stable state */
- private final File globalStateFlagFile;
-
- private final File openFileTraceFile;
-
- /** true when record manager service is started */
- private boolean serviceStarted = false;
-
- private Exception starterTrace;
-
- private Exception stopperTrace = new Exception("stopper trace");
-
- /** true when record manager transaction is opened */
- private boolean openedTransaction = false;
-
- /** the header node */
- private IFileStorable header;
-
- /** true if data loose, updated by {@link #wasBadFileStableState()} */
- private boolean dataLost = false;
-
- /**
- * maintain map of to write record identified by start position in file, it
- * is a record cache<br>
- * read are put in cache to guaranty that same object for same record is
- * returned in same transaction<br>
- */
- private final Map<Long, IFileStorable> heapRecordToWriteMap =
- /**/new TreeMap<Long, IFileStorable>();
-
- private final Map<Long, IFileStorable> readHeapRecordMap =
- /**/new TreeMap<Long, IFileStorable>();
-
- private final boolean fileOpenedInTransaction;
-
- private final boolean deleteRenamig;
-
- private final boolean clearResizeFile;
-
- private final int maxFileOperationRetry;
-
- private final int fileOperationRetryMsDelay;
-
- private final IHeapRecordFactory heapRecordFactory;
-
- private IDataRecordKeyManager dataRecordKeyManager;
-
- /**
- * construction for crash safe mode disabled<br>
- *
- * @param heapRecordFactory
- * @param fileForStorable
- * data file
- * @param deleteRenaming
- * @param clearResizeFile
- * @param maxFileOperationRetry
- * @param fileOperationRetryMsDelay
- * @param openFileTraceFile
- */
- public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
- final IFileForStorable fileForStorable,
- final boolean deleteRenaming, final boolean clearResizeFile,
- final int maxFileOperationRetry,
- final int fileOperationRetryMsDelay, final File openFileTraceFile) {
- super();
- this.heapRecordFactory = heapRecordFactory;
- crashSafeMode = false;
- fileOpenedInTransaction = false;
- this.fileForStorable = fileForStorable;
- this.openFileTraceFile = openFileTraceFile;
- this.stateOkFlagFile = null;// NOPMD no state ok flag file
- this.fileForStorableBackup = null;// NOPMD no backup file
- this.stateBackupOkFlagFile = null;// NOPMD no backup state flag file
- this.globalStateFlagFile = null;// NOPMD no global state ok flag file
- this.deleteRenamig = deleteRenaming;
- this.clearResizeFile = clearResizeFile;
- this.maxFileOperationRetry = maxFileOperationRetry;
- this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- }
-
- /**
- * construction for crash safe mode enabled<br>
- *
- * @param heapRecordFactory
- * @param fileForStorable
- * data file
- * @param stateOkFlagFile
- * flag file indicating data file state stable
- * @param fileForStorableBackup
- * data backup file
- * @param stateBackupOkFlagFile
- * flag file indicating backup data file state stable
- * @param globalStateFlagFile
- * flag file indicating backup and data file stable state
- * @param deleteRenaming
- * @param clearResizeFile
- * @param maxFileOperationRetry
- * @param fileOperationRetryMsDelay
- * @param openFileTraceFile
- * @throws HeapException
- * no files in stable state
- */
- public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
- final FileForStorable fileForStorable, final File stateOkFlagFile,
- final FileForStorable fileForStorableBackup,
- final File stateBackupOkFlagFile, final File globalStateFlagFile,
- final boolean deleteRenaming, final boolean clearResizeFile,
- final int maxFileOperationRetry,
- final int fileOperationRetryMsDelay, final File openFileTraceFile) {
- super();
- this.heapRecordFactory = heapRecordFactory;
- crashSafeMode = true;
- fileOpenedInTransaction = true;
- this.fileForStorable = fileForStorable;
- this.stateOkFlagFile = stateOkFlagFile;
- this.fileForStorableBackup = fileForStorableBackup;
- this.stateBackupOkFlagFile = stateBackupOkFlagFile;
- assert globalStateFlagFile != null;
- this.globalStateFlagFile = globalStateFlagFile;
- this.openFileTraceFile = openFileTraceFile;
- this.deleteRenamig = deleteRenaming;
- this.clearResizeFile = clearResizeFile;
- this.maxFileOperationRetry = maxFileOperationRetry;
- this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- }
-
- @Override
- public IFileForStorable getFileForStorable() {
- return fileForStorable;
- }
-
- @Override
- public long getFileSize() throws HeapException {
- return fileForStorable.getFileSize();
- }
-
- @Override
- public boolean wasBadFileStableState() throws HeapException {// NOPMD
- assertServiceIsStopped();
- final boolean restored;
-
- dataLost = false;
-
- if (crashSafeMode) {
- final boolean globalFlagExists = globalStateFlagFile.exists();
- final boolean dataFlagExists = stateOkFlagFile.exists();
- final boolean backupFlagExists = stateBackupOkFlagFile.exists();
- final boolean dataExists = fileForStorable.getFile().exists();
- final boolean backupExists = fileForStorableBackup.getFile()
- .exists();
-
- if (dataFlagExists && !dataExists) {
- final String message = "backup data flag "
- + stateBackupOkFlagFile.getName()
- + " exists but missing data backup file "
- + fileForStorableBackup.getFile().getName();
- /*
- * need some files maintenance
- */
- LOGGER.fatal(message);
- throw new HeapException(message, EnumFileState.STATE_UNSTABLE);
- } else if (backupFlagExists && !backupExists) {
- final String message = "data flag " + stateOkFlagFile.getName()
- + " exists but missing data file "
- + fileForStorable.getFile().getName();
- /*
- * need some files maintenance
- */
- LOGGER.fatal(message);
- throw new HeapException(message, EnumFileState.STATE_UNSTABLE);
-
- } else if (globalFlagExists) {
- /*
- * global flag exists
- */
- if (dataFlagExists && backupFlagExists) {
- /*
- * data and backup file in stable state
- */
- LOGGER.info(FILES_IN_STABLE_STATE);
- } else {
- /*
- * flag file inconsistency, data and backup flag file must
- * exists if global flag file exist
- */
- /*
- * may be first time case when there is no file present
- */
- inconsistencyCheck(backupExists, dataExists);
- }
- restored = false;
- } else {
- try {
- /*
- * global flag do not exists
- */
- if (dataFlagExists && backupFlagExists) {
- /*
- * backup file may not be up to date, create it from
- * data file
- */
- HELPER_FILE_UTIL.copyFile(fileForStorable.getFile(),
- fileForStorableBackup.getFile());
- LOGGER.warn(BACKUP_FILE_NOT_IN_STABLE_STATE_RESTORED);
- restored = true;
- } else if (!dataFlagExists && backupFlagExists) {
- /*
- * data file not in stable state
- */
- /*
- * since backup file in stable state, create data file
- * from backup file
- */
- HELPER_FILE_UTIL.copyFile(
- fileForStorableBackup.getFile(),
- fileForStorable.getFile());
- LOGGER.warn(DATA_FILE_NOT_IN_STABLE_STATE_RESTORED);
- restored = true;
- dataLost = true;
- } else if (dataFlagExists && !backupFlagExists) {
- /*
- * backup file not in stable state, create it from data
- * file
- */
- HELPER_FILE_UTIL.copyFile(fileForStorable.getFile(),
- fileForStorableBackup.getFile());
- LOGGER.warn(BACKUP_FILE_NOT_IN_STABLE_STATE_RESTORED);
- restored = true;
- } else {
- /*
- * flag file inconsistency, one of data and backup flag
- * file must exists if global flag file not exist
- */
- /*
- * may be first time case when there is no file present
- */
- inconsistencyCheck(backupExists, dataExists);
- restored = false;
- }
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- } else {
- restored = false;
- }
- if (restored) {
- markStableState();
- }
- return restored;
- }
-
- /**
- * file inconsistency checking: detect if first usage when data and backup
- * files absent
- *
- * @param dataExists
- * @param backupExists
- *
- * @throws HeapException
- * file should exist, need some files maintenance
- * @throws HeapException
- */
- private void inconsistencyCheck(final boolean backupExists,
- final boolean dataExists) throws HeapException, HeapException {
- if (dataExists || backupExists) {
- final String message = NO_FILES_IN_STABLE_STATE + ", file "
- + fileForStorable.getFile().getName() + " exist="
- + dataExists + ", file "
- + fileForStorableBackup.getFile().getName() + " exist="
- + backupExists;
- /*
- * need some files maintenance
- */
- LOGGER.fatal(message);
- throw new HeapException(message, EnumFileState.STATE_UNSTABLE);
- } else {
- /*
- * no data, empty
- */
- LOGGER.warn(NO_FILES);
- markStableState();
- }
- }
-
- @Override
- public boolean isDataLost() {
- return dataLost;
- }
-
- /**
- * mark files in stable state, must be call if
- * {@link #wasBadFileStableState()} returned true<br>
- * also use to mark stable after file deletion<br>
- * make able to fix some unstable state from restored state before mark
- * restored files stable<br>
- *
- * @throws HeapException
- * file access error
- */
- private void markStableState() throws HeapException {
- if (crashSafeMode) {
- try {
- HELPER_FILE_UTIL.touchFile(stateBackupOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.touchFile(stateOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.touchFile(globalStateFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- }
-
- @Override
- public void removeFiles() throws HeapException {
- // ASSERTX
- assert assertServiceStoppedOrTransactionClosed();
- // FIXMELUC _should clear flag files
- if (deleteRenamig) {
- fileForStorable.deleteFileIfExistsRenaming();
- } else {
- fileForStorable.deleteFileIfExists();
- }
- if (crashSafeMode) {
- if (deleteRenamig) {
- fileForStorableBackup.deleteFileIfExistsRenaming();
- } else {
- fileForStorableBackup.deleteFileIfExists();
- }
- }
- // ASSERTX
- assert readHeapRecordMap.isEmpty() : "heap record read cache must be empty";
- // ASSERTX
- assert heapRecordToWriteMap.isEmpty() : "heap record write cache must be empty";
- markStableState();
- }
-
- @Override
- public void clear() throws HeapException {
- // ASSERTX
- assert assertTransactionOpened();
- heapRecordToWriteMap.clear();
- readHeapRecordMap.clear();
- if (clearResizeFile) {
- try {
- setStartSaveFlagFile();
- fileForStorable.resetFileSize();
- } catch (HeapException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw new HeapException(OPEN_FAILED, exception);
- } catch (FileIOException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw new HeapException(OPEN_FAILED, exception);
- }
- if (crashSafeMode) {
- try {
- setStartBackupFlagFile();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- try {
- fileForStorableBackup.resetFileSize();
- } catch (HeapException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw exception;
- }
- }
- try {
- setEndSaveFlagFile();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- header.clear();
- /* to save new header */
- header.setValueIsChangedValueToSave();
- header.writeToFile();
- flushOnFile();
- }
-
- @Override
- public void startService() throws HeapException {
- // ASSERTX
- assert assertServiceIsStopped();
- starterTrace = new Exception("starter trace");
- serviceStarted = true;
- if (!fileOpenedInTransaction) {
- openFile();
- }
- }
-
- @Override
- public void stopService() throws HeapException {
- // ASSERTX
- assert assertServiceStarted();
- if (openedTransaction) {
- closeTransaction();
- }
- stopperTrace = new Exception("stopper trace");
- serviceStarted = false;
- if (!fileOpenedInTransaction) {
- closeFiles();
- }
- }
-
- @Override
- public boolean isServiceStarted() {
- return serviceStarted;
- }
-
- /**
- * assert service is started
- *
- * @throws HeapException
- * service is stopped
- */
- private boolean assertServiceStarted() throws HeapException {
- if (!serviceStarted) {
- LOGGER.fatal(RECORD_MANAGER_IS_STOPPED);
- throw new HeapException(RECORD_MANAGER_IS_STOPPED, stopperTrace);
- }
- return true;
- }
-
- /**
- * assert service is stopped
- *
- * @throws HeapException
- * service is started
- */
- private boolean assertServiceIsStopped() throws HeapException {
- if (serviceStarted) {
- LOGGER.fatal(RECORD_MANAGER_IS_STARTED);
- throw new HeapException(RECORD_MANAGER_IS_STARTED, starterTrace);
- }
- return true;
- }
-
- @Override
- public void openTransaction() throws HeapException {
- // ASSERTX
- assert assertServiceStartedAndTransactionClosed();
- if (fileOpenedInTransaction) {
- openFile();
- }
- clearHeaprecordToWriteMap();
- readHeapRecordMap.clear();
- try {
- final long fileSize = getFileSize();
- header.clear();
- if (fileSize == 0) {
- /* to save new header */
- header.setValueIsChangedValueToSave();
- header.writeToFile();
- flushOnFile();
- if (fileOpenedInTransaction) {
- closeFiles();
- openFile();
- }
- } else {
- header.readFromFile();
- }
- openedTransaction = true;
- } catch (HeapException exception) {
- LOGGER.fatal(READ_FILE_HEADER_FAILED, exception);
- throw new HeapException(READ_FILE_HEADER_FAILED, exception);
- }
- }
-
- private boolean assertServiceStartedAndTransactionClosed()
- throws HeapException {
- assertServiceStarted();
- assertTransactionClosed();
- return true;
- }
-
- private void assertTransactionClosed() throws HeapException {
- if (openedTransaction) {
- LOGGER.fatal(RECORD_MANAGER_TRANSACTION_ALREADY_OPENED);
- throw new HeapException(RECORD_MANAGER_TRANSACTION_ALREADY_OPENED);
- }
- }
-
- private boolean assertServiceStoppedOrTransactionClosed()
- throws HeapException {
- if (serviceStarted) {
- assertTransactionClosed();
- }
- return true;
- }
-
- private void openFile() throws HeapException {
- if (openFileTraceFile != null) {
- try {
- final PrintStream printStream = new PrintStream(
- openFileTraceFile);
- new Exception("open file trace").printStackTrace(printStream);
- printStream.close();
- } catch (Exception exception) {
- LOGGER.error("while writing open file trace", exception);
- }
- }
- try {
- fileForStorable.open();
- } catch (HeapException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw exception;
- }
- if (crashSafeMode) {
- try {
- fileForStorableBackup.open();
- } catch (HeapException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw exception;
- }
- }
- }
-
- @Override
- public void closeTransaction() throws HeapException {
- // ASSERTX
- assert assertTransactionOpened();
-
- final Set<ToBackupRecord> toBackupList;
- try {
- toBackupList = startSave();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
-
- saveHeader(toBackupList);
- save(toBackupList);
- if (crashSafeMode) {
- fileForStorable.flush();
- }
-
- updateBackup(toBackupList);
-
- clearHeaprecordToWriteMap();
- readHeapRecordMap.clear();
- if (crashSafeMode) {
- flushOnFile();
- }
- if (fileOpenedInTransaction) {
- closeFiles();
- }
- openedTransaction = false;
- }
-
- @Override
- public void closeTransactionDiscardChange() throws HeapException {
- // ASSERTX
- assert assertTransactionOpened();
- clearHeaprecordToWriteMap();
- readHeapRecordMap.clear();
- if (fileOpenedInTransaction) {
- closeFiles();
- }
- openedTransaction = false;
- }
-
- private void clearHeaprecordToWriteMap() {
- heapRecordToWriteMap.clear();
- }
-
- private void closeFiles() throws HeapException {
- try {
- if (openFileTraceFile != null && !openFileTraceFile.delete()) {
- LOGGER.error("while deleting open file trace");
- }
- } catch (Exception exception) {
- LOGGER.error("while deleting open file trace", exception);
- }
- fileForStorable.close();
- if (crashSafeMode) {
- fileForStorableBackup.close();
- }
- }
-
- private void flushOnFile() throws HeapException {
- flushOnFile(fileForStorable);
- if (crashSafeMode) {
- flushOnFile(fileForStorableBackup);
- }
- }
-
- /**
- * flush on file by closing and reopening ( crash safe mode only )
- *
- * @param fileForStorableToUpdate
- * @throws HeapException
- */
- private void flushOnFile(final IFileForStorable fileForStorableToUpdate)
- throws HeapException {
- fileForStorableToUpdate.flush();
- }
-
- @Override
- public boolean isTransactionOpened() {
- return openedTransaction;
- }
-
- private boolean assertTransactionOpened() throws HeapException {
- assertServiceStarted();
- if (!openedTransaction) {
- LOGGER.fatal(RECORD_MANAGER_TRANSACTION_IS_CLOSED);
- throw new HeapException(RECORD_MANAGER_TRANSACTION_IS_CLOSED);
- }
- return true;
- }
-
- private void save(final Set<ToBackupRecord> toBackupList)
- throws HeapException {
- long lastWrotePositionInFile = HeapHeader.HEAP_HEADER_SIZE - 1;
- long lastRecordPositionInFile = 0;
- for (Map.Entry<Long, IFileStorable> entry : heapRecordToWriteMap
- .entrySet()) {
- final IFileStorable heapRecord = entry.getValue();
- try {
- assert false;
- } catch (AssertionError error) {
- // ASSERTX
- final long recordPositionInFile = heapRecord
- .getPositionInFile();
- if (recordPositionInFile != entry.getKey()) {
- throw new HeapException(// NOPMD
- "integrity error record position is "
- + recordPositionInFile + " and map key is "
- + entry.getKey());
- }
- if (recordPositionInFile <= lastWrotePositionInFile) {
- throw new HeapException("last wrote position is "// NOPMD
- + lastWrotePositionInFile
- + " and record position in file is "
- + recordPositionInFile);
- }
- final long previousRecordPositionInFile = heapRecord
- .getPreviousRecordPositionInFile();
- if (previousRecordPositionInFile == -1) {
- if (recordPositionInFile != HeapHeader.HEAP_HEADER_SIZE) {
- throw new HeapException("bad position of first record "// NOPMD
- + recordPositionInFile
- + " for "
- + HeapHeader.HEAP_HEADER_SIZE + " expected");
- }
- } else if (previousRecordPositionInFile < lastRecordPositionInFile) {
- badPreviousRecordPositionInFileError(
- lastRecordPositionInFile, recordPositionInFile,
- previousRecordPositionInFile);
- }
- lastWrotePositionInFile = recordPositionInFile
- + heapRecord.getRecordSize() - 1;
- lastRecordPositionInFile = recordPositionInFile;
- }
- saveHeapRecord(heapRecord, toBackupList);
- }
- }
-
- private void updateBackup(final Set<ToBackupRecord> toBackupList)
- throws HeapException {
- if (crashSafeMode) {
- try {
- setStartBackupFlagFile();
-
- for (ToBackupRecord toBackupRecord : toBackupList) {
- fileForStorableBackup.write(toBackupRecord);
- }
- fileForStorableBackup.flush();
- setEndSaveFlagFile();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- }
-
- private void setStartBackupFlagFile() throws FileIOException {
- HELPER_FILE_UTIL.touchFile(stateOkFlagFile, maxFileOperationRetry,
- fileOperationRetryMsDelay);
- if (deleteRenamig) {
- HELPER_FILE_UTIL.deleteRenaming(stateBackupOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- } else {
- HELPER_FILE_UTIL.delete(stateBackupOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- }
- }
-
- private void setEndSaveFlagFile() throws FileIOException {
- if (crashSafeMode) {
- HELPER_FILE_UTIL.touchFile(stateBackupOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.touchFile(globalStateFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- }
- }
-
- private Set<ToBackupRecord> startSave() throws FileIOException {
- final Set<ToBackupRecord> toBackupList;
- if (crashSafeMode) {
- toBackupList = new TreeSet<ToBackupRecord>();
- setStartSaveFlagFile();
- } else {
- toBackupList = null;
- }
- return toBackupList;
- }
-
- private void setStartSaveFlagFile() throws FileIOException {
- if (crashSafeMode) {
- if (deleteRenamig) {
- HELPER_FILE_UTIL.deleteRenaming(globalStateFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.deleteRenaming(stateOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- } else {
- HELPER_FILE_UTIL.delete(globalStateFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.delete(stateOkFlagFile, maxFileOperationRetry,
- fileOperationRetryMsDelay);
- }
- }
- }
-
- private void saveHeader(final Set<ToBackupRecord> toBackupList)
- throws HeapException {
- if (header.isValueChangedToSave()) {
- if (LOGGER.debugEnabled) {
- LOGGER.debug("update file with header record");
- }
- try {
- if (toBackupList == null) {
- header.writeToFile();
- } else {
- final byte[] data = header.writeToFile();
- toBackupList.add(new ToBackupRecord(header
- .getPositionInFile(), data));
- }
- } catch (HeapException exception) {
- LOGGER.fatal(WRITE_FILE_HEADER_FAILED, exception);
- throw new HeapException(WRITE_FILE_HEADER_FAILED, exception);
-
- }
- }
- }
-
- private void saveHeapRecord(final IFileStorable heapRecord,
- final Set<ToBackupRecord> toBackupList) throws HeapException {
- // ASSERTX
- assert heapRecord.isValueChangedToSave() : "value not change for:\n"
- + heapRecord.toString();
- if (toBackupList == null) {
- heapRecord.writeToFile();
- } else {
- final byte[] data = heapRecord.writeToFile();
- toBackupList.add(new ToBackupRecord(heapRecord.getPositionInFile(),
- data));
- }
- }
-
- /**
- * bad previous record position in file error
- *
- * @param lastRecordPositionInFile
- * @param recordPositionInFile
- * @param previousRecordPositionInFile
- * @throws HeapException
- */
- private void badPreviousRecordPositionInFileError(
- final long lastRecordPositionInFile,
- final long recordPositionInFile,
- final long previousRecordPositionInFile) throws HeapException {
- String nextOfPrevious;
- try {
- final IFileStorable heapRecord = readHeapRecordInFile(previousRecordPositionInFile);
- final long nNextOfPrevious = previousRecordPositionInFile
- + heapRecord.getRecordSize();
- nextOfPrevious = String.valueOf(nNextOfPrevious);
-
- } catch (Exception exception) {
- nextOfPrevious = exception.getMessage();
- }
-
- final IFileStorable heapRecord = heapRecordToWriteMap
- .get(lastRecordPositionInFile);
-
- final long nEndOfFilePosition = lastRecordPositionInFile
- + heapRecord.getRecordSize();
- throw new HeapException("for record at " + recordPositionInFile
- + ", bad previous position in file "
- + previousRecordPositionInFile + ", last record position is "
- + lastRecordPositionInFile + ",next of previous position "
- + nextOfPrevious + ",next of last " + nEndOfFilePosition
- + Thread.currentThread().getName() + "\nrecord:\n"
- + heapRecord.toString());
- }
-
- /**
- * read any kind of heap record ( free record or data record ) without
- * putting it in the cache
- *
- * @param positionInFile
- * @return
- * @throws HeapException
- */
- private IFileStorable readHeapRecordInFile(final long positionInFile)
- throws HeapException {
- final IFileStorable heapRecord = heapRecordFactory.createHeapRecord(
- this, positionInFile);
- try {
- heapRecord.readFromFile();
- } catch (HeapException exception) {
- final String message = READ_HEAP_FILE_NODE_FAILED
- + " read record failed, position in file #"
- + positionInFile;
- LOGGER.fatal(message, exception);
- throw new HeapException(message, exception);
- }
- return heapRecord;
- }
-
- @Override
- public void setHeapHeader(final IFileStorable heapHeader)
- throws HeapException {
- this.header = heapHeader;
- }
-
- @Override
- public IFileStorable getHeapHeader() throws HeapException {
- assertTransactionOpened();
- return header;
- }
-
- @Override
- public IFileStorable readHeapFileDataRecord(final long positionInFile)
- throws HeapException {
- assertTransactionOpened();
- // ASSERTX
- assert assertPositionInFile(positionInFile);
- /*
- * in write mode, read are put in cache to guaranty that same object for
- * same record is returned in same transaction<br>
- */
-
- IFileStorable heapRecord;
- heapRecord = heapRecordToWriteMap.get(positionInFile);
- if (heapRecord == null) {
- heapRecord = readHeapRecordMap.get(positionInFile);
- }
- if (heapRecord == null) {
- heapRecord = heapRecordFactory.createHeapRecord(this,
- positionInFile);
- try {
- heapRecord.readFromFile();
- } catch (HeapException exception) {
- LOGGER.fatal(
- READ_HEAP_FILE_NODE_FAILED + " read record failed",
- exception);
- throw new HeapException(READ_HEAP_FILE_NODE_FAILED, exception);
- }
-
- readHeapRecordMap.put(positionInFile, heapRecord);
- }
- return heapRecord;
- }
-
- private boolean assertPositionInFile(final long positionInFile)
- throws HeapException {
- if (positionInFile < header.getRecordSize()) {
- LOGGER.fatal(READ_HEAP_FILE_NODE_FAILED + " position in heap file "
- + positionInFile + " in header of size="
- + header.getRecordSize());
- throw new HeapException(READ_HEAP_FILE_NODE_FAILED);
- }
- return true;
- }
-
- @Override
- public void appendHeapFileRecord(final IFileStorable heapRecord)
- throws HeapException {
- final long positionInFile = heapRecord.getPositionInFile();
- // ASSERTX
- assert assertTransactionOpened();
- // ASSERTX
- assert assertPositionInFile(positionInFile);
- IFileStorable previous = heapRecordToWriteMap.put(positionInFile,
- heapRecord);
- // ASSERTX
- assert assertNoPreviousOrPreviousSameAsCurrent(previous, heapRecord);
- if (previous == null) {
- previous = readHeapRecordMap.remove(positionInFile);
- // ASSERTX
- assert assertNoPreviousOrPreviousSameAsCurrent(previous, heapRecord);
- } else {
- // ASSERTX
- assert !readHeapRecordMap.containsKey(positionInFile) : "heap record must not be in read cache";
- }
- }
-
- private boolean assertNoPreviousOrPreviousSameAsCurrent(
- final IFileStorable previous, final IFileStorable current)
- throws HeapException {
- if (previous != null && previous != current) {// NOPMD I want to compare
- // reference
- mustNotHavePreviousException(previous, current);
- }
- return true;
- }
-
- private void mustNotHavePreviousException(final IFileStorable previous,
- final IFileStorable current) throws HeapException {
- throw new HeapException(
- "must not have a previous heap record: current=\n"
- + current.toString() + "\nprevious=\n"
- + previous.toString());
- }
-
- @Override
- public void delete(final long positionInFile) throws HeapException {
- // delete case : can be deleted even if not read nor write
- readHeapRecordMap.remove(positionInFile);
- heapRecordToWriteMap.remove(positionInFile);
- }
-
- @Override
- public int getNumberOfHeaprecordInMemory() {
- return readHeapRecordMap.size() + heapRecordToWriteMap.size();
- }
-
- @Override
- public void setDataRecordKeyManager(
- final IDataRecordKeyManager dataRecordKeyManager) {
- this.dataRecordKeyManager = dataRecordKeyManager;
- }
-
- @Override
- public IDataRecordKeyManager getDataRecordKeyManager() {
- return dataRecordKeyManager;
- }
-
- /**
- * FOR TEST ONLY<br>
- *
- * @param positionInFile
- * heap record position in file
- * @return heap record in read cache for position in file, null if none
- */
- @Fortest
- public IFileStorable getHeapFileRecordInReadCache(final long positionInFile) {
- return readHeapRecordMap.get(positionInFile);
- }
-
- /**
- * FOR TEST ONLY<br>
- *
- * @param positionInFile
- * heap record position in file
- * @return heap record in write cache for position in file, null if none
- */
- @Fortest
- public IFileStorable getHeapFileRecordInWriteCache(final long positionInFile) {
- return heapRecordToWriteMap.get(positionInFile);
- }
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -20,6 +20,7 @@
import net.sf.joafip.heapfile.record.entity.HeapFreeNode;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.entity.RBTSentinel;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -21,6 +21,7 @@
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.entity.RBTSentinel;
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -1,175 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.record.service;
-
-import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.kvstore.service.IFileForStorable;
-
-/**
- * Heap elements manager in heap file interface.<br>
- * elements are one header and the heap records<br>
- * heap element are heap header, heap record, and data block<br>
- * make able to get the heap element for read and possible modification<br>
- * the closing save the header and records modification<br>
- *
- * @author luc peuvrier
- *
- */
-public interface IHeapElementManager {
-
- /**
- *
- * @return file used by heap element manager
- */
- IFileForStorable getFileForStorable();
-
- /**
- * check file stable state, restore if possible<br>
- * service must not be started<br>
- * must be called before heap file access<br>
- *
- * @return true if file restored ( from backup to data or data to backup )
- * @throws HeapException
- * no file in stable state, no files in stable state
- */
- boolean wasBadFileStableState() throws HeapException;
-
- /**
- * the returned value is set by {@link #wasBadFileStableState()}
- *
- * @return true if data loose detected by {@link #wasBadFileStableState()}
- */
- boolean isDataLost();
-
- void removeFiles() throws HeapException;
-
- void clear() throws HeapException;
-
- /**
- * start heap record management service<br>
- *
- * @throws HeapException
- * file access error
- *
- * file data corrupted
- */
- void startService() throws HeapException;
-
- /**
- * stop heap record management service<br>
- *
- * @throws HeapException
- *
- */
- void stopService() throws HeapException;
-
- /**
- *
- * @return true if heap file management service is started
- */
- boolean isServiceStarted();
-
- /**
- * open the heap file transaction management
- *
- * @throws HeapException
- *
- */
- void openTransaction() throws HeapException;
-
- /**
- * close the heap file transaction management committing the modifications
- * to the file before
- *
- * @throws HeapException
- *
- */
- void closeTransaction() throws HeapException;
-
- /**
- * close the heap file transaction management without commit modification in
- * file
- *
- * @throws HeapException
- *
- */
- void closeTransactionDiscardChange() throws HeapException;
-
- /**
- *
- * @return true if heap file transaction opened
- */
- boolean isTransactionOpened();
-
- /**
- * set heap header
- *
- * @param heapHeader
- * @throws HeapException
- */
- void setHeapHeader(IFileStorable heapHeader) throws HeapException;
-
- /**
- *
- * @return the heap header in file
- * @throws HeapException
- */
- IFileStorable getHeapHeader() throws HeapException;
-
- /**
- * read heap record in file
- *
- * @param positionInFile
- * heap record position in file
- * @return heap file record
- * @throws HeapException
- *
- */
- IFileStorable readHeapFileDataRecord(final long positionInFile)
- throws HeapException;
-
- /**
- * append an heap file record that will be to write in file
- *
- * @param heapRecord
- * the heap file record to append
- * @throws HeapException
- */
- void appendHeapFileRecord(IFileStorable heapRecord) throws HeapException;
-
- /**
- *
- * @param positionInFile
- * @throws HeapException
- */
- void delete(long positionInFile) throws HeapException;
-
- /**
- * @return file for storage size
- * @throws HeapException
- */
- long getFileSize() throws HeapException;
-
- int getNumberOfHeaprecordInMemory();
-
- void setDataRecordKeyManager(IDataRecordKeyManager dataRecordKeyComparator);
-
- IDataRecordKeyManager getDataRecordKeyManager();
-}
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -1,38 +0,0 @@
-/*
- * Copyright 2012 Luc Peuvrier
- * All rights reserved.
- *
- * This file is a part of JOAFIP.
- *
- * JOAFIP is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * JOAFIP is distributed in the hope that it will be useful, but
- * unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.record.service;
-
-import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-public interface IHeapRecordFactory {
-
- IFileStorable createHeapRecord(HeapElementManager heapElementManager,
- long positionInFile) throws HeapException;
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -32,15 +32,15 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.record.service.HeapElementManager;
import net.sf.joafip.heapfile.record.service.HeapFreeNodeManager;
import net.sf.joafip.heapfile.record.service.HeapIdNodeManager;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
-import net.sf.joafip.heapfile.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.entity.EnumFileState;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.HeapElementManager;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -26,10 +26,10 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.record.service.HeapElementManager;
-import net.sf.joafip.heapfile.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.service.RBTException;
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -1,114 +0,0 @@
-package net.sf.joafip.heapfile.record.entity;
-
-/*
- * Copyright 2012 Luc Peuvrier
- * All rights reserved.
- *
- * This file is a part of JOAFIP.
- *
- * JOAFIP is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * JOAFIP is distributed in the hope that it will be useful, but
- * unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
-import net.sf.joafip.kvstore.entity.AbstractFileStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-public class RecordForTest extends AbstractFileStorable {
-
- private final int recordSize;
-
- private int value;
-
- public RecordForTest(final IHeapElementManager heapElementManager,
- final long positionInFile, final int recordSize) {
- super(heapElementManager.getFileForStorable(), positionInFile);
- this.recordSize = recordSize;
- }
-
- @Override
- public long getPreviousRecordPositionInFile() throws HeapException {
- throw new HeapException("unsupported");
- }
-
- @Override
- public int getRecordSize() throws HeapException {
- return recordSize;
- }
-
- @Override
- protected int toMarshallSize() throws HeapException {
- return 8;// integer vale and integer crc32
- }
-
- @Override
- protected void valueChangedAction() throws HeapException {
- // no implementation
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(final int value) throws HeapException {
- this.value = value;
- setValueIsChangedValueToSave();
- }
-
- @Override
- protected void unmarshallImpl() throws HeapException {
- readFileToIoBuffer(8);
- value = readInteger();
- readAndCheckCrc32();
- }
-
- @Override
- protected void marshallImpl() throws HeapException {
- writeInteger(value);
- writeCrc32();
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + recordSize;
- result = prime * result + value;
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- RecordForTest other = (RecordForTest) obj;
- if (recordSize != other.recordSize)
- return false;
- if (value != other.value)
- return false;
- return true;
- }
-}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -27,6 +27,8 @@
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -28,6 +28,9 @@
import net.sf.joafip.heapfile.record.entity...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-18 08:20:13
|
Revision: 3017
http://joafip.svn.sourceforge.net/joafip/?rev=3017&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:20:01 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
changes for heap element manager tests
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -996,7 +996,8 @@
}
@Override
- public void setHeapHeader(final HeapHeader heapHeader) throws HeapException {
+ public void setHeapHeader(final IFileStorable heapHeader)
+ throws HeapException {
this.header = heapHeader;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -124,7 +124,7 @@
* @param heapHeader
* @throws HeapException
*/
- void setHeapHeader(HeapHeader heapHeader) throws HeapException;
+ void setHeapHeader(IFileStorable heapHeader) throws HeapException;
/**
*
Added: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java (rev 0)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -0,0 +1,114 @@
+package net.sf.joafip.heapfile.record.entity;
+
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class RecordForTest extends AbstractFileStorable {
+
+ private final int recordSize;
+
+ private int value;
+
+ public RecordForTest(final IHeapElementManager heapElementManager,
+ final long positionInFile, final int recordSize) {
+ super(heapElementManager.getFileForStorable(), positionInFile);
+ this.recordSize = recordSize;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return recordSize;
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return 8;// integer vale and integer crc32
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(final int value) throws HeapException {
+ this.value = value;
+ setValueIsChangedValueToSave();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(8);
+ value = readInteger();
+ readAndCheckCrc32();
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeInteger(value);
+ writeCrc32();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + recordSize;
+ result = prime * result + value;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RecordForTest other = (RecordForTest) obj;
+ if (recordSize != other.recordSize)
+ return false;
+ if (value != other.value)
+ return false;
+ return true;
+ }
+}
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -1,498 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.record.service;
-
-import java.io.File;
-
-import net.sf.joafip.AbstractCommonDeleteFileTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestConstant;
-import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.redblacktree.entity.IRBTNode;
-import net.sf.joafip.redblacktree.service.RBTException;
-
-@NotStorableClass
-@DoNotTransform
-public class TestHeapElementManager extends AbstractCommonDeleteFileTestCase
- implements IHeapRecordFactory {// NOPMD
-
- private FileForStorable fileForStorable; // NOPMD
-
- private FileForStorable backupFileForStorable; // NOPMD
-
- private HeapElementManager heapElementManager; // NOPMD
-
- /** first record position */
- private long record1pos; // NOPMD
-
- /** second record position */
- private long record2pos; // NOPMD
-
- /** first record appended */
- private HeapRecord heapRecordAppened1; // NOPMD
-
- /** second record appended */
- private HeapRecord heapRecordAppened2; // NOPMD
-
- public TestHeapElementManager() throws TestException {
- super();
- }
-
- public TestHeapElementManager(final String name) throws TestException {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {// NOPMD override test case
- super.setUp();
- final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
-
- final File dataFile = new File(runtimePath + File.separator
- + "test.dat");
-
- final File backupFile = new File(runtimePath + File.separator
- + "backup.dat");
-
- final File stateDataBackupFile;
- stateDataBackupFile = new File(runtimePath + File.separator
- + "backup.flag");
-
- final File stateDataFile;
- stateDataFile = new File(runtimePath + File.separator + "data.flag");
- fileForStorable = new FileForStorable(dataFile, 1, 0);
- backupFileForStorable = new FileForStorable(backupFile, 1, 0);
- final File globalStateFile;
- globalStateFile = new File(runtimePath + File.separator + "global.flag");
- final File openFileTraceFile = new File(runtimePath + File.separator
- + "trace.txt");
- heapElementManager = new HeapElementManager(this, fileForStorable,
- stateDataFile, backupFileForStorable, stateDataBackupFile,
- globalStateFile, false, false, 1, 0, openFileTraceFile);
- heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
- }
-
- @Override
- protected void tearDown() throws Exception {// NOPMD override test case
- try {
- if (fileForStorable.isOpened()) {
- fileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- try {
- if (backupFileForStorable.isOpened()) {
- backupFileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- fileForStorable = null;// NOPMD
- backupFileForStorable = null;// NOPMD
- heapElementManager = null;// NOPMD
- heapRecordAppened1 = null;// NOPMD
- heapRecordAppened2 = null;// NOPMD
- super.tearDown();
- }
-
- /**
- * test creation of the heap header in empty heap file
- *
- * @throws HeapException
- *
- */
- public void testEmptyHeap() throws HeapException {// NOPMD assertion in
- // method called
-
- /* new heap header creation and write with check */
- final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
-
- /* check the wrote header */
- heapElementManager.startService();
- heapElementManager.openTransaction();
- getHeapHeaderAndCheckPosition(heapHeader1);
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- /**
- * test header modification saved in heap file
- *
- * @throws HeapException
- * @throws RBTException
- *
- */
- public void testChangeHeader() throws HeapException, RBTException {
- /* new heap header creation and write with check */
- final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
-
- /* then read header */
- heapElementManager.startService();
- heapElementManager.openTransaction();
- final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
- /* add heap record */
- final HeapRecord heapRecord = new HeapRecord(heapElementManager,
- /**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
- // heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
- // heapElementManager, heapRecord).getPositionInFile());
- heapHeader2.setFreeRootNodeFilePosition(heapRecord.getPositionInFile());
- // heapHeader2.setIdRootNodeFilePosition(new HeapIdNode(
- // heapElementManager, heapRecord).getPositionInFile());
- heapHeader2.setIdRootNodeFilePosition(heapRecord.getPositionInFile());
- /* write modifications */
- heapElementManager.closeTransaction();
-
- /* read the last modification */
- heapElementManager.openTransaction();
- final HeapHeader heapHeader3 = getHeapHeaderAndCheckPosition(heapHeader2);
-
- /* check modifications */
- assertEquals("FreeRootNodeFilePosition must be "
- + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
- heapHeader3.getFreeRootNodeFilePosition());
-
- assertEquals("IdRootNodeFilePosition must be "
- + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
- heapHeader3.getIdRootNodeFilePosition());
-
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- /**
- * test append done correctly
- *
- * @throws HeapException
- *
- */
- public void testAppendRecord() throws HeapException {
- appendRecord();
- heapElementManager.startService();
- heapElementManager.openTransaction();
-
- final int dataSize = 100;
- final HeapRecord heapRecord1 = readHeapFileDataRecord(record1pos);
- assertEquals("bad record position", record1pos,
- heapRecord1.getPositionInFile());
- assertEquals("bad record data size", dataSize, heapRecord1
- .getDataAssociatedSize().intValue());
- final byte[] data1 = heapRecord1.getDataAssociated();
- for (int index = 0; index < dataSize; index++) {
- assertEquals("bad record data", index, data1[index]);
- }
- logger.debug("heap record1\n" + heapRecord1.toString());
- assertEquals("read must be equals appened", heapRecordAppened1,
- heapRecord1);
-
- final HeapRecord heapRecord2 = readHeapFileDataRecord(record2pos);
- assertEquals("bad record position", record2pos,
- heapRecord2.getPositionInFile());
- assertEquals("bad record data size", dataSize, heapRecord2
- .getDataAssociatedSize().intValue());
- final byte[] data2 = heapRecord2.getDataAssociated();
- assertNotSame("heap record 1 and 2 must not have the same data", data1,
- data2);
- for (int index = 0; index < 100; index++) {
- assertEquals("bad record data", index, data2[index]);
- }
- logger.debug("heap record2\n" + heapRecord2.toString());
- assertEquals("read must be equals appened", heapRecordAppened2,
- heapRecord2);
-
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- public void testUpdateDataRecord() throws HeapException {
- appendRecord();
- final long pos = record1pos;
-
- heapElementManager.startService();
- heapElementManager.openTransaction();
- HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
- byte[] data1 = heapRecord1.getDataAssociated();
- for (int index = 0; index < data1.length; index++) {
- data1[index] = (byte) (data1.length - index);
- }
- heapRecord1.setDataAssociated(data1);
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- data1 = heapRecord1.getDataAssociated();
- for (int index = 0; index < data1.length; index++) {
- assertEquals("bad record data", data1.length - index, data1[index]);
- }
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
-
- }
-
- public void testUpdateNodeRecord() throws HeapException, RBTException {
- appendRecord();
- final long pos = record1pos;
-
- heapElementManager.startService();
-
- heapElementManager.openTransaction();
- HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
-
- try {
- assert false;
- } catch (AssertionError error) {
- try {
- heapRecord1.getFreeNode();
- fail("must not obtain free node");// NOPMD
- } catch (AssertionError error2) {// NOPMD nothing to do when
- // exception thrown
- // expected
- }
- }
- IRBTNode<?> node = heapRecord1.getIdNode();
- boolean color;
- if (node.isColorSetted()) {
- color = node.getColor();
- } else {
- color = true;
- }
- node.setColor(!color);
- assertTrue("value must have changed",
- heapRecord1.isValueChangedToSave());
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- node = heapRecord1.getIdNode();
- assertEquals("color must have changed", !color, node.getColor());
- assertFalse("not modified record", heapRecord1.isValueChangedToSave());
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- heapRecord1.freeRecord();
- try {
- assert false;
- } catch (AssertionError error) {
- try {
- heapRecord1.getIdNode();
- fail("must not obtain id node");// NOPMD
- } catch (AssertionError error2) {// NOPMD nothing to do when
- // exception thrown
- // expected
- }
- }
- node = heapRecord1.getFreeNode();
- if (node.isColorSetted()) {
- color = node.getColor();
- } else {
- color = true;
- }
- node.setColor(!color);
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- node = heapRecord1.getFreeNode();
- assertEquals("color must have changed", !color, node.getColor());
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- public void testChangeManageDataMode() throws HeapException {
- appendRecord();
- final long pos = record1pos;
- heapElementManager.startService();
- heapElementManager.openTransaction();
- /*
- * read record 1 whithout data managing and check state
- */
- HeapRecord heapRecord1 = readHeapFileDataRecord(
- /**/pos/* position in file */);
- assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
- assertFalse("record1 must be in state just created",
- heapRecord1.isJustCreated());
- assertTrue("record1 has been read", heapRecord1.isHeaderRead());
- assertFalse("record1 value must not changed state",
- heapRecord1.isValueChangedToSave());
-
- /*
- * set record 1 value changer, check if added to be wrote
- */
- heapRecord1.setValueIsChangedValueToSave();
- assertNotNull("must be in cache",
- heapElementManager.getHeapFileRecordInWriteCache(pos));
-
- // heapRecord1.createDataArea();
-
- heapElementManager.closeTransaction();
- heapElementManager.openTransaction();
-
- /*
- * change to manage data mode
- */
- heapRecord1 = readHeapFileDataRecord(
- /**/pos/* position in file */);
- assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
- assertFalse("must not be just created", heapRecord1.isJustCreated());
- assertTrue("must has been read", heapRecord1.isHeaderRead());
- assertFalse("value changed must not change",
- heapRecord1.isValueChangedToSave());
- assertNotNull("must be in cache",
- heapElementManager.getHeapFileRecordInReadCache(pos));
-
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- /**
- * append heap header in heap empty file
- *
- * @return appened heap header
- * @throws HeapException
- *
- */
- private HeapHeader appendHeaderInEmptyFile() throws HeapException {
- heapElementManager.startService();
- heapElementManager.openTransaction();
- final HeapHeader heapHeader1 = getHeapHeaderAndCheckPosition(null);
- assertEquals("FreeRootNodeFilePosition must be -1", -1,
- heapHeader1.getFreeRootNodeFilePosition());
- assertEquals("IdRootNodeFilePosition must be -1", -1,
- heapHeader1.getIdRootNodeFilePosition());
- // assertTrue("created header must be to save", heapHeader1
- // .isValueChangedToSave());
- assertFalse("created header must be saved",
- heapHeader1.isValueChangedToSave());
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- assertFalse("saving implies no more value changed",
- heapHeader1.isValueChangedToSave());
- assertFalse("just created must be false", heapHeader1.isJustCreated());
- return heapHeader1;
- }
-
- /**
- * append two records
- *
- * @throws HeapException
- */
- private void appendRecord() throws HeapException {
- appendHeaderInEmptyFile();
- heapElementManager.startService();
- heapElementManager.openTransaction();
- record1pos = HeapHeader.HEAP_HEADER_SIZE;
- final int dataSize = 100;
- final DataRecordIdentifier dataRecordIdentifier = DataRecordIdentifier.ZERO;
- heapRecordAppened1 = new HeapRecord(heapElementManager, record1pos,
- -1L/* prev pos */, dataRecordIdentifier/* id */,
- false/* free */, dataSize, dataSize
- + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- * area size: +
- * 4 for crc32
- */);
- // heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
- // -1L/* prev pos */, dataRecordIdentifier/* id */,
- // false/* free */, dataSize, dataSize
- // + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- // * area size: +
- // * 4 for crc32
- // */);
- heapElementManager.appendHeapFileRecord(heapRecordAppened1);
- try {
- assert false;
- } catch (AssertionError error) {
- try {
- heapRecordAppened1.getDataAssociated();
- fail("there is no data associated to record");
- } catch (AssertionError error2) {// NOPMD
- // expected error
- }
- }
-
- byte[] testData = new byte[dataSize];
- for (int index = 0; index < dataSize; index++) {
- testData[index] = (byte) index;
- }
- heapRecordAppened1.setDataAssociated(testData);
-
- heapElementManager.closeTransaction();
- logger.debug("appened heap record1\n" + heapRecordAppened1.toString());
-
- heapElementManager.openTransaction();
-
- record2pos = record1pos + heapRecordAppened1.getRecordSize();
- heapRecordAppened2 = new HeapRecord(heapElementManager, record2pos,
- record1pos, dataRecordIdentifier/* id */, false/* free */,
- dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- * 4 for
- * crc32
- */);
- // heapRecordAppened2 = heapElementManager.newHeapFileRecord(record2pos,
- // record1pos, dataRecordIdentifier/* id */, false/* free */,
- // dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- // * 4 for
- // * crc32
- // */);
- heapElementManager.appendHeapFileRecord(heapRecordAppened2);
- heapRecordAppened2.setDataAssociated(testData);
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- logger.debug("appened heap record2\n" + heapRecordAppened2.toString());
- }
-
- /**
- * get heap header and check its position
- *
- * @param heapHeaderReference
- *
- * @return heap header
- * @throws HeapException
- */
- private HeapHeader getHeapHeaderAndCheckPosition(
- final HeapHeader heapHeaderReference) throws HeapException {
- final HeapHeader heapHeader = (HeapHeader) heapElementManager
- .getHeapHeader();
- assertEquals("header must be at file beginning", 0,
- heapHeader.getPositionInFile());
- if (heapHeaderReference != null) {
- // header is now the same object
- // assertNotSame("new header must not be same of creation one",
- // heapHeaderReference, heapHeader);
- assertEquals("wrote and read must be equals", heapHeaderReference,
- heapHeader);
- }
- return heapHeader;
- }
-
- private HeapRecord readHeapFileDataRecord(final long positionInFile)
- throws HeapException {
- return (HeapRecord) heapElementManager
- .readHeapFileDataRecord(positionInFile);
- }
-
- @Override
- public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
- final long positionInFile) throws HeapException {
- return new HeapRecord(heapElementManager, positionInFile);
- }
-}
Copied: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java (from rev 3016, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java)
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java (rev 0)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -0,0 +1,499 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.heapfile.record.service;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.heapfile.record.entity.HeapHeader;
+import net.sf.joafip.heapfile.record.entity.HeapRecord;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.redblacktree.entity.IRBTNode;
+import net.sf.joafip.redblacktree.service.RBTException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestHeapElementManagerWithHeapRecord extends
+ AbstractCommonDeleteFileTestCase implements IHeapRecordFactory {// NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ private FileForStorable backupFileForStorable; // NOPMD
+
+ private HeapElementManager heapElementManager; // NOPMD
+
+ /** first record position */
+ private long record1pos; // NOPMD
+
+ /** second record position */
+ private long record2pos; // NOPMD
+
+ /** first record appended */
+ private HeapRecord heapRecordAppened1; // NOPMD
+
+ /** second record appended */
+ private HeapRecord heapRecordAppened2; // NOPMD
+
+ public TestHeapElementManagerWithHeapRecord() throws TestException {
+ super();
+ }
+
+ public TestHeapElementManagerWithHeapRecord(final String name)
+ throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {// NOPMD override test case
+ super.setUp();
+ final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
+
+ final File dataFile = new File(runtimePath + File.separator
+ + "test.dat");
+
+ final File backupFile = new File(runtimePath + File.separator
+ + "backup.dat");
+
+ final File stateDataBackupFile;
+ stateDataBackupFile = new File(runtimePath + File.separator
+ + "backup.flag");
+
+ final File stateDataFile;
+ stateDataFile = new File(runtimePath + File.separator + "data.flag");
+ fileForStorable = new FileForStorable(dataFile, 1, 0);
+ backupFileForStorable = new FileForStorable(backupFile, 1, 0);
+ final File globalStateFile;
+ globalStateFile = new File(runtimePath + File.separator + "global.flag");
+ final File openFileTraceFile = new File(runtimePath + File.separator
+ + "trace.txt");
+ heapElementManager = new HeapElementManager(this, fileForStorable,
+ stateDataFile, backupFileForStorable, stateDataBackupFile,
+ globalStateFile, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ try {
+ if (backupFileForStorable.isOpened()) {
+ backupFileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileForStorable = null;// NOPMD
+ backupFileForStorable = null;// NOPMD
+ heapElementManager = null;// NOPMD
+ heapRecordAppened1 = null;// NOPMD
+ heapRecordAppened2 = null;// NOPMD
+ super.tearDown();
+ }
+
+ /**
+ * test creation of the heap header in empty heap file
+ *
+ * @throws HeapException
+ *
+ */
+ public void testEmptyHeap() throws HeapException {// NOPMD assertion in
+ // method called
+
+ /* new heap header creation and write with check */
+ final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
+
+ /* check the wrote header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ getHeapHeaderAndCheckPosition(heapHeader1);
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * test header modification saved in heap file
+ *
+ * @throws HeapException
+ * @throws RBTException
+ *
+ */
+ public void testChangeHeader() throws HeapException, RBTException {
+ /* new heap header creation and write with check */
+ final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
+
+ /* then read header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
+ /* add heap record */
+ final HeapRecord heapRecord = new HeapRecord(heapElementManager,
+ /**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
+ // heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
+ // heapElementManager, heapRecord).getPositionInFile());
+ heapHeader2.setFreeRootNodeFilePosition(heapRecord.getPositionInFile());
+ // heapHeader2.setIdRootNodeFilePosition(new HeapIdNode(
+ // heapElementManager, heapRecord).getPositionInFile());
+ heapHeader2.setIdRootNodeFilePosition(heapRecord.getPositionInFile());
+ /* write modifications */
+ heapElementManager.closeTransaction();
+
+ /* read the last modification */
+ heapElementManager.openTransaction();
+ final HeapHeader heapHeader3 = getHeapHeaderAndCheckPosition(heapHeader2);
+
+ /* check modifications */
+ assertEquals("FreeRootNodeFilePosition must be "
+ + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
+ heapHeader3.getFreeRootNodeFilePosition());
+
+ assertEquals("IdRootNodeFilePosition must be "
+ + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
+ heapHeader3.getIdRootNodeFilePosition());
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * test append done correctly
+ *
+ * @throws HeapException
+ *
+ */
+ public void testAppendRecord() throws HeapException {
+ appendRecord();
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+
+ final int dataSize = 100;
+ final HeapRecord heapRecord1 = readHeapFileDataRecord(record1pos);
+ assertEquals("bad record position", record1pos,
+ heapRecord1.getPositionInFile());
+ assertEquals("bad record data size", dataSize, heapRecord1
+ .getDataAssociatedSize().intValue());
+ final byte[] data1 = heapRecord1.getDataAssociated();
+ for (int index = 0; index < dataSize; index++) {
+ assertEquals("bad record data", index, data1[index]);
+ }
+ logger.debug("heap record1\n" + heapRecord1.toString());
+ assertEquals("read must be equals appened", heapRecordAppened1,
+ heapRecord1);
+
+ final HeapRecord heapRecord2 = readHeapFileDataRecord(record2pos);
+ assertEquals("bad record position", record2pos,
+ heapRecord2.getPositionInFile());
+ assertEquals("bad record data size", dataSize, heapRecord2
+ .getDataAssociatedSize().intValue());
+ final byte[] data2 = heapRecord2.getDataAssociated();
+ assertNotSame("heap record 1 and 2 must not have the same data", data1,
+ data2);
+ for (int index = 0; index < 100; index++) {
+ assertEquals("bad record data", index, data2[index]);
+ }
+ logger.debug("heap record2\n" + heapRecord2.toString());
+ assertEquals("read must be equals appened", heapRecordAppened2,
+ heapRecord2);
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testUpdateDataRecord() throws HeapException {
+ appendRecord();
+ final long pos = record1pos;
+
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
+ byte[] data1 = heapRecord1.getDataAssociated();
+ for (int index = 0; index < data1.length; index++) {
+ data1[index] = (byte) (data1.length - index);
+ }
+ heapRecord1.setDataAssociated(data1);
+ heapElementManager.closeTransaction();
+
+ heapElementManager.openTransaction();
+ heapRecord1 = readHeapFileDataRecord(pos);
+ data1 = heapRecord1.getDataAssociated();
+ for (int index = 0; index < data1.length; index++) {
+ assertEquals("bad record data", data1.length - index, data1[index]);
+ }
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+
+ }
+
+ public void testUpdateNodeRecord() throws HeapException, RBTException {
+ appendRecord();
+ final long pos = record1pos;
+
+ heapElementManager.startService();
+
+ heapElementManager.openTransaction();
+ HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
+
+ try {
+ assert false;
+ } catch (AssertionError error) {
+ try {
+ heapRecord1.getFreeNode();
+ fail("must not obtain free node");// NOPMD
+ } catch (AssertionError error2) {// NOPMD nothing to do when
+ // exception thrown
+ // expected
+ }
+ }
+ IRBTNode<?> node = heapRecord1.getIdNode();
+ boolean color;
+ if (node.isColorSetted()) {
+ color = node.getColor();
+ } else {
+ color = true;
+ }
+ node.setColor(!color);
+ assertTrue("value must have changed",
+ heapRecord1.isValueChangedToSave());
+ heapElementManager.closeTransaction();
+
+ heapElementManager.openTransaction();
+ heapRecord1 = readHeapFileDataRecord(pos);
+ node = heapRecord1.getIdNode();
+ assertEquals("color must have changed", !color, node.getColor());
+ assertFalse("not modified record", heapRecord1.isValueChangedToSave());
+ heapElementManager.closeTransaction();
+
+ heapElementManager.openTransaction();
+ heapRecord1 = readHeapFileDataRecord(pos);
+ heapRecord1.freeRecord();
+ try {
+ assert false;
+ } catch (AssertionError error) {
+ try {
+ heapRecord1.getIdNode();
+ fail("must not obtain id node");// NOPMD
+ } catch (AssertionError error2) {// NOPMD nothing to do when
+ // exception thrown
+ // expected
+ }
+ }
+ node = heapRecord1.getFreeNode();
+ if (node.isColorSetted()) {
+ color = node.getColor();
+ } else {
+ color = true;
+ }
+ node.setColor(!color);
+ heapElementManager.closeTransaction();
+
+ heapElementManager.openTransaction();
+ heapRecord1 = readHeapFileDataRecord(pos);
+ node = heapRecord1.getFreeNode();
+ assertEquals("color must have changed", !color, node.getColor());
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testChangeManageDataMode() throws HeapException {
+ appendRecord();
+ final long pos = record1pos;
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ /*
+ * read record 1 whithout data managing and check state
+ */
+ HeapRecord heapRecord1 = readHeapFileDataRecord(
+ /**/pos/* position in file */);
+ assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
+ assertFalse("record1 must be in state just created",
+ heapRecord1.isJustCreated());
+ assertTrue("record1 has been read", heapRecord1.isHeaderRead());
+ assertFalse("record1 value must not changed state",
+ heapRecord1.isValueChangedToSave());
+
+ /*
+ * set record 1 value changer, check if added to be wrote
+ */
+ heapRecord1.setValueIsChangedValueToSave();
+ assertNotNull("must be in cache",
+ heapElementManager.getHeapFileRecordInWriteCache(pos));
+
+ // heapRecord1.createDataArea();
+
+ heapElementManager.closeTransaction();
+ heapElementManager.openTransaction();
+
+ /*
+ * change to manage data mode
+ */
+ heapRecord1 = readHeapFileDataRecord(
+ /**/pos/* position in file */);
+ assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
+ assertFalse("must not be just created", heapRecord1.isJustCreated());
+ assertTrue("must has been read", heapRecord1.isHeaderRead());
+ assertFalse("value changed must not change",
+ heapRecord1.isValueChangedToSave());
+ assertNotNull("must be in cache",
+ heapElementManager.getHeapFileRecordInReadCache(pos));
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * append heap header in heap empty file
+ *
+ * @return appened heap header
+ * @throws HeapException
+ *
+ */
+ private HeapHeader appendHeaderInEmptyFile() throws HeapException {
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final HeapHeader heapHeader1 = getHeapHeaderAndCheckPosition(null);
+ assertEquals("FreeRootNodeFilePosition must be -1", -1,
+ heapHeader1.getFreeRootNodeFilePosition());
+ assertEquals("IdRootNodeFilePosition must be -1", -1,
+ heapHeader1.getIdRootNodeFilePosition());
+ // assertTrue("created header must be to save", heapHeader1
+ // .isValueChangedToSave());
+ assertFalse("created header must be saved",
+ heapHeader1.isValueChangedToSave());
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ assertFalse("saving implies no more value changed",
+ heapHeader1.isValueChangedToSave());
+ assertFalse("just created must be false", heapHeader1.isJustCreated());
+ return heapHeader1;
+ }
+
+ /**
+ * append two records
+ *
+ * @throws HeapException
+ */
+ private void appendRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ record1pos = HeapHeader.HEAP_HEADER_SIZE;
+ final int dataSize = 100;
+ final DataRecordIdentifier dataRecordIdentifier = DataRecordIdentifier.ZERO;
+ heapRecordAppened1 = new HeapRecord(heapElementManager, record1pos,
+ -1L/* prev pos */, dataRecordIdentifier/* id */,
+ false/* free */, dataSize, dataSize
+ + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
+ * area size: +
+ * 4 for crc32
+ */);
+ // heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
+ // -1L/* prev pos */, dataRecordIdentifier/* id */,
+ // false/* free */, dataSize, dataSize
+ // + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
+ // * area size: +
+ // * 4 for crc32
+ // */);
+ heapElementManager.appendHeapFileRecord(heapRecordAppened1);
+ try {
+ assert false;
+ } catch (AssertionError error) {
+ try {
+ heapRecordAppened1.getDataAssociated();
+ fail("there is no data associated to record");
+ } catch (AssertionError error2) {// NOPMD
+ // expected error
+ }
+ }
+
+ byte[] testData = new byte[dataSize];
+ for (int index = 0; index < dataSize; index++) {
+ testData[index] = (byte) index;
+ }
+ heapRecordAppened1.setDataAssociated(testData);
+
+ heapElementManager.closeTransaction();
+ logger.debug("appened heap record1\n" + heapRecordAppened1.toString());
+
+ heapElementManager.openTransaction();
+
+ record2pos = record1pos + heapRecordAppened1.getRecordSize();
+ heapRecordAppened2 = new HeapRecord(heapElementManager, record2pos,
+ record1pos, dataRecordIdentifier/* id */, false/* free */,
+ dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
+ * 4 for
+ * crc32
+ */);
+ // heapRecordAppened2 = heapElementManager.newHeapFileRecord(record2pos,
+ // record1pos, dataRecordIdentifier/* id */, false/* free */,
+ // dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
+ // * 4 for
+ // * crc32
+ // */);
+ heapElementManager.appendHeapFileRecord(heapRecordAppened2);
+ heapRecordAppened2.setDataAssociated(testData);
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ logger.debug("appened heap record2\n" + heapRecordAppened2.toString());
+ }
+
+ /**
+ * get heap header and check its position
+ *
+ * @param heapHeaderReference
+ *
+ * @return heap header
+ * @throws HeapException
+ */
+ private HeapHeader getHeapHeaderAndCheckPosition(
+ final HeapHeader heapHeaderReference) throws HeapException {
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
+ assertEquals("header must be at file beginning", 0,
+ heapHeader.getPositionInFile());
+ if (heapHeaderReference != null) {
+ // header is now the same object
+ // assertNotSame("new header must not be same of creation one",
+ // heapHeaderReference, heapHeader);
+ assertEquals("wrote and read must be equals", heapHeaderReference,
+ heapHeader);
+ }
+ return heapHeader;
+ }
+
+ private HeapRecord readHeapFileDataRecord(final long positionInFile)
+ throws HeapException {
+ return (HeapRecord) heapElementManager
+ .readHeapFileDataRecord(positionInFile);
+ }
+
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ return new HeapRecord(heapElementManager, positionInFile);
+ }
+}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -34,6 +34,12 @@
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.service.RBTException;
+/**
+ * test {@link HeapRecord} store and restore
+ *
+ * @author luc peuvrier
+ *
+ */
@NotStorableClass
@DoNotTransform
public class TestStoreRestore extends AbstractCommonDeleteFileTestCase
@@ -251,7 +257,8 @@
}
@Override
- public void setHeapHeader(final HeapHeader heapHeader) throws HeapException {
+ public void setHeapHeader(final IFileStorable heapHeader)
+ throws HeapException {
// do nothing
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -153,10 +153,7 @@
*/
protected abstract void marshallImpl() throws HeapException;
- /**
- *
- * @return true if just created ( not read from file and not setted )
- */
+ @Override
public boolean isJustCreated() {
return justCreated;
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -76,10 +76,17 @@
boolean isValueChangedToSave();
/**
+ *
+ * @return true if just created ( not read from file and not setted )
+ */
+ boolean isJustCreated();
+
+ /**
* get the record size
*
* @return the record size
* @throws HeapException
*/
int getRecordSize() throws HeapException;
+
}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -24,8 +24,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import net.sf.joafip.java.util.TestSunTreeMap;
-import net.sf.joafip.pmap.TestFileTreeMap;
+import net.sf.joafip.heapfile.record.service.TestHeapElementManagerWithHeapRecord;
+import net.sf.joafip.heapfile.record.service.TestHeapRecordManage;
/**
*
@@ -42,8 +42,8 @@
public static Test suite() {
final TestSuite suite = new TestSuite("in error Tests");
// $JUnit-BEGIN$
- suite.addTestSuite(TestSunTreeMap.class);
- suite.addTestSuite(TestFileTreeMap.class);
+ suite.addTestSuite(TestHeapElementManagerWithHeapRecord.class);
+ suite.addTestSuite(TestHeapRecordManage.class);
// suite.addTest(xxxx.suite());
// $JUnit-END$
return suite;
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -27,7 +27,7 @@
final TestSuite suite = new TestSuite(
"Test for heapfile.record.service");
// $JUnit-BEGIN$
- suite.addTestSuite(TestHeapElementManager.class);
+ suite.addTestSuite(TestHeapElementManagerWithHeapRecord.class);
suite.addTestSuite(TestHeapRecordManage.class);
suite.addTestSuite(TestStoreRestore.class);
// $JUnit-END$
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|