diff options
author | UbitUmarov | 2016-07-30 03:13:23 +0100 |
---|---|---|
committer | UbitUmarov | 2016-07-30 03:13:23 +0100 |
commit | 202212bcbcb64ad1889025dedc34b48d0704de96 (patch) | |
tree | 2168c87892f518991c9d95855b93243ec7e57add /OpenSim/Region/CoreModules | |
parent | in RegionInfoCache, replace lib omv ExpireCaches by a single dedicated one (diff) | |
download | opensim-SC_OLD-202212bcbcb64ad1889025dedc34b48d0704de96.zip opensim-SC_OLD-202212bcbcb64ad1889025dedc34b48d0704de96.tar.gz opensim-SC_OLD-202212bcbcb64ad1889025dedc34b48d0704de96.tar.bz2 opensim-SC_OLD-202212bcbcb64ad1889025dedc34b48d0704de96.tar.xz |
add a regionInfoCache get by world 2D position
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs | 63 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/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 | |||
109 | 109 | ||
110 | return null; | 110 | return null; |
111 | } | 111 | } |
112 | |||
113 | public GridRegion Get(UUID scopeID, int x, int y, out bool inCache) | ||
114 | { | ||
115 | inCache = false; | ||
116 | |||
117 | GridRegion rinfo = null; | ||
118 | if (m_Cache.TryGetValue(scopeID, x, y, out rinfo)) | ||
119 | { | ||
120 | inCache = true; | ||
121 | return rinfo; | ||
122 | } | ||
123 | |||
124 | return null; | ||
125 | } | ||
126 | |||
112 | } | 127 | } |
113 | 128 | ||
114 | 129 | ||
@@ -222,8 +237,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
222 | 237 | ||
223 | public sealed class RegionsExpiringCache | 238 | public sealed class RegionsExpiringCache |
224 | { | 239 | { |
225 | const double CACHE_PURGE_HZ = 60; | 240 | const double CACHE_PURGE_HZ = 60; // seconds |
226 | const int MAX_LOCK_WAIT = 5000; // milliseconds | 241 | const int MAX_LOCK_WAIT = 10000; // milliseconds |
227 | 242 | ||
228 | /// <summary>For thread safety</summary> | 243 | /// <summary>For thread safety</summary> |
229 | object syncRoot = new object(); | 244 | object syncRoot = new object(); |
@@ -463,6 +478,50 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
463 | return false; | 478 | return false; |
464 | } | 479 | } |
465 | 480 | ||
481 | // gets a region that contains world position (x,y) | ||
482 | // hopefull will not take ages | ||
483 | public bool TryGetValue(UUID scope, int x, int y, out GridRegion value) | ||
484 | { | ||
485 | if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) | ||
486 | throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); | ||
487 | try | ||
488 | { | ||
489 | value = null; | ||
490 | |||
491 | if(timedStorage.Count == 0) | ||
492 | return false; | ||
493 | |||
494 | foreach(KeyValuePair<RegionKey, GridRegion> kvp in timedStorage) | ||
495 | { | ||
496 | if(kvp.Key.ScopeID != scope) | ||
497 | continue; | ||
498 | |||
499 | GridRegion r = kvp.Value; | ||
500 | if(r == null) // ?? | ||
501 | continue; | ||
502 | int test = r.RegionLocX; | ||
503 | if(x < test) | ||
504 | continue; | ||
505 | test += r.RegionSizeX; | ||
506 | if(x >= test) | ||
507 | continue; | ||
508 | test = r.RegionLocY; | ||
509 | if(y < test) | ||
510 | continue; | ||
511 | test += r.RegionSizeY; | ||
512 | if (y < test) | ||
513 | { | ||
514 | value = r; | ||
515 | return true; | ||
516 | } | ||
517 | } | ||
518 | } | ||
519 | finally { Monitor.Exit(syncRoot); } | ||
520 | |||
521 | value = null; | ||
522 | return false; | ||
523 | } | ||
524 | |||
466 | public bool Update(UUID scope, GridRegion region, double expirationSeconds) | 525 | public bool Update(UUID scope, GridRegion region, double expirationSeconds) |
467 | { | 526 | { |
468 | if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) | 527 | 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 | |||
193 | // The coordinates are world coords (meters), NOT region units. | 193 | // The coordinates are world coords (meters), NOT region units. |
194 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | 194 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) |
195 | { | 195 | { |
196 | // try in cache by handler first | ||
196 | ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y); | 197 | ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y); |
197 | uint regionX = Util.WorldToRegionLoc((uint)x); | ||
198 | uint regionY = Util.WorldToRegionLoc((uint)y); | ||
199 | 198 | ||
200 | /* this is no longer valid | ||
201 | // Sanity check | ||
202 | if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y)) | ||
203 | { | ||
204 | m_log.WarnFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{0},{1}>, Should Be=<{2},{3}>", | ||
205 | x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY)); | ||
206 | } | ||
207 | */ | ||
208 | bool inCache = false; | 199 | bool inCache = false; |
209 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache); | 200 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache); |
210 | if (inCache) | 201 | if (inCache) |
211 | { | ||
212 | // m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Found region {0} in cache. Pos=<{1},{2}>, RegionHandle={3}", | ||
213 | // (rinfo == null) ? "<missing>" : rinfo.RegionName, regionX, regionY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); | ||
214 | return rinfo; | 202 | return rinfo; |
215 | } | 203 | |
204 | // try in cache by slower position next | ||
205 | rinfo = m_RegionInfoCache.Get(scopeID, x, y, out inCache); | ||
206 | if (inCache) | ||
207 | return rinfo; | ||
216 | 208 | ||
217 | rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); | 209 | rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); |
218 | if (rinfo == null) | 210 | if (rinfo == null) |
@@ -221,7 +213,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
221 | m_RegionInfoCache.Cache(rinfo); | 213 | m_RegionInfoCache.Cache(rinfo); |
222 | 214 | ||
223 | if (rinfo == null) | 215 | if (rinfo == null) |
216 | { | ||
217 | uint regionX = Util.WorldToRegionLoc((uint)x); | ||
218 | uint regionY = Util.WorldToRegionLoc((uint)y); | ||
224 | m_log.WarnFormat("[REMOTE GRID CONNECTOR]: Requested region {0}-{1} not found", regionX, regionY); | 219 | m_log.WarnFormat("[REMOTE GRID CONNECTOR]: Requested region {0}-{1} not found", regionX, regionY); |
220 | } | ||
225 | else | 221 | else |
226 | m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", | 222 | m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", |
227 | rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); | 223 | rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); |