public VariableLengthBlittableAllocator(LogSettings settings, VariableLengthStructSettings <Key, Value> vlSettings, IFasterEqualityComparer <Key> comparer, Action <long, long> evictCallback = null, LightEpoch epoch = null, Action <CommitInfo> flushCallback = null)
            : base(settings, comparer, evictCallback, epoch, flushCallback)
        {
            overflowPagePool = new OverflowPool <PageUnit>(4, p => p.handle.Free());

            values   = new byte[BufferSize][];
            handles  = new GCHandle[BufferSize];
            pointers = new long[BufferSize];

            ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
            nativePointers = (long *)ptrHandle.AddrOfPinnedObject();

            KeyLength   = vlSettings.keyLength;
            ValueLength = vlSettings.valueLength;

            if (KeyLength == null)
            {
                fixedSizeKey = true;
                KeyLength    = new FixedLengthStruct <Key>();
            }

            if (ValueLength == null)
            {
                fixedSizeValue = true;
                ValueLength    = new FixedLengthStruct <Value>();
            }
        }
Beispiel #2
0
        public BlittableAllocator(LogSettings settings, IFasterEqualityComparer <Key> comparer, Action <long, long> evictCallback = null, LightEpoch epoch = null, Action <CommitInfo> flushCallback = null)
            : base(settings, comparer, evictCallback, epoch, flushCallback)
        {
            overflowPagePool = new OverflowPool <PageUnit>(4, p =>
#if NET5_0_OR_GREATER
                                                           { }
#else
                                                           p.handle.Free()
#endif
                                                           );


            if (BufferSize > 0)
            {
                values = new byte[BufferSize][];

#if NET5_0_OR_GREATER
                pointers       = GC.AllocateArray <long>(BufferSize, true);
                nativePointers = (long *)Unsafe.AsPointer(ref pointers[0]);
#else
                pointers       = new long[BufferSize];
                handles        = new GCHandle[BufferSize];
                ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
                nativePointers = (long *)ptrHandle.AddrOfPinnedObject();
#endif
            }
        }
Beispiel #3
0
        public BlittableAllocator(LogSettings settings, IFasterEqualityComparer <Key> comparer, Action <long, long> evictCallback = null, LightEpoch epoch = null, Action <CommitInfo> flushCallback = null)
            : base(settings, comparer, evictCallback, epoch, flushCallback)
        {
            overflowPagePool = new OverflowPool <PageUnit>(4, p => p.handle.Free());

            values   = new byte[BufferSize][];
            handles  = new GCHandle[BufferSize];
            pointers = new long[BufferSize];

            ptrHandle      = GCHandle.Alloc(pointers, GCHandleType.Pinned);
            nativePointers = (long *)ptrHandle.AddrOfPinnedObject();
        }
Beispiel #4
0
        public GenericAllocator(LogSettings settings, SerializerSettings <Key, Value> serializerSettings, IFasterEqualityComparer <Key> comparer, Action <long, long> evictCallback = null, LightEpoch epoch = null, Action <CommitInfo> flushCallback = null)
            : base(settings, comparer, evictCallback, epoch, flushCallback)
        {
            overflowPagePool = new OverflowPool <Record <Key, Value>[]>(4);

            if (settings.ObjectLogDevice == null)
            {
                throw new FasterException("LogSettings.ObjectLogDevice needs to be specified (e.g., use Devices.CreateLogDevice, AzureStorageDevice, or NullDevice)");
            }

            SerializerSettings = serializerSettings ?? new SerializerSettings <Key, Value>();

            if ((!keyBlittable) && (settings.LogDevice as NullDevice == null) && ((SerializerSettings == null) || (SerializerSettings.keySerializer == null)))
            {
#if DEBUG
                if (typeof(Key) != typeof(byte[]) && typeof(Key) != typeof(string))
                {
                    Debug.WriteLine("Key is not blittable, but no serializer specified via SerializerSettings. Using (slow) DataContractSerializer as default.");
                }
#endif
                SerializerSettings.keySerializer = ObjectSerializer.Get <Key>();
            }

            if ((!valueBlittable) && (settings.LogDevice as NullDevice == null) && ((SerializerSettings == null) || (SerializerSettings.valueSerializer == null)))
            {
#if DEBUG
                if (typeof(Value) != typeof(byte[]) && typeof(Value) != typeof(string))
                {
                    Debug.WriteLine("Value is not blittable, but no serializer specified via SerializerSettings. Using (slow) DataContractSerializer as default.");
                }
#endif
                SerializerSettings.valueSerializer = ObjectSerializer.Get <Value>();
            }

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

            objectLogDevice = settings.ObjectLogDevice;

            if ((settings.LogDevice as NullDevice == null) && (KeyHasObjects() || ValueHasObjects()))
            {
                if (objectLogDevice == null)
                {
                    throw new FasterException("Objects in key/value, but object log not provided during creation of FASTER instance");
                }
                if (objectLogDevice.SegmentSize != -1)
                {
                    throw new FasterException("Object log device should not have fixed segment size. Set preallocateFile to false when calling CreateLogDevice for object log");
                }
            }
        }