Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void confirmTargetDirectoryIsWritable(org.neo4j.io.layout.StoreLayout storeLayout) throws CannotWriteException, java.io.IOException
        private static void ConfirmTargetDirectoryIsWritable(StoreLayout storeLayout)
        {
            using (System.IDisposable ignored = StoreLockChecker.Check(storeLayout))
            {
                // empty
            }
        }
Exemple #2
0
        public virtual DatabaseLayout DatabaseLayout(File storeDir)
        {
            DatabaseLayout databaseLayout = StoreLayout.of(storeDir).databaseLayout(DEFAULT_DATABASE_DIRECTORY);

            CreateDirectory(databaseLayout.DatabaseDirectory());
            return(databaseLayout);
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRespectTheStoreLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRespectTheStoreLock()
        {
            Path        databaseDirectory = _homeDir.resolve("data/databases/foo.db");
            StoreLayout storeLayout       = DatabaseLayout.of(databaseDirectory.toFile()).StoreLayout;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker storeLocker = new StoreLocker(fileSystem, storeLayout))
            {
                storeLocker.CheckLock();

                CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));
                assertEquals("the database is in use -- stop Neo4j and try again", commandFailed.Message);
            }
        }
Exemple #4
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            StoreLayout that = ( StoreLayout )o;

            return(Objects.Equals(_storeDirectory, that._storeDirectory));
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldExcludeTheStoreLockFromTheArchiveToAvoidProblemsWithReadingLockedFilesOnWindows() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldExcludeTheStoreLockFromTheArchiveToAvoidProblemsWithReadingLockedFilesOnWindows()
        {
            File lockFile = StoreLayout.of(new File(".")).storeLockFile();

            doAnswer(invocation =>
            {
                Predicate <Path> exclude = invocation.getArgument(4);
                assertThat(exclude.test(Paths.get(lockFile.Name)), @is(true));
                assertThat(exclude.test(Paths.get("some-other-file")), @is(false));
                return(null);
            }).when(_dumper).dump(any(), any(), any(), any(), any());

            Execute("foo.db");
        }
Exemple #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void prepareDirectory(Class testClass, String test) throws java.io.IOException
        public virtual void PrepareDirectory(Type testClass, string test)
        {
            if (_owningTest == null)
            {
                _owningTest = testClass;
            }
            if (string.ReferenceEquals(test, null))
            {
                test = "static";
            }
            _testDirectory         = PrepareDirectoryForTest(test);
            _storeLayout           = StoreLayout.of(_testDirectory);
            _defaultDatabaseLayout = _storeLayout.databaseLayout(DEFAULT_DATABASE_DIRECTORY);
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock()
        {
            StoreLayout storeLayout = DatabaseLayout.of(_databaseDirectory.toFile()).StoreLayout;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker storeLocker = new StoreLocker(fileSystem, storeLayout))
            {
                storeLocker.CheckLock();

                using (System.IDisposable ignored = withPermissions(storeLayout.StoreLockFile().toPath(), emptySet()))
                {
                    CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));
                    assertEquals(commandFailed.Message, "you do not have permission to dump the database -- is Neo4j running as a different user?");
                }
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void complete(boolean success) throws java.io.IOException
        public virtual void Complete(bool success)
        {
            try
            {
                if (success && _testDirectory != null && !_keepDirectoryAfterSuccessfulTest)
                {
                    _fileSystem.deleteRecursively(_testDirectory);
                }
                _testDirectory         = null;
                _storeLayout           = null;
                _defaultDatabaseLayout = null;
            }
            finally
            {
                _fileSystem.Dispose();
            }
        }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void checkLock(org.neo4j.io.layout.StoreLayout storeLayout) throws org.neo4j.commandline.admin.CommandFailed
        public static void CheckLock(StoreLayout storeLayout)
        {
            try
            {
                using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker storeLocker = new GlobalStoreLocker(fileSystem, storeLayout))
                {
                    storeLocker.CheckLock();
                }
            }
            catch (StoreLockException e)
            {
                throw new CommandFailed("the database is in use -- stop Neo4j and try again", e);
            }
            catch (IOException e)
            {
                WrapIOException(e);
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotObtainLockWhenUnableToOpenLockFile() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotObtainLockWhenUnableToOpenLockFile()
        {
            FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstractionAnonymousInnerClass4(this, FileSystemRule.get());

            StoreLayout storeLayout = Target.storeLayout();

            try
            {
                using (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction, storeLayout))
                {
                    storeLocker.CheckLock();
                    fail();
                }
            }
            catch (StoreLockException e)
            {
                string msg = format("Unable to obtain lock on store lock file: %s. " + "Please ensure no other process is using this database, and that the " + "directory is writable (required even for read-only access)", storeLayout.StoreLockFile());
                assertThat(e.Message, @is(msg));
            }
        }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void onlyTheLatestTransactionIsKeptAfterIncrementalBackup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void OnlyTheLatestTransactionIsKeptAfterIncrementalBackup()
        {
            // given database exists with data
            int port = PortAuthority.allocatePort();

            StartDb(port);
            CreateSomeData(_db);

            // and backup client is told to rotate conveniently
            Config config             = Config.builder().withSetting(GraphDatabaseSettings.logical_log_rotation_threshold, "1m").build();
            File   configOverrideFile = _testDirectory.file("neo4j-backup.conf");

            OnlineBackupCommandBuilder.WriteConfigToFile(config, configOverrideFile);

            // and we have a full backup
            string backupName = "backupName" + RecordFormat;
            string address    = "localhost:" + port;

            assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(_backupDir, "--from", address, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--protocol=common", "--additional-config=" + configOverrideFile, "--name=" + backupName));

            // and the database contains a few more transactions
            Transactions1M(_db);
            Transactions1M(_db);                 // rotation, second tx log file

            // when we perform an incremental backup
            assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(_backupDir, "--from", address, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--protocol=common", "--additional-config=" + configOverrideFile, "--name=" + backupName));

            // then there has been a rotation
            BackupTransactionLogFilesHelper backupTransactionLogFilesHelper = new BackupTransactionLogFilesHelper();
            LogFiles logFiles = BackupTransactionLogFilesHelper.ReadLogFiles(StoreLayout.of(_backupDir).databaseLayout(backupName));
            long     highestTxIdInLogFiles = logFiles.HighestLogVersion;

            assertEquals(2, highestTxIdInLogFiles);

            // and the original log has not been removed since the transactions are applied at start
            long lowestTxIdInLogFiles = logFiles.LowestLogVersion;

            assertEquals(0, lowestTxIdInLogFiles);
        }
Exemple #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void keepLockWhenOtherTryToTakeLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void KeepLockWhenOtherTryToTakeLock()
        {
            StoreLayout storeLayout = Target.storeLayout();
            DefaultFileSystemAbstraction fileSystemAbstraction = FileSystemRule.get();
            StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction, storeLayout);

            storeLocker.CheckLock();

            try
            {
                using (StoreLocker storeLocker1 = new StoreLocker(fileSystemAbstraction, storeLayout))
                {
                    storeLocker1.CheckLock();
                    fail();
                }
            }
            catch (StoreLockException)
            {
                // Expected
            }

            // Initial locker should still have a valid lock
            try
            {
                using (StoreLocker storeLocker1 = new StoreLocker(fileSystemAbstraction, storeLayout))
                {
                    storeLocker1.CheckLock();
                    fail();
                }
            }
            catch (StoreLockException)
            {
                // Expected
            }

            storeLocker.Dispose();
        }
Exemple #13
0
 public StoreLocker(FileSystemAbstraction fileSystemAbstraction, StoreLayout storeLayout)
 {
     this.FileSystemAbstraction = fileSystemAbstraction;
     StoreLockFile = storeLayout.StoreLockFile();
 }
Exemple #14
0
 public GlobalStoreLocker(FileSystemAbstraction fileSystemAbstraction, StoreLayout storeLayout) : base(fileSystemAbstraction, storeLayout)
 {
 }
Exemple #15
0
        public PlatformModule(File providedStoreDir, Config config, DatabaseInfo databaseInfo, GraphDatabaseFacadeFactory.Dependencies externalDependencies)
        {
            this.DatabaseInfo      = databaseInfo;
            this.DataSourceManager = new DataSourceManager(config);
            Dependencies           = new Dependencies();
            Dependencies.satisfyDependency(databaseInfo);

            Clock = Dependencies.satisfyDependency(CreateClock());
            Life  = Dependencies.satisfyDependency(CreateLife());

            this.StoreLayout = StoreLayout.of(providedStoreDir);

            config.AugmentDefaults(GraphDatabaseSettings.neo4j_home, StoreLayout.storeDirectory().Path);
            this.Config = Dependencies.satisfyDependency(config);

            FileSystem = Dependencies.satisfyDependency(CreateFileSystemAbstraction());
            Life.add(new FileSystemLifecycleAdapter(FileSystem));

            // Component monitoring
            Monitors = externalDependencies.Monitors() == null ? new Monitors() : externalDependencies.Monitors();
            Dependencies.satisfyDependency(Monitors);

            JobScheduler = Life.add(Dependencies.satisfyDependency(CreateJobScheduler()));
            StartDeferredExecutors(JobScheduler, externalDependencies.DeferredExecutors());

            // Cleanup after recovery, used by GBPTree, added to life in NeoStoreDataSource
            RecoveryCleanupWorkCollector = new GroupingRecoveryCleanupWorkCollector(JobScheduler);
            Dependencies.satisfyDependency(RecoveryCleanupWorkCollector);

            // Database system information, used by UDC
            UsageData = new UsageData(JobScheduler);
            Dependencies.satisfyDependency(Life.add(UsageData));

            // If no logging was passed in from the outside then create logging and register
            // with this life
            Logging = Dependencies.satisfyDependency(CreateLogService(externalDependencies.UserLogProvider()));

            config.Logger = Logging.getInternalLog(typeof(Config));

            Life.add(Dependencies.satisfyDependency(new StoreLockerLifecycleAdapter(CreateStoreLocker())));

            (new JvmChecker(Logging.getInternalLog(typeof(JvmChecker)), new JvmMetadataRepository())).checkJvmCompatibilityAndIssueWarning();

            string desiredImplementationName = config.Get(GraphDatabaseSettings.tracer);

            Tracers = Dependencies.satisfyDependency(new Tracers(desiredImplementationName, Logging.getInternalLog(typeof(Tracers)), Monitors, JobScheduler, Clock));
            Dependencies.satisfyDependency(Tracers.pageCacheTracer);
            Dependencies.satisfyDependency(FirstImplementor(typeof(LogRotationMonitor), Tracers.transactionTracer, LogRotationMonitor.NULL));
            Dependencies.satisfyDependency(FirstImplementor(typeof(CheckPointerMonitor), Tracers.checkPointTracer, CheckPointerMonitor.NULL));

            VersionContextSupplier = CreateCursorContextSupplier(config);

            CollectionsFactorySupplier = CreateCollectionsFactorySupplier(config, Life);

            Dependencies.satisfyDependency(VersionContextSupplier);
            PageCache = Dependencies.satisfyDependency(CreatePageCache(FileSystem, config, Logging, Tracers, VersionContextSupplier, JobScheduler));

            Life.add(new PageCacheLifecycle(PageCache));

            DiagnosticsManager = Life.add(Dependencies.satisfyDependency(new DiagnosticsManager(Logging.getInternalLog(typeof(DiagnosticsManager)))));
            SystemDiagnostics.registerWith(DiagnosticsManager);

            Dependencies.satisfyDependency(DataSourceManager);

            KernelExtensionFactories = externalDependencies.KernelExtensions();
            EngineProviders          = externalDependencies.ExecutionEngines();
            GlobalKernelExtensions   = Dependencies.satisfyDependency(new GlobalKernelExtensions(new SimpleKernelContext(StoreLayout.storeDirectory(), databaseInfo, Dependencies), KernelExtensionFactories, Dependencies, KernelExtensionFailureStrategies.fail()));

            UrlAccessRule = Dependencies.satisfyDependency(URLAccessRules.combined(externalDependencies.UrlAccessRules()));

            ConnectorPortRegister = new ConnectorPortRegister();
            Dependencies.satisfyDependency(ConnectorPortRegister);

            EventHandlers       = new KernelEventHandlers(Logging.getInternalLog(typeof(KernelEventHandlers)));
            PanicEventGenerator = new DatabasePanicEventGenerator(EventHandlers);

            PublishPlatformInfo(Dependencies.resolveDependency(typeof(UsageData)));
        }
        /// <summary>
        /// Sets the store layout for the enterprise. By default, storeLayoutType is set to "basic" and the basic store layout is enabled. The basic layout only contains apps approved by the admin, and that have been added to the available product set for a user (using the  setAvailableProductSet call). Apps on the page are sorted in order of their product ID value. If you create a custom store layout (by setting storeLayoutType = "custom" and setting a homepage), the basic store layout is disabled.
        /// Documentation https://developers.google.com/androidenterprise/v1/reference/enterprises/setStoreLayout
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Androidenterprise service.</param>
        /// <param name="enterpriseId">The ID of the enterprise.</param>
        /// <param name="body">A valid Androidenterprise v1 body.</param>
        /// <returns>StoreLayoutResponse</returns>
        public static StoreLayout SetStoreLayout(AndroidenterpriseService service, string enterpriseId, StoreLayout body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (enterpriseId == null)
                {
                    throw new ArgumentNullException(enterpriseId);
                }

                // Make the request.
                return(service.Enterprises.SetStoreLayout(body, enterpriseId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Enterprises.SetStoreLayout failed.", ex);
            }
        }