Ejemplo n.º 1
0
        public PosixPageFileBackedMemoryMapPager(string file, long?initialFileSize = null)
        {
            var instanceId = Interlocked.Increment(ref _counter);

            _file = "/" + Syscall.getpid() + "-" + instanceId + "-" + file;
            _fd   = Rt.shm_open(_file, OpenFlags.O_RDWR | OpenFlags.O_CREAT, (int)FilePermissions.ALLPERMS);
            if (_fd == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }

            SysPageSize = Syscall.sysconf(SysconfName._SC_PAGESIZE);

            if (initialFileSize.HasValue)
            {
                _totalAllocationSize = NearestSizeToPageSize(initialFileSize.Value);
            }

            _totalAllocationSize = NearestSizeToPageSize(_totalAllocationSize);
            var result = Syscall.ftruncate(_fd, _totalAllocationSize);

            if (result != 0)
            {
                PosixHelper.ThrowLastError(result);
            }

            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
            PagerState.Release();
            PagerState = CreatePagerState();
        }
Ejemplo n.º 2
0
        public PosixTempMemoryMapPager(string file, long?initialFileSize = null)
        {
            var instanceId = Interlocked.Increment(ref _counter);

            _file = "/var/tmp/ravendb-" + Syscall.getpid() + "-" + instanceId + "-" + file;
            _fd   = Syscall.open(_file, OpenFlags.O_RDWR | OpenFlags.O_CREAT | OpenFlags.O_EXCL,
                                 FilePermissions.S_IWUSR | FilePermissions.S_IRUSR);
            if (_fd == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }
            DeleteOnClose = true;

            SysPageSize = Syscall.sysconf(SysconfName._SC_PAGESIZE);

            _totalAllocationSize = NearestSizeToPageSize(initialFileSize ?? _totalAllocationSize);
            PosixHelper.AllocateFileSpace(_fd, (ulong)_totalAllocationSize);

            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
            PagerState.Release();
            PagerState = CreatePagerState();
        }