let LocalGridServiceConnector also have a RegionInfoCache, use the remote one if this is active.

LSLKeyTest
UbitUmarov 2016-07-30 14:35:43 +01:00
parent 3c4d908cda
commit 79b7787eff
3 changed files with 83 additions and 94 deletions

View File

@ -52,6 +52,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
private IGridService m_GridService; private IGridService m_GridService;
private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>();
private RegionInfoCache m_RegionInfoCache = null;
private bool m_Enabled; private bool m_Enabled;
@ -60,10 +61,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
m_log.DebugFormat("{0} LocalGridServicesConnector no parms.", LogHeader); m_log.DebugFormat("{0} LocalGridServicesConnector no parms.", LogHeader);
} }
public LocalGridServicesConnector(IConfigSource source) public LocalGridServicesConnector(IConfigSource source, RegionInfoCache regionInfoCache)
{ {
m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader); m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader);
InitialiseService(source); InitialiseService(source, regionInfoCache);
} }
#region ISharedRegionModule #region ISharedRegionModule
@ -86,19 +87,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
string name = moduleConfig.GetString("GridServices", ""); string name = moduleConfig.GetString("GridServices", "");
if (name == Name) if (name == Name)
{ {
InitialiseService(source);
if(InitialiseService(source,null))
m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled"); m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled");
} }
} }
} }
private void InitialiseService(IConfigSource source) private bool InitialiseService(IConfigSource source, RegionInfoCache ric)
{ {
if(ric == null)
m_RegionInfoCache = new RegionInfoCache();
else
m_RegionInfoCache = ric;
IConfig config = source.Configs["GridService"]; IConfig config = source.Configs["GridService"];
if (config == null) if (config == null)
{ {
m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini"); m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini");
return; return false;
} }
string serviceDll = config.GetString("LocalServiceModule", String.Empty); string serviceDll = config.GetString("LocalServiceModule", String.Empty);
@ -106,7 +113,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
if (serviceDll == String.Empty) if (serviceDll == String.Empty)
{ {
m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService"); m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService");
return; return false;
} }
Object[] args = new Object[] { source }; Object[] args = new Object[] { source };
@ -117,10 +124,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
if (m_GridService == null) if (m_GridService == null)
{ {
m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service"); m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service");
return; return false;
} }
m_Enabled = true; m_Enabled = true;
return true;
} }
public void PostInitialise() public void PostInitialise()
@ -189,7 +197,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{ {
return m_GridService.GetRegionByUUID(scopeID, regionID); bool inCache = false;
GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionID,out inCache);
if (inCache)
return rinfo;
rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
if(rinfo != null)
m_RegionInfoCache.Cache(scopeID, rinfo);
return rinfo;
} }
// Get a region given its base coordinates. // Get a region given its base coordinates.
@ -197,52 +213,37 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
// be the base coordinate of the region. // be the base coordinate of the region.
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{ {
GridRegion region = null; // try in cache by handler first
uint regionX = Util.WorldToRegionLoc((uint)x); ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y);
uint regionY = Util.WorldToRegionLoc((uint)y);
// First see if it's a neighbour, even if it isn't on this sim. bool inCache = false;
// Neighbour data is cached in memory, so this is fast GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache);
if (inCache)
return rinfo;
lock (m_LocalCache) // try in cache by slower position next
{ rinfo = m_RegionInfoCache.Get(scopeID, x, y, out inCache);
foreach (RegionCache rcache in m_LocalCache.Values) if (inCache)
{ return rinfo;
region = rcache.GetRegionByPosition(x, y);
if (region != null)
{
//m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache (of region {2}). Pos=<{3},{4}>",
// LogHeader, region.RegionName, rcache.RegionName,
// Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
break;
}
}
}
// Then try on this sim (may be a lookup in DB if this is using MySql). // Then try on this sim (may be a lookup in DB if this is using MySql).
if (region == null) rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
{ if(rinfo != null)
region = m_GridService.GetRegionByPosition(scopeID, x, y); m_RegionInfoCache.Cache(scopeID, rinfo);
return rinfo;
if (region == null)
{
m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>",
LogHeader, regionX, regionY);
}
else
{
m_log.DebugFormat("{0} GetRegionByPosition. Got region {1} from grid service. Pos=<{2},{3}>",
LogHeader, region.RegionName,
Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
}
}
return region;
} }
public GridRegion GetRegionByName(UUID scopeID, string regionName) public GridRegion GetRegionByName(UUID scopeID, string regionName)
{ {
return m_GridService.GetRegionByName(scopeID, regionName); bool inCache = false;
GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionName, out inCache);
if (inCache)
return rinfo;
rinfo = m_GridService.GetRegionByName(scopeID, regionName);
if(rinfo != null)
m_RegionInfoCache.Cache(scopeID, rinfo);
return rinfo;
} }
public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)

View File

@ -87,38 +87,46 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
string name = moduleConfig.GetString("GridServices", ""); string name = moduleConfig.GetString("GridServices", "");
if (name == Name) if (name == Name)
{ {
InitialiseServices(source); if(InitialiseServices(source))
{
m_Enabled = true; m_Enabled = true;
m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled");
} }
} }
} }
}
private void InitialiseServices(IConfigSource source) private bool InitialiseServices(IConfigSource source)
{ {
IConfig gridConfig = source.Configs["GridService"]; IConfig gridConfig = source.Configs["GridService"];
if (gridConfig == null) if (gridConfig == null)
{ {
m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini"); m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini");
return; return false;
} }
string networkConnector = gridConfig.GetString("NetworkConnector", string.Empty); string networkConnector = gridConfig.GetString("NetworkConnector", string.Empty);
if (networkConnector == string.Empty) if (networkConnector == string.Empty)
{ {
m_log.Error("[REMOTE GRID CONNECTOR]: Please specify a network connector under [GridService]"); m_log.Error("[REMOTE GRID CONNECTOR]: Please specify a network connector under [GridService]");
return; return false;
} }
Object[] args = new Object[] { source }; Object[] args = new Object[] { source };
m_RemoteGridService = ServerUtils.LoadPlugin<IGridService>(networkConnector, args); m_RemoteGridService = ServerUtils.LoadPlugin<IGridService>(networkConnector, args);
m_LocalGridService = new LocalGridServicesConnector(source); m_LocalGridService = new LocalGridServicesConnector(source, m_RegionInfoCache);
if (m_LocalGridService == null)
{
m_log.Error("[REMOTE GRID CONNECTOR]: failed to loar local connector");
return false;
}
return true;
} }
public void PostInitialise() public void PostInitialise()
{ {
if (m_LocalGridService != null)
((ISharedRegionModule)m_LocalGridService).PostInitialise(); ((ISharedRegionModule)m_LocalGridService).PostInitialise();
} }
@ -131,13 +139,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
if (m_Enabled) if (m_Enabled)
scene.RegisterModuleInterface<IGridService>(this); scene.RegisterModuleInterface<IGridService>(this);
if (m_LocalGridService != null)
((ISharedRegionModule)m_LocalGridService).AddRegion(scene); ((ISharedRegionModule)m_LocalGridService).AddRegion(scene);
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
{ {
if (m_LocalGridService != null)
((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene); ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene);
} }
@ -174,15 +180,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{ {
bool inCache = false; GridRegion rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionID,out inCache); if (rinfo != null)
if (inCache)
return rinfo; return rinfo;
rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
if (rinfo == null)
rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID); rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID);
m_RegionInfoCache.Cache(scopeID, rinfo); m_RegionInfoCache.Cache(scopeID, rinfo);
return rinfo; return rinfo;
} }
@ -193,25 +195,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
// The coordinates are world coords (meters), NOT region units. // The coordinates are world coords (meters), NOT region units.
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{ {
// try in cache by handler first GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y);
ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y); if (rinfo != null)
{
bool inCache = false; m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache from local. Pos=<{1},{2}>, RegionHandle={3}",
GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache); rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, rinfo.RegionHandle);
if (inCache)
return rinfo; return rinfo;
}
// try in cache by slower position next
rinfo = m_RegionInfoCache.Get(scopeID, x, y, out inCache);
if (inCache)
return rinfo;
rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y);
if (rinfo == null)
rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y);
if (rinfo == null) if (rinfo == null)
{ {
uint regionX = Util.WorldToRegionLoc((uint)x); uint regionX = Util.WorldToRegionLoc((uint)x);
@ -223,23 +216,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
m_RegionInfoCache.Cache(scopeID, rinfo); m_RegionInfoCache.Cache(scopeID, rinfo);
m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}",
rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, rinfo.RegionHandle);
} }
return rinfo; return rinfo;
} }
public GridRegion GetRegionByName(UUID scopeID, string regionName) public GridRegion GetRegionByName(UUID scopeID, string regionName)
{ {
bool inCache = false; GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionName, out inCache); if (rinfo != null)
if (inCache)
return rinfo; return rinfo;
rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
if (rinfo == null)
rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName); rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName);
// can't cache negative results for name lookups
m_RegionInfoCache.Cache(scopeID, rinfo); m_RegionInfoCache.Cache(scopeID, rinfo);
return rinfo; return rinfo;
} }

View File

@ -64,7 +64,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
config.Configs["GridService"].Set("Region_Test_Region_3", "FallbackRegion"); config.Configs["GridService"].Set("Region_Test_Region_3", "FallbackRegion");
config.Configs["GridService"].Set("Region_Other_Region_4", "FallbackRegion"); config.Configs["GridService"].Set("Region_Other_Region_4", "FallbackRegion");
m_LocalConnector = new LocalGridServicesConnector(config); m_LocalConnector = new LocalGridServicesConnector(config, null);
} }
/// <summary> /// <summary>