Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(String[] args) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public override void Execute(string[] args)
        {
            try
            {
                Config config                 = LoadNeo4jConfig(_homeDir, _configDir, _arguments.parse(args).get(ARG_DATABASE));
                File   dataDirectory          = config.Get(GraphDatabaseSettings.data_directory);
                Path   pathToSpecificDatabase = config.Get(GraphDatabaseSettings.database_path).toPath();

                bool hasDatabase = true;
                try
                {
                    Validators.CONTAINS_EXISTING_DATABASE.validate(pathToSpecificDatabase.toFile());
                }
                catch (System.ArgumentException)
                {
                    // No such database, it must have been deleted. Must be OK to delete cluster state
                    hasDatabase = false;
                }

                if (hasDatabase)
                {
                    ConfirmTargetDirectoryIsWritable(DatabaseLayout.of(pathToSpecificDatabase.toFile()).StoreLayout);
                }

                ClusterStateDirectory clusterStateDirectory = ClusterStateDirectory.withoutInitializing(dataDirectory);

                if (_outsideWorld.fileSystem().fileExists(clusterStateDirectory.Get()))
                {
                    DeleteClusterStateIn(clusterStateDirectory.Get());
                }
                else
                {
                    _outsideWorld.stdErrLine("This instance was not bound. No work performed.");
                }
            }
            catch (StoreLockException e)
            {
                throw new CommandFailed("Database is currently locked. Please shutdown Neo4j.", e);
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }
            catch (Exception e) when(e is UnbindFailureException || e is CannotWriteException || e is IOException)
            {
                throw new CommandFailed(e.Message, e);
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMigrateClusterStateFromStoreDir() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMigrateClusterStateFromStoreDir()
        {
            // given
            File storeDir = new File(new File(_dataDir, "databases"), GraphDatabaseSettings.DEFAULT_DATABASE_NAME);

            string fileName = "file";

            File oldStateDir         = new File(storeDir, ClusterStateDirectory.CLUSTER_STATE_DIRECTORY_NAME);
            File oldClusterStateFile = new File(oldStateDir, fileName);

            _fs.mkdirs(oldStateDir);
            _fs.create(oldClusterStateFile).close();

            // when
            ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory(_dataDir, storeDir, false);

            clusterStateDirectory.Initialize(_fs);

            // then
            assertEquals(clusterStateDirectory.Get(), _stateDir);
            assertTrue(_fs.fileExists(new File(clusterStateDirectory.Get(), fileName)));
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleCaseOfStoreDirBeingDataDir() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleCaseOfStoreDirBeingDataDir()
        {
            // given
            File storeDir = _dataDir;

            string fileName = "file";

            File oldStateDir         = new File(storeDir, ClusterStateDirectory.CLUSTER_STATE_DIRECTORY_NAME);
            File oldClusterStateFile = new File(oldStateDir, fileName);

            _fs.mkdirs(oldStateDir);
            _fs.create(oldClusterStateFile).close();

            // when
            ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory(_dataDir, storeDir, false);

            clusterStateDirectory.Initialize(_fs);

            // then
            assertEquals(clusterStateDirectory.Get(), _stateDir);
            assertTrue(_fs.fileExists(new File(clusterStateDirectory.Get(), fileName)));
        }
Exemplo n.º 4
0
 private void InitializeInstanceFields()
 {
     _clusterStateDirectory = new ClusterStateDirectory(_dataDir, false);
 }
Exemplo n.º 5
0
 protected internal virtual ClusteringModule GetClusteringModule(PlatformModule platformModule, DiscoveryServiceFactory discoveryServiceFactory, ClusterStateDirectory clusterStateDirectory, IdentityModule identityModule, Dependencies dependencies, DatabaseLayout databaseLayout)
 {
     return(new ClusteringModule(discoveryServiceFactory, identityModule.Myself(), platformModule, clusterStateDirectory.Get(), databaseLayout));
 }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public EnterpriseCoreEditionModule(final org.neo4j.graphdb.factory.module.PlatformModule platformModule, final org.neo4j.causalclustering.discovery.DiscoveryServiceFactory discoveryServiceFactory)
        public EnterpriseCoreEditionModule(PlatformModule platformModule, DiscoveryServiceFactory discoveryServiceFactory)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.Dependencies dependencies = platformModule.dependencies;
            Dependencies dependencies = platformModule.Dependencies;

            Config = platformModule.Config;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.logging.internal.LogService logging = platformModule.logging;
            LogService logging = platformModule.Logging;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.FileSystemAbstraction fileSystem = platformModule.fileSystem;
            FileSystemAbstraction fileSystem = platformModule.FileSystem;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.layout.DatabaseLayout databaseLayout = platformModule.storeLayout.databaseLayout(config.get(org.neo4j.graphdb.factory.GraphDatabaseSettings.active_database));
            DatabaseLayout databaseLayout = platformModule.StoreLayout.databaseLayout(Config.get(GraphDatabaseSettings.active_database));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.lifecycle.LifeSupport life = platformModule.life;
            LifeSupport life = platformModule.Life;

            CoreMonitor.register(logging.InternalLogProvider, logging.UserLogProvider, platformModule.Monitors);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File dataDir = config.get(org.neo4j.graphdb.factory.GraphDatabaseSettings.data_directory);
            File dataDir = Config.get(GraphDatabaseSettings.data_directory);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.state.ClusterStateDirectory clusterStateDirectory = new org.neo4j.causalclustering.core.state.ClusterStateDirectory(dataDir, databaseLayout.databaseDirectory(), false);
            ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory(dataDir, databaseLayout.DatabaseDirectory(), false);

            try
            {
                clusterStateDirectory.Initialize(fileSystem);
            }
            catch (ClusterStateException e)
            {
                throw new Exception(e);
            }
            dependencies.SatisfyDependency(clusterStateDirectory);

            AvailabilityGuard globalGuard = GetGlobalAvailabilityGuard(platformModule.Clock, logging, platformModule.Config);

            ThreadToTransactionBridgeConflict = dependencies.SatisfyDependency(new ThreadToStatementContextBridge(globalGuard));

            LogProvider = logging.InternalLogProvider;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final System.Func<org.neo4j.kernel.internal.DatabaseHealth> databaseHealthSupplier = () -> platformModule.dataSourceManager.getDataSource().getDependencyResolver().resolveDependency(org.neo4j.kernel.internal.DatabaseHealth.class);
            System.Func <DatabaseHealth> databaseHealthSupplier = () => platformModule.DataSourceManager.DataSource.DependencyResolver.resolveDependency(typeof(DatabaseHealth));

            WatcherServiceFactoryConflict = directory => CreateFileSystemWatcherService(fileSystem, directory, logging, platformModule.JobScheduler, Config, FileWatcherFileNameFilter());
            dependencies.SatisfyDependencies(WatcherServiceFactoryConflict);
            LogFiles      logFiles      = BuildLocalDatabaseLogFiles(platformModule, fileSystem, databaseLayout);
            LocalDatabase localDatabase = new LocalDatabase(databaseLayout, new StoreFiles(fileSystem, platformModule.PageCache), logFiles, platformModule.DataSourceManager, databaseHealthSupplier, globalGuard, LogProvider);

            IdentityModule identityModule = new IdentityModule(platformModule, clusterStateDirectory.Get());

            ClusteringModule clusteringModule = GetClusteringModule(platformModule, discoveryServiceFactory, clusterStateDirectory, identityModule, dependencies, databaseLayout);

            // We need to satisfy the dependency here to keep users of it, such as BoltKernelExtension, happy.
            dependencies.SatisfyDependency(SslPolicyLoader.create(Config, LogProvider));

            PipelineWrapper clientPipelineWrapper       = PipelineWrapperFactory().forClient(Config, dependencies, LogProvider, CausalClusteringSettings.SslPolicy);
            PipelineWrapper serverPipelineWrapper       = PipelineWrapperFactory().forServer(Config, dependencies, LogProvider, CausalClusteringSettings.SslPolicy);
            PipelineWrapper backupServerPipelineWrapper = PipelineWrapperFactory().forServer(Config, dependencies, LogProvider, OnlineBackupSettings.ssl_policy);

            NettyPipelineBuilderFactory clientPipelineBuilderFactory       = new NettyPipelineBuilderFactory(clientPipelineWrapper);
            NettyPipelineBuilderFactory serverPipelineBuilderFactory       = new NettyPipelineBuilderFactory(serverPipelineWrapper);
            NettyPipelineBuilderFactory backupServerPipelineBuilderFactory = new NettyPipelineBuilderFactory(backupServerPipelineWrapper);

            _topologyService = clusteringModule.TopologyService();

            long logThresholdMillis = Config.get(CausalClusteringSettings.UnknownAddressLoggingThrottle).toMillis();

            SupportedProtocolCreator                 supportedProtocolCreator   = new SupportedProtocolCreator(Config, LogProvider);
            ApplicationSupportedProtocols            supportedRaftProtocols     = supportedProtocolCreator.CreateSupportedRaftProtocol();
            ICollection <ModifierSupportedProtocols> supportedModifierProtocols = supportedProtocolCreator.CreateSupportedModifierProtocols();

            ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository(Org.Neo4j.causalclustering.protocol.Protocol_ApplicationProtocols.values(), supportedRaftProtocols);
            ModifierProtocolRepository    modifierProtocolRepository    = new ModifierProtocolRepository(Org.Neo4j.causalclustering.protocol.Protocol_ModifierProtocols.values(), supportedModifierProtocols);

            ProtocolInstallerRepository <Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation_Client> protocolInstallerRepository = new ProtocolInstallerRepository <Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation_Client>(asList(new RaftProtocolClientInstallerV2.Factory(clientPipelineBuilderFactory, LogProvider), new RaftProtocolClientInstallerV1.Factory(clientPipelineBuilderFactory, LogProvider)), Org.Neo4j.causalclustering.protocol.ModifierProtocolInstaller_Fields.AllClientInstallers);

            Duration handshakeTimeout = Config.get(CausalClusteringSettings.HandshakeTimeout);
            HandshakeClientInitializer channelInitializer = new HandshakeClientInitializer(applicationProtocolRepository, modifierProtocolRepository, protocolInstallerRepository, clientPipelineBuilderFactory, handshakeTimeout, LogProvider, platformModule.Logging.UserLogProvider);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.messaging.SenderService raftSender = new org.neo4j.causalclustering.messaging.SenderService(channelInitializer, logProvider);
            SenderService raftSender = new SenderService(channelInitializer, LogProvider);

            life.Add(raftSender);
            this._clientInstalledProtocols = raftSender.installedProtocols;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.logging.MessageLogger<org.neo4j.causalclustering.identity.MemberId> messageLogger = createMessageLogger(config, life, identityModule.myself());
            MessageLogger <MemberId> messageLogger = CreateMessageLogger(Config, life, identityModule.Myself());

            RaftOutbound raftOutbound = new RaftOutbound(_topologyService, raftSender, clusteringModule.ClusterIdentity(), LogProvider, logThresholdMillis);
            Outbound <MemberId, Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> loggingOutbound = new LoggingOutbound <MemberId, Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>(raftOutbound, identityModule.Myself(), messageLogger);

            _consensusModule = new ConsensusModule(identityModule.Myself(), platformModule, loggingOutbound, clusterStateDirectory.Get(), _topologyService);

            dependencies.SatisfyDependency(_consensusModule.raftMachine());

            _replicationModule = new ReplicationModule(_consensusModule.raftMachine(), identityModule.Myself(), platformModule, Config, loggingOutbound, clusterStateDirectory.Get(), fileSystem, LogProvider, globalGuard, localDatabase);

            _coreStateMachinesModule = new CoreStateMachinesModule(identityModule.Myself(), platformModule, clusterStateDirectory.Get(), Config, _replicationModule.Replicator, _consensusModule.raftMachine(), dependencies, localDatabase);

            IdContextFactoryConflict = IdContextFactoryBuilder.of(_coreStateMachinesModule.idTypeConfigurationProvider, platformModule.JobScheduler).withIdGenerationFactoryProvider(ignored => _coreStateMachinesModule.idGeneratorFactory).withFactoryWrapper(generator => new FreeIdFilteredIdGeneratorFactory(generator, _coreStateMachinesModule.freeIdCondition)).build();

            // TODO: this is broken, coreStateMachinesModule.tokenHolders should be supplier, somehow...
            this.TokenHoldersProviderConflict = databaseName => _coreStateMachinesModule.tokenHolders;
            this.LocksSupplierConflict        = _coreStateMachinesModule.locksSupplier;
            this.CommitProcessFactoryConflict = _coreStateMachinesModule.commitProcessFactory;
            this.AccessCapabilityConflict     = new LeaderCanWrite(_consensusModule.raftMachine());

            InstalledProtocolHandler serverInstalledProtocolHandler = new InstalledProtocolHandler();

            this._coreServerModule = new CoreServerModule(identityModule, platformModule, _consensusModule, _coreStateMachinesModule, clusteringModule, _replicationModule, localDatabase, databaseHealthSupplier, clusterStateDirectory.Get(), clientPipelineBuilderFactory, serverPipelineBuilderFactory, backupServerPipelineBuilderFactory, serverInstalledProtocolHandler);

            TypicallyConnectToRandomReadReplicaStrategy defaultStrategy = new TypicallyConnectToRandomReadReplicaStrategy(2);

            defaultStrategy.Inject(_topologyService, Config, LogProvider, identityModule.Myself());
            UpstreamDatabaseStrategySelector catchupStrategySelector = CreateUpstreamDatabaseStrategySelector(identityModule.Myself(), Config, LogProvider, _topologyService, defaultStrategy);

            Org.Neo4j.causalclustering.catchup.CatchupAddressProvider_PrioritisingUpstreamStrategyBasedAddressProvider catchupAddressProvider = new Org.Neo4j.causalclustering.catchup.CatchupAddressProvider_PrioritisingUpstreamStrategyBasedAddressProvider(_consensusModule.raftMachine(), _topologyService, catchupStrategySelector);
            RaftServerModule.CreateAndStart(platformModule, _consensusModule, identityModule, _coreServerModule, localDatabase, serverPipelineBuilderFactory, messageLogger, catchupAddressProvider, supportedRaftProtocols, supportedModifierProtocols, serverInstalledProtocolHandler);
            _serverInstalledProtocols = serverInstalledProtocolHandler.installedProtocols;

            EditionInvariants(platformModule, dependencies, Config, logging, life);

            life.Add(_coreServerModule.membershipWaiterLifecycle);
        }