diff options
author | UbitUmarov | 2016-07-30 17:14:17 +0100 |
---|---|---|
committer | UbitUmarov | 2016-07-30 17:14:17 +0100 |
commit | bf593dd6f4d1939b66335aa9ca5c006be2a751bb (patch) | |
tree | 05f7b70c02329f18710959958e8e23613387b1bc /OpenSim | |
parent | let LocalGridServiceConnector also have a RegionInfoCache, use the remote one... (diff) | |
download | opensim-SC-bf593dd6f4d1939b66335aa9ca5c006be2a751bb.zip opensim-SC-bf593dd6f4d1939b66335aa9ca5c006be2a751bb.tar.gz opensim-SC-bf593dd6f4d1939b66335aa9ca5c006be2a751bb.tar.bz2 opensim-SC-bf593dd6f4d1939b66335aa9ca5c006be2a751bb.tar.xz |
fix RegionInfoCache keys compare, remove RegionCache now replaced by RegionInfoCache
Diffstat (limited to '')
3 files changed, 70 insertions, 134 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 3e03a5e..58bd4ea 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | |||
@@ -51,7 +51,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
51 | private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]"; | 51 | private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]"; |
52 | 52 | ||
53 | private IGridService m_GridService; | 53 | private IGridService m_GridService; |
54 | private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); | ||
55 | private RegionInfoCache m_RegionInfoCache = null; | 54 | private RegionInfoCache m_RegionInfoCache = null; |
56 | 55 | ||
57 | private bool m_Enabled; | 56 | private bool m_Enabled; |
@@ -151,13 +150,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
151 | 150 | ||
152 | scene.RegisterModuleInterface<IGridService>(this); | 151 | scene.RegisterModuleInterface<IGridService>(this); |
153 | 152 | ||
154 | lock (m_LocalCache) | 153 | m_RegionInfoCache.CacheLocal(new GridRegion(scene.RegionInfo)); |
155 | { | 154 | scene.EventManager.OnRegionUp += OnRegionUp; |
156 | if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) | ||
157 | m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); | ||
158 | else | ||
159 | m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); | ||
160 | } | ||
161 | } | 155 | } |
162 | 156 | ||
163 | public void RemoveRegion(Scene scene) | 157 | public void RemoveRegion(Scene scene) |
@@ -165,11 +159,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
165 | if (!m_Enabled) | 159 | if (!m_Enabled) |
166 | return; | 160 | return; |
167 | 161 | ||
168 | lock (m_LocalCache) | 162 | m_RegionInfoCache.Remove(scene.RegionInfo.ScopeID, scene.RegionInfo.RegionID); |
169 | { | 163 | scene.EventManager.OnRegionUp -= OnRegionUp; |
170 | m_LocalCache[scene.RegionInfo.RegionID].Clear(); | ||
171 | m_LocalCache.Remove(scene.RegionInfo.RegionID); | ||
172 | } | ||
173 | } | 164 | } |
174 | 165 | ||
175 | public void RegionLoaded(Scene scene) | 166 | public void RegionLoaded(Scene scene) |
@@ -180,6 +171,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
180 | 171 | ||
181 | #region IGridService | 172 | #region IGridService |
182 | 173 | ||
174 | private void OnRegionUp(GridRegion region) | ||
175 | { | ||
176 | // This shouldn't happen | ||
177 | if (region == null) | ||
178 | return; | ||
179 | |||
180 | m_RegionInfoCache.CacheNearNeighbour(region.ScopeID, region); | ||
181 | } | ||
182 | |||
183 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) | 183 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) |
184 | { | 184 | { |
185 | return m_GridService.RegisterRegion(scopeID, regionInfo); | 185 | return m_GridService.RegisterRegion(scopeID, regionInfo); |
@@ -291,7 +291,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
291 | public void HandleShowNeighboursCommand(string module, string[] cmdparams) | 291 | public void HandleShowNeighboursCommand(string module, string[] cmdparams) |
292 | { | 292 | { |
293 | System.Text.StringBuilder caps = new System.Text.StringBuilder(); | 293 | System.Text.StringBuilder caps = new System.Text.StringBuilder(); |
294 | 294 | /* temporary broken | |
295 | lock (m_LocalCache) | 295 | lock (m_LocalCache) |
296 | { | 296 | { |
297 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) | 297 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) |
@@ -304,6 +304,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
304 | } | 304 | } |
305 | 305 | ||
306 | MainConsole.Instance.Output(caps.ToString()); | 306 | MainConsole.Instance.Output(caps.ToString()); |
307 | */ | ||
308 | MainConsole.Instance.Output("Neighbours list not avaiable in this version\n"); | ||
307 | } | 309 | } |
308 | } | 310 | } |
309 | } | 311 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs deleted file mode 100644 index 2961c10..0000000 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs +++ /dev/null | |||
@@ -1,103 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
41 | { | ||
42 | public class RegionCache | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private Scene m_scene; | ||
49 | private Dictionary<ulong, GridRegion> m_neighbours = new Dictionary<ulong, GridRegion>(); | ||
50 | |||
51 | public string RegionName | ||
52 | { | ||
53 | get { return m_scene.RegionInfo.RegionName; } | ||
54 | } | ||
55 | |||
56 | public RegionCache(Scene s) | ||
57 | { | ||
58 | m_scene = s; | ||
59 | m_scene.EventManager.OnRegionUp += OnRegionUp; | ||
60 | } | ||
61 | |||
62 | private void OnRegionUp(GridRegion otherRegion) | ||
63 | { | ||
64 | // This shouldn't happen | ||
65 | if (otherRegion == null) | ||
66 | return; | ||
67 | |||
68 | m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}", | ||
69 | m_scene.RegionInfo.RegionName, otherRegion.RegionName, Util.WorldToRegionLoc((uint)otherRegion.RegionLocX), Util.WorldToRegionLoc((uint)otherRegion.RegionLocY)); | ||
70 | |||
71 | m_neighbours[otherRegion.RegionHandle] = otherRegion; | ||
72 | } | ||
73 | |||
74 | public void Clear() | ||
75 | { | ||
76 | m_scene.EventManager.OnRegionUp -= OnRegionUp; | ||
77 | m_neighbours.Clear(); | ||
78 | } | ||
79 | |||
80 | public List<GridRegion> GetNeighbours() | ||
81 | { | ||
82 | return new List<GridRegion>(m_neighbours.Values); | ||
83 | } | ||
84 | |||
85 | public GridRegion GetRegionByPosition(int x, int y) | ||
86 | { | ||
87 | // do actual search by position | ||
88 | // not the best, but this will not hold that many regions | ||
89 | GridRegion foundRegion = null; | ||
90 | foreach(GridRegion r in m_neighbours.Values) | ||
91 | { | ||
92 | if (x >= r.RegionLocX && x < r.RegionLocX + r.RegionSizeX | ||
93 | && y >= r.RegionLocY && y < r.RegionLocY + r.RegionSizeY) | ||
94 | { | ||
95 | foundRegion = r; | ||
96 | break; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | return foundRegion; | ||
101 | } | ||
102 | } | ||
103 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index ffe3fab..8736402 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs | |||
@@ -59,26 +59,42 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
59 | 59 | ||
60 | public void Cache(UUID scopeID, GridRegion rinfo) | 60 | public void Cache(UUID scopeID, GridRegion rinfo) |
61 | { | 61 | { |
62 | // for now, do not cache negative results; this is because | ||
63 | // we need to figure out how to handle regions coming online | ||
64 | // in a timely way | ||
65 | if (rinfo == null) | 62 | if (rinfo == null) |
66 | return; | 63 | return; |
67 | 64 | ||
68 | m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); | 65 | m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); |
69 | } | 66 | } |
70 | 67 | ||
68 | public void CacheLocal(GridRegion rinfo) | ||
69 | { | ||
70 | if (rinfo == null) | ||
71 | return; | ||
72 | |||
73 | m_Cache.AddOrUpdate(rinfo.ScopeID, rinfo, 1e7f); | ||
74 | } | ||
75 | |||
76 | public void CacheNearNeighbour(UUID scopeID, GridRegion rinfo) | ||
77 | { | ||
78 | if (rinfo == null) | ||
79 | return; | ||
80 | |||
81 | // m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); | ||
82 | m_Cache.Add(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); // don't override local regions | ||
83 | } | ||
84 | |||
71 | public void Cache(UUID scopeID, GridRegion rinfo, float expireSeconds) | 85 | public void Cache(UUID scopeID, GridRegion rinfo, float expireSeconds) |
72 | { | 86 | { |
73 | // for now, do not cache negative results; this is because | ||
74 | // we need to figure out how to handle regions coming online | ||
75 | // in a timely way | ||
76 | if (rinfo == null) | 87 | if (rinfo == null) |
77 | return; | 88 | return; |
78 | 89 | ||
79 | m_Cache.AddOrUpdate(scopeID, rinfo, expireSeconds); | 90 | m_Cache.AddOrUpdate(scopeID, rinfo, expireSeconds); |
80 | } | 91 | } |
81 | 92 | ||
93 | public void Remove(UUID scopeID, UUID regionID) | ||
94 | { | ||
95 | m_Cache.Remove(scopeID, regionID); | ||
96 | } | ||
97 | |||
82 | public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache) | 98 | public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache) |
83 | { | 99 | { |
84 | inCache = false; | 100 | inCache = false; |
@@ -134,15 +150,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
134 | 150 | ||
135 | return null; | 151 | return null; |
136 | } | 152 | } |
137 | |||
138 | } | 153 | } |
139 | 154 | ||
140 | 155 | ||
141 | // following code partialy adapted from lib OpenMetaverse | 156 | // following code partialy adapted from lib OpenMetaverse |
142 | public class RegionKey : IComparable<RegionKey> | 157 | public class RegionKey |
143 | { | 158 | { |
144 | private UUID m_scopeID; | 159 | public UUID m_scopeID; |
145 | private UUID m_RegionID; | 160 | public UUID m_RegionID; |
146 | private DateTime m_expirationDate; | 161 | private DateTime m_expirationDate; |
147 | 162 | ||
148 | public RegionKey(UUID scopeID, UUID id) | 163 | public RegionKey(UUID scopeID, UUID id) |
@@ -161,16 +176,34 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
161 | set { m_expirationDate = value; } | 176 | set { m_expirationDate = value; } |
162 | } | 177 | } |
163 | 178 | ||
164 | public int GetHaskCode() | 179 | public override int GetHashCode() |
165 | { | 180 | { |
166 | int hash = m_scopeID.GetHashCode(); | 181 | int hash = m_scopeID.GetHashCode(); |
167 | hash += hash * 23 + m_RegionID.GetHashCode(); | 182 | hash += hash * 23 + m_RegionID.GetHashCode(); |
168 | return hash; | 183 | return hash; |
169 | } | 184 | } |
170 | 185 | ||
171 | public int CompareTo(RegionKey other) | 186 | public override bool Equals(Object b) |
187 | { | ||
188 | if(b == null) | ||
189 | return false; | ||
190 | RegionKey kb = b as RegionKey; | ||
191 | return (m_scopeID == kb.m_scopeID && m_RegionID == kb.m_RegionID); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | class RegionKeyEqual : EqualityComparer<RegionKey> | ||
196 | { | ||
197 | public override int GetHashCode(RegionKey rk) | ||
198 | { | ||
199 | int hash = rk.m_scopeID.GetHashCode(); | ||
200 | hash += hash * 23 + rk.m_RegionID.GetHashCode(); | ||
201 | return hash; | ||
202 | } | ||
203 | |||
204 | public override bool Equals(RegionKey a, RegionKey b) | ||
172 | { | 205 | { |
173 | return GetHashCode().CompareTo(other.GetHashCode()); | 206 | return (a.m_scopeID == b.m_scopeID && a.m_RegionID == b.m_RegionID); |
174 | } | 207 | } |
175 | } | 208 | } |
176 | 209 | ||
@@ -246,7 +279,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
246 | } | 279 | } |
247 | } | 280 | } |
248 | 281 | ||
249 | public sealed class RegionsExpiringCache | 282 | public class RegionsExpiringCache |
250 | { | 283 | { |
251 | const double CACHE_PURGE_HZ = 60; // seconds | 284 | const double CACHE_PURGE_HZ = 60; // seconds |
252 | const int MAX_LOCK_WAIT = 10000; // milliseconds | 285 | const int MAX_LOCK_WAIT = 10000; // milliseconds |
@@ -256,7 +289,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
256 | /// <summary>For thread safety</summary> | 289 | /// <summary>For thread safety</summary> |
257 | object isPurging = new object(); | 290 | object isPurging = new object(); |
258 | 291 | ||
259 | Dictionary<RegionKey, GridRegion> timedStorage = new Dictionary<RegionKey, GridRegion>(); | 292 | static RegionKeyEqual keyequal = new RegionKeyEqual(); |
293 | Dictionary<RegionKey, GridRegion> timedStorage = new Dictionary<RegionKey, GridRegion>(keyequal); | ||
260 | Dictionary<UUID, RegionInfoByScope> InfobyScope = new Dictionary<UUID, RegionInfoByScope>(); | 294 | Dictionary<UUID, RegionInfoByScope> InfobyScope = new Dictionary<UUID, RegionInfoByScope>(); |
261 | private System.Timers.Timer timer = new System.Timers.Timer(TimeSpan.FromSeconds(CACHE_PURGE_HZ).TotalMilliseconds); | 295 | private System.Timers.Timer timer = new System.Timers.Timer(TimeSpan.FromSeconds(CACHE_PURGE_HZ).TotalMilliseconds); |
262 | 296 | ||
@@ -370,10 +404,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
370 | return timedStorage.Count; | 404 | return timedStorage.Count; |
371 | } | 405 | } |
372 | } | 406 | } |
373 | |||
374 | public bool Remove(UUID scope, GridRegion region) | 407 | public bool Remove(UUID scope, GridRegion region) |
375 | { | 408 | { |
376 | RegionKey key = new RegionKey(scope, region.RegionID); | 409 | return Remove(scope, region.RegionID); |
410 | } | ||
411 | public bool Remove(UUID scope, UUID regionID) | ||
412 | { | ||
413 | RegionKey key = new RegionKey(scope, regionID); | ||
377 | 414 | ||
378 | if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) | 415 | if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) |
379 | throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); | 416 | throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); |