コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void copyStoreFromMasterIfNeeded(java.net.URI masterUri, java.net.URI me, org.neo4j.helpers.CancellationRequest cancellationRequest) throws Throwable
        private void CopyStoreFromMasterIfNeeded(URI masterUri, URI me, CancellationRequest cancellationRequest)
        {
            if (!isStorePresent(PageCache, DatabaseLayout))
            {
                bool success = false;
                Monitor.storeCopyStarted();
                LifeSupport copyLife = new LifeSupport();
                try
                {
                    MasterClient masterClient = NewMasterClient(masterUri, me, null, copyLife);
                    copyLife.Start();

                    bool masterIsOld = Org.Neo4j.Kernel.ha.com.slave.MasterClient_Fields.Current.CompareTo(masterClient.ProtocolVersion) > 0;
                    if (masterIsOld)
                    {
                        throw new UnableToCopyStoreFromOldMasterException(Org.Neo4j.Kernel.ha.com.slave.MasterClient_Fields.Current.ApplicationProtocol, masterClient.ProtocolVersion.ApplicationProtocol);
                    }
                    else
                    {
                        CopyStoreFromMaster(masterClient, cancellationRequest, MoveAfterCopy.moveReplaceExisting());
                        success = true;
                    }
                }
                finally
                {
                    Monitor.storeCopyCompleted(success);
                    copyLife.Shutdown();
                }
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement()
        {
            // Given
            StoreCopyClient storeCopyClient = mock(typeof(StoreCopyClient));

            doAnswer(invocation =>
            {
                MoveAfterCopy moveAfterCopy = invocation.getArgument(2);
                moveAfterCopy.move(Stream.empty(), new File(""), Function.identity());
                return(null);
            }).when(storeCopyClient).copyStore(any(typeof(StoreCopyClient.StoreCopyRequester)), any(typeof(CancellationRequest)), any(typeof(MoveAfterCopy)));

            PageCache pageCacheMock = mock(typeof(PageCache));
            PagedFile pagedFileMock = mock(typeof(PagedFile));

            when(pagedFileMock.LastPageId).thenReturn(1L);
            when(pageCacheMock.Map(any(typeof(File)), anyInt())).thenReturn(pagedFileMock);

            SwitchToSlaveCopyThenBranch switchToSlave = NewSwitchToSlaveSpy(pageCacheMock, storeCopyClient);

            URI masterUri = new URI("cluster://localhost?serverId=1");
            URI me        = new URI("cluster://localhost?serverId=2");
            CancellationRequest cancellationRequest = Org.Neo4j.Helpers.CancellationRequest_Fields.NeverCancelled;

            MasterClient masterClient = mock(typeof(MasterClient));

            when(masterClient.Handshake(anyLong(), any(typeof(StoreId)))).thenThrow(new BranchedDataException(""));

            TransactionIdStore transactionIdStore = mock(typeof(TransactionIdStore));

            when(transactionIdStore.LastCommittedTransaction).thenReturn(new TransactionId(42, 42, 42));
            when(transactionIdStore.LastCommittedTransactionId).thenReturn(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID);

            // When
            BranchedDataPolicy branchPolicy = mock(typeof(BranchedDataPolicy));

            switchToSlave.StopServicesAndHandleBranchedStore(branchPolicy, masterUri, me, cancellationRequest);

            // Then
            InOrder inOrder = Mockito.inOrder(storeCopyClient, branchPolicy);

            inOrder.verify(storeCopyClient).copyStore(any(typeof(StoreCopyClient.StoreCopyRequester)), any(typeof(CancellationRequest)), any(typeof(MoveAfterCopy)));
            inOrder.verify(branchPolicy).handle(TestDirectory.databaseDir(), pageCacheMock, NullLogService.Instance);
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void copyStoreFromMaster(org.neo4j.kernel.ha.com.slave.MasterClient masterClient, org.neo4j.helpers.CancellationRequest cancellationRequest, org.neo4j.com.storecopy.MoveAfterCopy moveAfterCopy) throws Throwable
        internal virtual void CopyStoreFromMaster(MasterClient masterClient, CancellationRequest cancellationRequest, MoveAfterCopy moveAfterCopy)
        {
            try
            {
                UserLog.info("Copying store from master");
                StoreCopyClient.StoreCopyRequester requester = new StoreCopyRequesterAnonymousInnerClass(this, masterClient);
                MoveAfterCopy moveAfterCopyWithLogging       = (moves, fromDirectory, toDirectory) =>
                {
                    UserLog.info("Copied store from master to " + fromDirectory);
                    MsgLog.info("Starting post copy operation to move store from " + fromDirectory + " to " + toDirectory);
                    moveAfterCopy.Move(moves, fromDirectory, toDirectory);
                };
                _storeCopyClient.copyStore(requester, cancellationRequest, moveAfterCopyWithLogging);

                StartServicesAgain();
                UserLog.info("Finished copying store from master");
            }
            catch (Exception t)
            {
                // Delete store so that we can copy from master without conflicts next time
                CleanStoreDir();
                throw t;
            }
        }
コード例 #4
0
        private BackupOutcome FullBackup(FileSystemAbstraction fileSystem, string sourceHostNameOrIp, int sourcePort, DatabaseLayout targetLayout, ConsistencyCheck consistencyCheck, Config tuningConfiguration, long timeout, bool forensics)
        {
            try
            {
                if (!DirectoryIsEmpty(targetLayout))
                {
                    throw new Exception("Can only perform a full backup into an empty directory but " + targetLayout + " is not empty");
                }
                long timestamp       = DateTimeHelper.CurrentUnixTimeMillis();
                long lastCommittedTx = -1;
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                StoreCopyClient storeCopier = new StoreCopyClient(targetLayout, tuningConfiguration, LoadKernelExtensions(), _logProvider, fileSystem, _pageCacheContianer.PageCache, _monitors.newMonitor(typeof(StoreCopyClientMonitor), this.GetType().FullName), forensics);
                FullBackupStoreCopyRequester storeCopyRequester = new FullBackupStoreCopyRequester(sourceHostNameOrIp, sourcePort, timeout, forensics, _monitors);
                storeCopier.CopyStore(storeCopyRequester, Org.Neo4j.Helpers.CancellationRequest_Fields.NeverCancelled, MoveAfterCopy.moveReplaceExisting());

                tuningConfiguration.augment(logs_directory, targetLayout.databaseDirectory().toPath().toRealPath().ToString());
                File debugLogFile = tuningConfiguration.get(store_internal_log_path);
                BumpDebugDotLogFileVersion(debugLogFile, timestamp);
                bool consistent = CheckDbConsistency(fileSystem, targetLayout, consistencyCheck, tuningConfiguration, _pageCacheContianer.PageCache);
                ClearIdFiles(fileSystem, targetLayout);
                return(new BackupOutcome(lastCommittedTx, consistent));
            }
            catch (Exception e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new Exception(e);
            }
        }