Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPruneReadersOfVersion() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPruneReadersOfVersion()
        {
            // given
            _pool = new ReaderPool(8, Instance, _fileNames, _fsa, _clock);

            Reader readerA = spy(_pool.acquire(0, 0));
            Reader readerB = spy(_pool.acquire(1, 0));
            Reader readerC = spy(_pool.acquire(1, 0));
            Reader readerD = spy(_pool.acquire(2, 0));

            _pool.release(readerA);
            _pool.release(readerB);
            _pool.release(readerC);
            _pool.release(readerD);

            // when
            _pool.prune(1);

            // then
            verify(readerA, never()).close();
            verify(readerB).close();
            verify(readerC).close();
            verify(readerD, never()).close();

            // when
            _pool.prune(0);
            // then
            verify(readerA).close();
            verify(readerD, never()).close();

            // when
            _pool.prune(2);
            // then
            verify(readerD).close();
        }
Esempio n. 2
0
        public override void Close()
        {
            CloseWriter();
            _readerPool.prune(_version);

            if (!_refCount.tryDispose())
            {
                throw new System.InvalidOperationException(format("Segment still referenced. Value: %d", _refCount.get()));
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPruneOldReaders() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPruneOldReaders()
        {
            // given
            Reader readerA = spy(_pool.acquire(0, 0));
            Reader readerB = spy(_pool.acquire(0, 0));

            _pool.release(readerA);

            _clock.forward(2, MINUTES);
            _pool.release(readerB);

            // when
            _clock.forward(1, MINUTES);
            _pool.prune(2, MINUTES);

            // then
            verify(readerA).close();
            verify(readerB, never()).close();
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void start() throws java.io.IOException, DamagedLogStorageException, DisposedException
        public override void Start()
        {
            lock (this)
            {
                if (!_directory.exists() && !_directory.mkdirs())
                {
                    throw new IOException("Could not create: " + _directory);
                }

                _state = (new RecoveryProtocol(_fileSystem, _fileNames, _readerPool, _contentMarshal, _logProvider)).run();
                _log.info("log started with recovered state %s", _state);

                /*
                 * Recovery guarantees that once complete the header of the last raft log file is intact. No such guarantee
                 * is made for the last log entry in the last file (or any of the files for that matter). To complete
                 * recovery we need to rotate away the last log file, so that any incomplete entries at the end of the last
                 * do not have entries appended after them, which would result in unaligned (and therefore wrong) reads.
                 * As an obvious optimization, we don't need to rotate if the file contains only the header, such as is
                 * the case of a newly created log.
                 */
                if (_state.segments.last().size() > SegmentHeader.Size)
                {
                    RotateSegment(_state.appendIndex, _state.appendIndex, _state.terms.latest());
                }

                _readerPoolPruner = _scheduler.scheduleRecurring(Group.RAFT_READER_POOL_PRUNER, () => _readerPool.prune(_readerPoolMaxAge, MINUTES), _readerPoolMaxAge, _readerPoolMaxAge, MINUTES);
            }
        }