示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRestartServicesIfCopyStoreFails() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRestartServicesIfCopyStoreFails()
        {
            when(_updatePuller.tryPullUpdates()).thenReturn(true);

            PageCache pageCacheMock = MockPageCache();

            StoreCopyClient storeCopyClient = mock(typeof(StoreCopyClient));

            doThrow(new Exception()).doNothing().when(storeCopyClient).copyStore(any(typeof(StoreCopyClient.StoreCopyRequester)), any(typeof(CancellationRequest)), any(typeof(MoveAfterCopy)));

            SwitchToSlaveCopyThenBranch switchToSlave = NewSwitchToSlaveSpy(pageCacheMock, storeCopyClient);

            URI localhost = LocalhostUri;

            try
            {
                switchToSlave.SwitchToSlaveConflict(mock(typeof(LifeSupport)), localhost, localhost, mock(typeof(CancellationRequest)));
                fail("Should have thrown an Exception");
            }
            catch (Exception)
            {
                verify(_requestContextFactory, never()).start();
                // Store should have been deleted due to failure in copy
                verify(switchToSlave).cleanStoreDir();

                // Try again, should succeed
                switchToSlave.SwitchToSlaveConflict(mock(typeof(LifeSupport)), localhost, localhost, mock(typeof(CancellationRequest)));
                verify(_requestContextFactory).start();
            }
        }
示例#2
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);
            }
        }
示例#3
0
        private BackupDelegator BackupDelegatorFromConfig(PageCache pageCache, Config config)
        {
            CatchUpClient catchUpClient = catchUpClient(config);
            TxPullClient  txPullClient  = new TxPullClient(catchUpClient, Monitors);
            ExponentialBackoffStrategy backOffStrategy = new ExponentialBackoffStrategy(1, config.Get(CausalClusteringSettings.store_copy_backoff_max_wait).toMillis(), TimeUnit.MILLISECONDS);
            StoreCopyClient            storeCopyClient = new StoreCopyClient(catchUpClient, Monitors, LogProvider, backOffStrategy);

            RemoteStore remoteStore = new RemoteStore(LogProvider, FileSystemAbstraction, pageCache, storeCopyClient, txPullClient, TransactionLogCatchUpFactory, config, Monitors);

            return(BackupDelegator(remoteStore, catchUpClient, storeCopyClient));
        }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy() throws Exception
        private SwitchToSlaveBranchThenCopy NewSwitchToSlaveSpy()
        {
            PageCache pageCacheMock = mock(typeof(PageCache));
            PagedFile pagedFileMock = mock(typeof(PagedFile));

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

            when(fileSystemAbstraction.StreamFilesRecursive(any(typeof(File)))).thenAnswer(f => Stream.empty());

            StoreCopyClient storeCopyClient = mock(typeof(StoreCopyClient));

            return(NewSwitchToSlaveSpy(pageCacheMock, storeCopyClient));
        }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy() throws Exception
        private SwitchToSlaveCopyThenBranch NewSwitchToSlaveSpy()
        {
            PageCache pageCacheMock = mock(typeof(PageCache));
            PagedFile pagedFileMock = mock(typeof(PagedFile));

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

            StoreCopyClient storeCopyClient = mock(typeof(StoreCopyClient));
            Stream          mockStream      = mock(typeof(Stream));

            when(mockStream.filter(any(typeof(System.Predicate)))).thenReturn(mockStream);
            FileSystemAbstraction fileSystemAbstraction = mock(typeof(FileSystemAbstraction));

            when(fileSystemAbstraction.StreamFilesRecursive(any(typeof(File)))).thenReturn(mockStream);
            return(NewSwitchToSlaveSpy(pageCacheMock, storeCopyClient));
        }
示例#6
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);
        }
示例#7
0
 internal SwitchToSlave(HaIdGeneratorFactory idGeneratorFactory, Monitors monitors, RequestContextFactory requestContextFactory, DelegateInvocationHandler <Master> masterDelegateHandler, ClusterMemberAvailability clusterMemberAvailability, MasterClientResolver masterClientResolver, Monitor monitor, PullerFactory pullerFactory, UpdatePuller updatePuller, System.Func <Slave, SlaveServer> slaveServerFactory, Config config, LogService logService, PageCache pageCache, DatabaseLayout databaseLayout, System.Func <TransactionIdStore> transactionIdStoreSupplier, System.Func <DatabaseTransactionStats> transactionStatsSupplier, System.Func <NeoStoreDataSource> neoDataSourceSupplier, StoreCopyClient storeCopyClient)
 {
     this._idGeneratorFactory        = idGeneratorFactory;
     this.Monitors                   = monitors;
     this.RequestContextFactory      = requestContextFactory;
     this._masterDelegateHandler     = masterDelegateHandler;
     this._clusterMemberAvailability = clusterMemberAvailability;
     this._masterClientResolver      = masterClientResolver;
     this.UserLog = logService.GetUserLog(this.GetType());
     this.MsgLog  = logService.GetInternalLog(this.GetType());
     this.Monitor = monitor;
     this._updatePullerFactory = pullerFactory;
     this.UpdatePuller         = updatePuller;
     this._slaveServerFactory  = slaveServerFactory;
     this.Config         = config;
     this.PageCache      = pageCache;
     this.DatabaseLayout = databaseLayout;
     this._transactionIdStoreSupplier = transactionIdStoreSupplier;
     this._transactionStatsSupplier   = transactionStatsSupplier;
     this._neoDataSourceSupplier      = neoDataSourceSupplier;
     this._storeCopyClient            = storeCopyClient;
 }
示例#8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy(org.neo4j.io.pagecache.PageCache pageCacheMock, org.neo4j.com.storecopy.StoreCopyClient storeCopyClient)
        private SwitchToSlaveCopyThenBranch NewSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient)
        {
            ClusterMembers clusterMembers = mock(typeof(ClusterMembers));
            ClusterMember  master         = mock(typeof(ClusterMember));

            when(master.StoreId).thenReturn(_storeId);
            when(master.HARole).thenReturn(HighAvailabilityModeSwitcher.MASTER);
            when(master.HasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true);
            when(master.InstanceId).thenReturn(new InstanceId(1));
            when(clusterMembers.Members).thenReturn(asList(master));

            Dependencies         resolver             = new Dependencies();
            DatabaseAvailability databaseAvailability = mock(typeof(DatabaseAvailability));

            when(databaseAvailability.Started).thenReturn(true);
            resolver.SatisfyDependencies(_requestContextFactory, clusterMembers, mock(typeof(TransactionObligationFulfiller)), mock(typeof(OnlineBackupKernelExtension)), mock(typeof(IndexConfigStore)), mock(typeof(TransactionCommittingResponseUnpacker)), mock(typeof(DataSourceManager)), mock(typeof(StoreLockerLifecycleAdapter)), mock(typeof(FileSystemWatcherService)), databaseAvailability);

            NeoStoreDataSource dataSource = mock(typeof(NeoStoreDataSource));

            when(dataSource.StoreId).thenReturn(_storeId);
            when(dataSource.DependencyResolver).thenReturn(resolver);

            DatabaseTransactionStats transactionCounters = mock(typeof(DatabaseTransactionStats));

            when(transactionCounters.NumberOfActiveTransactions).thenReturn(0L);

            Response <HandshakeResult> response = mock(typeof(Response));

            when(response.ResponseConflict()).thenReturn(new HandshakeResult(42, 2));
            when(_masterClient.handshake(anyLong(), any(typeof(StoreId)))).thenReturn(response);
            when(_masterClient.ProtocolVersion).thenReturn(Org.Neo4j.Kernel.ha.com.slave.MasterClient_Fields.Current);

            TransactionIdStore transactionIdStoreMock = mock(typeof(TransactionIdStore));

            // note that the checksum (the second member of the array) is the same as the one in the handshake mock above
            when(transactionIdStoreMock.LastCommittedTransaction).thenReturn(new TransactionId(42, 42, 42));

            MasterClientResolver masterClientResolver = mock(typeof(MasterClientResolver));

            when(masterClientResolver.Instantiate(anyString(), anyInt(), anyString(), any(typeof(Monitors)), argThat(_storeId => true), any(typeof(LifeSupport)))).thenReturn(_masterClient);

            return(spy(new SwitchToSlaveCopyThenBranch(TestDirectory.databaseLayout(), NullLogService.Instance, ConfigMock(), mock(typeof(HaIdGeneratorFactory)), mock(typeof(DelegateInvocationHandler)), mock(typeof(ClusterMemberAvailability)), _requestContextFactory, _pullerFactory, masterClientResolver, mock(typeof(SwitchToSlave.Monitor)), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave =>
            {
                SlaveServer server = mock(typeof(SlaveServer));
                InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42);

                when(server.SocketAddress).thenReturn(inetSocketAddress);
                return server;
            }, _updatePuller, pageCacheMock, mock(typeof(Monitors)), () => transactionCounters)));
        }
示例#9
0
 private static BackupDelegator BackupDelegator(RemoteStore remoteStore, CatchUpClient catchUpClient, StoreCopyClient storeCopyClient)
 {
     return(new BackupDelegator(remoteStore, catchUpClient, storeCopyClient));
 }