You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ka...@apache.org on 2013/04/10 10:02:29 UTC
svn commit: r1466361 - in
/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src:
main/java/org/apache/mavibot/btree/ test/java/org/apache/mavibot/btree/
Author: kayyagari
Date: Wed Apr 10 08:02:28 2013
New Revision: 1466361
URL: http://svn.apache.org/r1466361
Log:
o removed file parameters for data and journal storage
o create data and journal files under the configured data directory
Modified:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1466361&r1=1466360&r2=1466361&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java Wed Apr 10 08:02:28 2013
@@ -65,7 +65,7 @@ public class BTree<K, V>
public static final String DEFAULT_JOURNAL = "mavibot.log";
/** The default data file suffix */
- public static final String DATA_SUFFIX = ".data";
+ public static final String DATA_SUFFIX = ".db";
/** The default journal file suffix */
public static final String JOURNAL_SUFFIX = ".log";
@@ -324,30 +324,35 @@ public class BTree<K, V>
*/
public BTree( BTreeConfiguration<K, V> configuration ) throws IOException
{
- String fileName = configuration.getFileName();
- String journalName = configuration.getJournalName();
-
- if ( fileName == null )
+ String name = configuration.getName();
+
+ if( name == null )
+ {
+ throw new IllegalArgumentException( "BTree name cannot be null" );
+ }
+
+ String filePath = configuration.getFilePath();
+
+ if ( filePath == null )
{
type = BTreeTypeEnum.IN_MEMORY;
}
else
{
- file = new File( configuration.getFilePath(), fileName );
-
- String journalPath = configuration.getJournalPath();
-
- if ( journalPath == null )
+ File dir = new File( filePath );
+ if( !dir.exists() )
{
- journalPath = configuration.getFilePath();
+ boolean created = dir.mkdirs();
+ if( !created )
+ {
+ throw new IllegalStateException( "Could not create the directory " + filePath + " for storing data" );
+ }
}
+
+ this.file = new File( dir, configuration.getName() + DATA_SUFFIX );
- if ( journalName == null )
- {
- journalName = fileName + JOURNAL_SUFFIX;
- }
+ this.journal = new File( dir, file.getName() + JOURNAL_SUFFIX );
- journal = new File( journalPath, journalName );
type = BTreeTypeEnum.PERSISTENT;
}
@@ -383,7 +388,7 @@ public class BTree<K, V>
public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
throws IOException
{
- this( name, null, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
+ this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
}
@@ -395,64 +400,54 @@ public class BTree<K, V>
public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
throws IOException
{
- this( name, null, null, keySerializer, valueSerializer, pageSize );
+ this( name, null, keySerializer, valueSerializer, pageSize );
}
/**
* Creates a new BTree with a default page size and a comparator, with an associated file.
- *
- * @param file The file storing the BTree data
* @param comparator The comparator to use
* @param serializer The serializer to use
*/
- public BTree( String name, String path, String file, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer )
+ public BTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
throws IOException
{
- this( name, path, file, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
+ this( name, path, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
}
/**
* Creates a new BTree with a specific page size and a comparator, with an associated file.
- *
- * @param file The file storing the BTree data
+ * @param pageSize The number of elements we can store in a page
* @param comparator The comparator to use
* @param serializer The serializer to use
- * @param pageSize The number of elements we can store in a page
*/
- public BTree( String name, String path, String file, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer,
+ public BTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
int pageSize )
throws IOException
{
btreeHeader = new BTreeHeader();
btreeHeader.setName( name );
- if ( ( path == null ) && ( file == null ) )
+ if ( path == null )
{
type = BTreeTypeEnum.IN_MEMORY;
}
else
{
- if ( new File( path, file ).exists() )
+ File dir = new File( path );
+ if( !dir.exists() )
{
- this.file = new File( path, file );
- }
- else
- {
- this.file = new File( path, file + DATA_SUFFIX );
+ boolean created = dir.mkdirs();
+ if( !created )
+ {
+ throw new IllegalStateException( "Could not create the directory " + path + " for storing data" );
+ }
}
+
+ this.file = new File( dir, name + DATA_SUFFIX );
- if ( new File( path, file + JOURNAL_SUFFIX ).exists() )
- {
- this.journal = new File( path, file );
- }
- else
- {
- this.journal = new File( path, file + JOURNAL_SUFFIX );
- }
+ this.journal = new File( dir, file.getName() + JOURNAL_SUFFIX );
type = BTreeTypeEnum.PERSISTENT;
}
Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java?rev=1466361&r1=1466360&r2=1466361&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java Wed Apr 10 08:02:28 2013
@@ -54,11 +54,6 @@ public class BTreeConfiguration<K, V>
*/
private String filePath;
- /**
- * The BTree file's name.
- */
- private String fileName;
-
/**
* The maximum delay to wait before a revision is considered as unused.
* This delay is necessary so that a read that does not ends does not
@@ -74,11 +69,6 @@ public class BTreeConfiguration<K, V>
*/
private long journalSize = 10 * 1024 * 1024L;
- /** The path where the journal will be stored. Default to the local
- * temporary directory.
- */
- private String journalPath;
-
/**
* The journal's name. Default to "mavibot.log".
*/
@@ -232,42 +222,6 @@ public class BTreeConfiguration<K, V>
/**
- * @return the file name
- */
- public String getFileName()
- {
- return fileName;
- }
-
-
- /**
- * @param fileName the file name to set
- */
- public void setFileName( String fileName )
- {
- this.fileName = fileName;
- }
-
-
- /**
- * @return the journalPath
- */
- public String getJournalPath()
- {
- return journalPath;
- }
-
-
- /**
- * @param journalPath the journalPath to set
- */
- public void setJournalPath( String journalPath )
- {
- this.journalPath = journalPath;
- }
-
-
- /**
* @return the journal name
*/
public String getJournalName()
@@ -317,7 +271,7 @@ public class BTreeConfiguration<K, V>
*/
public void setName( String name )
{
- this.name = name;
+ this.name = name.trim();
}
Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java?rev=1466361&r1=1466360&r2=1466361&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java Wed Apr 10 08:02:28 2013
@@ -114,6 +114,7 @@ public class BTreeConfigurationTest
public void testConfigurationBasic() throws IOException, KeyNotFoundException
{
BTreeConfiguration<Integer, String> config = new BTreeConfiguration<Integer, String>();
+ config.setName( "basic" );
config.setPageSize( 32 );
config.setSerializers( new IntSerializer(), new StringSerializer() );
@@ -159,7 +160,7 @@ public class BTreeConfigurationTest
config.setSerializers( new IntSerializer(), new StringSerializer() );
config.setFilePath( parent );
- config.setFileName( "mavibot" );
+ config.setName( "mavibot" );
// Create the BTree
BTree<Integer, String> btree = new BTree<Integer, String>( config );
Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java?rev=1466361&r1=1466360&r2=1466361&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java Wed Apr 10 08:02:28 2013
@@ -215,17 +215,17 @@ public class BTreeFlushTest
// Create the file, it will be deleted on exit
File tempFile = File.createTempFile( "testFlush", null );
String path = tempFile.getParent();
- String fileName = "mavibot";
tempFile.delete();
- File journal = new File( path, fileName + BTree.JOURNAL_SUFFIX );
- File data = new File( path, fileName + BTree.DATA_SUFFIX );
+ BTree<Integer, String> btree = new BTree<Integer, String>( "test", path, new IntSerializer(), new StringSerializer() );
+ btree.setName( "flush" );
+ btree.setPageSize( 8 );
+
+ File journal = btree.getJournal();
+ File data = btree.getFile();
+
try
{
- BTree<Integer, String> btree = new BTree<Integer, String>( "test", path, fileName, new IntSerializer(),
- new StringSerializer() );
- btree.setPageSize( 8 );
-
// Inject the values
for ( int value : sortedValues )
{
@@ -244,8 +244,7 @@ public class BTreeFlushTest
assertEquals( 0, journal.length() );
// Load the data into a new tree
- BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( "test", path, fileName,
- new IntSerializer(),
+ BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( "test", path, new IntSerializer(),
new StringSerializer() );
btree.setPageSize( 8 );
@@ -288,7 +287,6 @@ public class BTreeFlushTest
BTree<Long, String> btree = new BTree<Long, String>(
"test",
dataFile.getParent(),
- dataFile.getName(),
new LongSerializer(),
new StringSerializer() );
btree.setPageSize( 32 );
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org