예제 #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
            }
        }
예제 #2
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)
        {
            string database = _arguments.parse(args).get(ARG_DATABASE);
            Path   archive  = CalculateArchive(database, _arguments.getMandatoryPath("to"));

            Config         config                   = BuildConfig(database);
            Path           databaseDirectory        = canonicalPath(GetDatabaseDirectory(config));
            DatabaseLayout databaseLayout           = DatabaseLayout.of(databaseDirectory.toFile());
            Path           transactionLogsDirectory = canonicalPath(GetTransactionalLogsDirectory(config));

            try
            {
                Validators.CONTAINS_EXISTING_DATABASE.validate(databaseLayout.DatabaseDirectory());
            }
            catch (System.ArgumentException e)
            {
                throw new CommandFailed("database does not exist: " + database, e);
            }

            try
            {
                using (System.IDisposable ignored = StoreLockChecker.Check(databaseLayout.StoreLayout))
                {
                    CheckDbState(databaseLayout, config);
                    Dump(database, databaseLayout, transactionLogsDirectory, archive);
                }
            }
            catch (StoreLockException e)
            {
                throw new CommandFailed("the database is in use -- stop Neo4j and try again", e);
            }
            catch (IOException e)
            {
                WrapIOException(e);
            }
            catch (CannotWriteException e)
            {
                throw new CommandFailed("you do not have permission to dump the database -- is Neo4j running as a different user?", e);
            }
        }
예제 #3
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)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.nio.file.Path databaseDirectory = arguments.parse(args).getMandatoryPath("store");
            Path databaseDirectory = _arguments.parse(args).getMandatoryPath("store");

            Validators.CONTAINS_EXISTING_DATABASE.validate(databaseDirectory.toFile());

            DatabaseLayout databaseLayout = DatabaseLayout.of(databaseDirectory.toFile());

            try
            {
                using (System.IDisposable ignored = StoreLockChecker.Check(databaseLayout.StoreLayout), DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem, jobScheduler))
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String storeVersion = new org.neo4j.kernel.impl.storemigration.StoreVersionCheck(pageCache).getVersion(databaseLayout.metadataStore()).orElseThrow(() -> new org.neo4j.commandline.admin.CommandFailed(String.format("Could not find version metadata in store '%s'", databaseDirectory)));
                    string storeVersion = (new StoreVersionCheck(pageCache)).getVersion(databaseLayout.MetadataStore()).orElseThrow(() => new CommandFailed(string.Format("Could not find version metadata in store '{0}'", databaseDirectory)));

                    const string fmt = "%-30s%s";
                    @out.accept(string.format(fmt, "Store format version:", storeVersion));

                    RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
                    @out.accept(string.format(fmt, "Store format introduced in:", format.IntroductionVersion()));

                    findSuccessor(format).map(next => string.format(fmt, "Store format superseded in:", next.introductionVersion())).ifPresent(@out);
                }
            }
            catch (StoreLockException e)
            {
                throw new CommandFailed("the database is in use -- stop Neo4j and try again", e);
            }
            catch (Exception e)
            {
                throw new CommandFailed(e.Message, e);
            }
        }
예제 #4
0
        /// <summary>
        /// Create store lock checker with lock on a provided store layout if it exists and writable </summary>
        /// <param name="storeLayout"> store layout to check </param>
        /// <returns> lock checker or empty closeable in case if path does not exists or is not writable </returns>
        /// <exception cref="CannotWriteException">
        /// </exception>
        /// <seealso cref= StoreLocker </seealso>
        /// <seealso cref= Files </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static java.io.Closeable check(org.neo4j.io.layout.StoreLayout storeLayout) throws CannotWriteException
        internal static System.IDisposable Check(StoreLayout storeLayout)
        {
            Path lockFile = storeLayout.StoreLockFile().toPath();

            if (Files.exists(lockFile))
            {
                if (Files.isWritable(lockFile))
                {
                    StoreLockChecker storeLocker = new StoreLockChecker(new DefaultFileSystemAbstraction(), storeLayout);
                    try
                    {
                        storeLocker.CheckLock();
                        return(storeLocker);
                    }
                    catch (StoreLockException le)
                    {
                        try
                        {
                            storeLocker.Dispose();
                        }
                        catch (IOException e)
                        {
                            le.addSuppressed(e);
                        }
                        throw le;
                    }
                }
                else
                {
                    throw new CannotWriteException(lockFile);
                }
            }
            return(() =>
            {
            });
        }