Skip to content

Commit

Permalink
Embryo of combined SchemaIndexProvider
Browse files Browse the repository at this point in the history
just setting the general structure, or trying it out rather.
  • Loading branch information
tinwelint committed Aug 4, 2017
1 parent 853189a commit ec0373a
Show file tree
Hide file tree
Showing 6 changed files with 595 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema.combined;

import java.io.File;
import java.io.IOException;

import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.helpers.collection.BoundedIterable;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexAccessor;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.storageengine.api.schema.IndexReader;

import static java.util.Arrays.asList;

import static org.neo4j.helpers.collection.Iterators.concatResourceIterators;

class CombinedIndexAccessor implements IndexAccessor
{
private final IndexAccessor boostAccessor;
private final IndexAccessor fallbackAccessor;

CombinedIndexAccessor( IndexAccessor boostAccessor, IndexAccessor fallbackAccessor )
{
this.boostAccessor = boostAccessor;
this.fallbackAccessor = fallbackAccessor;
}

@Override
public void drop() throws IOException
{
try
{
boostAccessor.drop();
}
finally
{
fallbackAccessor.drop();
}
}

@Override
public IndexUpdater newUpdater( IndexUpdateMode mode )
{
return new CombinedIndexUpdater( boostAccessor.newUpdater( mode ), fallbackAccessor.newUpdater( mode ) );
}

@Override
public void force() throws IOException
{
boostAccessor.force();
fallbackAccessor.force();
}

@Override
public void close() throws IOException
{
try
{
boostAccessor.close();
}
finally
{
fallbackAccessor.close();
}
}

@Override
public IndexReader newReader()
{
return new CombinedIndexReader( boostAccessor.newReader(), fallbackAccessor.newReader() );
}

@Override
public BoundedIterable<Long> newAllEntriesReader()
{
return null;
}

@Override
public ResourceIterator<File> snapshotFiles() throws IOException
{
return concatResourceIterators(
asList( boostAccessor.snapshotFiles(), fallbackAccessor.snapshotFiles() ).iterator() );
}

@Override
public void verifyDeferredConstraints( PropertyAccessor propertyAccessor )
throws IndexEntryConflictException, IOException
{
boostAccessor.verifyDeferredConstraints( propertyAccessor );
fallbackAccessor.verifyDeferredConstraints( propertyAccessor );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema.combined;

import java.io.IOException;
import java.util.Collection;

import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.storageengine.api.schema.IndexSample;

import static org.neo4j.kernel.impl.index.schema.combined.CombinedSchemaIndexProvider.combineSamples;
import static org.neo4j.kernel.impl.index.schema.combined.CombinedSchemaIndexProvider.select;

class CombinedIndexPopulator implements IndexPopulator
{
private final IndexPopulator boostPopulator;
private final IndexPopulator fallbackPopulator;

CombinedIndexPopulator( IndexPopulator boostPopulator, IndexPopulator fallbackPopulator )
{
this.boostPopulator = boostPopulator;
this.fallbackPopulator = fallbackPopulator;
}

@Override
public void create() throws IOException
{
boostPopulator.create();
fallbackPopulator.create();
}

@Override
public void drop() throws IOException
{
try
{
boostPopulator.drop();
}
finally
{
fallbackPopulator.drop();
}
}

@Override
public void add( Collection<? extends IndexEntryUpdate<?>> updates ) throws IndexEntryConflictException, IOException
{
for ( IndexEntryUpdate<?> update : updates )
{
add( update );
}
}

@Override
public void add( IndexEntryUpdate<?> update ) throws IndexEntryConflictException, IOException
{
select( update.values(), boostPopulator, fallbackPopulator ).add( update );
}

@Override
public void verifyDeferredConstraints( PropertyAccessor propertyAccessor )
throws IndexEntryConflictException, IOException
{
boostPopulator.verifyDeferredConstraints( propertyAccessor );
fallbackPopulator.verifyDeferredConstraints( propertyAccessor );
}

@Override
public IndexUpdater newPopulatingUpdater( PropertyAccessor accessor ) throws IOException
{
return new CombinedIndexUpdater(
boostPopulator.newPopulatingUpdater( accessor ),
fallbackPopulator.newPopulatingUpdater( accessor ) );
}

@Override
public void close( boolean populationCompletedSuccessfully ) throws IOException
{
try
{
boostPopulator.close( populationCompletedSuccessfully );
}
finally
{
fallbackPopulator.close( populationCompletedSuccessfully );
}
}

@Override
public void markAsFailed( String failure ) throws IOException
{
try
{
boostPopulator.markAsFailed( failure );
}
finally
{
fallbackPopulator.markAsFailed( failure );
}
}

@Override
public void includeSample( IndexEntryUpdate update )
{
boostPopulator.includeSample( update );
fallbackPopulator.includeSample( update );
}

@Override
public void configureSampling( boolean onlineSampling )
{
boostPopulator.configureSampling( onlineSampling );
fallbackPopulator.configureSampling( onlineSampling );
}

@Override
public IndexSample sampleResult()
{
return combineSamples( boostPopulator.sampleResult(), fallbackPopulator.sampleResult() );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema.combined;

import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException;
import org.neo4j.kernel.api.schema.IndexQuery;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.IndexSampler;
import org.neo4j.values.storable.Value;

import static org.neo4j.kernel.impl.index.schema.combined.CombinedSchemaIndexProvider.select;

class CombinedIndexReader implements IndexReader
{
private final IndexReader boostReader;
private final IndexReader fallbackReader;

CombinedIndexReader( IndexReader boostReader, IndexReader fallbackReader )
{
this.boostReader = boostReader;
this.fallbackReader = fallbackReader;
}

@Override
public void close()
{
try
{
boostReader.close();
}
finally
{
fallbackReader.close();
}
}

@Override
public long countIndexedNodes( long nodeId, Value... propertyValues )
{
return select( propertyValues, boostReader, fallbackReader ).countIndexedNodes( nodeId, propertyValues );
}

@Override
public IndexSampler createSampler()
{
return new CombinedIndexSampler( boostReader.createSampler(), fallbackReader.createSampler() );
}

@Override
public PrimitiveLongIterator query( IndexQuery... predicates ) throws IndexNotApplicableKernelException
{
throw new UnsupportedOperationException( "Tricky stuff, not implemented yet" );
}

@Override
public boolean hasFullNumberPrecision()
{
// Since we know that boost reader can do this we return true
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema.combined;

import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.storageengine.api.schema.IndexSample;
import org.neo4j.storageengine.api.schema.IndexSampler;

import static org.neo4j.kernel.impl.index.schema.combined.CombinedSchemaIndexProvider.combineSamples;

class CombinedIndexSampler implements IndexSampler
{
private final IndexSampler boostSampler;
private final IndexSampler fallbackSampler;

CombinedIndexSampler( IndexSampler boostSampler, IndexSampler fallbackSampler )
{
this.boostSampler = boostSampler;
this.fallbackSampler = fallbackSampler;
}

@Override
public IndexSample sampleIndex() throws IndexNotFoundKernelException
{
return combineSamples( boostSampler.sampleIndex(), fallbackSampler.sampleIndex() );
}
}

0 comments on commit ec0373a

Please sign in to comment.