add some locks around DataSet manipulation to ensure we are doing this

safely
afrisby
Sean Dague 2007-09-13 13:10:21 +00:00
parent 7a9f5ed6b3
commit 888133e987
1 changed files with 93 additions and 117 deletions

View File

@ -48,6 +48,7 @@ namespace OpenSim.DataStore.MonoSqlite
// primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema");
TestTables(conn); TestTables(conn);
lock(ds) {
ds.Tables.Add(createPrimTable()); ds.Tables.Add(createPrimTable());
setupPrimCommands(primDa, conn); setupPrimCommands(primDa, conn);
primDa.Fill(ds.Tables["prims"]); primDa.Fill(ds.Tables["prims"]);
@ -69,19 +70,19 @@ namespace OpenSim.DataStore.MonoSqlite
} }
return; return;
} }
}
public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID) public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID)
{ {
lock (ds) {
foreach (SceneObjectPart prim in obj.Children.Values) foreach (SceneObjectPart prim in obj.Children.Values)
{ {
MainLog.Instance.Verbose("DATASTORE", "Adding obj: " + obj.UUID + " to region: " + regionUUID); MainLog.Instance.Verbose("DATASTORE", "Adding obj: " + obj.UUID + " to region: " + regionUUID);
addPrim(prim, obj.UUID, regionUUID); addPrim(prim, obj.UUID, regionUUID);
} }
}
// MainLog.Instance.Verbose("Attempting to do database update...."); Commit();
primDa.Update(ds, "prims");
shapeDa.Update(ds, "primshapes");
ds.AcceptChanges();
// MainLog.Instance.Verbose("Dump of prims:", ds.GetXml()); // MainLog.Instance.Verbose("Dump of prims:", ds.GetXml());
} }
@ -91,6 +92,7 @@ namespace OpenSim.DataStore.MonoSqlite
DataTable shapes = ds.Tables["primshapes"]; DataTable shapes = ds.Tables["primshapes"];
string selectExp = "SceneGroupID = '" + obj.ToString() + "'"; string selectExp = "SceneGroupID = '" + obj.ToString() + "'";
lock (ds) {
DataRow[] primRows = prims.Select(selectExp); DataRow[] primRows = prims.Select(selectExp);
foreach (DataRow row in primRows) foreach (DataRow row in primRows)
{ {
@ -102,9 +104,9 @@ namespace OpenSim.DataStore.MonoSqlite
} }
row.Delete(); row.Delete();
} }
}
primDa.Update(ds, "prims"); Commit();
shapeDa.Update(ds, "primshapes");
} }
public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID)
@ -118,6 +120,8 @@ namespace OpenSim.DataStore.MonoSqlite
string byRegion = "RegionUUID = '" + regionUUID.ToString() + "'"; string byRegion = "RegionUUID = '" + regionUUID.ToString() + "'";
string orderByParent = "ParentID ASC"; string orderByParent = "ParentID ASC";
lock (ds) {
DataRow[] primsForRegion = prims.Select(byRegion, orderByParent); DataRow[] primsForRegion = prims.Select(byRegion, orderByParent);
MainLog.Instance.Verbose("DATASTORE", "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); MainLog.Instance.Verbose("DATASTORE", "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
@ -165,7 +169,6 @@ namespace OpenSim.DataStore.MonoSqlite
} }
catch (Exception e) catch (Exception e)
{ {
MainLog.Instance.Error("DATASTORE", "Failed create prim object, exception and data follows"); MainLog.Instance.Error("DATASTORE", "Failed create prim object, exception and data follows");
MainLog.Instance.Verbose(e.ToString()); MainLog.Instance.Verbose(e.ToString());
foreach (DataColumn col in prims.Columns) foreach (DataColumn col in prims.Columns)
@ -174,6 +177,7 @@ namespace OpenSim.DataStore.MonoSqlite
} }
} }
} }
}
return retvals; return retvals;
} }
@ -203,47 +207,19 @@ namespace OpenSim.DataStore.MonoSqlite
return new List<Land>(); return new List<Land>();
} }
public void Shutdown() public void Commit()
{ {
// TODO: DataSet commit lock (ds) {
primDa.Update(ds, "prims");
shapeDa.Update(ds, "primshapes");
ds.AcceptChanges();
}
} }
// public class TextureBlock public void Shutdown()
// { {
// public byte[] TextureData; Commit();
// public byte[] ExtraParams = new byte[1]; }
// public TextureBlock(byte[] data)
// {
// TextureData = data;
// }
// public TextureBlock()
// {
// }
// public string ToXMLString()
// {
// StringWriter sw = new StringWriter();
// XmlTextWriter writer = new XmlTextWriter(sw);
// XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock));
// serializer.Serialize(writer, this);
// return sw.ToString();
// }
// public static TextureBlock FromXmlString(string xmlData)
// {
// TextureBlock textureEntry = null;
// StringReader sr = new StringReader(xmlData);
// XmlTextReader reader = new XmlTextReader(sr);
// XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock));
// textureEntry = (TextureBlock)serializer.Deserialize(reader);
// reader.Close();
// sr.Close();
// return textureEntry;
// }
// }
/*********************************************************************** /***********************************************************************
* *