/** * @return The config reflecting the state of the builder. * @throws InvalidSettingException is thrown if an invalid setting is encountered and {@link * GraphDatabaseSettings#strict_config_validation} is true. */ @Nonnull public Config build() throws InvalidSettingException { List<LoadableConfig> loadableConfigs = Optional.ofNullable( settingsClasses ).orElseGet( LoadableConfig::allConfigClasses ); // If reading from a file, make sure we always have a neo4j_home if ( configFile != null && !initialSettings.containsKey( GraphDatabaseSettings.neo4j_home.name() ) ) { initialSettings.put( GraphDatabaseSettings.neo4j_home.name(), System.getProperty( "user.dir" ) ); } Config config = new Config( configFile, throwOnFileLoadFailure, initialSettings, overriddenDefaults, validators, loadableConfigs ); if ( connectorsDisabled ) { config.augment( config.allConnectorIdentifiers().stream().collect( Collectors.toMap( id -> new Connector( id ).enabled.name(), id -> Settings.FALSE ) ) ); } return config; } }
/** * @return The config reflecting the state of the builder. * @throws InvalidSettingException is thrown if an invalid setting is encountered and {@link * GraphDatabaseSettings#strict_config_validation} is true. */ @Nonnull public Config build() throws InvalidSettingException { List<LoadableConfig> loadableConfigs = Optional.ofNullable( settingsClasses ).orElseGet( LoadableConfig::allConfigClasses ); // If reading from a file, make sure we always have a neo4j_home if ( configFile != null && !initialSettings.containsKey( GraphDatabaseSettings.neo4j_home.name() ) ) { initialSettings.put( GraphDatabaseSettings.neo4j_home.name(), System.getProperty( "user.dir" ) ); } Config config = new Config( configFile, throwOnFileLoadFailure, initialSettings, overriddenDefaults, validators, loadableConfigs ); if ( connectorsDisabled ) { config.augment( config.allConnectorIdentifiers().stream().collect( Collectors.toMap( id -> new Connector( id ).enabled.name(), id -> Settings.FALSE ) ) ); } return config; } }
public CoreGraphDatabase( File storeDir, Map<String,String> params, GraphDatabaseFacadeFactory.Dependencies dependencies, DiscoveryServiceFactory discoveryServiceFactory ) { CustomIOConfigValidator.assertCustomIOConfigNotUsed( new Config( params ), CUSTOM_IO_EXCEPTION_MESSAGE ); Function<PlatformModule,EditionModule> factory = ( platformModule ) -> new EnterpriseCoreEditionModule( platformModule, discoveryServiceFactory ); new GraphDatabaseFacadeFactory( DatabaseInfo.CORE, factory ).initFacade( storeDir, params, dependencies, this ); }
@Override public void start() { tempDirectory = createTempDirectory(); Map<String, String> opts = new HashMap<>(); // Neo4j 2.x opts.put(DBMS_SECURITY_AUTH_ENABLED, Boolean.FALSE.toString()); opts.put(ORG_NEO_4J_SERVER_WEBSERVER_ADDRESS, embeddedNeo4jConfiguration.getListenAddress()); opts.put(ORG_NEO_4J_SERVER_WEBSERVER_PORT, Integer.toString(embeddedNeo4jConfiguration.getHttpPort())); // Neo4j 2.x/3.x String sslDir = tempDirectory.toFile().getAbsolutePath() + "neo4j-home/"; opts.put(ServerSettings.tls_key_file.name(), sslDir + "/ssl/snakeoil.key"); opts.put(ServerSettings.tls_certificate_file.name(), sslDir + "/ssl/snakeoil.cert"); Config defaults = new Config(opts); // Config.empty().with(opts); FormattedLogProvider logProvider = FormattedLogProvider.withDefaultLogLevel(Level.INFO).toOutputStream(System.out); GraphDatabaseDependencies graphDatabaseDependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(logProvider); Database.Factory factory = new Database.Factory() { @Override public Database newDatabase(Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) { return new WrappedDatabase((GraphDatabaseAPI) graphDatabaseService); } }; communityNeoServer = new CommunityNeoServer(defaults, factory, graphDatabaseDependencies, logProvider); communityNeoServer.start(); }
public EdgeGraphDatabase( File storeDir, Map<String,String> params, Dependencies dependencies, DiscoveryServiceFactory discoveryServiceFactory ) { CustomIOConfigValidator.assertCustomIOConfigNotUsed( new Config( params ), CUSTOM_IO_EXCEPTION_MESSAGE ); Function<PlatformModule,EditionModule> factory = ( platformModule ) -> new EnterpriseEdgeEditionModule( platformModule, discoveryServiceFactory ); new GraphDatabaseFacadeFactory( DatabaseInfo.EDGE, factory ).initFacade( storeDir, params, dependencies, this ); } }
static Config config( TaskExecutionOrder executionOrder ) { Map<String,String> params = stringMap( ConsistencyCheckSettings.consistency_check_execution_order.name(), executionOrder.name(), // Enable property owners check by default in tests: ConsistencyCheckSettings.consistency_check_property_owners.name(), "true" ); return new Config( params, GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); }
@Test public void shouldFailIfTheStoreInNotConsistent() throws Exception { // given breakNodeStore(); Date timestamp = new Date(); ConsistencyCheckService service = new ConsistencyCheckService( timestamp ); Config configuration = new Config( settings(), GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); // when ConsistencyCheckService.Result result = service.runFullConsistencyCheck( fixture.directory(), configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); // then assertEquals( ConsistencyCheckService.Result.FAILURE, result ); File reportFile = new File( fixture.directory(), defaultLogFileName( timestamp ) ); assertTrue( "Inconsistency report file " + reportFile + " not generated", reportFile.exists() ); }
@Test public void shouldSucceedIfStoreIsConsistent() throws Exception { // given Date timestamp = new Date(); ConsistencyCheckService service = new ConsistencyCheckService( timestamp ); Config configuration = new Config( settings(), GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); // when ConsistencyCheckService.Result result = service.runFullConsistencyCheck( fixture.directory(), configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); // then assertEquals( ConsistencyCheckService.Result.SUCCESS, result ); File reportFile = new File( fixture.directory(), defaultLogFileName( timestamp ) ); assertFalse( "Unexpected generation of consistency check report file: " + reportFile, reportFile.exists() ); }
@Test public void shouldWriteInconsistenciesToLogFileAtSpecifiedLocation() throws Exception { // given breakNodeStore(); ConsistencyCheckService service = new ConsistencyCheckService(); File specificLogFile = new File( testDirectory.directory(), "specific_logfile.txt" ); Config configuration = new Config( settings( ConsistencyCheckSettings.consistency_check_report_file.name(), specificLogFile.getPath() ), GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); // when service.runFullConsistencyCheck( fixture.directory(), configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); // then assertTrue( "Inconsistency report file " + specificLogFile + " not generated", specificLogFile.exists() ); }
private void assertConsistent( File storeDir ) throws ConsistencyCheckIncompleteException, IOException { ConsistencyCheckService consistencyChecker = new ConsistencyCheckService(); Result result = consistencyChecker.runFullConsistencyCheck( storeDir, new Config( stringMap( GraphDatabaseSettings.pagecache_memory.name(), "8m" ) ), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); assertTrue( "Database contains inconsistencies, there should be a report in " + storeDir, result.isSuccessful() ); }
public static void assertConsistentStore( File dir ) throws ConsistencyCheckIncompleteException, IOException { final Config configuration = new Config( stringMap( GraphDatabaseSettings.pagecache_memory.name(), "8m" ), GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); final ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck( dir, configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); assertTrue( result.isSuccessful() ); } }
final BatchImporter inserter = new ParallelBatchImporter( directory.graphDbDir(), new DefaultFileSystemAbstraction(), config, NullLogService.getInstance(), processorAssigner, EMPTY, new Config() );
@Test public void shouldReportNodesThatAreNotIndexed() throws Exception { // given IndexSamplingConfig samplingConfig = new IndexSamplingConfig( new Config() ); for ( IndexRule indexRule : loadAllIndexRules( fixture.directStoreAccess().nativeStores().getSchemaStore() ) ) { IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor( indexRule.getId(), new IndexConfiguration( indexRule.isConstraintIndex() ), samplingConfig ); IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ); updater.remove( asPrimitiveLongSet( indexedNodes ) ); updater.close(); accessor.close(); } // when ConsistencySummaryStatistics stats = check(); // then on( stats ).verify( RecordType.NODE, 1 ) .andThatsAllFolks(); }
IndexDescriptor descriptor = new IndexDescriptor( rule.getLabel(), rule.getPropertyKey() ); IndexConfiguration indexConfig = new IndexConfiguration( false ); IndexSamplingConfig samplingConfig = new IndexSamplingConfig( new Config() ); IndexPopulator populator = storeAccess.indexes().getPopulator( rule.getId(), descriptor, indexConfig, samplingConfig );
@Test public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Exception { // given IndexConfiguration indexConfig = new IndexConfiguration( false ); IndexSamplingConfig samplingConfig = new IndexSamplingConfig( new Config() ); for ( IndexRule indexRule : loadAllIndexRules( fixture.directStoreAccess().nativeStores().getSchemaStore() ) ) { IndexAccessor accessor = fixture.directStoreAccess() .indexes() .getOnlineAccessor( indexRule.getId(), indexConfig, samplingConfig ); IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ); updater.process( NodePropertyUpdate.add( 42, 0, "value", new long[]{3} ) ); updater.close(); accessor.close(); } // when ConsistencySummaryStatistics stats = check(); // then on( stats ).verify( RecordType.NODE, 1 ) .verify( RecordType.INDEX, 2 ) .andThatsAllFolks(); }
public DirectStoreAccess directStoreAccess() { if ( directStoreAccess == null ) { DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); PageCache pageCache = getPageCache( fileSystem ); StoreAccess nativeStores = new StoreAccess( fileSystem, pageCache, directory ).initialize(); Config config = new Config(); OperationalMode operationalMode = OperationalMode.single; directStoreAccess = new DirectStoreAccess( nativeStores, new LuceneLabelScanStoreBuilder( directory, nativeStores.getRawNeoStores(), fileSystem, config, operationalMode, FormattedLogProvider.toOutputStream( System.out ) ).build(), createIndexes( fileSystem, config, operationalMode ) ); } return directStoreAccess; }
@Test public void shouldAllowGraphCheckDisabled() throws IOException, ConsistencyCheckIncompleteException { GraphDatabaseService gds = new GraphDatabaseFactory().newEmbeddedDatabase( testDirectory.absolutePath() ); try ( Transaction tx = gds.beginTx() ) { gds.createNode(); tx.success(); } gds.shutdown(); ConsistencyCheckService service = new ConsistencyCheckService(); Config configuration = new Config( settings(), GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); configuration.applyChanges( MapUtil.stringMap( ConsistencyCheckSettings.consistency_check_graph.name(), Settings.FALSE ) ); // when Result result = service.runFullConsistencyCheck( testDirectory.graphDbDir(), configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); // then assertEquals( ConsistencyCheckService.Result.SUCCESS, result ); }
@Test public void shouldNotReportDuplicateForHugeLongValues() throws Exception { // given ConsistencyCheckService service = new ConsistencyCheckService(); Config configuration = new Config( settings(), GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.graphDbDir() ); String propertyKey = "itemId"; Label label = DynamicLabel.label( "Item" ); try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { set( db.createNode( label ), property( propertyKey, 973305894188596880L ) ); set( db.createNode( label ), property( propertyKey, 973305894188596864L ) ); tx.success(); } db.shutdown(); // when Result result = service.runFullConsistencyCheck( testDirectory.graphDbDir(), configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), new DefaultFileSystemAbstraction() ); // then assertEquals( ConsistencyCheckService.Result.SUCCESS, result ); }