Perform asset storage transactionally

xassetservice
Justin Clark-Casey (justincc) 2012-03-02 23:41:54 +00:00
parent 7113b44bdd
commit 94b323d1d8
1 changed files with 72 additions and 60 deletions

View File

@ -166,6 +166,9 @@ namespace OpenSim.Data.MySQL
{ {
dbcon.Open(); dbcon.Open();
using (MySqlTransaction transaction = dbcon.BeginTransaction())
{
string assetName = asset.Name; string assetName = asset.Name;
if (asset.Name.Length > 64) if (asset.Name.Length > 64)
{ {
@ -205,13 +208,16 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
cmd.Parameters.AddWithValue("?data", asset.Data); cmd.Parameters.AddWithValue("?data", asset.Data);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Dispose();
} }
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset metadata {0} with name \"{1}\". Error: {2}", m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset metadata {0} with name \"{1}\". Error: {2}",
asset.FullID, asset.Name, e.Message); asset.FullID, asset.Name, e.Message);
transaction.Rollback();
return;
} }
try try
@ -224,13 +230,19 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("?hash", hash); cmd.Parameters.AddWithValue("?hash", hash);
cmd.Parameters.AddWithValue("?data", asset.Data); cmd.Parameters.AddWithValue("?data", asset.Data);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Dispose();
} }
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}", m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}",
asset.FullID, asset.Name, e.Message); asset.FullID, asset.Name, e.Message);
transaction.Rollback();
return;
}
transaction.Commit();
} }
} }
} }