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,14 +154,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(userID, out inCache);
account = m_Cache.Get(userID, out inCache);
if (inCache)
return account;
account = UserAccountService.GetUserAccount(scopeID, userID);
lock(m_Cache)
m_Cache.Cache(userID, account);
m_Cache.Cache(userID, account);
return account;
}
@ -170,15 +168,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(firstName + " " + lastName, out inCache);
account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache)
return account;
account = UserAccountService.GetUserAccount(scopeID, firstName, lastName);
if (account != null)
lock(m_Cache)
m_Cache.Cache(account.PrincipalID, account);
m_Cache.Cache(account.PrincipalID, account);
return account;
}
@ -201,8 +197,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
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)
ret.Add(account);
else
@ -220,8 +215,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
foreach(UserAccount acc in ext)
{
if(acc != null)
lock(m_Cache)
m_Cache.Cache(acc.PrincipalID, acc);
m_Cache.Cache(acc.PrincipalID, acc);
}
}
return ret;

View File

@ -128,8 +128,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
// flags, title, etc. And country, don't forget country!
private void OnNewClient(IClientAPI client)
{
lock(m_Cache)
m_Cache.Remove(client.Name);
m_Cache.Remove(client.Name);
}
#region Overwritten methods from IUserAccountService
@ -138,17 +137,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(userID, out inCache);
account = m_Cache.Get(userID, out inCache);
if (inCache)
return account;
account = base.GetUserAccount(scopeID, userID);
if(account != null)
{
lock(m_Cache)
m_Cache.Cache(userID, account);
}
m_Cache.Cache(userID, account);
return account;
}
@ -156,17 +152,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(firstName + " " + lastName, out inCache);
account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache)
return account;
account = base.GetUserAccount(scopeID, firstName, lastName);
if (account != null)
{
lock(m_Cache)
m_Cache.Cache(account.PrincipalID, account);
}
m_Cache.Cache(account.PrincipalID, account);
return account;
}
@ -183,8 +176,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
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)
accs.Add(account);
else
@ -202,8 +194,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
if(acc != null)
{
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<string, UUID> m_NameCache;
private object accessLock = new object();
public UserAccountCache()
{
@ -54,60 +55,73 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
public void Cache(UUID userID, UserAccount account)
{
// Cache even null accounts
m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
if (account != null)
m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
lock(accessLock)
{
m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
if (account != null)
m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
//m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
}
}
public void Invalidate(UUID userID)
{
m_UUIDCache.Remove(userID);
lock(accessLock)
m_UUIDCache.Remove(userID);
}
public UserAccount Get(UUID userID, out bool inCache)
{
UserAccount account = null;
inCache = false;
if (m_UUIDCache.TryGetValue(userID, out account))
lock(accessLock)
{
//m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
inCache = true;
return account;
if (m_UUIDCache.TryGetValue(userID, out account))
{
//m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
inCache = true;
return account;
}
}
return null;
}
public UserAccount Get(string name, out bool inCache)
{
inCache = false;
if (!m_NameCache.Contains(name))
return null;
lock(accessLock)
{
if (!m_NameCache.Contains(name))
return null;
UserAccount account = null;
UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid))
if (m_UUIDCache.TryGetValue(uuid, out account))
UserAccount account = null;
UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid))
{
inCache = true;
return account;
if (m_UUIDCache.TryGetValue(uuid, out account))
{
inCache = true;
return account;
}
}
}
return null;
}
public void Remove(string name)
{
if (!m_NameCache.Contains(name))
return;
UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid))
lock(accessLock)
{
m_NameCache.Remove(name);
m_UUIDCache.Remove(uuid);
if (!m_NameCache.Contains(name))
return;
UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid))
{
m_NameCache.Remove(name);
m_UUIDCache.Remove(uuid);
}
}
}
}