diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index 4dc9033283..ffe3fab250 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs @@ -38,7 +38,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { public class RegionInfoCache { - private const double CACHE_EXPIRATION_SECONDS = 120; // 2 minutes opensim regions change a lot + private const float CACHE_EXPIRATION_SECONDS = 120; // 2 minutes opensim regions change a lot // private static readonly ILog m_log = // LogManager.GetLogger( @@ -54,10 +54,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void Cache(GridRegion rinfo) { if (rinfo != null) - this.Cache(rinfo.ScopeID,rinfo.RegionID,rinfo); + this.Cache(rinfo.ScopeID, rinfo); } - public void Cache(UUID scopeID, UUID regionID, GridRegion rinfo) + public void Cache(UUID scopeID, GridRegion rinfo) { // for now, do not cache negative results; this is because // we need to figure out how to handle regions coming online @@ -68,6 +68,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); } + public void Cache(UUID scopeID, GridRegion rinfo, float expireSeconds) + { + // for now, do not cache negative results; this is because + // we need to figure out how to handle regions coming online + // in a timely way + if (rinfo == null) + return; + + m_Cache.AddOrUpdate(scopeID, rinfo, expireSeconds); + } + public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache) { inCache = false; @@ -109,6 +120,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return null; } + + public GridRegion Get(UUID scopeID, int x, int y, out bool inCache) + { + inCache = false; + + GridRegion rinfo = null; + if (m_Cache.TryGetValue(scopeID, x, y, out rinfo)) + { + inCache = true; + return rinfo; + } + + return null; + } + } @@ -222,8 +248,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public sealed class RegionsExpiringCache { - const double CACHE_PURGE_HZ = 60; - const int MAX_LOCK_WAIT = 5000; // milliseconds + const double CACHE_PURGE_HZ = 60; // seconds + const int MAX_LOCK_WAIT = 10000; // milliseconds /// For thread safety object syncRoot = new object(); @@ -240,7 +266,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid timer.Start(); } - public bool Add(UUID scope, GridRegion region, double expirationSeconds) + public bool Add(UUID scope, GridRegion region, float expirationSeconds) { if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); @@ -269,7 +295,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid finally { Monitor.Exit(syncRoot);} } - public bool AddOrUpdate(UUID scope, GridRegion region, double expirationSeconds) + public bool AddOrUpdate(UUID scope, GridRegion region, float expirationSeconds) { if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); @@ -463,6 +489,50 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return false; } + // gets a region that contains world position (x,y) + // hopefull will not take ages + public bool TryGetValue(UUID scope, int x, int y, out GridRegion value) + { + if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) + throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); + try + { + value = null; + + if(timedStorage.Count == 0) + return false; + + foreach(KeyValuePair kvp in timedStorage) + { + if(kvp.Key.ScopeID != scope) + continue; + + GridRegion r = kvp.Value; + if(r == null) // ?? + continue; + int test = r.RegionLocX; + if(x < test) + continue; + test += r.RegionSizeX; + if(x >= test) + continue; + test = r.RegionLocY; + if(y < test) + continue; + test += r.RegionSizeY; + if (y < test) + { + value = r; + return true; + } + } + } + finally { Monitor.Exit(syncRoot); } + + value = null; + return false; + } + public bool Update(UUID scope, GridRegion region, double expirationSeconds) { if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 9e27abe42c..6575cfd27a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -183,7 +183,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (rinfo == null) rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID); - m_RegionInfoCache.Cache(scopeID,regionID,rinfo); + m_RegionInfoCache.Cache(scopeID, rinfo); return rinfo; } @@ -193,46 +193,45 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // The coordinates are world coords (meters), NOT region units. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { + // try in cache by handler first ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y); - uint regionX = Util.WorldToRegionLoc((uint)x); - uint regionY = Util.WorldToRegionLoc((uint)y); -/* this is no longer valid - // Sanity check - if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y)) - { - m_log.WarnFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{0},{1}>, Should Be=<{2},{3}>", - x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY)); - } -*/ bool inCache = false; GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache); if (inCache) - { -// m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Found region {0} in cache. Pos=<{1},{2}>, RegionHandle={3}", -// (rinfo == null) ? "" : rinfo.RegionName, regionX, regionY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); return rinfo; - } + + // try in cache by slower position next + rinfo = m_RegionInfoCache.Get(scopeID, x, y, out inCache); + if (inCache) + return rinfo; rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); - m_RegionInfoCache.Cache(rinfo); + if (rinfo == null) + { + uint regionX = Util.WorldToRegionLoc((uint)x); + uint regionY = Util.WorldToRegionLoc((uint)y); m_log.WarnFormat("[REMOTE GRID CONNECTOR]: Requested region {0}-{1} not found", regionX, regionY); + } else + { + m_RegionInfoCache.Cache(scopeID, rinfo); + m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); - + } return rinfo; } public GridRegion GetRegionByName(UUID scopeID, string regionName) { bool inCache = false; - GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionName, out inCache); + GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionName, out inCache); if (inCache) return rinfo; @@ -241,7 +240,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName); // can't cache negative results for name lookups - m_RegionInfoCache.Cache(rinfo); + m_RegionInfoCache.Cache(scopeID, rinfo); return rinfo; } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 7c1a763137..c59238557e 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -4539,7 +4539,13 @@ namespace OpenSim.Region.Framework.Scenes if (Scene.AttachmentsModule != null) Scene.AttachmentsModule.CopyAttachments(this, cAgent); - cAgent.CrossingFlags = isCrossUpdate ? crossingFlags : (byte)0; + if(isCrossUpdate) + { + cAgent.CrossingFlags = crossingFlags; + cAgent.CrossingFlags |= 1; + } + else + cAgent.CrossingFlags = 0; if(isCrossUpdate && haveGroupInformation) {