Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,31 @@


public class BerkeleyDbBatchInserterIndex implements BatchInserterIndex {

// private final boolean createdNow;
// private Map<String, LruCache<String, Collection<Long>>> cache;

private final Map<String, Database> dbs = new HashMap<String, Database>();

private final Pair<String, Boolean> storeDir;

private final IndexIdentifier identifier;


BerkeleyDbBatchInserterIndex( BerkeleyDbBatchInserterIndexProvider provider, BatchInserter inserter,
IndexIdentifier identifier, Map<String, String> config )
{
System.err.println( this.getClass() + " initing with id=" + identifier + " config=" + config.get( "provider" ) );

this.identifier = identifier;
String dbStoreDir = ( (BatchInserterImpl)inserter ).getStore();
storeDir =
BerkeleyDbDataSource.getStoreDir( dbStoreDir + "/index/bdb/" + identifier.itemClass.getSimpleName() + "/"
+ identifier.indexName );
// this.createdNow = storeDir.other();
}


@Override
public void add( long entityId, Map<String, Object> properties ) {
try {
Expand All @@ -88,15 +88,15 @@ public void add( long entityId, Map<String, Object> properties ) {
dos.writeLong( entityId );
dos.flush();
db.put( null, valueEntry, new DatabaseEntry( baus.toByteArray() ) );

dos.close();
}
} catch ( Exception e ) {
throw new RuntimeException( e );
}
}


public Database createDB( String key ) {
try {
EnvironmentConfig environmentConfig = new EnvironmentConfig();
Expand All @@ -116,9 +116,9 @@ public Database createDB( String key ) {
throw new RuntimeException( e );
}
}



@Override
public void updateOrAdd( long entityId, Map<String, Object> properties ) {
try {
Expand All @@ -127,9 +127,9 @@ public void updateOrAdd( long entityId, Map<String, Object> properties ) {
throw new RuntimeException( e );
}
}



@Override
public IndexHits<Long> get( String key, Object value ) {
ArrayList<Long> resultList = new ArrayList<Long>();
Expand All @@ -156,8 +156,8 @@ public IndexHits<Long> get( String key, Object value ) {
}
return new IndexHitsImpl<Long>( resultList, resultList.size() );
}


public void shutdown() {
System.err.println( "shutting down batch inserter index: " + identifier );
for ( Database db : dbs.values() ) {
Expand All @@ -168,32 +168,32 @@ public void shutdown() {
}
}
}


@Override
public void flush() {
// writerModified = true;
}


@Override
public IndexHits<Long> query( String key, Object queryOrQueryObject ) {
// TODO Auto-generated method stub
return null;
}


@Override
public IndexHits<Long> query( Object queryOrQueryObject ) {
// TODO Auto-generated method stub
return null;
}


@Override
public void setCacheCapacity( String key, int size ) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@
* are compatible with {@link Index}s from {@link LuceneIndexProvider}.
*/
public class BerkeleyDbBatchInserterIndexProvider implements BatchInserterIndexProvider {

private final BatchInserter inserter;
private final Map<IndexIdentifier, BerkeleyDbBatchInserterIndex> indexes =
new HashMap<IndexIdentifier, BerkeleyDbBatchInserterIndex>();
final IndexStore indexStore;


public BerkeleyDbBatchInserterIndexProvider( final BatchInserter inserter ) {
this.inserter = inserter;
indexStore = ( (BatchInserterImpl)inserter ).getIndexStore();

}


@Override
public BatchInserterIndex nodeIndex( String indexName, Map<String, String> config ) {
config( Node.class, indexName, config );
return index( new IndexIdentifier( Node.class, indexName ), config );
}


private Map<String, String> config( Class<? extends PropertyContainer> cls, String indexName, Map<String, String> config ) {
// TODO Doesn't look right
if ( config != null ) {
Expand All @@ -74,15 +74,15 @@ private Map<String, String> config( Class<? extends PropertyContainer> cls, Stri
return indexStore.get( cls, indexName );
}
}


@Override
public BatchInserterIndex relationshipIndex( String indexName, Map<String, String> config ) {
config( Relationship.class, indexName, config );
return index( new IndexIdentifier( Relationship.class, indexName ), config );
}


private BatchInserterIndex index( IndexIdentifier identifier, Map<String, String> config ) {
// We don't care about threads here... c'mon... it's a
// single-threaded batch inserter
Expand All @@ -93,8 +93,8 @@ private BatchInserterIndex index( IndexIdentifier identifier, Map<String, String
}
return index;
}


@Override
public void shutdown() {
System.err.println( "org.neo4j.index.bdbje.BerkeleyDbBatchInserterIndexProvider.shutdown()" );
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/neo4j/index/bdbje/BerkeleyDbCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class BerkeleyDbCommand extends XaCommand

static final byte NODE = (byte) 1;
static final byte RELATIONSHIP = (byte) 2;

final IndexIdentifier indexId;
final long[] entityIds;
final String key;
Expand Down Expand Up @@ -144,7 +144,7 @@ private static void writeLengthAndString( LogBuffer buffer, String string ) thro
buffer.putInt( chars.length );
buffer.put( chars );
}

static XaCommand readCommand( ReadableByteChannel channel, ByteBuffer buffer,
BerkeleyDbDataSource dataSource ) throws IOException
{
Expand Down Expand Up @@ -198,13 +198,13 @@ static XaCommand readCommand( ReadableByteChannel channel, ByteBuffer buffer,
{
return null;
}

Map<String, String> creationConfig = null;
if ( commandType == CREATE_COMMAND )
{
creationConfig = IoPrimitiveUtils.readMap( channel, buffer );
}

IndexIdentifier identifier = new IndexIdentifier( itemsClass, indexName );
switch ( commandType )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class BerkeleyDbDataSource extends LogBackedXaDataSource {

/**
* Constructs this data source.
*
*
* @param params
* XA parameters.
* @throws InstantiationException
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/org/neo4j/index/bdbje/BerkeleyDbTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BerkeleydbTransaction extends XaTransaction
new HashMap<IndexIdentifier, TxDataBoth>();
private final BerkeleyDbDataSource dataSource;

private final Map<IndexIdentifier,Collection<BerkeleyDbCommand>> commandMap =
private final Map<IndexIdentifier,Collection<BerkeleyDbCommand>> commandMap =
new HashMap<IndexIdentifier,Collection<BerkeleyDbCommand>>();

BerkeleydbTransaction( int identifier, XaLogicalLog xaLog,
Expand All @@ -60,13 +60,13 @@ <T extends PropertyContainer> void add( BerkeleyDbIndex<T> index, T entity,
TxDataBoth data = getTxData( index, true );
insert( index, entity, key, value, data.added( true ), data.removed( false ) );
}

private long getEntityId( PropertyContainer entity )
{
return entity instanceof Node ? ((Node) entity).getId() :
((Relationship) entity).getId();
}

<T extends PropertyContainer> TxDataBoth getTxData( BerkeleyDbIndex<T> index,
boolean createIfNotExists )
{
Expand All @@ -86,7 +86,7 @@ <T extends PropertyContainer> void remove( BerkeleyDbIndex<T> index, T entity,
TxDataBoth data = getTxData( index, true );
insert( index, entity, key, value, data.removed( true ), data.added( false ) );
}

private void queueCommand( BerkeleyDbCommand command )
{
IndexIdentifier indexId = command.indexId;
Expand All @@ -98,7 +98,7 @@ private void queueCommand( BerkeleyDbCommand command )
}
commands.add( command );
}

private <T extends PropertyContainer> void insert( BerkeleyDbIndex<T> index,
T entity, String key, Object value, TxData insertInto, TxData removeFrom )
{
Expand All @@ -121,7 +121,7 @@ <T extends PropertyContainer> Set<Long> getRemovedIds( BerkeleyDbIndex<T> index,
Set<Long> ids = removed.getEntityIds( key, value );
return ids != null ? ids : Collections.<Long>emptySet();
}

<T extends PropertyContainer> Set<Long> getAddedIds( BerkeleyDbIndex<T> index,
String key, Object value )
{
Expand All @@ -133,7 +133,7 @@ <T extends PropertyContainer> Set<Long> getAddedIds( BerkeleyDbIndex<T> index,
Set<Long> ids = added.getEntityIds( key, value );
return ids != null ? ids : Collections.<Long>emptySet();
}

private <T extends PropertyContainer> TxData addedTxDataOrNull( BerkeleyDbIndex<T> index )
{
TxDataBoth data = getTxData( index, false );
Expand All @@ -143,7 +143,7 @@ private <T extends PropertyContainer> TxData addedTxDataOrNull( BerkeleyDbIndex<
}
return data.added( false );
}

private <T extends PropertyContainer> TxData removedTxDataOrNull( BerkeleyDbIndex<T> index )
{
TxDataBoth data = getTxData( index, false );
Expand All @@ -153,12 +153,12 @@ private <T extends PropertyContainer> TxData removedTxDataOrNull( BerkeleyDbInde
}
return data.removed( false );
}

@Override
protected void doAddCommand( XaCommand command )
{ // we override inject command and manage our own in memory command list
}

@Override
protected void injectCommand( XaCommand command )
{
Expand All @@ -184,7 +184,7 @@ protected void doCommit()
((CreateCommand) command).config );
continue;
}

long[] entityIds = command.entityIds;
String key = command.key;
String value = command.value;
Expand Down Expand Up @@ -253,7 +253,7 @@ protected void doPrepare()
}
}
}

// TODO Fix duplicate code for-loop
for ( TxDataBoth txData : this.txData.values() )
{
Expand Down Expand Up @@ -296,21 +296,21 @@ public boolean isReadOnly()
}
return true;
}

// Bad name
private class TxDataBoth
{
private TxData add;
private TxData remove;
@SuppressWarnings("unchecked")
private final BerkeleyDbIndex index;

@SuppressWarnings("unchecked")
public TxDataBoth( BerkeleyDbIndex index )
{
this.index = index;
}

TxData added( boolean createIfNotExists )
{
if ( this.add == null && createIfNotExists )
Expand All @@ -319,7 +319,7 @@ TxData added( boolean createIfNotExists )
}
return this.add;
}

TxData removed( boolean createIfNotExists )
{
if ( this.remove == null && createIfNotExists )
Expand All @@ -328,7 +328,7 @@ TxData removed( boolean createIfNotExists )
}
return this.remove;
}

void close()
{
safeClose( add );
Expand Down
Loading