Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring includes two things: - remove batching from NonUniqueLuceneIndexPopulator because similar batching already happens in BatchingMultipleIndexPopulator higher in the stack; - pull out populating updaters from index populators, make them top-level classes and add tests; this is done to avoid code duplication and for better testability.
- Loading branch information
Showing
8 changed files
with
741 additions
and
143 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...rc/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulatingUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.api.impl.schema.populator; | ||
|
||
import org.apache.lucene.document.Document; | ||
import org.apache.lucene.index.Term; | ||
|
||
import java.io.IOException; | ||
|
||
import org.neo4j.collection.primitive.PrimitiveLongSet; | ||
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; | ||
import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; | ||
import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter; | ||
import org.neo4j.kernel.api.index.IndexUpdater; | ||
import org.neo4j.kernel.api.index.NodePropertyUpdate; | ||
import org.neo4j.kernel.impl.api.index.UpdateMode; | ||
|
||
/** | ||
* An {@link IndexUpdater} used while index population is in progress. Takes special care of node property additions | ||
* and changes applying them via {@link LuceneIndexWriter#updateDocument(Term, Document)} to make sure no duplicated | ||
* documents are inserted. | ||
*/ | ||
public abstract class LuceneIndexPopulatingUpdater implements IndexUpdater | ||
{ | ||
private final LuceneIndexWriter writer; | ||
|
||
public LuceneIndexPopulatingUpdater( LuceneIndexWriter writer ) | ||
{ | ||
this.writer = writer; | ||
} | ||
|
||
@Override | ||
public void process( NodePropertyUpdate update ) throws IOException, IndexEntryConflictException | ||
{ | ||
long nodeId = update.getNodeId(); | ||
|
||
switch ( update.getUpdateMode() ) | ||
{ | ||
case ADDED: | ||
added( update ); | ||
writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), | ||
LuceneDocumentStructure.documentRepresentingProperty( nodeId, update.getValueAfter() ) ); | ||
break; | ||
case CHANGED: | ||
changed( update ); | ||
writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), | ||
LuceneDocumentStructure.documentRepresentingProperty( nodeId, update.getValueAfter() ) ); | ||
break; | ||
case REMOVED: | ||
removed( update ); | ||
writer.deleteDocuments( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) ); | ||
break; | ||
default: | ||
throw new IllegalStateException( "Unknown update mode " + update.getUpdateMode() ); | ||
} | ||
} | ||
|
||
@Override | ||
public final void remove( PrimitiveLongSet nodeIds ) | ||
{ | ||
throw new UnsupportedOperationException( "Should not remove from populating index" ); | ||
} | ||
|
||
/** | ||
* Method is invoked when {@link NodePropertyUpdate} with {@link UpdateMode#ADDED} is processed. | ||
* | ||
* @param update the update being processed. | ||
*/ | ||
protected abstract void added( NodePropertyUpdate update ); | ||
|
||
/** | ||
* Method is invoked when {@link NodePropertyUpdate} with {@link UpdateMode#CHANGED} is processed. | ||
* | ||
* @param update the update being processed. | ||
*/ | ||
protected abstract void changed( NodePropertyUpdate update ); | ||
|
||
/** | ||
* Method is invoked when {@link NodePropertyUpdate} with {@link UpdateMode#REMOVED} is processed. | ||
* | ||
* @param update the update being processed. | ||
*/ | ||
protected abstract void removed( NodePropertyUpdate update ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ava/org/neo4j/kernel/api/impl/schema/populator/NonUniqueLuceneIndexPopulatingUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.api.impl.schema.populator; | ||
|
||
import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; | ||
import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter; | ||
import org.neo4j.kernel.api.index.NodePropertyUpdate; | ||
import org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler; | ||
|
||
/** | ||
* A {@link LuceneIndexPopulatingUpdater} used for non-unique Lucene schema indexes. | ||
*/ | ||
public class NonUniqueLuceneIndexPopulatingUpdater extends LuceneIndexPopulatingUpdater | ||
{ | ||
private final NonUniqueIndexSampler sampler; | ||
|
||
public NonUniqueLuceneIndexPopulatingUpdater( LuceneIndexWriter writer, NonUniqueIndexSampler sampler ) | ||
{ | ||
super( writer ); | ||
this.sampler = sampler; | ||
} | ||
|
||
@Override | ||
protected void added( NodePropertyUpdate update ) | ||
{ | ||
String encodedValue = LuceneDocumentStructure.encodedStringValue( update.getValueAfter() ); | ||
sampler.include( encodedValue ); | ||
} | ||
|
||
@Override | ||
protected void changed( NodePropertyUpdate update ) | ||
{ | ||
String encodedValueBefore = LuceneDocumentStructure.encodedStringValue( update.getValueBefore() ); | ||
sampler.exclude( encodedValueBefore ); | ||
|
||
String encodedValueAfter = LuceneDocumentStructure.encodedStringValue( update.getValueAfter() ); | ||
sampler.include( encodedValueAfter ); | ||
} | ||
|
||
@Override | ||
protected void removed( NodePropertyUpdate update ) | ||
{ | ||
String removedValue = LuceneDocumentStructure.encodedStringValue( update.getValueBefore() ); | ||
sampler.exclude( removedValue ); | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.