add a regionInfoCache get by world 2D position

LSLKeyTest
UbitUmarov 2016-07-30 03:13:23 +01:00
parent 55b2d01028
commit 202212bcbc
2 changed files with 71 additions and 16 deletions

View File

@ -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
/// <summary>For thread safety</summary>
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<RegionKey, GridRegion> 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))

View File

@ -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) ? "<missing>" : 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);