Skip to content

Commit

Permalink
Consolidate config checking logic and use better exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Sumrall committed Apr 12, 2016
1 parent 1757945 commit d781f76
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 34 deletions.
Expand Up @@ -22,7 +22,6 @@
import java.io.File;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.DatabaseInfo;
import org.neo4j.kernel.impl.util.DependencySatisfier;

Expand All @@ -35,6 +34,4 @@ public interface KernelContext
DatabaseInfo databaseInfo();

DependencySatisfier dependencySatisfier();

boolean customIOConfigurationUsed( Config config );
}
Expand Up @@ -21,9 +21,7 @@

import java.io.File;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.DatabaseInfo;
import org.neo4j.kernel.impl.util.DependencySatisfier;

Expand Down Expand Up @@ -66,10 +64,4 @@ public DependencySatisfier dependencySatisfier()
{
return satisfier;
}

@Override
public boolean customIOConfigurationUsed( Config config )
{
return config.get( GraphDatabaseSettings.pagecache_swapper ) != null;
}
}
Expand Up @@ -32,6 +32,7 @@
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor;
import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor.Section;
import org.neo4j.kernel.impl.util.CustomIOConfigValidator;
import org.neo4j.logging.Log;
import org.neo4j.logging.LogProvider;

Expand Down Expand Up @@ -114,10 +115,7 @@ public void migrateIfNeeded( File storeDirectory)
throw new UpgradeNotAllowedByConfigurationException();
}

if( customIOConfigurationUsed( config ) )
{
throw new IllegalArgumentException( CUSTOM_IO_EXCEPTION_MESSAGE );
}
CustomIOConfigValidator.assertCustomIOConfigNotUsed( config, CUSTOM_IO_EXCEPTION_MESSAGE );

// One or more participants would like to do migration
progressMonitor.started();
Expand Down Expand Up @@ -157,11 +155,6 @@ public void migrateIfNeeded( File storeDirectory)
progressMonitor.completed();
}

private boolean customIOConfigurationUsed( Config config )
{
return config.get( GraphDatabaseSettings.pagecache_swapper ) != null;
}

private boolean isUpgradeAllowed()
{
return config.get( GraphDatabaseSettings.allow_store_upgrade );
Expand Down
@@ -0,0 +1,47 @@
/*
* 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.impl.util;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.kernel.configuration.Config;

public class CustomIOConfigValidator
{
public static void assertCustomIOConfigNotUsed( Config config, String message )
{
if ( customIOConfigUsed( config ) )
{
throw new CustomIOConfigNotSupportedException( message );
}
}

private static boolean customIOConfigUsed( Config config )
{
return config.get( GraphDatabaseSettings.pagecache_swapper ) != null;
}

private static class CustomIOConfigNotSupportedException extends RuntimeException
{
CustomIOConfigNotSupportedException( String message )
{
super( message );
}
}
}
Expand Up @@ -32,6 +32,7 @@
import org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer;
import org.neo4j.kernel.impl.util.CustomIOConfigValidator;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.kernel.lifecycle.Lifecycle;
import org.neo4j.kernel.monitoring.Monitors;
Expand Down Expand Up @@ -79,10 +80,7 @@ public Class<OnlineBackupSettings> getSettingsClass()
@Override
public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable
{
if ( context.customIOConfigurationUsed( dependencies.getConfig() ) )
{
throw new IllegalArgumentException( CUSTOM_IO_EXCEPTION_MESSAGE );
}
CustomIOConfigValidator.assertCustomIOConfigNotUsed( dependencies.getConfig(), CUSTOM_IO_EXCEPTION_MESSAGE );

return new OnlineBackupKernelExtension( dependencies.getConfig(), dependencies.getGraphDatabaseAPI(),
dependencies.logService().getInternalLogProvider(), dependencies.monitors(),
Expand Down
Expand Up @@ -144,6 +144,7 @@
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer;
import org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader;
import org.neo4j.kernel.impl.util.CustomIOConfigValidator;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.kernel.impl.util.JobScheduler;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
Expand Down Expand Up @@ -191,10 +192,7 @@ public HighlyAvailableEditionModule( final PlatformModule platformModule )
final Monitors monitors = platformModule.monitors;

//Temporary check for custom IO
if ( customIOConfigurationUsed( platformModule.config ) )
{
throw new IllegalArgumentException( CUSTOM_IO_EXCEPTION_MESSAGE );
}
CustomIOConfigValidator.assertCustomIOConfigNotUsed( config, CUSTOM_IO_EXCEPTION_MESSAGE );

// Set Netty logger
InternalLoggerFactory.setDefaultFactory( new NettyLoggerFactory( logging.getInternalLogProvider() ) );
Expand Down Expand Up @@ -520,12 +518,6 @@ public void elected( String role, InstanceId instanceId, URI electedMember )
life.add( paxosLife );
}

private boolean customIOConfigurationUsed( Config config )
{
return config.get( GraphDatabaseSettings.pagecache_swapper ) != null;
}


private void publishServerId( Config config, UsageData sysInfo )
{
sysInfo.set( UsageDataKeys.serverId, config.get( ClusterSettings.server_id ).toString() );
Expand Down

0 comments on commit d781f76

Please sign in to comment.