Author: vgritsenko
Date: Fri Oct 27 20:18:08 2006
New Revision: 468625
URL: http://svn.apache.org/viewvc?view=rev&rev=468625
Log:
<action dev="VG" type="fix" fixes-bug="31159">
Add pagecount configuration parameter to Paged based
filers: HashFiler, BTreeFiler.
</action>
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/data/Key.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java
xml/xindice/trunk/status.xml
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/data/Key.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/data/Key.java?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/data/Key.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/data/Key.java Fri Oct 27 20:18:08 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * CVS $Id$
+ * $Id$
*/
package org.apache.xindice.core.data;
@@ -21,7 +21,7 @@
/**
* Key extends Value by providing a hash value for the Key.
*
- * @version CVS $Revision$, $Date$
+ * @version $Revision$, $Date$
*/
public final class Key extends Value {
private int hash = 0;
@@ -63,11 +63,10 @@
public boolean equals(Value value) {
if (value instanceof Key) {
Key key = (Key) value;
- return getHash() == key.getHash() ? compareTo(key) == 0
- : false;
- } else {
- return super.equals(value);
+ return getHash() == key.getHash() && compareTo(key) == 0;
}
+
+ return super.equals(value);
}
public int hashCode() {
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java Fri Oct 27 20:18:08 2006
@@ -88,6 +88,7 @@
private BTreeRootInfo rootInfo;
private BTreeNode rootNode;
+
public BTree() {
super();
fileHeader = (BTreeFileHeader) getFileHeader();
@@ -958,10 +959,7 @@
////////////////////////////////////////////////////////////////////
public FileHeader createFileHeader() {
- BTreeFileHeader header = new BTreeFileHeader();
- header.setPageCount(1);
- header.setTotalCount(1);
- return header;
+ return new BTreeFileHeader();
}
public FileHeader createFileHeader(boolean read) throws IOException {
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java Fri Oct 27 20:18:08 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * CVS $Id$
+ * $Id$
*/
package org.apache.xindice.core.filer;
@@ -40,9 +40,10 @@
/**
* BTreeFiler is a Filer implementation based on the BTree class.
*
- * @version CVS $Revision$, $Date$
+ * @version $Revision$, $Date$
*/
-public final class BTreeFiler extends BTree implements Filer {
+public final class BTreeFiler extends BTree
+ implements Filer {
private static final Log log = LogFactory.getLog(BTreeFiler.class);
@@ -174,14 +175,9 @@
return new BTreeFilerRecordSet();
}
- public void flush() throws DBException {
- super.flush();
- }
-
/**
* BTreeFilerRecordSet
*/
-
private class BTreeFilerRecordSet implements RecordSet, BTreeCallback {
private List keys = new ArrayList();
private Iterator iter;
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java Fri Oct 27 20:18:08 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * CVS $Id$
+ * $Id$
*/
package org.apache.xindice.core.filer;
@@ -26,6 +26,7 @@
import org.apache.xindice.core.data.Record;
import org.apache.xindice.core.data.RecordSet;
import org.apache.xindice.core.data.Value;
+import org.apache.xindice.util.Configuration;
import java.io.DataInput;
import java.io.DataOutput;
@@ -45,9 +46,10 @@
* data and allocate Record space.
*
* @deprecated This class has been temporarily deprecated by BTreeFiler.
- * @version CVS $Revision$, $Date$
+ * @version $Revision$, $Date$
*/
-public final class HashFiler extends Paged implements Filer {
+public final class HashFiler extends Paged
+ implements Filer {
private static final Log log = LogFactory.getLog(HashFiler.class);
@@ -56,12 +58,6 @@
*/
protected static final byte RECORD = 1;
- /**
- * Name of the configuration attribute pagecount
- */
- private static final String PAGECOUNT = "pagecount";
-
-
private HashFileHeader fileHeader;
@@ -78,11 +74,11 @@
return "HashFiler";
}
- public boolean create() throws DBException {
- fileHeader.setPageCount(getConfig().getLongAttribute(PAGECOUNT,
- fileHeader.getPageCount()));
+ public void setConfig(Configuration config) {
+ super.setConfig(config);
+ // Since pageCount is used as a hash table size, all pageCount pages
+ // are considered used; so set totalCount to pageCount.
fileHeader.setTotalCount(fileHeader.getPageCount());
- return super.create();
}
private Page seekRecordPage(Key key) throws IOException {
@@ -290,13 +286,24 @@
try {
long pageNum = 0;
- while (pageNum < fileHeader.getTotalCount()) {
+ // Iterate over main hash table...
+ while (pageNum < fileHeader.getPageCount()) {
Page p = getPage(pageNum);
HashPageHeader ph = (HashPageHeader) p.getPageHeader();
if (ph.getStatus() == RECORD) {
keys.add(p.getKey());
}
+ // ... and over collision chains
+ while (ph.getNextCollision() != NO_PAGE) {
+ long pn = ph.getNextCollision();
+ p = getPage(pn);
+ ph = (HashPageHeader) p.getPageHeader();
+ if (ph.getStatus() == RECORD) {
+ keys.add(p.getKey());
+ }
+ }
+
pageNum++;
}
@@ -351,21 +358,27 @@
* HashFileHeader
*/
private final class HashFileHeader extends FileHeader {
- private long totalBytes = 0;
+ private long totalBytes;
public HashFileHeader() {
+ super();
+ // For hash filer, totalCount >= pageCount. See setConfig().
+ setTotalCount(getPageCount());
}
public HashFileHeader(long pageCount) {
super(pageCount);
+ setTotalCount(getPageCount());
}
public HashFileHeader(long pageCount, int pageSize) {
super(pageCount, pageSize);
+ setTotalCount(getPageCount());
}
public HashFileHeader(boolean read) throws IOException {
super(read);
+ setTotalCount(getPageCount());
}
public synchronized void read(RandomAccessFile raf) throws IOException {
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java Fri Oct 27 20:18:08 2006
@@ -87,17 +87,22 @@
/**
* Name of the configuration attribute "pagesize"
*/
- private static final String CONFIG_PAGESIZE = "pagesize";
+ protected static final String CONFIG_PAGESIZE = "pagesize";
+
+ /**
+ * Name of the configuration attribute "pagecount"
+ */
+ protected static final String CONFIG_PAGECOUNT = "pagecount";
/**
* Name of the configuration attribute "maxkeysize"
*/
- private static final String CONFIG_KEYSIZE_MAX = "maxkeysize";
+ protected static final String CONFIG_KEYSIZE_MAX = "maxkeysize";
/**
* Name of the configuration attribute "max-descriptors"
*/
- private static final String CONFIG_DESCRIPTORS_MAX = "max-descriptors";
+ protected static final String CONFIG_DESCRIPTORS_MAX = "max-descriptors";
/**
* Default value of the "pagesize".
@@ -105,6 +110,16 @@
private static final int DEFAULT_PAGESIZE = 4096;
/**
+ * Default value of the "pagecount".
+ */
+ private static final int DEFAULT_PAGECOUNT = 1024;
+
+ /**
+ * File header size
+ */
+ private static final int FILE_HEADER_SIZE = 4096;
+
+ /**
* Default value of the "maxkeysize".
*/
private static final int DEFAULT_KEYSIZE_MAX = 256;
@@ -209,6 +224,15 @@
public void setConfig(Configuration config) {
this.config = config;
+ // Read paged config
+ fileHeader.setPageSize(config.getIntAttribute(CONFIG_PAGESIZE,
+ fileHeader.getPageSize()));
+ fileHeader.setPageCount(config.getLongAttribute(CONFIG_PAGECOUNT,
+ fileHeader.getPageCount()));
+ fileHeader.setMaxKeySize(config.getShortAttribute(CONFIG_KEYSIZE_MAX,
+ fileHeader.getMaxKeySize()));
+ descriptorsMax = getConfig().getIntAttribute(CONFIG_DESCRIPTORS_MAX,
+ descriptorsMax);
}
public Configuration getConfig() {
@@ -567,10 +591,6 @@
}
public boolean create() throws DBException {
- fileHeader.setPageSize(config.getIntAttribute(CONFIG_PAGESIZE,
- fileHeader.getPageSize()));
- fileHeader.setMaxKeySize(config.getShortAttribute(CONFIG_KEYSIZE_MAX,
- fileHeader.getMaxKeySize()));
try {
createFile();
fileHeader.write();
@@ -597,15 +617,11 @@
public synchronized boolean open() throws DBException {
RandomAccessFile raf = null;
try {
- // Initialize configurable parameters
- descriptorsMax = getConfig().getIntAttribute(CONFIG_DESCRIPTORS_MAX,
- descriptorsMax);
-
if (exists()) {
raf = getDescriptor();
fileHeader.read();
- // These are the only properties that can be changed after creation
+ // This is the only property that can be changed after creation
fileHeader.setMaxKeySize(config.getShortAttribute(CONFIG_KEYSIZE_MAX,
fileHeader.getMaxKeySize()));
@@ -879,22 +895,38 @@
/**
* Paged file's header
*/
- public abstract class FileHeader {
- private boolean dirty = false;
+ protected abstract class FileHeader {
+ private boolean dirty;
private int workSize;
private short headerSize;
+
+ /**
+ * Size of the page in bytes.
+ */
private int pageSize;
+
+ /**
+ * Number of pages initially allocated for the file.
+ * Has a special (historical) meaning for HashFiler.
+ */
private long pageCount;
+
+ /**
+ * Number of pages used by the filer. Initially set to 0.
+ * Has somewhat different (historical) meaning for HashFiler.
+ */
private long totalCount;
+
private long firstFreePage = -1;
private long lastFreePage = -1;
private byte pageHeaderSize = 64;
private short maxKeySize = DEFAULT_KEYSIZE_MAX;
private long recordCount;
+
public FileHeader() {
- this(1024);
+ this(DEFAULT_PAGECOUNT);
}
public FileHeader(long pageCount) {
@@ -904,8 +936,7 @@
public FileHeader(long pageCount, int pageSize) {
this.pageSize = pageSize;
this.pageCount = pageCount;
- this.totalCount = 0;
- this.headerSize = (short) 4096;
+ this.headerSize = (short) FILE_HEADER_SIZE;
calculateWorkSize();
}
@@ -1127,7 +1158,7 @@
/**
* Paged file page's header
*/
- public abstract static class PageHeader implements Streamable {
+ protected abstract static class PageHeader implements Streamable {
private boolean dirty;
private byte status = UNUSED;
private short keyLen;
@@ -1254,7 +1285,7 @@
/**
* Paged file's page
*/
- public final class Page implements Comparable {
+ protected final class Page implements Comparable {
/**
* This page number
*/
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java Fri Oct 27 20:18:08 2006
@@ -41,31 +41,35 @@
*/
public class FilerTestBase extends TestCase {
- static public final String TEST_COLLECTION_NAME = "tests";
- static public final Key TEST_KEY = new Key("test.xml");
- static public final Value TEST_VALUE = new Value("<test><test></test><test>Just a test</test></test>");
- static public final Value TEST_VALUE_2 = new Value("<test><test></test><test>Just a test 2</test></test>");
- static public final Value TEST_VALUE_3 = new Value("<test><test></test><test>Just a test 3</test></test>");
+ public static final String TEST_COLLECTION_NAME = "tests";
+ public static final Key TEST_KEY = new Key("test.xml");
+ public static final Value TEST_VALUE = new Value("<test><test></test><test>Just a test</test></test>");
+ public static final Value TEST_VALUE_2 = new Value("<test><test></test><test>Just a test 2</test></test>");
+ public static final Value TEST_VALUE_3 = new Value("<test><test></test><test>Just a test 3</test></test>");
+
+ private static final File ROOT = new File(TEST_COLLECTION_NAME);
/**
- * Key size for the testLargeKey. FSFiler will set smaller value for its test.
+ * Key size for the testLargeKey. FSFiler and HashFiler will set smaller value
+ * for their tests.
*/
protected int LARGE_KEY_SIZE = 8192 + 32;
-
- private static final File root = new File(TEST_COLLECTION_NAME);
private Filer filer;
+
public FilerTestBase(String name, Filer filer) {
super(name);
this.filer = filer;
}
public void setUp() throws Exception {
- root.mkdir();
- filer.setLocation(root, TEST_COLLECTION_NAME);
+ ROOT.mkdir();
+ filer.setLocation(ROOT, TEST_COLLECTION_NAME);
// FSFiler needs location attribute
- filer.setConfig(new Configuration(DOMParser.toDocument("<filer location=\"" + TEST_COLLECTION_NAME + "\" />")));
+ String config = "<filer location='" + TEST_COLLECTION_NAME + "' " +
+ "pagecount='128' pagesize='4096'/>";
+ filer.setConfig(new Configuration(DOMParser.toDocument(config)));
if (!filer.exists()) {
filer.create();
}
@@ -84,11 +88,11 @@
filer.close();
}
- String[] files = root.list();
+ String[] files = ROOT.list();
for (int i = 0; i < files.length; i++) {
- new File(root, files[i]).delete();
+ new File(ROOT, files[i]).delete();
}
- root.delete();
+ ROOT.delete();
super.tearDown();
}
@@ -105,7 +109,7 @@
RecordSet set = filer.getRecordSet();
assertEquals(result.getValue(), set.getNextRecord().getValue());
- assertTrue(set.hasMoreRecords() == false);
+ assertFalse(set.hasMoreRecords());
filer.deleteRecord(TEST_KEY);
assertEquals(0, filer.getRecordCount());
@@ -195,7 +199,7 @@
assertEquals(1, filer.getRecordCount());
// These should all just fail silently.
- assertTrue(false == filer.deleteRecord(null));
+ assertFalse(filer.deleteRecord(null));
assertEquals(1, filer.getRecordCount());
}
@@ -204,7 +208,7 @@
assertEquals(1, filer.getRecordCount());
// These should all just fail silently.
- assertTrue(false == filer.deleteRecord(new Key("")));
+ assertFalse(filer.deleteRecord(new Key("")));
assertEquals(1, filer.getRecordCount());
}
@@ -213,7 +217,7 @@
assertEquals(1, filer.getRecordCount());
// These should all just fail silently.
- assertTrue(false == filer.deleteRecord(new Key("non-existant-key")));
+ assertFalse(filer.deleteRecord(new Key("non-existant-key")));
assertEquals(1, filer.getRecordCount());
}
@@ -276,6 +280,8 @@
}
assertTrue(filer.getRecordCount() == 0);
+ RecordSet result = filer.getRecordSet();
+ assertTrue(!result.hasMoreRecords());
}
public void testConcurrentInsert() throws Exception {
Modified: xml/xindice/trunk/status.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=468625&r1=468624&r2=468625
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Fri Oct 27 20:18:08 2006
@@ -73,7 +73,11 @@
</todo>
<changes>
- <release version="1.1b5-dev" date="Oct 24 2006">
+ <release version="1.1b5-dev" date="Oct 27 2006">
+ <action dev="VG" type="fix" fixes-bug="31159">
+ Add pagecount configuration parameter to Paged based
+ filers: HashFiler, BTreeFiler.
+ </action>
<action dev="VG" type="fix">
HashFiler did not allocate root page correctly.
</action>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.