Beispiel #1
0
        public Guid StartSession()
        {
            if (_threadCtx == null)
            {
                _threadCtx = new FastThreadLocal <FasterKV <Key, Value> .FasterExecutionContext <Input, Output, Context> >();
            }

            return(InternalAcquire());
        }
Beispiel #2
0
        public Guid StartSession()
        {
            if (threadCtx == null)
            {
                threadCtx = new FastThreadLocal <FasterExecutionContext>();
            }

            return(InternalAcquire());
        }
Beispiel #3
0
        /// <summary>
        /// Initialize the epoch table
        /// </summary>
        /// <param name="size"></param>
        unsafe void Initialize(int size)
        {
            threadEntryIndex = new FastThreadLocal <int>();
            numEntries       = size;

            // Over-allocate to do cache-line alignment
            tableRaw    = new Entry[size + 2];
            tableHandle = GCHandle.Alloc(tableRaw, GCHandleType.Pinned);
            long p = (long)tableHandle.AddrOfPinnedObject();

            // Force the pointer to align to 64-byte boundaries
            long p2 = (p + (Constants.kCacheLineBytes - 1)) & ~(Constants.kCacheLineBytes - 1);

            tableAligned = (Entry *)p2;

            CurrentEpoch       = 1;
            SafeToReclaimEpoch = 0;

            for (int i = 0; i < kDrainListSize; i++)
            {
                drainList[i].epoch = int.MaxValue;
            }
            drainCount = 0;
        }
Beispiel #4
0
        /// <summary>
        /// Create new instance
        /// </summary>
        /// <param name="returnPhysicalAddress"></param>
        /// <param name="epoch"></param>
        public MallocFixedPageSize(bool returnPhysicalAddress = false, LightEpoch epoch = null)
        {
            freeList = new FastThreadLocal <Queue <FreeItem> >();
            if (epoch == null)
            {
                this.epoch = new LightEpoch();
                ownedEpoch = true;
            }
            else
            {
                this.epoch = epoch;
            }

            values[0] = new T[PageSize];

#if !(CALLOC)
            Array.Clear(values[0], 0, PageSize);
#endif
            ReturnPhysicalAddress = returnPhysicalAddress;

            if (ForceUnpinnedAllocation)
            {
                IsPinned = false;
                ReturnPhysicalAddress = false;
            }
            else
            {
                IsPinned = true;
                if (default(T) == null)
                {
                    IsPinned = false;
                    ReturnPhysicalAddress = false;
                }
                else
                {
                    // The surefire way to check if a type is blittable
                    // it to try GCHandle.Alloc with a handle type of Pinned.
                    // If it throws an exception, we know the type is not blittable.
                    try
                    {
                        handles[0]      = GCHandle.Alloc(values[0], GCHandleType.Pinned);
                        pointers[0]     = handles[0].AddrOfPinnedObject();
                        handles0        = handles[0];
                        pointers0       = pointers[0];
                        RecordSize      = Marshal.SizeOf(values[0][0]);
                        AlignedPageSize = RecordSize * PageSize;
                    }
                    catch (Exception)
                    {
                        IsPinned = false;
                        ReturnPhysicalAddress = false;
                    }
                }
            }

            values0         = values[0];
            writeCacheLevel = -1;
            Interlocked.MemoryBarrier();

            BulkAllocate(); // null pointer
        }
Beispiel #5
0
        /// <summary>
        /// Create FASTER instance
        /// </summary>
        /// <param name="size">Size of core index (#cache lines)</param>
        /// <param name="comparer">FASTER equality comparer for key</param>
        /// <param name="variableLengthStructSettings"></param>
        /// <param name="functions">Callback functions</param>
        /// <param name="logSettings">Log settings</param>
        /// <param name="checkpointSettings">Checkpoint settings</param>
        /// <param name="serializerSettings">Serializer settings</param>
        public FasterKV(long size, Functions functions, LogSettings logSettings, CheckpointSettings checkpointSettings = null, SerializerSettings <Key, Value> serializerSettings = null, IFasterEqualityComparer <Key> comparer = null, VariableLengthStructSettings <Key, Value> variableLengthStructSettings = null)
        {
            threadCtx     = new FastThreadLocal <FasterExecutionContext>();
            prevThreadCtx = new FastThreadLocal <FasterExecutionContext>();

            if (comparer != null)
            {
                this.comparer = comparer;
            }
            else
            {
                if (typeof(IFasterEqualityComparer <Key>).IsAssignableFrom(typeof(Key)))
                {
                    this.comparer = new Key() as IFasterEqualityComparer <Key>;
                }
                else
                {
                    Console.WriteLine("***WARNING*** Creating default FASTER key equality comparer based on potentially slow EqualityComparer<Key>.Default. To avoid this, provide a comparer (IFasterEqualityComparer<Key>) as an argument to FASTER's constructor, or make Key implement the interface IFasterEqualityComparer<Key>");
                    this.comparer = FasterEqualityComparer <Key> .Default;
                }
            }

            if (checkpointSettings == null)
            {
                checkpointSettings = new CheckpointSettings();
            }

            if (checkpointSettings.CheckpointDir != null && checkpointSettings.CheckpointManager != null)
            {
                throw new Exception("Specify either CheckpointManager or CheckpointDir for CheckpointSettings, not both");
            }

            checkpointManager = checkpointSettings.CheckpointManager ?? new LocalCheckpointManager(checkpointSettings.CheckpointDir ?? "");

            FoldOverSnapshot = checkpointSettings.CheckPointType == core.CheckpointType.FoldOver;
            CopyReadsToTail  = logSettings.CopyReadsToTail;
            this.functions   = functions;

            if (logSettings.ReadCacheSettings != null)
            {
                CopyReadsToTail = false;
                UseReadCache    = true;
            }

            if (Utility.IsBlittable <Key>() && Utility.IsBlittable <Value>())
            {
                if (variableLengthStructSettings != null)
                {
                    hlog = new VariableLengthBlittableAllocator <Key, Value>(logSettings, variableLengthStructSettings, this.comparer, null, epoch);
                    Log  = new LogAccessor <Key, Value, Input, Output, Context>(this, hlog);
                    if (UseReadCache)
                    {
                        readcache = new VariableLengthBlittableAllocator <Key, Value>(
                            new LogSettings
                        {
                            PageSizeBits    = logSettings.ReadCacheSettings.PageSizeBits,
                            MemorySizeBits  = logSettings.ReadCacheSettings.MemorySizeBits,
                            SegmentSizeBits = logSettings.ReadCacheSettings.MemorySizeBits,
                            MutableFraction = 1 - logSettings.ReadCacheSettings.SecondChanceFraction
                        }, variableLengthStructSettings, this.comparer, ReadCacheEvict, epoch);
                        readcache.Initialize();
                        ReadCache = new LogAccessor <Key, Value, Input, Output, Context>(this, readcache);
                    }
                }
                else
                {
                    hlog = new BlittableAllocator <Key, Value>(logSettings, this.comparer, null, epoch);
                    Log  = new LogAccessor <Key, Value, Input, Output, Context>(this, hlog);
                    if (UseReadCache)
                    {
                        readcache = new BlittableAllocator <Key, Value>(
                            new LogSettings
                        {
                            PageSizeBits    = logSettings.ReadCacheSettings.PageSizeBits,
                            MemorySizeBits  = logSettings.ReadCacheSettings.MemorySizeBits,
                            SegmentSizeBits = logSettings.ReadCacheSettings.MemorySizeBits,
                            MutableFraction = 1 - logSettings.ReadCacheSettings.SecondChanceFraction
                        }, this.comparer, ReadCacheEvict, epoch);
                        readcache.Initialize();
                        ReadCache = new LogAccessor <Key, Value, Input, Output, Context>(this, readcache);
                    }
                }
            }
            else
            {
                WriteDefaultOnDelete = true;

                hlog = new GenericAllocator <Key, Value>(logSettings, serializerSettings, this.comparer, null, epoch);
                Log  = new LogAccessor <Key, Value, Input, Output, Context>(this, hlog);
                if (UseReadCache)
                {
                    readcache = new GenericAllocator <Key, Value>(
                        new LogSettings
                    {
                        PageSizeBits    = logSettings.ReadCacheSettings.PageSizeBits,
                        MemorySizeBits  = logSettings.ReadCacheSettings.MemorySizeBits,
                        SegmentSizeBits = logSettings.ReadCacheSettings.MemorySizeBits,
                        MutableFraction = 1 - logSettings.ReadCacheSettings.SecondChanceFraction
                    }, serializerSettings, this.comparer, ReadCacheEvict, epoch);
                    readcache.Initialize();
                    ReadCache = new LogAccessor <Key, Value, Input, Output, Context>(this, readcache);
                }
            }

            hlog.Initialize();

            sectorSize = (int)logSettings.LogDevice.SectorSize;
            Initialize(size, sectorSize);

            _systemState         = default(SystemState);
            _systemState.phase   = Phase.REST;
            _systemState.version = 1;
            _checkpointType      = CheckpointType.HYBRID_LOG_ONLY;
        }