コード例 #1
0
ファイル: TestLogPruning.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private int figureOutSampleTransactionSizeBytes() throws java.io.IOException
        private int FigureOutSampleTransactionSizeBytes()
        {
            _db = NewDb("true", 5);
            DoTransaction();
            _db.shutdown();
            return(( int )_fs.getFileSize(_files.getLogFileForVersion(0)));
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseWhenFileSizeIsLowerThanMaxSize()
        public virtual void ShouldReturnFalseWhenFileSizeIsLowerThanMaxSize()
        {
            // given
            const long maxSize = 10;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final FileSizeThreshold threshold = new FileSizeThreshold(fs, maxSize);
            FileSizeThreshold threshold = new FileSizeThreshold(_fs, maxSize);

            when(_fs.getFileSize(_file)).thenReturn(5L);

            // when
            threshold.Init();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean result = threshold.reached(file, version, source);
            bool result = threshold.Reached(_file, _version, _source);

            // then
            assertFalse(result);
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotDeleteAnythingIfThresholdDoesNotAllow()
        public virtual void ShouldNotDeleteAnythingIfThresholdDoesNotAllow()
        {
            // Given
            File fileName0 = new File("logical.log.v0");
            File fileName1 = new File("logical.log.v1");
            File fileName2 = new File("logical.log.v2");
            File fileName3 = new File("logical.log.v3");
            File fileName4 = new File("logical.log.v4");
            File fileName5 = new File("logical.log.v5");
            File fileName6 = new File("logical.log.v6");

            when(_files.getLogFileForVersion(6)).thenReturn(fileName6);
            when(_files.getLogFileForVersion(5)).thenReturn(fileName5);
            when(_files.getLogFileForVersion(4)).thenReturn(fileName4);
            when(_files.getLogFileForVersion(3)).thenReturn(fileName3);
            when(_files.getLogFileForVersion(2)).thenReturn(fileName2);
            when(_files.getLogFileForVersion(1)).thenReturn(fileName1);
            when(_files.getLogFileForVersion(0)).thenReturn(fileName0);

            when(_fileSystem.fileExists(fileName6)).thenReturn(true);
            when(_fileSystem.fileExists(fileName5)).thenReturn(true);
            when(_fileSystem.fileExists(fileName4)).thenReturn(true);
            when(_fileSystem.fileExists(fileName3)).thenReturn(true);
            when(_fileSystem.fileExists(fileName2)).thenReturn(true);
            when(_fileSystem.fileExists(fileName1)).thenReturn(true);
            when(_fileSystem.fileExists(fileName0)).thenReturn(true);

            when(_fileSystem.getFileSize(any())).thenReturn(LOG_HEADER_SIZE + 1L);

            when(_threshold.reached(any(), anyLong(), any())).thenReturn(false);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ThresholdBasedPruneStrategy strategy = new ThresholdBasedPruneStrategy(fileSystem, files, threshold);
            ThresholdBasedPruneStrategy strategy = new ThresholdBasedPruneStrategy(_fileSystem, _files, _threshold);

            // When
            strategy.FindLogVersionsToDelete(7L).forEachOrdered(v => _fileSystem.deleteFile(_files.getLogFileForVersion(v)));

            // Then
            verify(_threshold, times(1)).init();
            verify(_fileSystem, never()).deleteFile(any());
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteNewFileWhenExistingFileHasZeroLength() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteNewFileWhenExistingFileHasZeroLength()
        {
            // Given
            _file.createNewFile();

            // When
            IndexProviderStore store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong("3.5"), false);

            // Then
            assertTrue(_fileSystem.getFileSize(_file) > 0);
            store.Close();
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void copyTransactionLogContent(long logFileIndex, long logOffset, java.util.zip.ZipOutputStream destination, ByteBuffer byteBuffer) throws java.io.IOException
        private void CopyTransactionLogContent(long logFileIndex, long logOffset, ZipOutputStream destination, ByteBuffer byteBuffer)
        {
            File logFile = _logFiles.getLogFileForVersion(logFileIndex);

            if (_fs.getFileSize(logFile) == logOffset)
            {
                // file was recovered fully, nothing to backup
                return;
            }
            ZipEntry zipEntry = new ZipEntry(logFile.Name);

            destination.putNextEntry(zipEntry);
            using (StoreChannel transactionLogChannel = _fs.open(logFile, OpenMode.READ))
            {
                transactionLogChannel.Position(logOffset);
                while (transactionLogChannel.read(byteBuffer) >= 0)
                {
                    byteBuffer.flip();
                    destination.write(byteBuffer.array(), byteBuffer.position(), byteBuffer.remaining());
                    byteBuffer.clear();
                }
            }
            destination.closeEntry();
        }
コード例 #6
0
        public override LongStream FindLogVersionsToDelete(long upToVersion)
        {
            lock (this)
            {
                if (upToVersion == INITIAL_LOG_VERSION)
                {
                    return(LongStream.empty());
                }

                _threshold.init();
                long upper    = upToVersion - 1;
                bool exceeded = false;
                while (upper >= 0)
                {
                    File file = _files.getLogFileForVersion(upper);
                    if (!_fileSystem.fileExists(file))
                    {
                        // There aren't logs to prune anything. Just return
                        return(LongStream.empty());
                    }

                    if (_fileSystem.getFileSize(file) > LOG_HEADER_SIZE && _threshold.reached(file, upper, _logFileInformation))
                    {
                        exceeded = true;
                        break;
                    }
                    upper--;
                }

                if (!exceeded)
                {
                    return(LongStream.empty());
                }

                // Find out which log is the earliest existing (lower bound to prune)
                long lower = upper;
                while (_fileSystem.fileExists(_files.getLogFileForVersion(lower - 1)))
                {
                    lower--;
                }

                /*
                 * Here we make sure that at least one historical log remains behind, in addition of course to the
                 * current one. This is in order to make sure that at least one transaction remains always available for
                 * serving to whomever asks for it.
                 * To illustrate, imagine that there is a threshold in place configured so that it enforces pruning of the
                 * log file that was just rotated out (for example, a file size threshold that is misconfigured to be smaller
                 * than the smallest log). In such a case, until the database commits a transaction there will be no
                 * transactions present on disk, making impossible to serve any to whichever client might ask, leading to
                 * errors on both sides of the conversation.
                 * This if statement does nothing more complicated than checking if the next-to-last log would be pruned
                 * and simply skipping it if so.
                 */
                if (upper == upToVersion - 1)
                {
                    upper--;
                }

                // The reason we delete from lower to upper is that if it crashes in the middle we can be sure that no holes
                // are created.
                // We create a closed range because we want to include the 'upper' log version as well. The check above ensures
                // we don't accidentally leave the database without any logs.
                return(LongStream.rangeClosed(lower, upper));
            }
        }
コード例 #7
0
ファイル: FileSizeThreshold.cs プロジェクト: Neo4Net/Neo4Net
 public override bool Reached(File file, long version, LogFileInformation source)
 {
     _currentSize += _fileSystem.getFileSize(file);
     return(_currentSize >= _maxSize);
 }