From 202212bcbcb64ad1889025dedc34b48d0704de96 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 30 Jul 2016 03:13:23 +0100 Subject: add a regionInfoCache get by world 2D position --- .../ServiceConnectorsOut/Grid/RegionInfoCache.cs | 63 +++++++++++++++++++++- .../Grid/RemoteGridServiceConnector.cs | 24 ++++----- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index 4dc9033..8403362 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs @@ -109,6 +109,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 +237,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(); @@ -463,6 +478,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 9e27abe..1e1e8f8 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -193,26 +193,18 @@ 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) @@ -221,7 +213,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid 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_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); -- cgit v1.1 From a1759292c811829b3fa5a2016dd0fbb448e81c3c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 30 Jul 2016 03:31:03 +0100 Subject: add a regionInfoCache cache add region with expire time option --- .../ServiceConnectorsOut/Grid/RegionInfoCache.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index 8403362..77f002e 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( @@ -68,6 +68,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); } + public void Cache(UUID scopeID, UUID regionID, 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; @@ -255,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"); @@ -284,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"); -- cgit v1.1 From b44b8983315db81c60cc7227d1e0353e6e5597ab Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 30 Jul 2016 03:45:58 +0100 Subject: remove a unused parameter --- .../ServiceConnectorsOut/Grid/RegionInfoCache.cs | 6 +++--- .../ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index 77f002e..ffe3fab 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs @@ -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,7 +68,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); } - public void Cache(UUID scopeID, UUID regionID, GridRegion rinfo, float expireSeconds) + 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 diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 1e1e8f8..6575cfd 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; } @@ -210,7 +210,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (rinfo == null) rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); - m_RegionInfoCache.Cache(rinfo); + if (rinfo == null) { @@ -219,16 +219,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid 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; @@ -237,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; } -- cgit v1.1 From 6cd0a3e07c828071620ea6d2c6bd83fcade04a0d Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 30 Jul 2016 04:25:32 +0100 Subject: fix cAgent.CrossingFlags --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 7c1a7631..c592385 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) { -- cgit v1.1