Ejemplo n.º 1
0
        private void ReuseCacheFromPool()
        {
            // todo: include InstanceId to the cacheId...
            string           cacheId = string.Format("{0}{1}", File.Filename, GetId());
            ICollectionCache cache   = CachePoolManager.GetCache(cacheId);

            if (cache == null)
            {
                CachePoolManager.SetCache(cacheId, this);
            }
            else
            {
                MruManager = cache.MruManager;
                Blocks     = cache.Blocks;
                MruManager.SetDataStores(this, DataBlockDriver);
            }
        }
Ejemplo n.º 2
0
        public VirtualStore(string name, int mruMinCapacity = 4500, int mruMaxCapacity = 6000)
        {
            if (mruMinCapacity < 7)
            {
                mruMinCapacity = 7;
            }
            if (mruMaxCapacity < 10)
            {
                mruMaxCapacity = 10;
            }
            if (mruMinCapacity >= mruMaxCapacity)
            {
                mruMinCapacity = (int)(mruMaxCapacity * .75);
            }

            // todo: change to use ConcurrentMruManager ? for concurrency.
            MruManager = new MruManager(mruMinCapacity, mruMaxCapacity, new CacheKeyComparer());

            MruManager.SetDataStores(this, null);
            _name = name;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize. NOTE: this function doesn't open the file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="parameters"> </param>
        protected internal virtual void Initialize(File.IFile file, params KeyValuePair <string, object>[] parameters)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (transaction == null ||
                (transaction is Transaction.Transaction &&
                 ((Transaction.Transaction)transaction).Server != file.Server))
            {
                Transaction.ITransactionLogger trans = file.Transaction;
                if (trans != null)
                {
                    trans = ((Transaction.TransactionBase)trans).GetLeafChild();
                }
                if (trans == null ||
                    trans is Transaction.Transaction)
                {
                    transaction = trans;
                }
            }

            if (string.IsNullOrEmpty(this.Name))
            {
                var f = new FileInfo(file.Filename);
                Name = string.Format("{0} Collection {1}", f.Name, ((Sop.OnDisk.File.File)file).GetNewStoreId());
            }
            if (MruMinCapacity == 0)
            {
                MruMinCapacity = file.Profile.MruMinCapacity;
            }
            if (MruMaxCapacity == 0)
            {
                MruMaxCapacity = file.Profile.MruMaxCapacity;
            }

            if (File == null)
            {
                File = file;
            }
            if (DataBlockSize == DataBlockSize.Unknown)
            {
                DataBlockSize = file.DataBlockSize;
            }
            HeaderData hd = null;

            if (parameters != null && parameters.Length > 0)
            {
                foreach (KeyValuePair <string, object> o in parameters)
                {
                    switch (o.Key)
                    {
                    case "HasMruSegments":
                        break;

                    case "HeaderData":
                        hd = (HeaderData)o.Value;
                        break;

                    default:
                        if (o.Key == "DataBlockDriver" && o.Value != null)
                        {
                            DataBlockDriver = (IDataBlockDriver)o.Value;
                        }
                        break;
                    }
                }
            }
            if (DataBlockDriver == null)
            {
                DataBlockDriver = new DataBlockDriver(this, hd);
            }
            else
            {
                if (DataBlockDriver.HeaderData == null)
                {
                    DataBlockDriver.HeaderData = hd ?? new HeaderData(DataBlockSize);
                }
            }
            if (MruManager == null)
            {
                int min = MruMinCapacity;
                int max = MruMaxCapacity;

                //MruManager = new ConcurrentMruManager(min, max);
                MruManager = new MruManager(min, max);

                MruManager.SetDataStores(this, DataBlockDriver);
            }
            if (_diskBuffer == null)
            {
                _diskBuffer = CreateBlock(); //new Sop.DataBlock(DataBlockSize);
            }
        }