Skip to content

Commit

Permalink
NativeLabelScanStoreHaIT (part of lss compliance testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen authored and tinwelint committed Jan 22, 2017
1 parent 5b3656b commit f5fb65c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
Expand Up @@ -35,6 +35,8 @@ public class NativeLabelScanStoreExtension extends
KernelExtensionFactory<NativeLabelScanStoreExtension.Dependencies>
{
public static final String LABEL_SCAN_STORE_NAME = "native";
private final int priority;
private final LabelScanStore.Monitor monitor;

public interface Dependencies
{
Expand All @@ -46,8 +48,15 @@ public interface Dependencies
}

public NativeLabelScanStoreExtension()
{
this( 0 /*disabled by default*/, LabelScanStore.Monitor.EMPTY );
}

public NativeLabelScanStoreExtension( int priority, LabelScanStore.Monitor monitor )
{
super( LABEL_SCAN_STORE_NAME );
this.priority = priority;
this.monitor = monitor;
}

@Override
Expand All @@ -58,7 +67,7 @@ public Lifecycle newInstance( KernelContext context, Dependencies dependencies )
context.storeDir(),
new FullLabelStream( dependencies.indexStoreView() ),
dependencies.getConfig().get( GraphDatabaseSettings.read_only ),
LabelScanStore.Monitor.EMPTY );
return new LabelScanStoreProvider( LABEL_SCAN_STORE_NAME, labelScanStore, 0 /*disabled by default*/ );
monitor );
return new LabelScanStoreProvider( LABEL_SCAN_STORE_NAME, labelScanStore, priority );
}
}
Expand Up @@ -269,7 +269,8 @@ public void init() throws IOException
{
monitor.init();

if ( readOnly && !storeExists() )
boolean storeExists = storeExists();
if ( readOnly && !storeExists )
{
throw new UnsupportedOperationException( "Tried to create native label scan store " +
storeFile + " in read-only mode, but no such store exists" );
Expand All @@ -278,6 +279,7 @@ public void init() throws IOException
try
{
create( monitor );
needsRebuild = !storeExists;
}
catch ( MetadataMismatchException e )
{
Expand Down Expand Up @@ -327,23 +329,19 @@ private void drop() throws IOException
@Override
public void start() throws IOException
{
if ( needsRebuild || isEmpty() )
if ( needsRebuild )
{
if ( readOnly && needsRebuild )
if ( readOnly )
{
throw new IOException( "Tried to start label scan store " + storeFile +
" as read-only and the index needs rebuild. This makes the label scan store unusable" );
}

if ( !readOnly )
{
// todo log
monitor.rebuilding();
long numberOfNodes = LabelScanStoreProvider.rebuild( this, fullStoreChangeStream );
// todo log
monitor.rebuilt( numberOfNodes );
needsRebuild = false;
}
// todo log
monitor.rebuilding();
long numberOfNodes = LabelScanStoreProvider.rebuild( this, fullStoreChangeStream );
// todo log
monitor.rebuilt( numberOfNodes );
needsRebuild = false;
}
started = true;
}
Expand Down
Expand Up @@ -52,7 +52,9 @@ public void shouldCopyLabelScanStoreToNewSlaves() throws Exception
// This check is here o check so that the extension provided by this test is selected.
// It can be higher than 3 (number of cluster members) since some members may restart
// some services to switch role.
assertTrue( monitor.callsTo_init >= 3 );
assertTrue( "Expected initial calls to init to be at least one per cluster member (>= 3), " +
"but was " + monitor.callsTo_init,
monitor.callsTo_init >= 3 );

// GIVEN
// An HA cluster where the master started with initial data consisting
Expand Down Expand Up @@ -116,6 +118,7 @@ public void setUp()
if ( serverId == 1 )
{
GraphDatabaseService db = new TestGraphDatabaseFactory()
.addKernelExtension( testExtension )
.newEmbeddedDatabaseBuilder( storeDir.getAbsoluteFile() )
.newGraphDatabase();
try
Expand Down
@@ -0,0 +1,33 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.api.impl.labelscan;

import org.neo4j.kernel.api.labelscan.LabelScanStore;
import org.neo4j.kernel.extension.KernelExtensionFactory;
import org.neo4j.kernel.impl.api.scan.NativeLabelScanStoreExtension;

public class NativeLabelScanStoreHaIT extends LabelScanStoreHaIT
{
@Override
protected KernelExtensionFactory<?> labelScanStoreExtension( LabelScanStore.Monitor monitor )
{
return new NativeLabelScanStoreExtension( 100, monitor );
}
}

0 comments on commit f5fb65c

Please sign in to comment.