コード例 #1
0
        public Object GetObject(IObjRef oriToGet, ICacheIntern targetCache, CacheDirective cacheDirective)
        {
            CheckNotDisposed();
            if (oriToGet == null)
            {
                return(null);
            }
            List <IObjRef> orisToGet = new List <IObjRef>(1);

            orisToGet.Add(oriToGet);
            IList <Object> objects = GetObjects(orisToGet, targetCache, cacheDirective);

            if (objects.Count == 0)
            {
                return(null);
            }
            return(objects[0]);
        }
コード例 #2
0
ファイル: CacheMock.cs プロジェクト: vogelb/ambeth
        public IList <object> GetObjects(IList <IObjRef> orisToGet, CacheDirective cacheDirective)
        {
            IList <object> objs = new List <object>();

            foreach (IObjRef ori in orisToGet)
            {
                object obj;
                if (ori == null)
                {
                    obj = null;
                }
                else if (ori is IDirectObjRef)
                {
                    obj = ((IDirectObjRef)ori).Direct;
                }
                else
                {
                    obj = GetObject(ori.RealType, ori.Id);
                }
                objs.Add(obj);
            }

            return(objs);
        }
コード例 #3
0
        protected IList <Object> CreateResult(IList <IObjRef> orisToGet, CacheDirective cacheDirective, bool checkVersion)
        {
            List <Object> result = new List <Object>(orisToGet.Count);

            bool returnMisses = cacheDirective.HasFlag(CacheDirective.ReturnMisses);

            for (int a = 0, size = orisToGet.Count; a < size; a++)
            {
                IObjRef oriToGet = orisToGet[a];
                if (oriToGet == null)
                {
                    if (returnMisses)
                    {
                        result.Add(null);
                    }
                    continue;
                }
                if (oriToGet is IDirectObjRef)
                {
                    IDirectObjRef dori   = (IDirectObjRef)oriToGet;
                    Object        entity = dori.Direct;
                    if (entity != null)
                    {
                        result.Add(entity);
                        continue;
                    }
                }
                IEntityMetaData metaData   = EntityMetaDataProvider.GetMetaData(oriToGet.RealType);
                Object          cacheValue = GetCacheValue(metaData, oriToGet, checkVersion);
                if (cacheValue != null || returnMisses)
                {
                    result.Add(cacheValue);
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: CacheMock.cs プロジェクト: vogelb/ambeth
 public Object GetObject(Type type, Object id, CacheDirective cacheDirective)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
ファイル: CacheMock.cs プロジェクト: vogelb/ambeth
 public Object GetObject(IObjRef oriToGet, CacheDirective cacheDirective)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
ファイル: CacheMock.cs プロジェクト: vogelb/ambeth
 public IList <IObjRelationResult> GetObjRelations(IList <IObjRelation> objRels, CacheDirective cacheDirective)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
ファイル: CacheMock.cs プロジェクト: vogelb/ambeth
 public IList <Object> GetObjects(IList <IObjRef> orisToGet, CacheDirective cacheDirective)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
        protected void ChangeSecondLevelCacheIntern(CacheDependencyNode node, CacheDirective cacheDirective)
        {
            IRootCache rootCache = node.rootCache;
            HashMap <IObjRef, CacheValueAndPrivilege> objRefToLoadContainerDict = node.objRefToCacheValueMap;
            CHashSet <IObjRef> objRefsToLoad = new CHashSet <IObjRef>(node.objRefsToLoad);

            if (node.cacheChangeItems != null)
            {
                foreach (CacheChangeItem cci in node.cacheChangeItems)
                {
                    if (cci == null)
                    {
                        continue;
                    }
                    objRefsToLoad.AddAll(cci.UpdatedObjRefs);
                }
            }
            IList <IObjRef> objRefs       = objRefsToLoad.ToList();
            IList <Object>  refreshResult = rootCache.GetObjects(objRefs, cacheDirective);

            IPrivilege[] privileges = null;
            if (SecurityActivation != null && PrivilegeProvider != null && SecurityActivation.FilterActivated)
            {
                privileges = PrivilegeProvider.GetPrivilegesByObjRef(objRefs).GetPrivileges();
            }
            for (int a = refreshResult.Count; a-- > 0;)
            {
                RootCacheValue cacheValue = (RootCacheValue)refreshResult[a];
                if (cacheValue == null)
                {
                    continue;
                }
                objRefToLoadContainerDict.Put(objRefs[a], new CacheValueAndPrivilege(cacheValue, privileges != null ? privileges[a] : null));
            }
            CheckCascadeRefreshNeeded(node);

            CHashSet <IObjRef>      cascadeRefreshObjRefsSet      = node.cascadeRefreshObjRefsSet;
            CHashSet <IObjRelation> cascadeRefreshObjRelationsSet = node.cascadeRefreshObjRelationsSet;

            if (cascadeRefreshObjRelationsSet.Count > 0)
            {
                IList <IObjRelationResult> relationsResult = rootCache.GetObjRelations(cascadeRefreshObjRelationsSet.ToList(), cacheDirective);
                for (int a = relationsResult.Count; a-- > 0;)
                {
                    IObjRelationResult relationResult = relationsResult[a];
                    cascadeRefreshObjRefsSet.AddAll(relationResult.Relations);
                }
                // apply gathered information of unknown relations to the rootCache
                rootCache.Put(relationsResult);
            }
            if (cascadeRefreshObjRefsSet.Count > 0)
            {
                IList <IObjRef> cascadeRefreshObjRefsSetList = cascadeRefreshObjRefsSet.ToList();
                refreshResult = rootCache.GetObjects(cascadeRefreshObjRefsSetList, cacheDirective);
            }
            List <CacheDependencyNode> childNodes = node.childNodes;

            for (int a = childNodes.Count; a-- > 0;)
            {
                ChangeSecondLevelCacheIntern(childNodes[a], failInCacheHierarchyAndCacheValueResultAndReturnMissesSet);
            }
        }
コード例 #9
0
        /// <summary>Apply a CacheDirective to a file.</summary>
        /// <param name="directive">The CacheDirective to apply.</param>
        /// <param name="file">The file.</param>
        private void RescanFile(CacheDirective directive, INodeFile file)
        {
            BlockInfoContiguous[] blockInfos = file.GetBlocks();
            // Increment the "needed" statistics
            directive.AddFilesNeeded(1);
            // We don't cache UC blocks, don't add them to the total here
            long neededTotal = file.ComputeFileSizeNotIncludingLastUcBlock() * directive.GetReplication
                                   ();

            directive.AddBytesNeeded(neededTotal);
            // The pool's bytesNeeded is incremented as we scan. If the demand
            // thus far plus the demand of this file would exceed the pool's limit,
            // do not cache this file.
            CachePool pool = directive.GetPool();

            if (pool.GetBytesNeeded() > pool.GetLimit())
            {
                Log.Debug("Directive {}: not scanning file {} because " + "bytesNeeded for pool {} is {}, but the pool's limit is {}"
                          , directive.GetId(), file.GetFullPathName(), pool.GetPoolName(), pool.GetBytesNeeded
                              (), pool.GetLimit());
                return;
            }
            long cachedTotal = 0;

            foreach (BlockInfoContiguous blockInfo in blockInfos)
            {
                if (!blockInfo.GetBlockUCState().Equals(HdfsServerConstants.BlockUCState.Complete
                                                        ))
                {
                    // We don't try to cache blocks that are under construction.
                    Log.Trace("Directive {}: can't cache block {} because it is in state " + "{}, not COMPLETE."
                              , directive.GetId(), blockInfo, blockInfo.GetBlockUCState());
                    continue;
                }
                Block       block   = new Block(blockInfo.GetBlockId());
                CachedBlock ncblock = new CachedBlock(block.GetBlockId(), directive.GetReplication
                                                          (), mark);
                CachedBlock ocblock = cachedBlocks.Get(ncblock);
                if (ocblock == null)
                {
                    cachedBlocks.Put(ncblock);
                    ocblock = ncblock;
                }
                else
                {
                    // Update bytesUsed using the current replication levels.
                    // Assumptions: we assume that all the blocks are the same length
                    // on each datanode.  We can assume this because we're only caching
                    // blocks in state COMPLETE.
                    // Note that if two directives are caching the same block(s), they will
                    // both get them added to their bytesCached.
                    IList <DatanodeDescriptor> cachedOn = ocblock.GetDatanodes(DatanodeDescriptor.CachedBlocksList.Type
                                                                               .Cached);
                    long cachedByBlock = Math.Min(cachedOn.Count, directive.GetReplication()) * blockInfo
                                         .GetNumBytes();
                    cachedTotal += cachedByBlock;
                    if ((mark != ocblock.GetMark()) || (ocblock.GetReplication() < directive.GetReplication
                                                            ()))
                    {
                        //
                        // Overwrite the block's replication and mark in two cases:
                        //
                        // 1. If the mark on the CachedBlock is different from the mark for
                        // this scan, that means the block hasn't been updated during this
                        // scan, and we should overwrite whatever is there, since it is no
                        // longer valid.
                        //
                        // 2. If the replication in the CachedBlock is less than what the
                        // directive asks for, we want to increase the block's replication
                        // field to what the directive asks for.
                        //
                        ocblock.SetReplicationAndMark(directive.GetReplication(), mark);
                    }
                }
                Log.Trace("Directive {}: setting replication for block {} to {}", directive.GetId
                              (), blockInfo, ocblock.GetReplication());
            }
            // Increment the "cached" statistics
            directive.AddBytesCached(cachedTotal);
            if (cachedTotal == neededTotal)
            {
                directive.AddFilesCached(1);
            }
            Log.Debug("Directive {}: caching {}: {}/{} bytes", directive.GetId(), file.GetFullPathName
                          (), cachedTotal, neededTotal);
        }
コード例 #10
0
        public IList <IObjRelationResult> GetObjRelations(IList <IObjRelation> objRels, ICacheIntern targetCache, CacheDirective cacheDirective)
        {
            CheckNotDisposed();
            IEventQueue eventQueue = EventQueue;

            if (eventQueue != null)
            {
                eventQueue.Pause(this);
            }
            try
            {
                bool oldCacheModificationValue = CacheModification.Active;
                bool acquireSuccess            = AcquireHardRefTLIfNotAlready(objRels.Count);
                CacheModification.Active = true;
                try
                {
                    if (SecurityActive && ((targetCache == null && Privileged) || (targetCache != null && targetCache.Privileged) &&                 //
                                           SecurityActivation != null && SecurityActivation.FilterActivated))
                    {
                        return(SecurityActivation.ExecuteWithoutFiltering(delegate()
                        {
                            return Parent.GetObjRelations(objRels, targetCache, cacheDirective);
                        }));
                    }
                    else
                    {
                        return(Parent.GetObjRelations(objRels, targetCache, cacheDirective));
                    }
                }
                finally
                {
                    CacheModification.Active = oldCacheModificationValue;
                    ClearHardRefs(acquireSuccess);
                }
            }
            finally
            {
                if (eventQueue != null)
                {
                    eventQueue.Resume(this);
                }
            }
        }
コード例 #11
0
 public override IList <IObjRelationResult> GetObjRelations(IList <IObjRelation> objRels, CacheDirective cacheDirective)
 {
     return(GetObjRelations(objRels, this, cacheDirective));
 }
コード例 #12
0
        protected IList <Object> GetObjectsRetry(IList <IObjRef> orisToGet, CacheDirective cacheDirective, out bool doAnotherRetry)
        {
            doAnotherRetry = false;
            Lock readLock = ReadLock;

            if (cacheDirective.HasFlag(CacheDirective.FailEarly))
            {
                readLock.Lock();
                try
                {
                    return(CreateResult(orisToGet, cacheDirective, true));
                }
                finally
                {
                    readLock.Unlock();
                }
            }
            List <IObjRef> orisToLoad = new List <IObjRef>();
            int            cacheVersionBeforeLongTimeAction = WaitForConcurrentReadFinish(orisToGet, orisToLoad);

            if (orisToLoad.Count == 0)
            {
                // Everything found in the cache. We STILL hold the readlock so we can immediately create the result
                // We already even checked the version. So we do not bother version anymore here
                try
                {
                    return(CreateResult(orisToGet, cacheDirective, false));
                }
                finally
                {
                    readLock.Unlock();
                }
            }
            CacheDirective parentCacheDirective = CacheDirective.None;

            if (cacheDirective.HasFlag(CacheDirective.FailInCacheHierarchy))
            {
                parentCacheDirective = CacheDirective.FailEarly;
            }
            Parent.GetObjects(orisToLoad, this, parentCacheDirective);
            // Objects do not have to be put, because their were already
            // added by the parent to this cache
            readLock.Lock();
            try
            {
                int cacheVersionAfterLongTimeAction = changeVersion;
                if (cacheVersionAfterLongTimeAction != cacheVersionBeforeLongTimeAction)
                {
                    // Another thread did some changes (possibly DataChange-Remove actions)
                    // We have to ensure that our result-scope is still valid
                    // We return null to allow a further full retry of getObjects()
                    doAnotherRetry = true;
                    return(null);
                }
                return(CreateResult(orisToGet, cacheDirective, false));
            }
            finally
            {
                readLock.Unlock();
            }
        }
コード例 #13
0
        public IList <Object> GetObjects(IList <IObjRef> orisToGet, ICacheIntern targetCache, CacheDirective cacheDirective)
        {
            CheckNotDisposed();
            if (orisToGet == null || orisToGet.Count == 0)
            {
                return(new List <Object>(0));
            }
            IEventQueue eventQueue = EventQueue;

            if (eventQueue != null)
            {
                eventQueue.Pause(this);
            }
            try
            {
                bool oldCacheModificationValue = CacheModification.Active;
                bool acquireSuccess            = AcquireHardRefTLIfNotAlready(orisToGet.Count);
                CacheModification.Active = true;
                try
                {
                    if (cacheDirective.HasFlag(CacheDirective.LoadContainerResult) || cacheDirective.HasFlag(CacheDirective.CacheValueResult))
                    {
                        return(Parent.GetObjects(orisToGet, this, cacheDirective));
                    }
                    bool doAnotherRetry;
                    while (true)
                    {
                        doAnotherRetry = false;
                        IList <Object> result = GetObjectsRetry(orisToGet, cacheDirective, out doAnotherRetry);
                        if (!doAnotherRetry)
                        {
                            return(result);
                        }
                    }
                }
                finally
                {
                    CacheModification.Active = oldCacheModificationValue;
                    ClearHardRefs(acquireSuccess);
                }
            }
            finally
            {
                if (eventQueue != null)
                {
                    eventQueue.Resume(this);
                }
            }
        }
コード例 #14
0
 public override IList <Object> GetObjects(IList <IObjRef> orisToGet, CacheDirective cacheDirective)
 {
     return(GetObjects(orisToGet, this, cacheDirective));
 }