Esempio n. 1
0
        public void ToStream(AbstractPager src, long startPage, long numberOfPages, Stream output)
        {
            // In case of encryption, we don't want to decrypt the data for backup,
            // so let's work directly with the underlying encrypted data (Inner pager).

            if ((_buffer.Length % Constants.Storage.PageSize) != 0)
            {
                throw new ArgumentException("The buffer length must be a multiple of the page size");
            }

            var steps = _buffer.Length / Constants.Storage.PageSize;

            using (var tempTx = new TempPagerTransaction())
                fixed(byte *pBuffer = _buffer)
                {
                    for (long i = startPage; i < startPage + numberOfPages; i += steps)
                    {
                        var pagesToCopy = (int)(i + steps > numberOfPages ? numberOfPages - i : steps);
                        src.EnsureMapped(tempTx, i, pagesToCopy);
                        var ptr = src.AcquireRawPagePointer(tempTx, i);
                        Memory.Copy(pBuffer, ptr, pagesToCopy * Constants.Storage.PageSize);
                        output.Write(_buffer, 0, pagesToCopy * Constants.Storage.PageSize);
                    }
                }
        }
Esempio n. 2
0
        public void ToStream(AbstractPager src, long startPage, long numberOfPages,
                             Stream output, Action <string> infoNotify, CancellationToken cancellationToken)
        {
            // In case of encryption, we don't want to decrypt the data for backup,
            // so let's work directly with the underlying encrypted data (Inner pager).

            if ((_buffer.Length % Constants.Storage.PageSize) != 0)
            {
                throw new ArgumentException("The buffer length must be a multiple of the page size");
            }

            var  steps       = _buffer.Length / Constants.Storage.PageSize;
            long totalCopied = 0;
            var  toBeCopied  = new Size(numberOfPages * Constants.Storage.PageSize, SizeUnit.Bytes).ToString();
            var  totalSw     = Stopwatch.StartNew();
            var  sw          = Stopwatch.StartNew();

            using (var tempTx = new TempPagerTransaction())
                fixed(byte *pBuffer = _buffer)
                {
                    for (var i = startPage; i < startPage + numberOfPages; i += steps)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        var pagesToCopy = (int)(i + steps > numberOfPages ? numberOfPages - i : steps);
                        src.EnsureMapped(tempTx, i, pagesToCopy);
                        var ptr           = src.AcquireRawPagePointer(tempTx, i);
                        var copiedInBytes = pagesToCopy * Constants.Storage.PageSize;
                        Memory.Copy(pBuffer, ptr, copiedInBytes);
                        output.Write(_buffer, 0, copiedInBytes);

                        totalCopied += copiedInBytes;

                        if (sw.ElapsedMilliseconds > 500)
                        {
                            infoNotify($"Copied: {new Size(totalCopied, SizeUnit.Bytes)} / {toBeCopied}");
                            sw.Restart();
                        }
                    }
                }

            var totalSecElapsed = Math.Max((double)totalSw.ElapsedMilliseconds / 1000, 0.0001);

            infoNotify?.Invoke($"Finshed copying {new Size(totalCopied, SizeUnit.Bytes)}, " +
                               $"{new Size((long)(totalCopied / totalSecElapsed), SizeUnit.Bytes)}/sec");
        }