Adds size limits to JsonStore. Adds a separate configuration
variable to enable binding to dynamic attributes.user_profiles
parent
2b5eba9c74
commit
e93defd0ca
|
@ -93,6 +93,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
// extract the internals of a has reference
|
// extract the internals of a has reference
|
||||||
protected static Regex m_HashPattern = new Regex("{([^}]+)}");
|
protected static Regex m_HashPattern = new Regex("{([^}]+)}");
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// This is a simple estimator for the size of the stored data, it
|
||||||
|
/// is not precise, but should be close enough to implement reasonable
|
||||||
|
/// limits on the storage space used
|
||||||
|
/// </summary>
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
public int StringSpace { get; set; }
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -110,6 +119,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
public JsonStore()
|
public JsonStore()
|
||||||
{
|
{
|
||||||
|
StringSpace = 0;
|
||||||
m_TakeStore = new List<TakeValueCallbackClass>();
|
m_TakeStore = new List<TakeValueCallbackClass>();
|
||||||
m_ReadStore = new List<TakeValueCallbackClass>();
|
m_ReadStore = new List<TakeValueCallbackClass>();
|
||||||
}
|
}
|
||||||
|
@ -247,6 +257,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
{
|
{
|
||||||
ValueStore = ovalue;
|
ValueStore = ovalue;
|
||||||
|
StringSpace = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,8 +289,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
{
|
{
|
||||||
string npkey = String.Format("[{0}]",amap.Count);
|
string npkey = String.Format("[{0}]",amap.Count);
|
||||||
|
|
||||||
|
if (ovalue != null)
|
||||||
|
{
|
||||||
|
StringSpace += ComputeSizeOf(ovalue);
|
||||||
|
|
||||||
amap.Add(ovalue);
|
amap.Add(ovalue);
|
||||||
InvokeNextCallback(pexpr + npkey);
|
InvokeNextCallback(pexpr + npkey);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,9 +303,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
if (0 <= aval && aval < amap.Count)
|
if (0 <= aval && aval < amap.Count)
|
||||||
{
|
{
|
||||||
if (ovalue == null)
|
if (ovalue == null)
|
||||||
|
{
|
||||||
|
StringSpace -= ComputeSizeOf(amap[aval]);
|
||||||
amap.RemoveAt(aval);
|
amap.RemoveAt(aval);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
StringSpace -= ComputeSizeOf(amap[aval]);
|
||||||
|
StringSpace += ComputeSizeOf(ovalue);
|
||||||
amap[aval] = ovalue;
|
amap[aval] = ovalue;
|
||||||
InvokeNextCallback(pexpr + pkey);
|
InvokeNextCallback(pexpr + pkey);
|
||||||
}
|
}
|
||||||
|
@ -313,6 +334,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
OSDMap hmap = result as OSDMap;
|
OSDMap hmap = result as OSDMap;
|
||||||
if (ovalue != null)
|
if (ovalue != null)
|
||||||
{
|
{
|
||||||
|
StringSpace -= ComputeSizeOf(hmap[hkey]);
|
||||||
|
StringSpace += ComputeSizeOf(ovalue);
|
||||||
|
|
||||||
hmap[hkey] = ovalue;
|
hmap[hkey] = ovalue;
|
||||||
InvokeNextCallback(pexpr + pkey);
|
InvokeNextCallback(pexpr + pkey);
|
||||||
return true;
|
return true;
|
||||||
|
@ -321,6 +345,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
// this is the remove case
|
// this is the remove case
|
||||||
if (hmap.ContainsKey(hkey))
|
if (hmap.ContainsKey(hkey))
|
||||||
{
|
{
|
||||||
|
StringSpace -= ComputeSizeOf(hmap[hkey]);
|
||||||
hmap.Remove(hkey);
|
hmap.Remove(hkey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -531,8 +556,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
|
|
||||||
return pkey;
|
return pkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
protected static int ComputeSizeOf(OSD value)
|
||||||
|
{
|
||||||
|
string sval;
|
||||||
|
|
||||||
|
if (ConvertOutputValue(value,out sval,true))
|
||||||
|
return sval.Length;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
// -----------------------------------------------------------------
|
||||||
public class JsonObjectStore : JsonStore
|
public class JsonObjectStore : JsonStore
|
||||||
{
|
{
|
||||||
private static readonly ILog m_log =
|
private static readonly ILog m_log =
|
||||||
|
@ -566,6 +610,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
{
|
{
|
||||||
m_scene = scene;
|
m_scene = scene;
|
||||||
m_objectID = oid;
|
m_objectID = oid;
|
||||||
|
|
||||||
|
// the size limit is imposed on whatever is already in the store
|
||||||
|
StringSpace = ComputeSizeOf(ValueStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
|
|
||||||
private IConfig m_config = null;
|
private IConfig m_config = null;
|
||||||
private bool m_enabled = false;
|
private bool m_enabled = false;
|
||||||
|
private bool m_enableObjectStore = false;
|
||||||
|
private int m_maxStringSpace = Int32.MaxValue;
|
||||||
|
|
||||||
private Scene m_scene = null;
|
private Scene m_scene = null;
|
||||||
|
|
||||||
private Dictionary<UUID,JsonStore> m_JsonValueStore;
|
private Dictionary<UUID,JsonStore> m_JsonValueStore;
|
||||||
|
@ -90,6 +93,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
}
|
}
|
||||||
|
|
||||||
m_enabled = m_config.GetBoolean("Enabled", m_enabled);
|
m_enabled = m_config.GetBoolean("Enabled", m_enabled);
|
||||||
|
m_enableObjectStore = m_config.GetBoolean("EnableObjectStore", m_enableObjectStore);
|
||||||
|
m_maxStringSpace = m_config.GetInt("MaxStringSpace", m_maxStringSpace);
|
||||||
|
if (m_maxStringSpace == 0)
|
||||||
|
m_maxStringSpace = Int32.MaxValue;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -178,6 +185,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
public bool AttachObjectStore(UUID objectID)
|
public bool AttachObjectStore(UUID objectID)
|
||||||
{
|
{
|
||||||
if (! m_enabled) return false;
|
if (! m_enabled) return false;
|
||||||
|
if (! m_enableObjectStore) return false;
|
||||||
|
|
||||||
SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID);
|
SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID);
|
||||||
if (sop == null)
|
if (sop == null)
|
||||||
|
@ -311,8 +319,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (map)
|
lock (map)
|
||||||
|
{
|
||||||
|
if (map.StringSpace > m_maxStringSpace)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit",
|
||||||
|
storeID,map.StringSpace,m_maxStringSpace);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return map.SetValue(path,value,useJson);
|
return map.SetValue(path,value,useJson);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e);
|
m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e);
|
||||||
|
|
|
@ -1652,6 +1652,10 @@
|
||||||
[JsonStore]
|
[JsonStore]
|
||||||
Enabled = False
|
Enabled = False
|
||||||
|
|
||||||
|
;; Enable direct access to the SOP dynamic attributes
|
||||||
|
EnableObjectStore = False
|
||||||
|
MaxStringSpace = 0
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; These are defaults that are overwritten below in [Architecture].
|
;; These are defaults that are overwritten below in [Architecture].
|
||||||
;; These defaults allow OpenSim to work out of the box with
|
;; These defaults allow OpenSim to work out of the box with
|
||||||
|
|
Loading…
Reference in New Issue