Adds size limits to JsonStore. Adds a separate configuration

variable to enable binding to dynamic attributes.
user_profiles
Mic Bowman 2013-02-08 15:07:43 -08:00
parent 2b5eba9c74
commit e93defd0ca
3 changed files with 70 additions and 2 deletions

View File

@ -93,6 +93,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// extract the internals of a has reference
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>
///
@ -110,6 +119,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// -----------------------------------------------------------------
public JsonStore()
{
StringSpace = 0;
m_TakeStore = new List<TakeValueCallbackClass>();
m_ReadStore = new List<TakeValueCallbackClass>();
}
@ -247,6 +257,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
if (path.Count == 0)
{
ValueStore = ovalue;
StringSpace = 0;
return true;
}
@ -278,8 +289,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
{
string npkey = String.Format("[{0}]",amap.Count);
amap.Add(ovalue);
InvokeNextCallback(pexpr + npkey);
if (ovalue != null)
{
StringSpace += ComputeSizeOf(ovalue);
amap.Add(ovalue);
InvokeNextCallback(pexpr + npkey);
}
return true;
}
@ -287,9 +303,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
if (0 <= aval && aval < amap.Count)
{
if (ovalue == null)
{
StringSpace -= ComputeSizeOf(amap[aval]);
amap.RemoveAt(aval);
}
else
{
StringSpace -= ComputeSizeOf(amap[aval]);
StringSpace += ComputeSizeOf(ovalue);
amap[aval] = ovalue;
InvokeNextCallback(pexpr + pkey);
}
@ -313,6 +334,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
OSDMap hmap = result as OSDMap;
if (ovalue != null)
{
StringSpace -= ComputeSizeOf(hmap[hkey]);
StringSpace += ComputeSizeOf(ovalue);
hmap[hkey] = ovalue;
InvokeNextCallback(pexpr + pkey);
return true;
@ -321,6 +345,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// this is the remove case
if (hmap.ContainsKey(hkey))
{
StringSpace -= ComputeSizeOf(hmap[hkey]);
hmap.Remove(hkey);
return true;
}
@ -531,8 +556,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
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
{
private static readonly ILog m_log =
@ -566,6 +610,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
{
m_scene = scene;
m_objectID = oid;
// the size limit is imposed on whatever is already in the store
StringSpace = ComputeSizeOf(ValueStore);
}
}

View File

@ -54,6 +54,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
private IConfig m_config = null;
private bool m_enabled = false;
private bool m_enableObjectStore = false;
private int m_maxStringSpace = Int32.MaxValue;
private Scene m_scene = null;
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_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)
{
@ -178,6 +185,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
public bool AttachObjectStore(UUID objectID)
{
if (! m_enabled) return false;
if (! m_enableObjectStore) return false;
SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID);
if (sop == null)
@ -311,7 +319,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
try
{
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);
}
}
catch (Exception e)
{

View File

@ -1652,6 +1652,10 @@
[JsonStore]
Enabled = False
;; Enable direct access to the SOP dynamic attributes
EnableObjectStore = False
MaxStringSpace = 0
;;
;; These are defaults that are overwritten below in [Architecture].
;; These defaults allow OpenSim to work out of the box with