[Joafip-svn] SF.net SVN: joafip:[3165] trunk/joafip-heapfile/src
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2012-11-28 12:15:54
|
Revision: 3165
http://joafip.svn.sourceforge.net/joafip/?rev=3165&view=rev
Author: luc_peuvrier
Date: 2012-11-28 12:15:42 +0000 (Wed, 28 Nov 2012)
Log Message:
-----------
red black tree management changed. foreground garbage sweep changed
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/HeapRecord.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/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/DataRecordIterator.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-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -404,7 +404,8 @@
private void checkColorSetted() throws RBTException {
if (!colorSetted) {
- throw new RBTException("color is not setted:\n" + this.toString());
+ throw new RBTException("color is not setted:\n" + getClass() + "\n"
+ + this.toString());
}
}
@@ -516,9 +517,10 @@
@Override
public String toString() {
- return "color=" + color + " pos in file=" + positionInFile + " left="
- + leftPositionInFile + " right=" + rightPositionInFile
- + " parent=" + parentPositionInFile;
+ return "attached " + isAttached() + ", color=" + color
+ + ", pos in file=" + positionInFile + ", left="
+ + leftPositionInFile + ", right=" + rightPositionInFile
+ + ", parent=" + parentPositionInFile;
}
@Override
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-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -419,7 +419,7 @@
writeByte((byte) 0x02);
}
} else {
- writeByte((byte) 0x00);
+ throw new HeapException("data record color not set");
}
writeInteger(numberOfChild);
writeLong(nodeIdentifier.value);
@@ -470,7 +470,7 @@
writeByte((byte) 0x02);
}
} else {
- writeByte((byte) 0x00);
+ throw new HeapException("free record color not set");
}
// writeInteger(freeNode.getNumberOfChild());
writeInteger(numberOfChild);
@@ -539,7 +539,8 @@
colorSetted = true;
color = true;
} else {
- colorSetted = false;
+ // colorSetted = false;
+ throw new HeapException("data record color not set");
}
numberOfChild = readInteger();
final long long1 = readLong();
@@ -576,7 +577,8 @@
colorSetted = true;
color = true;
} else {
- colorSetted = false;
+ // colorSetted = false;
+ throw new HeapException("free record color not set");
}
// freeNode.setNumberOfChildUnmarshalling(readInteger());
numberOfChild = readInteger();
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-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AutoSaveHeapFileDataManager.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -22,6 +22,7 @@
*/
package net.sf.joafip.heapfile.service;
+import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
@@ -95,6 +96,87 @@
return created;
}
+ @Override
+ public boolean deleteDataRecordImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ final boolean result = super.deleteDataRecordImpl(dataRecordIdentifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected boolean hasDataRecordImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ final boolean result = super.hasDataRecordImpl(dataRecordIdentifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected DataRecordIdentifier firstDataRecordIdentifierImpl()
+ throws HeapException {
+ final DataRecordIdentifier result = super.firstDataRecordIdentifierImpl();
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ public DataRecordIdentifier nextDataRecordIdentifierImpl(
+ DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ final DataRecordIdentifier result = super.nextDataRecordIdentifier(dataRecordIdentifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected DataRecordIdentifier lastDataRecordIdentifierImpl()
+ throws HeapException {
+ final DataRecordIdentifier result = super.lastDataRecordIdentifierImpl();
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected DataRecordIdentifier lowerDataRecordIdentifierImpl(
+ DataRecordIdentifier identifier) throws HeapException {
+ final DataRecordIdentifier result = super.lowerDataRecordIdentifierImpl(identifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected DataRecordIdentifier floorDataRecordIdentifierImpl(
+ DataRecordIdentifier identifier) throws HeapException {
+ final DataRecordIdentifier result = super.floorDataRecordIdentifierImpl(identifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected DataRecordIdentifier ceilingDataRecordIdentifierImpl(
+ DataRecordIdentifier identifier) throws HeapException {
+ final DataRecordIdentifier result = super.ceilingDataRecordIdentifierImpl(identifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ protected DataRecordIdentifier higherDataRecordIdentifierImpl(
+ DataRecordIdentifier identifier) throws HeapException {
+ final DataRecordIdentifier result = super.higherDataRecordIdentifierImpl(identifier);
+ checkForSave();
+ return result;
+ }
+
+ @Override
+ @Fortest
+ public long getRecordPositionInfile(DataRecordIdentifier identifier)
+ throws HeapException {
+ final long result = super.getRecordPositionInfile(identifier);
+ checkForSave();
+ return result;
+ }
+
private void checkForSave() throws HeapException {
if (heapElementManager.getNumberOfHeaprecordInMemory() >= maxRecord) {
flushImp();
Added: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/DataRecordIterator.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/DataRecordIterator.java (rev 0)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/DataRecordIterator.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -0,0 +1,90 @@
+/*
+ * 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.service;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.HeapRuntimeException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class DataRecordIterator implements Iterator<DataRecordIdentifier> {
+
+ private final HeapFileDataManager heapFileDataManager;
+
+ private DataRecordIdentifier next;
+
+ private DataRecordIdentifier removable;
+
+ public DataRecordIterator(HeapFileDataManager heapFileDataManager) {
+ super();
+ this.heapFileDataManager=heapFileDataManager;
+ try {
+ next=heapFileDataManager.firstDataRecordIdentifier();
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ return next!=null;
+ }
+
+ @Override
+ public DataRecordIdentifier next() {
+ if( next==null){
+ throw new NoSuchElementException();
+ }
+ final DataRecordIdentifier result = next;
+ try {
+ next=heapFileDataManager.nextDataRecordIdentifier(next);
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ removable=result;
+ return result;
+ }
+
+ @Override
+ public void remove() {
+ if( removable==null) {
+ throw new IllegalStateException();
+ }
+ try {
+ heapFileDataManager.deleteDataRecord(removable);
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ removable=null;
+ }
+}
Property changes on: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/DataRecordIterator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -145,12 +145,13 @@
}
@Override
- protected void stopServiceImpl(final boolean removeFiles) throws HeapException {
+ protected void stopServiceImpl(final boolean removeFiles)
+ throws HeapException {
if (heapElementManager.isTransactionOpened()) {
heapElementManager.closeTransactionDiscardChange();
}
heapElementManager.stopService();
- if( removeFiles) {
+ if (removeFiles) {
heapElementManager.removeFiles();
}
}
@@ -789,6 +790,35 @@
}
@Override
+ public DataRecordIdentifier nextDataRecordIdentifier(
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final HeapIdNode currentHeapIdNode;
+ try {
+ currentHeapIdNode = (HeapIdNode) idNodeSearchMayBeNotExist(dataRecordIdentifier);
+ } catch (HeapException exception) {
+ final String message = "failed get current node";
+ logger.fatal(message);
+ throw new HeapException(message, exception);
+ }
+ final HeapIdNode nextHeapIdNode;
+ try {
+ nextHeapIdNode = (HeapIdNode) idNodeTree.next(currentHeapIdNode);
+ } catch (RBTException exception) {
+ final String message = "failed get next node";
+ logger.fatal(message);
+ throw new HeapException(message, exception);
+ }
+ final DataRecordIdentifier element;
+ if (nextHeapIdNode == null) {
+ element = null;
+ } else {
+ element = nextHeapIdNode.getElement();
+ }
+ return element;
+ }
+
+ @Override
protected DataRecordIdentifier lastDataRecordIdentifierImpl()
throws HeapException {
try {
@@ -1057,40 +1087,9 @@
return file.getAbsolutePath();
}
- @NotStorableClass
- private class DataRecordIterator implements Iterator<DataRecordIdentifier> {
-
- private final Iterator<IRBTNode<DataRecordIdentifier>> iterator;
-
- public DataRecordIterator() {
- super();
- iterator = idNodeTree.iterator();
- }
-
- @Override
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @Override
- public DataRecordIdentifier next() {
- final IRBTNode<DataRecordIdentifier> nextRbtNode = iterator.next();
- try {
- return nextRbtNode.getElement();
- } catch (RBTException exception) {
- throw new RuntimeException(exception);// NOPMD
- }
- }
-
- @Override
- public void remove() {
- iterator.remove();
- }
- }
-
@Override
protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl() {
- return new DataRecordIterator();
+ return new DataRecordIterator(this);
}
@Override
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-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -28,6 +28,7 @@
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
+import net.sf.joafip.redblacktree.service.RedBlackTree;
@NotStorableClass
@DoNotTransform
@@ -136,9 +137,10 @@
* test append done correctly
*
* @throws HeapException
+ * @throws RBTException
*
*/
- public void testAppendRecord() throws HeapException {
+ public void testAppendRecord() throws HeapException, RBTException {
appendRecord();
heapElementManager.startService();
heapElementManager.openTransaction();
@@ -176,7 +178,7 @@
heapElementManager.stopService();
}
- public void testUpdateDataRecord() throws HeapException {
+ public void testUpdateDataRecord() throws HeapException, RBTException {
appendRecord();
final long pos = record1pos;
@@ -271,7 +273,7 @@
heapElementManager.stopService();
}
- public void testChangeManageDataMode() throws HeapException {
+ public void testChangeManageDataMode() throws HeapException, RBTException {
appendRecord();
final long pos = record1pos;
heapElementManager.startService();
@@ -346,8 +348,9 @@
* append two records
*
* @throws HeapException
+ * @throws RBTException
*/
- private void appendRecord() throws HeapException {
+ private void appendRecord() throws HeapException, RBTException {
appendHeaderInEmptyFile();
heapElementManager.startService();
heapElementManager.openTransaction();
@@ -361,6 +364,7 @@
* area size: +
* 4 for crc32
*/);
+
// heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
// -1L/* prev pos */, dataRecordIdentifier/* id */,
// false/* free */, dataSize, dataSize
@@ -369,6 +373,10 @@
// * 4 for crc32
// */);
heapElementManager.appendHeapFileRecord(heapRecordAppened1);
+
+ IRBTNode<DataRecordIdentifier> idNode = heapRecordAppened1.getIdNode();
+ idNode.setColor(RedBlackTree.BLACK);
+
try {
assert false;
} catch (AssertionError error) {
@@ -405,6 +413,10 @@
// * crc32
// */);
heapElementManager.appendHeapFileRecord(heapRecordAppened2);
+
+ idNode = heapRecordAppened2.getIdNode();
+ idNode.setColor(RedBlackTree.BLACK);
+
heapRecordAppened2.setDataAssociated(testData);
heapElementManager.closeTransaction();
heapElementManager.stopService();
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java 2012-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -106,6 +106,11 @@
heapIdNode.setLeftPositionInFile(2);
heapIdNode.setRightPositionInFile(3);
heapIdNode.setParentPositionInFile(4);
+ try {
+ heapIdNode.setBlack();
+ } catch (Exception exception) {
+ // ignore error
+ }
// byte[] data = heapRecord.getDataAssociated();
final byte[] data = new byte[10];
heapRecord.setDataAssociated(data);
@@ -133,6 +138,11 @@
heapFreeNode.setLeftPositionInFile(91);
heapFreeNode.setRightPositionInFile(92);
heapFreeNode.setParentPositionInFile(93);
+ try {
+ heapFreeNode.setBlack();
+ } catch (Exception exception) {
+ // ignore error
+ }
// to force write
heapRecord.setValueIsChangedValueToSave();
heapRecord.writeToFile();
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-11-28 12:15:18 UTC (rev 3164)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapFileCheckerDataManager.java 2012-11-28 12:15:42 UTC (rev 3165)
@@ -186,6 +186,19 @@
}
@Override
+ public DataRecordIdentifier nextDataRecordIdentifier(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ final DataRecordIdentifier dr1 = heapFileDataManager
+ .nextDataRecordIdentifier(dataRecordIdentifier);
+ final DataRecordIdentifier dr2 = heapMultiFileDataManager
+ .nextDataRecordIdentifier(dataRecordIdentifier);
+ if (dr1.value != dr2.value) {
+ throw new HeapException(NOT_SAME_DATA_RECORD);
+ }
+ return dr1;
+ }
+
+ @Override
public DataRecordIdentifier lastDataRecordIdentifier() throws HeapException {
final DataRecordIdentifier dr1 = heapFileDataManager
.lastDataRecordIdentifier();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|