move UserAccountCache access locking to its methods and not callers.

melanie
UbitUmarov 2016-11-09 20:09:49 +00:00
parent 924c5fb55e
commit 1e1d0d8204
3 changed files with 54 additions and 55 deletions

View File

@ -154,13 +154,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
bool inCache = false; bool inCache = false;
UserAccount account; UserAccount account;
lock(m_Cache)
account = m_Cache.Get(userID, out inCache); account = m_Cache.Get(userID, out inCache);
if (inCache) if (inCache)
return account; return account;
account = UserAccountService.GetUserAccount(scopeID, userID); account = UserAccountService.GetUserAccount(scopeID, userID);
lock(m_Cache)
m_Cache.Cache(userID, account); m_Cache.Cache(userID, account);
return account; return account;
@ -170,14 +168,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
bool inCache = false; bool inCache = false;
UserAccount account; UserAccount account;
lock(m_Cache)
account = m_Cache.Get(firstName + " " + lastName, out inCache); account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache) if (inCache)
return account; return account;
account = UserAccountService.GetUserAccount(scopeID, firstName, lastName); account = UserAccountService.GetUserAccount(scopeID, firstName, lastName);
if (account != null) if (account != null)
lock(m_Cache)
m_Cache.Cache(account.PrincipalID, account); m_Cache.Cache(account.PrincipalID, account);
return account; return account;
@ -201,7 +197,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
if(UUID.TryParse(id, out uuid)) if(UUID.TryParse(id, out uuid))
{ {
lock(m_Cache)
account = m_Cache.Get(uuid, out inCache); account = m_Cache.Get(uuid, out inCache);
if (inCache) if (inCache)
ret.Add(account); ret.Add(account);
@ -220,7 +215,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
foreach(UserAccount acc in ext) foreach(UserAccount acc in ext)
{ {
if(acc != null) if(acc != null)
lock(m_Cache)
m_Cache.Cache(acc.PrincipalID, acc); m_Cache.Cache(acc.PrincipalID, acc);
} }
} }

View File

@ -128,7 +128,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
// flags, title, etc. And country, don't forget country! // flags, title, etc. And country, don't forget country!
private void OnNewClient(IClientAPI client) private void OnNewClient(IClientAPI client)
{ {
lock(m_Cache)
m_Cache.Remove(client.Name); m_Cache.Remove(client.Name);
} }
@ -138,17 +137,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
bool inCache = false; bool inCache = false;
UserAccount account; UserAccount account;
lock(m_Cache)
account = m_Cache.Get(userID, out inCache); account = m_Cache.Get(userID, out inCache);
if (inCache) if (inCache)
return account; return account;
account = base.GetUserAccount(scopeID, userID); account = base.GetUserAccount(scopeID, userID);
if(account != null) if(account != null)
{
lock(m_Cache)
m_Cache.Cache(userID, account); m_Cache.Cache(userID, account);
}
return account; return account;
} }
@ -156,17 +152,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
bool inCache = false; bool inCache = false;
UserAccount account; UserAccount account;
lock(m_Cache)
account = m_Cache.Get(firstName + " " + lastName, out inCache); account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache) if (inCache)
return account; return account;
account = base.GetUserAccount(scopeID, firstName, lastName); account = base.GetUserAccount(scopeID, firstName, lastName);
if (account != null) if (account != null)
{
lock(m_Cache)
m_Cache.Cache(account.PrincipalID, account); m_Cache.Cache(account.PrincipalID, account);
}
return account; return account;
} }
@ -183,7 +176,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
if(UUID.TryParse(id, out uuid)) if(UUID.TryParse(id, out uuid))
{ {
lock(m_Cache)
account = m_Cache.Get(uuid, out inCache); account = m_Cache.Get(uuid, out inCache);
if (inCache) if (inCache)
accs.Add(account); accs.Add(account);
@ -202,7 +194,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
if(acc != null) if(acc != null)
{ {
accs.Add(acc); accs.Add(acc);
lock(m_Cache)
m_Cache.Cache(acc.PrincipalID, acc); m_Cache.Cache(acc.PrincipalID, acc);
} }
} }

View File

@ -44,6 +44,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
private ExpiringCache<UUID, UserAccount> m_UUIDCache; private ExpiringCache<UUID, UserAccount> m_UUIDCache;
private ExpiringCache<string, UUID> m_NameCache; private ExpiringCache<string, UUID> m_NameCache;
private object accessLock = new object();
public UserAccountCache() public UserAccountCache()
{ {
@ -54,15 +55,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
public void Cache(UUID userID, UserAccount account) public void Cache(UUID userID, UserAccount account)
{ {
// Cache even null accounts // Cache even null accounts
lock(accessLock)
{
m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
if (account != null) if (account != null)
m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS); m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
//m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
} }
}
public void Invalidate(UUID userID) public void Invalidate(UUID userID)
{ {
lock(accessLock)
m_UUIDCache.Remove(userID); m_UUIDCache.Remove(userID);
} }
@ -70,35 +75,43 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{ {
UserAccount account = null; UserAccount account = null;
inCache = false; inCache = false;
lock(accessLock)
{
if (m_UUIDCache.TryGetValue(userID, out account)) if (m_UUIDCache.TryGetValue(userID, out account))
{ {
//m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
inCache = true; inCache = true;
return account; return account;
} }
}
return null; return null;
} }
public UserAccount Get(string name, out bool inCache) public UserAccount Get(string name, out bool inCache)
{ {
inCache = false; inCache = false;
lock(accessLock)
{
if (!m_NameCache.Contains(name)) if (!m_NameCache.Contains(name))
return null; return null;
UserAccount account = null; UserAccount account = null;
UUID uuid = UUID.Zero; UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid)) if (m_NameCache.TryGetValue(name, out uuid))
{
if (m_UUIDCache.TryGetValue(uuid, out account)) if (m_UUIDCache.TryGetValue(uuid, out account))
{ {
inCache = true; inCache = true;
return account; return account;
} }
}
}
return null; return null;
} }
public void Remove(string name) public void Remove(string name)
{
lock(accessLock)
{ {
if (!m_NameCache.Contains(name)) if (!m_NameCache.Contains(name))
return; return;
@ -112,3 +125,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
} }
} }
} }
}