Skip to content

Commit

Permalink
Add builtin procedure dbms.resampleOutdatedIndexes
Browse files Browse the repository at this point in the history
  • Loading branch information
benbc committed Sep 14, 2016
1 parent a1203a8 commit 8cc0611
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public void resampleIndex( @Name( "label" ) String labelName,
}
}

@Description( "Schedule resampling of all outdated indexes." )
@Procedure( name = "db.resampleOutdatedIndexes", mode = READ )
public void resampleOutdatedIndexes()
{
try ( IndexProcedures indexProcedures = indexProcedures() )
{
indexProcedures.resampleOutdatedIndexes();
}
}

@Description( "List all constraints in the database." )
@Procedure( name = "db.constraints", mode = READ )
public Stream<ConstraintResult> listConstraints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public void resampleIndex( String labelName, String propertyKeyName ) throws Pro
formatIndex( labelName, propertyKeyName ) ) );
}

public void resampleOutdatedIndexes()
{
indexingService.triggerIndexSampling( IndexSamplingMode.TRIGGER_REBUILD_UPDATED );
}

private int getLabelId( String labelName ) throws ProcedureException
{
int labelId = operations.labelGetForName( labelName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void shouldListCorrectBuiltinProcedures() throws Throwable
record( "db.propertyKeys", "db.propertyKeys() :: (propertyKey :: STRING?)", "List all property keys in the database." ),
record( "db.relationshipTypes", "db.relationshipTypes() :: (relationshipType :: STRING?)", "List all relationship types in the database." ),
record( "db.resampleIndex", "db.resampleIndex(label :: STRING?, property :: STRING?) :: VOID", "Schedule resampling of an index." ),
record( "db.resampleOutdatedIndexes", "db.resampleOutdatedIndexes() :: VOID", "Schedule resampling of all outdated indexes." ),
record( "dbms.components", "dbms.components() :: (name :: STRING?, versions :: LIST? OF STRING?, edition :: STRING?)", "List DBMS components and their versions." ),
record( "dbms.procedures", "dbms.procedures() :: (name :: STRING?, signature :: STRING?, description :: STRING?)", "List all procedures in the DBMS." ),
record( "dbms.functions", "dbms.functions() :: (name :: STRING?, signature :: STRING?, description :: STRING?)", "List all user functions in the DBMS." ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.builtinprocs;

import org.junit.Test;

import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class ResampleOutdatedIndexesProcedureTest
{
private final IndexingService indexingService = mock( IndexingService.class );
private final IndexProcedures procedure = new IndexProcedures( new StubKernelTransaction( null ), indexingService );

@Test
public void shouldTriggerResampling() throws SchemaRuleNotFoundException, ProcedureException
{
procedure.resampleOutdatedIndexes();

verify( indexingService ).triggerIndexSampling( IndexSamplingMode.TRIGGER_REBUILD_UPDATED );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public void listProcedures() throws Throwable
"timeOutSeconds = 300 :: INTEGER?) :: VOID", "Wait for an index to come online."} ),
equalTo( new Object[]{"db.resampleIndex", "db.resampleIndex(label :: STRING?, property :: STRING?) " +
":: VOID", "Schedule resampling of an index."} ),
equalTo( new Object[]{"db.resampleOutdatedIndexes", "db.resampleOutdatedIndexes() :: VOID",
"Schedule resampling of all outdated indexes."} ),
equalTo( new Object[]{"db.propertyKeys", "db.propertyKeys() :: (propertyKey :: STRING?)", "List all property keys in the database."} ),
equalTo( new Object[]{"db.labels", "db.labels() :: (label :: STRING?)", "List all labels in the database."} ),
equalTo( new Object[]{"db.relationshipTypes", "db.relationshipTypes() :: (relationshipType :: " +
Expand Down

0 comments on commit 8cc0611

Please sign in to comment.