예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="hlog"></param>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="scanBufferingMode"></param>
        public unsafe BlittableScanIterator(BlittableAllocator <Key, Value> hlog, long beginAddress, long endAddress, ScanBufferingMode scanBufferingMode)
        {
            this.hlog         = hlog;
            this.beginAddress = beginAddress;
            this.endAddress   = endAddress;
            currentAddress    = beginAddress;

            if (scanBufferingMode == ScanBufferingMode.SinglePageBuffering)
            {
                frameSize = 1;
            }
            else
            {
                frameSize = 2;
            }

            frame  = new BlittableFrame(frameSize, hlog.PageSize, hlog.GetDeviceSectorSize());
            loaded = new CountdownEvent[frameSize];

            var frameNumber = (currentAddress >> hlog.LogPageSizeBits) % frameSize;

            hlog.AsyncReadPagesFromDeviceToFrame
                (currentAddress >> hlog.LogPageSizeBits,
                1, AsyncReadPagesCallback, Empty.Default,
                frame, out loaded[frameNumber]);
        }
예제 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="hlog"></param>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="scanBufferingMode"></param>
        /// <param name="epoch"></param>
        /// <param name="forceInMemory">Provided address range is known by caller to be in memory, even if less than HeadAddress</param>
        public BlittableScanIterator(BlittableAllocator <Key, Value> hlog, long beginAddress, long endAddress, ScanBufferingMode scanBufferingMode, LightEpoch epoch, bool forceInMemory = false)
            : base(beginAddress == 0 ? hlog.GetFirstValidLogicalAddress(0) : beginAddress, endAddress, scanBufferingMode, epoch, hlog.LogPageSizeBits)
        {
            this.hlog          = hlog;
            this.forceInMemory = forceInMemory;

            if (frameSize > 0)
            {
                frame = new BlittableFrame(frameSize, hlog.PageSize, hlog.GetDeviceSectorSize());
            }
        }
예제 #3
0
        /// <summary>
        /// Create new log instance
        /// </summary>
        /// <param name="logSettings"></param>
        public FasterLog(FasterLogSettings logSettings)
        {
            bool oldCommitManager = false;

            if (oldCommitManager)
            {
                logCommitManager = logSettings.LogCommitManager ??
                                   new LocalLogCommitManager(logSettings.LogCommitFile ??
                                                             logSettings.LogDevice.FileName + ".commit");
            }
            else
            {
                logCommitManager = logSettings.LogCommitManager ??
                                   new DeviceLogCommitCheckpointManager
                                       (new LocalStorageNamedDeviceFactory(),
                                       new DefaultCheckpointNamingScheme(
                                           new FileInfo(logSettings.LogDevice.FileName).Directory.FullName));
            }

            if (logSettings.LogCommitManager == null)
            {
                disposeLogCommitManager = true;
            }

            // Reserve 8 byte checksum in header if requested
            logChecksum           = logSettings.LogChecksum;
            headerSize            = logChecksum == LogChecksumType.PerEntry ? 12 : 4;
            getMemory             = logSettings.GetMemory;
            epoch                 = new LightEpoch();
            CommittedUntilAddress = Constants.kFirstValidAddress;
            CommittedBeginAddress = Constants.kFirstValidAddress;
            SafeTailAddress       = Constants.kFirstValidAddress;

            allocator = new BlittableAllocator <Empty, byte>(
                logSettings.GetLogSettings(), null,
                null, epoch, CommitCallback);
            allocator.Initialize();

            // FasterLog is used as a read-only iterator
            if (logSettings.ReadOnlyMode)
            {
                readOnlyMode          = true;
                allocator.HeadAddress = long.MaxValue;
            }

            Restore(out RecoveredIterators);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="hlog"></param>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="scanBufferingMode"></param>
        /// <param name="epoch"></param>
        /// <param name="forceInMemory">Provided address range is known by caller to be in memory, even if less than HeadAddress</param>
        public unsafe BlittableScanIterator(BlittableAllocator <Key, Value> hlog, long beginAddress, long endAddress, ScanBufferingMode scanBufferingMode, LightEpoch epoch, bool forceInMemory = false)
        {
            this.hlog          = hlog;
            this.forceInMemory = forceInMemory;

            // If we are protected when creating the iterator, we do not need per-GetNext protection
            if (!epoch.ThisInstanceProtected())
            {
                this.epoch = epoch;
            }

            if (beginAddress == 0)
            {
                beginAddress = hlog.GetFirstValidLogicalAddress(0);
            }

            this.endAddress = endAddress;
            currentAddress  = -1;
            nextAddress     = beginAddress;

            if (scanBufferingMode == ScanBufferingMode.SinglePageBuffering)
            {
                frameSize = 1;
            }
            else if (scanBufferingMode == ScanBufferingMode.DoublePageBuffering)
            {
                frameSize = 2;
            }
            else if (scanBufferingMode == ScanBufferingMode.NoBuffering)
            {
                frameSize = 0;
                return;
            }

            frame  = new BlittableFrame(frameSize, hlog.PageSize, hlog.GetDeviceSectorSize());
            loaded = new CountdownEvent[frameSize];

            // Only load addresses flushed to disk
            if (nextAddress < hlog.HeadAddress && !forceInMemory)
            {
                var frameNumber = (nextAddress >> hlog.LogPageSizeBits) % frameSize;
                hlog.AsyncReadPagesFromDeviceToFrame
                    (nextAddress >> hlog.LogPageSizeBits,
                    1, endAddress, AsyncReadPagesCallback, Empty.Default,
                    frame, out loaded[frameNumber]);
            }
        }
예제 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fasterLog"></param>
        /// <param name="hlog"></param>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="scanBufferingMode"></param>
        /// <param name="epoch"></param>
        /// <param name="headerSize"></param>
        /// <param name="name"></param>
        /// <param name="getMemory"></param>
        /// <param name="scanUncommitted"></param>
        internal unsafe FasterLogScanIterator(FasterLog fasterLog, BlittableAllocator <Empty, byte> hlog, long beginAddress, long endAddress, GetMemory getMemory, ScanBufferingMode scanBufferingMode, LightEpoch epoch, int headerSize, string name, bool scanUncommitted = false)
            : base(beginAddress == 0 ? hlog.GetFirstValidLogicalAddress(0) : beginAddress, endAddress, scanBufferingMode, epoch, hlog.LogPageSizeBits)
        {
            this.fasterLog       = fasterLog;
            this.allocator       = hlog;
            this.getMemory       = getMemory;
            this.headerSize      = headerSize;
            this.scanUncommitted = scanUncommitted;

            this.name             = name;
            CompletedUntilAddress = beginAddress;

            if (frameSize > 0)
            {
                frame = new BlittableFrame(frameSize, hlog.PageSize, hlog.GetDeviceSectorSize());
            }
        }
예제 #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fasterLog"></param>
        /// <param name="hlog"></param>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="scanBufferingMode"></param>
        /// <param name="epoch"></param>
        /// <param name="headerSize"></param>
        /// <param name="name"></param>
        /// <param name="getMemory"></param>
        /// <param name="scanUncommitted"></param>
        internal unsafe FasterLogScanIterator(FasterLog fasterLog, BlittableAllocator <Empty, byte> hlog, long beginAddress, long endAddress, GetMemory getMemory, ScanBufferingMode scanBufferingMode, LightEpoch epoch, int headerSize, string name, bool scanUncommitted = false)
        {
            this.fasterLog       = fasterLog;
            this.allocator       = hlog;
            this.getMemory       = getMemory;
            this.epoch           = epoch;
            this.headerSize      = headerSize;
            this.scanUncommitted = scanUncommitted;

            if (beginAddress == 0)
            {
                beginAddress = hlog.GetFirstValidLogicalAddress(0);
            }

            this.name       = name;
            this.endAddress = endAddress;
            NextAddress     = CompletedUntilAddress = beginAddress;

            if (scanBufferingMode == ScanBufferingMode.SinglePageBuffering)
            {
                frameSize = 1;
            }
            else if (scanBufferingMode == ScanBufferingMode.DoublePageBuffering)
            {
                frameSize = 2;
            }
            else if (scanBufferingMode == ScanBufferingMode.NoBuffering)
            {
                frameSize = 0;
                return;
            }

            frame          = new BlittableFrame(frameSize, hlog.PageSize, hlog.GetDeviceSectorSize());
            loaded         = new CountdownEvent[frameSize];
            loadedCancel   = new CancellationTokenSource[frameSize];
            loadedPage     = new long[frameSize];
            nextLoadedPage = new long[frameSize];
            for (int i = 0; i < frameSize; i++)
            {
                loadedPage[i]     = -1;
                nextLoadedPage[i] = -1;
                loadedCancel[i]   = new CancellationTokenSource();
            }
        }
        /// <summary>
        /// Create new log instance
        /// </summary>
        /// <param name="logSettings"></param>
        public FasterLog(FasterLogSettings logSettings)
        {
            logCommitManager = logSettings.LogCommitManager ??
                               new LocalLogCommitManager(logSettings.LogCommitFile ??
                                                         logSettings.LogDevice.FileName + ".commit");

            // Reserve 8 byte checksum in header if requested
            logChecksum           = logSettings.LogChecksum;
            headerSize            = logChecksum == LogChecksumType.PerEntry ? 12 : 4;
            getMemory             = logSettings.GetMemory;
            epoch                 = new LightEpoch();
            CommittedUntilAddress = Constants.kFirstValidAddress;
            CommittedBeginAddress = Constants.kFirstValidAddress;

            allocator = new BlittableAllocator <Empty, byte>(
                logSettings.GetLogSettings(), null,
                null, epoch, CommitCallback);
            allocator.Initialize();
            Restore(out RecoveredIterators);
        }
예제 #8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="hlog"></param>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="scanBufferingMode"></param>
        public unsafe BlittableScanIterator(BlittableAllocator <Key, Value> hlog, long beginAddress, long endAddress, ScanBufferingMode scanBufferingMode)
        {
            this.hlog = hlog;

            if (beginAddress == 0)
            {
                beginAddress = hlog.GetFirstValidLogicalAddress(0);
            }

            this.beginAddress = beginAddress;
            this.endAddress   = endAddress;
            currentAddress    = -1;
            nextAddress       = beginAddress;

            if (scanBufferingMode == ScanBufferingMode.SinglePageBuffering)
            {
                frameSize = 1;
            }
            else if (scanBufferingMode == ScanBufferingMode.DoublePageBuffering)
            {
                frameSize = 2;
            }
            else if (scanBufferingMode == ScanBufferingMode.NoBuffering)
            {
                frameSize = 0;
                return;
            }

            frame  = new BlittableFrame(frameSize, hlog.PageSize, hlog.GetDeviceSectorSize());
            loaded = new CountdownEvent[frameSize];

            // Only load addresses flushed to disk
            if (nextAddress < hlog.HeadAddress)
            {
                var frameNumber = (nextAddress >> hlog.LogPageSizeBits) % frameSize;
                hlog.AsyncReadPagesFromDeviceToFrame
                    (nextAddress >> hlog.LogPageSizeBits,
                    1, endAddress, AsyncReadPagesCallback, Empty.Default,
                    frame, out loaded[frameNumber]);
            }
        }