コード例 #1
0
        public GenericAllocator(LogSettings settings, SerializerSettings <Key, Value> serializerSettings, IFasterEqualityComparer <Key> comparer)
            : base(settings, comparer)
        {
            SerializerSettings = serializerSettings;

            if (default(Key) == null && ((SerializerSettings == null) || (SerializerSettings.keySerializer == null)))
            {
                throw new Exception("Key is a class, but no serializer specified via SerializerSettings");
            }

            if (default(Value) == null && ((SerializerSettings == null) || (SerializerSettings.valueSerializer == null)))
            {
                throw new Exception("Value is a class, but no serializer specified via SerializerSettings");
            }

            values         = new Record <Key, Value> [BufferSize][];
            segmentOffsets = new long[SegmentBufferSize];

            objectLogDevice = settings.ObjectLogDevice;

            if (KeyHasObjects() || ValueHasObjects())
            {
                if (objectLogDevice == null)
                {
                    throw new Exception("Objects in key/value, but object log not provided during creation of FASTER instance");
                }
            }

            epoch        = LightEpoch.Instance;
            ioBufferPool = SectorAlignedBufferPool.GetPool(1, sectorSize);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="preallocateFile"></param>
        /// <param name="deleteOnClose"></param>
        public ManagedLocalStorageDevice(string filename, bool preallocateFile = false, bool deleteOnClose = false)
            : base(filename, GetSectorSize(filename))
        {
            pool = new SectorAlignedBufferPool(1, 1);

            this.preallocateFile = preallocateFile;
            this.deleteOnClose   = deleteOnClose;
            logHandles           = new ConcurrentDictionary <int, Stream>();
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="preallocateFile"></param>
        /// <param name="deleteOnClose"></param>
        /// <param name="capacity">The maximal number of bytes this storage device can accommondate, or CAPACITY_UNSPECIFIED if there is no such limit </param>
        public ManagedLocalStorageDevice(string filename, bool preallocateFile = false, bool deleteOnClose = false, long capacity = Devices.CAPACITY_UNSPECIFIED)
            : base(filename, GetSectorSize(filename), capacity)
        {
            pool = new SectorAlignedBufferPool(1, 1);

            this.preallocateFile = preallocateFile;
            this.deleteOnClose   = deleteOnClose;
            logHandles           = new ConcurrentDictionary <int, Stream>();
            RecoverFiles();
        }
コード例 #4
0
        /// <summary>
        /// Note: pads the bytes with zeros to achieve sector alignment
        /// </summary>
        /// <param name="device"></param>
        /// <param name="address"></param>
        /// <param name="buffer"></param>
        /// <param name="size"></param>
        private unsafe void WriteInto(IDevice device, ulong address, byte[] buffer, int size)
        {
            if (bufferPool == null)
            {
                bufferPool = new SectorAlignedBufferPool(1, (int)device.SectorSize);
            }

            long numBytesToWrite = size;

            numBytesToWrite = ((numBytesToWrite + (device.SectorSize - 1)) & ~(device.SectorSize - 1));

            var pbuffer = bufferPool.Get((int)numBytesToWrite);

            fixed(byte *bufferRaw = buffer)
            {
                Buffer.MemoryCopy(bufferRaw, pbuffer.aligned_pointer, size, size);
            }

            device.WriteAsync((IntPtr)pbuffer.aligned_pointer, address, (uint)numBytesToWrite, IOCallback, null);
            semaphore.Wait();

            pbuffer.Return();
        }
コード例 #5
0
        /// <summary>
        /// Note: will read potentially more data (based on sector alignment)
        /// </summary>
        /// <param name="device"></param>
        /// <param name="address"></param>
        /// <param name="buffer"></param>
        /// <param name="size"></param>
        private unsafe void ReadInto(IDevice device, ulong address, out byte[] buffer, int size)
        {
            if (bufferPool == null)
            {
                bufferPool = new SectorAlignedBufferPool(1, (int)device.SectorSize);
            }

            long numBytesToRead = size;

            numBytesToRead = ((numBytesToRead + (device.SectorSize - 1)) & ~(device.SectorSize - 1));

            var pbuffer = bufferPool.Get((int)numBytesToRead);

            device.ReadAsync(address, (IntPtr)pbuffer.aligned_pointer,
                             (uint)numBytesToRead, IOCallback, null);
            semaphore.Wait();

            buffer = new byte[numBytesToRead];

            fixed(byte *bufferRaw = buffer)
            Buffer.MemoryCopy(pbuffer.aligned_pointer, bufferRaw, numBytesToRead, numBytesToRead);

            pbuffer.Return();
        }
コード例 #6
0
        public unsafe VarLenHeapContainer(ref T obj, IVariableLengthStruct <T> varLenStruct, SectorAlignedBufferPool pool)
        {
            var len = varLenStruct.GetLength(ref obj);

            mem = pool.Get(len);
            Buffer.MemoryCopy(Unsafe.AsPointer(ref obj), mem.GetValidPointer(), len, len);
        }