diff options
author | UbitUmarov | 2016-07-30 20:08:14 +0100 |
---|---|---|
committer | UbitUmarov | 2016-07-30 20:08:14 +0100 |
commit | e62f8fd09eb3798f2ee9eb34e30b8890e81d94c3 (patch) | |
tree | b56b64b1243b87d1e8cd13ad3cf404e32b9c7e53 /OpenSim/Region | |
parent | fix RegionInfoCache keys compare, remove RegionCache now replaced by RegionI... (diff) | |
download | opensim-SC-e62f8fd09eb3798f2ee9eb34e30b8890e81d94c3.zip opensim-SC-e62f8fd09eb3798f2ee9eb34e30b8890e81d94c3.tar.gz opensim-SC-e62f8fd09eb3798f2ee9eb34e30b8890e81d94c3.tar.bz2 opensim-SC-e62f8fd09eb3798f2ee9eb34e30b8890e81d94c3.tar.xz |
change RegionInfoCache expires control
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs | 84 |
1 files changed, 36 insertions, 48 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index 8736402..8f3dfc1 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs | |||
@@ -156,30 +156,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
156 | // following code partialy adapted from lib OpenMetaverse | 156 | // following code partialy adapted from lib OpenMetaverse |
157 | public class RegionKey | 157 | public class RegionKey |
158 | { | 158 | { |
159 | public UUID m_scopeID; | 159 | public UUID ScopeID; |
160 | public UUID m_RegionID; | 160 | public UUID RegionID; |
161 | private DateTime m_expirationDate; | ||
162 | 161 | ||
163 | public RegionKey(UUID scopeID, UUID id) | 162 | public RegionKey(UUID scopeID, UUID id) |
164 | { | 163 | { |
165 | m_scopeID = scopeID; | 164 | ScopeID = scopeID; |
166 | m_RegionID = id; | 165 | RegionID = id; |
167 | } | 166 | } |
168 | 167 | ||
169 | public UUID ScopeID | ||
170 | { | ||
171 | get { return m_scopeID; } | ||
172 | } | ||
173 | public DateTime ExpirationDate | ||
174 | { | ||
175 | get { return m_expirationDate; } | ||
176 | set { m_expirationDate = value; } | ||
177 | } | ||
178 | |||
179 | public override int GetHashCode() | 168 | public override int GetHashCode() |
180 | { | 169 | { |
181 | int hash = m_scopeID.GetHashCode(); | 170 | int hash = ScopeID.GetHashCode(); |
182 | hash += hash * 23 + m_RegionID.GetHashCode(); | 171 | hash += hash * 23 + RegionID.GetHashCode(); |
183 | return hash; | 172 | return hash; |
184 | } | 173 | } |
185 | 174 | ||
@@ -188,7 +177,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
188 | if(b == null) | 177 | if(b == null) |
189 | return false; | 178 | return false; |
190 | RegionKey kb = b as RegionKey; | 179 | RegionKey kb = b as RegionKey; |
191 | return (m_scopeID == kb.m_scopeID && m_RegionID == kb.m_RegionID); | 180 | return (ScopeID == kb.ScopeID && RegionID == kb.RegionID); |
192 | } | 181 | } |
193 | } | 182 | } |
194 | 183 | ||
@@ -196,14 +185,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
196 | { | 185 | { |
197 | public override int GetHashCode(RegionKey rk) | 186 | public override int GetHashCode(RegionKey rk) |
198 | { | 187 | { |
199 | int hash = rk.m_scopeID.GetHashCode(); | 188 | return rk.GetHashCode(); |
200 | hash += hash * 23 + rk.m_RegionID.GetHashCode(); | ||
201 | return hash; | ||
202 | } | 189 | } |
203 | 190 | ||
204 | public override bool Equals(RegionKey a, RegionKey b) | 191 | public override bool Equals(RegionKey a, RegionKey b) |
205 | { | 192 | { |
206 | return (a.m_scopeID == b.m_scopeID && a.m_RegionID == b.m_RegionID); | 193 | return (a.ScopeID == b.ScopeID && a.RegionID == b.RegionID); |
207 | } | 194 | } |
208 | } | 195 | } |
209 | 196 | ||
@@ -291,6 +278,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
291 | 278 | ||
292 | static RegionKeyEqual keyequal = new RegionKeyEqual(); | 279 | static RegionKeyEqual keyequal = new RegionKeyEqual(); |
293 | Dictionary<RegionKey, GridRegion> timedStorage = new Dictionary<RegionKey, GridRegion>(keyequal); | 280 | Dictionary<RegionKey, GridRegion> timedStorage = new Dictionary<RegionKey, GridRegion>(keyequal); |
281 | Dictionary<RegionKey, DateTime> timedExpires = new Dictionary<RegionKey, DateTime>(); | ||
294 | Dictionary<UUID, RegionInfoByScope> InfobyScope = new Dictionary<UUID, RegionInfoByScope>(); | 282 | Dictionary<UUID, RegionInfoByScope> InfobyScope = new Dictionary<UUID, RegionInfoByScope>(); |
295 | private System.Timers.Timer timer = new System.Timers.Timer(TimeSpan.FromSeconds(CACHE_PURGE_HZ).TotalMilliseconds); | 283 | private System.Timers.Timer timer = new System.Timers.Timer(TimeSpan.FromSeconds(CACHE_PURGE_HZ).TotalMilliseconds); |
296 | 284 | ||
@@ -312,8 +300,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
312 | if (timedStorage.ContainsKey(key)) | 300 | if (timedStorage.ContainsKey(key)) |
313 | return false; | 301 | return false; |
314 | 302 | ||
315 | key.ExpirationDate = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds); | 303 | DateTime expire = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds); |
316 | timedStorage.Add(key, region); | 304 | timedStorage[key] = region; |
305 | timedExpires[key] = expire; | ||
317 | 306 | ||
318 | RegionInfoByScope ris = null; | 307 | RegionInfoByScope ris = null; |
319 | if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) | 308 | if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) |
@@ -337,12 +326,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
337 | try | 326 | try |
338 | { | 327 | { |
339 | RegionKey key = new RegionKey(scope, region.RegionID); | 328 | RegionKey key = new RegionKey(scope, region.RegionID); |
340 | key.ExpirationDate = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds); | 329 | DateTime expire = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds); |
341 | 330 | ||
342 | if (timedStorage.ContainsKey(key)) | 331 | if (timedStorage.ContainsKey(key)) |
343 | { | 332 | { |
344 | timedStorage.Remove(key); | 333 | timedStorage[key] = region; |
345 | timedStorage.Add(key, region); | 334 | if(expire > timedExpires[key]) |
335 | timedExpires[key] = expire; | ||
346 | 336 | ||
347 | if(!InfobyScope.ContainsKey(scope)) | 337 | if(!InfobyScope.ContainsKey(scope)) |
348 | { | 338 | { |
@@ -353,7 +343,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
353 | } | 343 | } |
354 | else | 344 | else |
355 | { | 345 | { |
356 | timedStorage.Add(key, region); | 346 | timedStorage[key] = region; |
347 | timedExpires[key] = expire; | ||
357 | RegionInfoByScope ris = null; | 348 | RegionInfoByScope ris = null; |
358 | if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) | 349 | if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) |
359 | { | 350 | { |
@@ -375,6 +366,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
375 | try | 366 | try |
376 | { | 367 | { |
377 | timedStorage.Clear(); | 368 | timedStorage.Clear(); |
369 | timedExpires.Clear(); | ||
378 | InfobyScope.Clear(); | 370 | InfobyScope.Clear(); |
379 | } | 371 | } |
380 | finally { Monitor.Exit(syncRoot); } | 372 | finally { Monitor.Exit(syncRoot); } |
@@ -428,6 +420,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
428 | InfobyScope.Remove(scope); | 420 | InfobyScope.Remove(scope); |
429 | } | 421 | } |
430 | timedStorage.Remove(key); | 422 | timedStorage.Remove(key); |
423 | timedExpires.Remove(key); | ||
431 | return true; | 424 | return true; |
432 | } | 425 | } |
433 | else | 426 | else |
@@ -581,9 +574,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
581 | if (!timedStorage.ContainsKey(key)) | 574 | if (!timedStorage.ContainsKey(key)) |
582 | return false; | 575 | return false; |
583 | 576 | ||
584 | timedStorage.Remove(key); | 577 | DateTime expire = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds); |
585 | key.ExpirationDate = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds); | 578 | timedStorage[key] = region; |
586 | timedStorage.Add(key, region); | 579 | if(expire > timedExpires[key]) |
580 | timedExpires[key] = expire; | ||
581 | |||
587 | return true; | 582 | return true; |
588 | } | 583 | } |
589 | finally { Monitor.Exit(syncRoot); } | 584 | finally { Monitor.Exit(syncRoot); } |
@@ -609,26 +604,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
609 | return; | 604 | return; |
610 | try | 605 | try |
611 | { | 606 | { |
612 | OpenMetaverse.Lazy<List<object>> expiredItems = new OpenMetaverse.Lazy<List<object>>(); | 607 | List<RegionKey> expiredkeys = new List<RegionKey>(); |
613 | 608 | ||
614 | foreach (RegionKey timedKey in timedStorage.Keys) | 609 | foreach (KeyValuePair<RegionKey, DateTime> kvp in timedExpires) |
615 | { | 610 | { |
616 | if (timedKey.ExpirationDate < signalTime) | 611 | if (kvp.Value < signalTime) |
617 | { | 612 | expiredkeys.Add(kvp.Key); |
618 | // Mark the object for purge | ||
619 | expiredItems.Value.Add(timedKey); | ||
620 | } | ||
621 | else | ||
622 | { | ||
623 | break; | ||
624 | } | ||
625 | } | 613 | } |
626 | 614 | ||
627 | 615 | if (expiredkeys.Count > 0) | |
628 | RegionInfoByScope ris; | ||
629 | if (expiredItems.IsValueCreated) | ||
630 | { | 616 | { |
631 | foreach (RegionKey key in expiredItems.Value) | 617 | RegionInfoByScope ris; |
618 | foreach (RegionKey key in expiredkeys) | ||
632 | { | 619 | { |
633 | ris = null; | 620 | ris = null; |
634 | if(InfobyScope.TryGetValue(key.ScopeID, out ris) && ris != null) | 621 | if(InfobyScope.TryGetValue(key.ScopeID, out ris) && ris != null) |
@@ -641,6 +628,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
641 | InfobyScope.Remove(key.ScopeID); | 628 | InfobyScope.Remove(key.ScopeID); |
642 | } | 629 | } |
643 | timedStorage.Remove(key); | 630 | timedStorage.Remove(key); |
631 | timedExpires.Remove(key); | ||
644 | } | 632 | } |
645 | } | 633 | } |
646 | } | 634 | } |