From 710f1424969ea1d3c5e339e1107f1ed1cb50b972 Mon Sep 17 00:00:00 2001 From: Ragnar Mellbin Date: Wed, 23 Aug 2017 16:58:35 +0200 Subject: [PATCH] Add procedures for querying the bloom index --- enterprise/bloom-index/pom.xml | 6 ++ .../impl/bloom/BloomDocumentStructure.java | 12 +-- .../api/impl/bloom/BloomFieldEncoding.java | 12 +-- .../kernel/api/impl/bloom/BloomIndex.java | 12 +-- .../api/impl/bloom/BloomIndexReader.java | 12 +-- .../BloomIndexTransactionEventUpdater.java | 12 +-- .../api/impl/bloom/BloomLuceneIndex.java | 12 +-- .../bloom/PartitionedBloomIndexReader.java | 12 +-- .../bloom/PartitionedInsightBloomWriter.java | 12 +-- .../impl/bloom/SimpleBloomIndexReader.java | 12 +-- .../bloom/WritableDatabaseBloomIndex.java | 12 +-- .../BloomKernelExtension.java | 28 ++++--- .../BloomKernelExtensionFactory.java | 19 +++-- .../bloom/integration/BloomNodeProcedure.java | 78 +++++++++++++++++++ .../BloomRelationshipProcedure.java | 78 +++++++++++++++++++ .../bloom/BloomLuceneIndexUpdaterTest.java | 21 ++--- .../api/impl/bloom/integration/BloomIT.java | 78 +++++++++++++++++++ enterprise/pom.xml | 1 + 18 files changed, 341 insertions(+), 88 deletions(-) rename enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/{extension => integration}/BloomKernelExtension.java (65%) rename enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/{extension => integration}/BloomKernelExtensionFactory.java (71%) create mode 100644 enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomNodeProcedure.java create mode 100644 enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomRelationshipProcedure.java create mode 100644 enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/integration/BloomIT.java diff --git a/enterprise/bloom-index/pom.xml b/enterprise/bloom-index/pom.xml index 7039403100273..78ba725d4af30 100644 --- a/enterprise/bloom-index/pom.xml +++ b/enterprise/bloom-index/pom.xml @@ -113,6 +113,12 @@ neo4j-lucene-index 3.3.0-SNAPSHOT + + org.neo4j + neo4j-community + 3.3.0-SNAPSHOT + test + diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomDocumentStructure.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomDocumentStructure.java index e157c91b3e475..a963edbd3afdc 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomDocumentStructure.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomDocumentStructure.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomFieldEncoding.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomFieldEncoding.java index eba947b716c4c..4867477e101cd 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomFieldEncoding.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomFieldEncoding.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndex.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndex.java index 1ab5dc9bb6b74..c70c66b50b93f 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndex.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndex.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexReader.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexReader.java index 37d701334f821..237bfe0130888 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexReader.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexReader.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexTransactionEventUpdater.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexTransactionEventUpdater.java index 39d85f9d12298..5163600f082d5 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexTransactionEventUpdater.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomIndexTransactionEventUpdater.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndex.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndex.java index 45d081e3c8810..6cc83d8d46131 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndex.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndex.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedBloomIndexReader.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedBloomIndexReader.java index ab2c7d0d29ac2..56401ac27dcb3 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedBloomIndexReader.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedBloomIndexReader.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedInsightBloomWriter.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedInsightBloomWriter.java index 4d72807c3f8e3..c2bf2eadedaae 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedInsightBloomWriter.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/PartitionedInsightBloomWriter.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/SimpleBloomIndexReader.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/SimpleBloomIndexReader.java index 17fa3aa33e19c..050f1a7880d1b 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/SimpleBloomIndexReader.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/SimpleBloomIndexReader.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/WritableDatabaseBloomIndex.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/WritableDatabaseBloomIndex.java index eb9c7e8376ad4..3fd59296d26a8 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/WritableDatabaseBloomIndex.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/WritableDatabaseBloomIndex.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/extension/BloomKernelExtension.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomKernelExtension.java similarity index 65% rename from enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/extension/BloomKernelExtension.java rename to enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomKernelExtension.java index e78338d6a8e5a..565f305b781d1 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/extension/BloomKernelExtension.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomKernelExtension.java @@ -5,29 +5,30 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ -package org.neo4j.kernel.api.impl.bloom.extension; +package org.neo4j.kernel.api.impl.bloom.integration; import java.io.File; import java.io.IOException; import org.neo4j.graphdb.GraphDatabaseService; -import org.neo4j.index.impl.lucene.legacy.LuceneIndexImplementation; import org.neo4j.io.fs.FileSystemAbstraction; +import org.neo4j.kernel.api.exceptions.ProcedureException; import org.neo4j.kernel.api.impl.bloom.BloomIndex; import org.neo4j.kernel.api.impl.bloom.BloomIndexTransactionEventUpdater; import org.neo4j.kernel.configuration.Config; +import org.neo4j.kernel.impl.proc.Procedures; import org.neo4j.kernel.lifecycle.LifecycleAdapter; public class BloomKernelExtension extends LifecycleAdapter @@ -36,23 +37,30 @@ public class BloomKernelExtension extends LifecycleAdapter private final Config config; private final FileSystemAbstraction fileSystemAbstraction; private GraphDatabaseService db; + private Procedures procedures; private BloomIndex bloomIndex; private BloomIndexTransactionEventUpdater bloomIndexTransactionEventUpdater; - public BloomKernelExtension( FileSystemAbstraction fileSystemAbstraction, File storeDir, Config config, GraphDatabaseService db ) + public BloomKernelExtension( FileSystemAbstraction fileSystemAbstraction, File storeDir, Config config, GraphDatabaseService db, Procedures procedures ) { this.storeDir = storeDir; this.config = config; this.fileSystemAbstraction = fileSystemAbstraction; this.db = db; + this.procedures = procedures; } @Override - public void init() throws IOException + public void init() throws IOException, ProcedureException { bloomIndex = new BloomIndex( fileSystemAbstraction, storeDir, config ); bloomIndexTransactionEventUpdater = bloomIndex.getUpdater(); db.registerTransactionEventHandler( bloomIndexTransactionEventUpdater ); + + BloomNodeProcedure nodeProc = new BloomNodeProcedure( bloomIndex ); + BloomRelationshipProcedure relProc = new BloomRelationshipProcedure( bloomIndex ); + procedures.register( nodeProc ); + procedures.register( relProc ); } @Override diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/extension/BloomKernelExtensionFactory.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomKernelExtensionFactory.java similarity index 71% rename from enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/extension/BloomKernelExtensionFactory.java rename to enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomKernelExtensionFactory.java index 102ba71dc3d91..3596cf6f5a09c 100644 --- a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/extension/BloomKernelExtensionFactory.java +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomKernelExtensionFactory.java @@ -5,24 +5,25 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ -package org.neo4j.kernel.api.impl.bloom.extension; +package org.neo4j.kernel.api.impl.bloom.integration; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.extension.KernelExtensionFactory; +import org.neo4j.kernel.impl.proc.Procedures; import org.neo4j.kernel.impl.spi.KernelContext; import org.neo4j.kernel.lifecycle.Lifecycle; @@ -38,6 +39,8 @@ public interface Dependencies GraphDatabaseService db(); FileSystemAbstraction fileSystem(); + + Procedures procedures(); } public BloomKernelExtensionFactory() @@ -48,6 +51,6 @@ public BloomKernelExtensionFactory() @Override public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable { - return new BloomKernelExtension( dependencies.fileSystem(), context.storeDir(), dependencies.getConfig(), dependencies.db() ); + return new BloomKernelExtension( dependencies.fileSystem(), context.storeDir(), dependencies.getConfig(), dependencies.db(), dependencies.procedures() ); } } diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomNodeProcedure.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomNodeProcedure.java new file mode 100644 index 0000000000000..7754a5a7cfbe0 --- /dev/null +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomNodeProcedure.java @@ -0,0 +1,78 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.api.impl.bloom.integration; + +import java.util.Arrays; + +import org.neo4j.collection.RawIterator; +import org.neo4j.collection.primitive.PrimitiveLongIterator; +import org.neo4j.kernel.api.exceptions.ProcedureException; +import org.neo4j.kernel.api.exceptions.Status; +import org.neo4j.kernel.api.impl.bloom.BloomIndex; +import org.neo4j.kernel.api.impl.bloom.BloomIndexReader; +import org.neo4j.kernel.api.proc.CallableProcedure; +import org.neo4j.kernel.api.proc.Context; +import org.neo4j.kernel.api.proc.Neo4jTypes; +import org.neo4j.kernel.api.proc.QualifiedName; + +import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature; + +public class BloomNodeProcedure extends CallableProcedure.BasicProcedure +{ + private static final String PROCEDURE_NAME = "bloomNodes"; + private static final String[] PROCEDURE_NAMESPACE = {"dbms", "bloom"}; + private static final String OUTPUT_NAME = "nodeid"; + private BloomIndex bloomIndex; + + BloomNodeProcedure( BloomIndex bloomIndex ) + { + super( procedureSignature( new QualifiedName( PROCEDURE_NAMESPACE, PROCEDURE_NAME ) ).in( "terms", Neo4jTypes.NTList( Neo4jTypes.NTString ) ).out( + OUTPUT_NAME, Neo4jTypes.NTInteger ).description( "Queries the bloom index for nodes." ).build() ); + this.bloomIndex = bloomIndex; + } + + @Override + public RawIterator apply( Context ctx, Object[] input ) throws ProcedureException + { + String[] query = Arrays.stream( input ).map( Object::toString ).toArray( String[]::new ); + try ( BloomIndexReader nodeReader = bloomIndex.getNodeReader() ) + { + PrimitiveLongIterator primitiveLongIterator = nodeReader.query( query ); + return new RawIterator() + { + @Override + public boolean hasNext() throws ProcedureException + { + return primitiveLongIterator.hasNext(); + } + + @Override + public Object[] next() throws ProcedureException + { + return new Long[]{primitiveLongIterator.next()}; + } + }; + } + catch ( Exception e ) + { + throw new ProcedureException( Status.statusCodeOf( e ), e, "Failed to query bloom index for nodes", input ); + } + } +} diff --git a/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomRelationshipProcedure.java b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomRelationshipProcedure.java new file mode 100644 index 0000000000000..af398838f5a1d --- /dev/null +++ b/enterprise/bloom-index/src/main/java/org/neo4j/kernel/api/impl/bloom/integration/BloomRelationshipProcedure.java @@ -0,0 +1,78 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.api.impl.bloom.integration; + +import java.util.Arrays; + +import org.neo4j.collection.RawIterator; +import org.neo4j.collection.primitive.PrimitiveLongIterator; +import org.neo4j.kernel.api.exceptions.ProcedureException; +import org.neo4j.kernel.api.exceptions.Status; +import org.neo4j.kernel.api.impl.bloom.BloomIndex; +import org.neo4j.kernel.api.impl.bloom.BloomIndexReader; +import org.neo4j.kernel.api.proc.CallableProcedure; +import org.neo4j.kernel.api.proc.Context; +import org.neo4j.kernel.api.proc.Neo4jTypes; +import org.neo4j.kernel.api.proc.QualifiedName; + +import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature; + +public class BloomRelationshipProcedure extends CallableProcedure.BasicProcedure +{ + private static final String PROCEDURE_NAME = "bloomRelationships"; + private static final String[] PROCEDURE_NAMESPACE = {"dbms", "bloom"}; + private static final String OUTPUT_NAME = "relid"; + private BloomIndex bloomIndex; + + BloomRelationshipProcedure( BloomIndex bloomIndex ) + { + super( procedureSignature( new QualifiedName( PROCEDURE_NAMESPACE, PROCEDURE_NAME ) ).in( "terms", Neo4jTypes.NTList( Neo4jTypes.NTString ) ).out( + OUTPUT_NAME, Neo4jTypes.NTInteger ).description( "Queries the bloom index for relationships." ).build() ); + this.bloomIndex = bloomIndex; + } + + @Override + public RawIterator apply( Context ctx, Object[] input ) throws ProcedureException + { + String[] query = Arrays.stream( input ).map( Object::toString ).toArray( String[]::new ); + try ( BloomIndexReader relationshipReader = bloomIndex.getRelationshipReader() ) + { + PrimitiveLongIterator primitiveLongIterator = relationshipReader.query( query ); + return new RawIterator() + { + @Override + public boolean hasNext() throws ProcedureException + { + return primitiveLongIterator.hasNext(); + } + + @Override + public Object[] next() throws ProcedureException + { + return new Long[]{primitiveLongIterator.next()}; + } + }; + } + catch ( Exception e ) + { + throw new ProcedureException( Status.statusCodeOf( e ), e, "Failed to query bloom index for relationships", input ); + } + } +} diff --git a/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndexUpdaterTest.java b/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndexUpdaterTest.java index ece01e6127a6c..ad5b423a925e6 100644 --- a/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndexUpdaterTest.java +++ b/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/BloomLuceneIndexUpdaterTest.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.bloom; @@ -248,14 +248,15 @@ public void shouldSearchAcrossMultipleProperties() throws Exception tx.success(); } + PrimitiveLongIterator iterator; try ( BloomIndexReader reader = bloomIndex.getNodeReader() ) { - PrimitiveLongIterator iterator = reader.query( "tomtar", "karl" ); - assertEquals( secondID, iterator.next() ); - assertEquals( thirdID, iterator.next() ); - assertEquals( firstID, iterator.next() ); + iterator = reader.query( "tomtar", "karl" ); } + assertEquals( secondID, iterator.next() ); + assertEquals( thirdID, iterator.next() ); + assertEquals( firstID, iterator.next() ); } } diff --git a/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/integration/BloomIT.java b/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/integration/BloomIT.java new file mode 100644 index 0000000000000..77ec4ee5a1ea6 --- /dev/null +++ b/enterprise/bloom-index/src/test/java/org/neo4j/kernel/api/impl/bloom/integration/BloomIT.java @@ -0,0 +1,78 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.api.impl.bloom.integration; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.Collections; + +import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.graphdb.Result; +import org.neo4j.graphdb.Transaction; +import org.neo4j.graphdb.factory.GraphDatabaseSettings; +import org.neo4j.test.TestGraphDatabaseFactory; +import org.neo4j.test.rule.fs.EphemeralFileSystemRule; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +public class BloomIT +{ + public static final String NODES = "CALL dbms.bloom.bloomNodes([\"%s\"])"; + public static final String NODEID = "nodeid"; + @Rule + public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); + + private TestGraphDatabaseFactory factory; + private GraphDatabaseService db; + + @Before + public void before() throws Exception + { + factory = new TestGraphDatabaseFactory(); + factory.setFileSystem( fs.get() ); + factory.addKernelExtensions( Collections.singletonList( new BloomKernelExtensionFactory() ) ); + db = factory.newImpermanentDatabase( Collections.singletonMap( GraphDatabaseSettings.bloom_indexed_properties, "prop" ) ); + } + + @Test + public void shouldPopulateAndQueryIndexes() throws Exception + { + try ( Transaction transaction = db.beginTx() ) + { + db.createNode().setProperty( "prop", "This is a integration test." ); + transaction.success(); + } + + Result result = db.execute( String.format( NODES, "integration" ) ); + + assertEquals( 0l, result.next().get( NODEID ) ); + assertFalse( result.hasNext() ); + } + + @After + public void after() throws Exception + { + db.shutdown(); + } +} \ No newline at end of file diff --git a/enterprise/pom.xml b/enterprise/pom.xml index a2ce458d5323c..7b402a2ae74b8 100644 --- a/enterprise/pom.xml +++ b/enterprise/pom.xml @@ -46,6 +46,7 @@ deferred-locks ha procedure-compiler-enterprise-tests + bloom-index