Beispiel #1
0
        public Buffer PinNew(string filename, IPageFormatter pageFormatter)
        {
            //try
            //{
            long timestamp = DateTime.UtcNow.Ticks;

            Buffer buffer = null;

            lock (_bufferGatheringLock)
            {
                buffer = _poolStrategy.PinNew(filename, pageFormatter);
            }

            while (buffer == null && !WaitingForTooLong(timestamp))
            {
                Thread.Sleep(_tickWaitingTime);

                lock (_bufferGatheringLock)
                {
                    buffer = _poolStrategy.PinNew(filename, pageFormatter);
                }
            }

            if (buffer == null)
            {
                throw new BufferBusyException();
            }

            return(buffer);
            //}
            //catch (ThreadAbortException)
            //{
            //    throw new BufferBusyException();
            //}
        }
Beispiel #2
0
            public void CanUnpinBuffer()
            {
                _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);

                var filename      = RandomFilename;
                var pageFormatter = new BasePageFormatter();
                var buffer1       = _poolStrategy.PinNew(filename, pageFormatter);
                var buffer2       = _poolStrategy.PinNew(filename, pageFormatter);

                Assert.IsTrue(buffer1.IsPinned);
                Assert.IsTrue(buffer2.IsPinned);
                Assert.AreEqual(filename, buffer1.Block.Filename);
                Assert.AreEqual(0, buffer1.Block.Id);
                Assert.AreEqual(filename, buffer2.Block.Filename);
                Assert.AreEqual(1, buffer2.Block.Id);
                Assert.AreEqual(1, _poolStrategy.Available);

                _poolStrategy.Unpin(buffer1);
                Assert.IsFalse(buffer1.IsPinned);
                Assert.AreEqual(2, _poolStrategy.Available);

                _poolStrategy.Unpin(buffer2);
                Assert.IsFalse(buffer2.IsPinned);
                Assert.AreEqual(3, _poolStrategy.Available);
            }
Beispiel #3
0
        public void CanPinBufferMultipleTimesAndUnpinMultipleTimes()
        {
            _poolStrategy = new NaiveBufferPoolStrategy(_logManager, _fileManager, 3);

            var filename      = RandomFilename;
            var pageFormatter = new BasePageFormatter();

            var buffer1 = _poolStrategy.PinNew(filename, pageFormatter);

            Assert.IsTrue(buffer1.IsPinned);
            Assert.AreEqual(2, _poolStrategy.Available);

            var buffer2 = _poolStrategy.Pin(buffer1.Block);

            Assert.IsTrue(buffer2.IsPinned);
            Assert.AreEqual(2, _poolStrategy.Available);

            _poolStrategy.Unpin(buffer1);

            Assert.IsTrue(buffer1.IsPinned);
            Assert.AreEqual(2, _poolStrategy.Available);

            _poolStrategy.Unpin(buffer2);

            Assert.IsFalse(buffer2.IsPinned);
            Assert.AreEqual(3, _poolStrategy.Available);
        }
Beispiel #4
0
            public void CannotPinMoreNewBlocksThatPoolHave()
            {
                _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);

                var filename      = RandomFilename;
                var pageFormatter = new BasePageFormatter();

                var buffer1 = _poolStrategy.PinNew(filename, pageFormatter);
                var buffer2 = _poolStrategy.PinNew(filename, pageFormatter);
                var buffer3 = _poolStrategy.PinNew(filename, pageFormatter);
                var buffer4 = _poolStrategy.PinNew(filename, pageFormatter);

                Assert.IsTrue(buffer1.IsPinned);
                Assert.IsTrue(buffer2.IsPinned);
                Assert.IsTrue(buffer3.IsPinned);
                Assert.AreEqual(filename, buffer1.Block.Filename);
                Assert.AreEqual(0, buffer1.Block.Id);
                Assert.AreEqual(filename, buffer2.Block.Filename);
                Assert.AreEqual(1, buffer2.Block.Id);
                Assert.AreEqual(filename, buffer3.Block.Filename);
                Assert.AreEqual(2, buffer3.Block.Id);
                Assert.IsNull(buffer4);
                Assert.AreEqual(0, _poolStrategy.Available);
            }
Beispiel #5
0
            public void CanPinBufferWriteAndFlush()
            {
                _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);

                var filename      = RandomFilename;
                var pageFormatter = new BasePageFormatter();

                var buffer1 = _poolStrategy.PinNew(filename, pageFormatter);

                buffer1.SetInt(0, 123, 1, 1);
                _poolStrategy.FlushAll(1);
                _poolStrategy.Unpin(buffer1);

                var page    = _fileManager.ResolvePage();
                var canRead = page.Read(new Block(filename, 0));

                var canGetValue = page.GetInt(0, out var value);

                Assert.IsFalse(buffer1.IsPinned);
                Assert.IsTrue(canRead);
                Assert.IsTrue(canGetValue);
                Assert.AreEqual(123, value);
            }