Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void prepareNeoStoreFile(String storeVersion, org.neo4j.io.pagecache.PageCache pageCache) throws java.io.IOException
        private void PrepareNeoStoreFile(string storeVersion, PageCache pageCache)
        {
            File neoStoreFile = CreateNeoStoreFile();
            long value        = MetaDataStore.versionStringToLong(storeVersion);

            MetaDataStore.setRecord(pageCache, neoStoreFile, STORE_VERSION, value);
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void StartTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed()
        {
            // given
            // create a store
            File databaseDirectory  = _testDirectory.databaseDir();
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(databaseDirectory);

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            Db.shutdown();

            // mess up the version in the metadatastore
            string badStoreVersion = "bad";

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler(), PageCache pageCache = createPageCache(fileSystem, scheduler))
            {
                MetaDataStore.setRecord(pageCache, _testDirectory.databaseLayout().metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion));
            }

            Exception exception = assertThrows(typeof(Exception), () => (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(databaseDirectory).setConfig(GraphDatabaseSettings.allow_upgrade, "true").newGraphDatabase());

            assertTrue(exception.InnerException is LifecycleException);
            assertTrue(exception.InnerException.InnerException is StoreUpgrader.UnexpectedUpgradingStoreVersionException);
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws java.io.IOException
        private void AppendNullTransactionLogEntryToSetRaftIndexToMinusOne()
        {
            ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(_pageCache, _databaseLayout);
            LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(_databaseLayout, _fs, _pageCache).withConfig(_config).withLastCommittedTransactionIdSupplier(() => readOnlyTransactionIdStore.LastClosedTransactionId - 1).build();

            long dummyTransactionId;

            using (Lifespan lifespan = new Lifespan(logFiles))
            {
                FlushableChannel     channel = logFiles.LogFile.Writer;
                TransactionLogWriter writer  = new TransactionLogWriter(new LogEntryWriter(channel));

                long lastCommittedTransactionId      = readOnlyTransactionIdStore.LastCommittedTransactionId;
                PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(Collections.emptyList());
                sbyte[] txHeaderBytes = LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader(-1);
                tx.SetHeader(txHeaderBytes, -1, -1, -1, lastCommittedTransactionId, -1, -1);

                dummyTransactionId = lastCommittedTransactionId + 1;
                writer.Append(tx, dummyTransactionId);
                channel.PrepareForFlush().flush();
            }

            File neoStoreFile = _databaseLayout.metadataStore();

            MetaDataStore.setRecord(_pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId);
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void prepareNeoStoreFile(org.neo4j.io.fs.FileSystemAbstraction fileSystem, org.neo4j.io.layout.DatabaseLayout databaseLayout, String storeVersion, org.neo4j.io.pagecache.PageCache pageCache) throws java.io.IOException
        private static void PrepareNeoStoreFile(FileSystemAbstraction fileSystem, DatabaseLayout databaseLayout, string storeVersion, PageCache pageCache)
        {
            File neoStoreFile = CreateNeoStoreFile(fileSystem, databaseLayout);
            long value        = MetaDataStore.versionStringToLong(storeVersion);

            MetaDataStore.setRecord(pageCache, neoStoreFile, STORE_VERSION, value);
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void StartTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed()
        {
            // given
            // create a store
            File databaseDir        = _testDirectory.databaseDir();
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(databaseDir);

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            Db.shutdown();

            // mess up the version in the metadatastore
            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler(), PageCache pageCache = createPageCache(fileSystem, scheduler))
            {
                MetaDataStore.setRecord(pageCache, _testDirectory.databaseLayout().metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"));
            }

            Exception exception = assertThrows(typeof(Exception), () => (new TestGraphDatabaseFactory()).newEmbeddedDatabase(databaseDir));

            assertTrue(exception.InnerException is LifecycleException);
            assertTrue(exception.InnerException.InnerException is System.ArgumentException);
            assertEquals("Unknown store version 'bad'", exception.InnerException.InnerException.Message);
        }
Exemple #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void changeStoreId(org.neo4j.causalclustering.discovery.ReadReplica replica) throws java.io.IOException
        private static void ChangeStoreId(ReadReplica replica)
        {
            File      neoStoreFile = DatabaseLayout.of(replica.DatabaseDirectory()).metadataStore();
            PageCache pageCache    = replica.Database().DependencyResolver.resolveDependency(typeof(PageCache));

            MetaDataStore.setRecord(pageCache, neoStoreFile, TIME, DateTimeHelper.CurrentUnixTimeMillis());
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustReadStoreId() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustReadStoreId()
        {
            File              dir                  = BaseDir;
            DatabaseLayout    databaseLayout       = TestDirectory.databaseLayout(dir);
            File              neostore             = databaseLayout.MetadataStore();
            ThreadLocalRandom rng                  = ThreadLocalRandom.current();
            long              time                 = rng.nextLong();
            long              randomNumber         = rng.nextLong();
            long              upgradeTime          = rng.nextLong();
            long              upgradeTransactionId = rng.nextLong();

            CreateOnFileSystem(neostore);

            MetaDataStore.setRecord(_pageCache, neostore, MetaDataStore.Position.TIME, time);
            MetaDataStore.setRecord(_pageCache, neostore, MetaDataStore.Position.RANDOM_NUMBER, randomNumber);
            MetaDataStore.setRecord(_pageCache, neostore, MetaDataStore.Position.STORE_VERSION, rng.nextLong());
            MetaDataStore.setRecord(_pageCache, neostore, MetaDataStore.Position.UPGRADE_TIME, upgradeTime);
            MetaDataStore.setRecord(_pageCache, neostore, MetaDataStore.Position.UPGRADE_TRANSACTION_ID, upgradeTransactionId);

            StoreId storeId = _storeFiles.readStoreId(databaseLayout);

            assertThat(storeId.CreationTime, @is(time));
            assertThat(storeId.RandomId, @is(randomNumber));
            assertThat(storeId.UpgradeTime, @is(upgradeTime));
            assertThat(storeId.UpgradeId, @is(upgradeTransactionId));
        }
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void clearLastTransactionCommitTimestampField(org.neo4j.io.layout.DatabaseLayout databaseLayout) throws Exception
        private static void ClearLastTransactionCommitTimestampField(DatabaseLayout databaseLayout)
        {
            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pageCache = createPageCache(fileSystem, jobScheduler))
            {
                File neoStore = databaseLayout.MetadataStore();
                MetaDataStore.setRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, MetaDataStore.BASE_TX_COMMIT_TIMESTAMP);
            }
        }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void changeStoreId(org.neo4j.io.layout.DatabaseLayout databaseLayout) throws Exception
        private void ChangeStoreId(DatabaseLayout databaseLayout)
        {
            File neoStoreFile = databaseLayout.MetadataStore();

            using (JobScheduler jobScheduler = new ThreadPoolJobScheduler(), PageCache pageCache = StandalonePageCacheFactory.createPageCache(_fs, jobScheduler))
            {
                MetaDataStore.setRecord(pageCache, neoStoreFile, RANDOM_NUMBER, DateTimeHelper.CurrentUnixTimeMillis());
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void Setup()
            {
                FileSystem     = FileSystemRule.get();
                DatabaseLayout = TestDirectory.databaseLayout();
                // doesn't matter which version we pick we are changing it to the wrong one...
                MigrationTestUtils.FindFormatStoreDirectoryForVersion(StandardV2_3.STORE_VERSION, DatabaseLayout.databaseDirectory());
                changeVersionNumber(FileSystem, DatabaseLayout.file(NEOSTORE_FILENAME), Version);
                File      metadataStore = DatabaseLayout.metadataStore();
                PageCache pageCache     = PageCacheRule.getPageCache(FileSystem);

                MetaDataStore.setRecord(pageCache, metadataStore, STORE_VERSION, MetaDataStore.versionStringToLong(Version));
                VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(DatabaseLayout.databaseDirectory(), FileSystem).build();

                TailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors());
            }
Exemple #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void updateOrAddNeoStoreFieldsAsPartOfMigration(org.neo4j.io.layout.DatabaseLayout migrationStructure, org.neo4j.io.layout.DatabaseLayout sourceDirectoryStructure, String versionToMigrateTo, org.neo4j.kernel.impl.transaction.log.LogPosition lastClosedTxLogPosition) throws java.io.IOException
        private void UpdateOrAddNeoStoreFieldsAsPartOfMigration(DatabaseLayout migrationStructure, DatabaseLayout sourceDirectoryStructure, string versionToMigrateTo, LogPosition lastClosedTxLogPosition)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File storeDirNeoStore = sourceDirectoryStructure.metadataStore();
            File storeDirNeoStore = sourceDirectoryStructure.MetadataStore();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File migrationDirNeoStore = migrationStructure.metadataStore();
            File migrationDirNeoStore = migrationStructure.MetadataStore();

            fileOperation(COPY, _fileSystem, sourceDirectoryStructure, migrationStructure, Iterables.iterable(DatabaseFile.METADATA_STORE), true, ExistingTargetStrategy.SKIP);

            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.UPGRADE_TRANSACTION_ID, MetaDataStore.getRecord(_pageCache, storeDirNeoStore, MetaDataStore.Position.LAST_TRANSACTION_ID));
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.UPGRADE_TIME, DateTimeHelper.CurrentUnixTimeMillis());

            // Store the checksum of the transaction id the upgrade is at right now. Store it both as
            // LAST_TRANSACTION_CHECKSUM and UPGRADE_TRANSACTION_CHECKSUM. Initially the last transaction and the
            // upgrade transaction will be the same, but imagine this scenario:
            //  - legacy store is migrated on instance A at transaction T
            //  - upgraded store is copied, via backup or HA or whatever to instance B
            //  - instance A performs a transaction
            //  - instance B would like to communicate with A where B's last transaction checksum
            //    is verified on A. A, at this point not having logs from pre-migration era, will need to
            //    know the checksum of transaction T to accommodate for this request from B. A will be able
            //    to look up checksums for transactions succeeding T by looking at its transaction logs,
            //    but T needs to be stored in neostore to be accessible. Obviously this scenario is only
            //    problematic as long as we don't migrate and translate old logs.
            TransactionId lastTxInfo = ReadLastTxInformation(migrationStructure);

            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.LAST_TRANSACTION_CHECKSUM, lastTxInfo.Checksum());
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.UPGRADE_TRANSACTION_CHECKSUM, lastTxInfo.Checksum());
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.CommitTimestamp());
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.CommitTimestamp());

            // add LAST_CLOSED_TRANSACTION_LOG_VERSION and LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET to the migrated
            // NeoStore
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, lastClosedTxLogPosition.LogVersion);
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, lastClosedTxLogPosition.ByteOffset);

            // Upgrade version in NeoStore
            MetaDataStore.setRecord(_pageCache, migrationDirNeoStore, MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(versionToMigrateTo));
        }
Exemple #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void close() throws java.io.IOException
        public override void Close()
        {
            lock (this)
            {
                if (_asPartOfStoreCopy)
                {
                    /* A checkpoint which points to the beginning of all the log files, meaning that
                     * all the streamed transactions will be applied as part of recovery. */
                    long        logVersion         = _logFiles.LowestLogVersion;
                    LogPosition checkPointPosition = new LogPosition(logVersion, LOG_HEADER_SIZE);

                    _log.info("Writing checkpoint as part of store copy: " + checkPointPosition);
                    _writer.checkPoint(checkPointPosition);

                    // * comment copied from old StoreCopyClient *
                    // since we just create new log and put checkpoint into it with offset equals to
                    // LOG_HEADER_SIZE we need to update last transaction offset to be equal to this newly defined max
                    // offset otherwise next checkpoint that use last transaction offset will be created for non
                    // existing offset that is in most of the cases bigger than new log size.
                    // Recovery will treat that as last checkpoint and will not try to recover store till new
                    // last closed transaction offset will not overcome old one. Till that happens it will be
                    // impossible for recovery process to restore the store
                    File neoStore = _databaseLayout.metadataStore();
                    MetaDataStore.setRecord(_pageCache, neoStore, LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, checkPointPosition.ByteOffset);
                }

                _lifespan.close();

                if (_lastTxId != -1)
                {
                    File neoStoreFile = _databaseLayout.metadataStore();
                    MetaDataStore.setRecord(_pageCache, neoStoreFile, LAST_TRANSACTION_ID, _lastTxId);
                }
                _stores.close();
            }
        }