* Synchronize asset storage operations to mysql as well as reads

* This may help with asset server mysql problems, since both the previous osgrid failures occurred when both a read and write were attempted in the same second
ThreadPoolClientBranch
Justin Clarke Casey 2008-02-04 17:30:53 +00:00
parent cd658ea845
commit bde363b572
1 changed files with 36 additions and 32 deletions

View File

@ -76,6 +76,7 @@ namespace OpenSim.Framework.Data.MySQL
_dbConnection.Connection); _dbConnection.Connection);
MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16); MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
p.Value = assetID.GetBytes(); p.Value = assetID.GetBytes();
try try
{ {
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
@ -107,39 +108,42 @@ namespace OpenSim.Framework.Data.MySQL
} }
public void CreateAsset(AssetBase asset) public void CreateAsset(AssetBase asset)
{ {
MySqlCommand cmd = lock (_dbConnection)
new MySqlCommand(
"REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" +
"VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)",
_dbConnection.Connection);
// need to ensure we dispose
try
{
using (cmd)
{
MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
p.Value = asset.FullID.GetBytes();
cmd.Parameters.AddWithValue("?name", asset.Name);
cmd.Parameters.AddWithValue("?description", asset.Description);
cmd.Parameters.AddWithValue("?assetType", asset.Type);
cmd.Parameters.AddWithValue("?invType", asset.InvType);
cmd.Parameters.AddWithValue("?local", asset.Local);
cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
cmd.Parameters.AddWithValue("?data", asset.Data);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
}
catch (Exception e)
{ {
MainLog.Instance.Error( MySqlCommand cmd =
"ASSETS", new MySqlCommand(
"MySql failure creating asset {0} with name {1}" + Environment.NewLine + e.ToString() "REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" +
+ Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name); "VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)",
_dbConnection.Reconnect(); _dbConnection.Connection);
}
// need to ensure we dispose
try
{
using (cmd)
{
MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
p.Value = asset.FullID.GetBytes();
cmd.Parameters.AddWithValue("?name", asset.Name);
cmd.Parameters.AddWithValue("?description", asset.Description);
cmd.Parameters.AddWithValue("?assetType", asset.Type);
cmd.Parameters.AddWithValue("?invType", asset.InvType);
cmd.Parameters.AddWithValue("?local", asset.Local);
cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
cmd.Parameters.AddWithValue("?data", asset.Data);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
}
catch (Exception e)
{
MainLog.Instance.Error(
"ASSETS",
"MySql failure creating asset {0} with name {1}" + Environment.NewLine + e.ToString()
+ Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
_dbConnection.Reconnect();
}
}
} }
public void UpdateAsset(AssetBase asset) public void UpdateAsset(AssetBase asset)