Properly lock new separate database accesses

ThreadPoolClientBranch
Justin Clarke Casey 2008-01-21 15:12:00 +00:00
parent 504ae63669
commit 7ca8e28a9a
2 changed files with 118 additions and 112 deletions

View File

@ -1203,72 +1203,75 @@ namespace OpenSim.Framework.Data.MySQL
MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID); MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID);
// Find all existing inventory rows for this prim lock (m_dataSet)
DataTable dbItems = m_itemsTable; {
// Find all existing inventory rows for this prim
String sql = String.Format("primID = '{0}'", primID); DataTable dbItems = m_itemsTable;
DataRow[] dbItemRows = dbItems.Select(sql);
String sql = String.Format("primID = '{0}'", primID);
// Build structures for manipulation purposes DataRow[] dbItemRows = dbItems.Select(sql);
IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>();
ICollection<TaskInventoryItem> itemsToAdd = new List<TaskInventoryItem>();
foreach (DataRow row in dbItemRows)
{
// MainLog.Instance.Verbose(
// "DATASTORE",
// "Found item {0}, {1} in prim id {2}",
// row["name"], row["itemID"], primID);
dbItemsToRemove.Add((String)row["itemID"], row); // Build structures for manipulation purposes
} IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>();
ICollection<TaskInventoryItem> itemsToAdd = new List<TaskInventoryItem>();
// Eliminate rows from the deletion set which already exist for this prim's inventory
// TODO Very temporary, need to take account of simple metadata changes soon foreach (DataRow row in dbItemRows)
lock (items)
{
foreach (LLUUID itemId in items.Keys)
{ {
String rawItemId = itemId.ToString(); // MainLog.Instance.Verbose(
// "DATASTORE",
// "Found item {0}, {1} in prim id {2}",
// row["name"], row["itemID"], primID);
if (dbItemsToRemove.ContainsKey(rawItemId)) dbItemsToRemove.Add((String)row["itemID"], row);
}
// Eliminate rows from the deletion set which already exist for this prim's inventory
// TODO Very temporary, need to take account of simple metadata changes soon
lock (items)
{
foreach (LLUUID itemId in items.Keys)
{ {
// MainLog.Instance.Verbose( String rawItemId = itemId.ToString();
// "DATASTORE",
// "Discarding item {0}, {1} from remove candidates for prim id {2}",
// items[itemId].Name, rawItemId, primID);
dbItemsToRemove.Remove(rawItemId); if (dbItemsToRemove.ContainsKey(rawItemId))
} {
else // MainLog.Instance.Verbose(
{ // "DATASTORE",
itemsToAdd.Add(items[itemId]); // "Discarding item {0}, {1} from remove candidates for prim id {2}",
} // items[itemId].Name, rawItemId, primID);
}
} dbItemsToRemove.Remove(rawItemId);
}
// Delete excess rows else
foreach (DataRow row in dbItemsToRemove.Values) {
{ itemsToAdd.Add(items[itemId]);
MainLog.Instance.Verbose( }
"DATASTORE", }
"Removing item {0}, {1} from prim ID {2}", }
row["name"], row["itemID"], row["primID"]);
row.Delete(); // Delete excess rows
} foreach (DataRow row in dbItemsToRemove.Values)
{
// Insert items not already present MainLog.Instance.Verbose(
foreach (TaskInventoryItem newItem in itemsToAdd) "DATASTORE",
{ "Removing item {0}, {1} from prim ID {2}",
MainLog.Instance.Verbose( row["name"], row["itemID"], row["primID"]);
"DATASTORE",
"Adding item {0}, {1} to prim ID {2}", row.Delete();
newItem.Name, newItem.ItemID, newItem.ParentPartID); }
DataRow newItemRow = dbItems.NewRow(); // Insert items not already present
fillItemRow(newItemRow, newItem); foreach (TaskInventoryItem newItem in itemsToAdd)
dbItems.Rows.Add(newItemRow); {
MainLog.Instance.Verbose(
"DATASTORE",
"Adding item {0}, {1} to prim ID {2}",
newItem.Name, newItem.ItemID, newItem.ParentPartID);
DataRow newItemRow = dbItems.NewRow();
fillItemRow(newItemRow, newItem);
dbItems.Rows.Add(newItemRow);
}
} }
} }

View File

@ -1258,63 +1258,66 @@ namespace OpenSim.Framework.Data.SQLite
MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID); MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID);
// Find all existing inventory rows for this prim lock (ds)
DataTable dbItems = ds.Tables["primitems"];
String sql = String.Format("primID = '{0}'", primID);
DataRow[] dbItemRows = dbItems.Select(sql);
// Build structures for manipulation purposes
IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>();
ICollection<TaskInventoryItem> itemsToAdd
= new List<TaskInventoryItem>();
foreach (DataRow row in dbItemRows)
{ {
dbItemsToRemove.Add((String)row["itemID"], row); // Find all existing inventory rows for this prim
} DataTable dbItems = ds.Tables["primitems"];
// Eliminate rows from the deletion set which already exist for this prim's inventory String sql = String.Format("primID = '{0}'", primID);
// TODO Very temporary, need to take account of simple metadata changes soon DataRow[] dbItemRows = dbItems.Select(sql);
lock (items)
{ // Build structures for manipulation purposes
foreach (LLUUID itemId in items.Keys) IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>();
ICollection<TaskInventoryItem> itemsToAdd
= new List<TaskInventoryItem>();
foreach (DataRow row in dbItemRows)
{ {
String rawItemId = itemId.ToString(); dbItemsToRemove.Add((String)row["itemID"], row);
}
// Eliminate rows from the deletion set which already exist for this prim's inventory
// TODO Very temporary, need to take account of simple metadata changes soon
lock (items)
{
foreach (LLUUID itemId in items.Keys)
{
String rawItemId = itemId.ToString();
if (dbItemsToRemove.ContainsKey(rawItemId))
{
dbItemsToRemove.Remove(rawItemId);
}
else
{
itemsToAdd.Add(items[itemId]);
}
}
}
// Delete excess rows
foreach (DataRow row in dbItemsToRemove.Values)
{
MainLog.Instance.Verbose(
"DATASTORE",
"Removing item {0}, {1} from prim ID {2}",
row["name"], row["itemID"], row["primID"]);
if (dbItemsToRemove.ContainsKey(rawItemId)) row.Delete();
{ }
dbItemsToRemove.Remove(rawItemId);
}
else
{
itemsToAdd.Add(items[itemId]);
}
}
}
// Delete excess rows
foreach (DataRow row in dbItemsToRemove.Values)
{
MainLog.Instance.Verbose(
"DATASTORE",
"Removing item {0}, {1} from prim ID {2}",
row["name"], row["itemID"], row["primID"]);
row.Delete(); // Insert items not already present
} foreach (TaskInventoryItem newItem in itemsToAdd)
{
// Insert items not already present MainLog.Instance.Verbose(
foreach (TaskInventoryItem newItem in itemsToAdd) "DATASTORE",
{ "Adding item {0}, {1} to prim ID {2}",
MainLog.Instance.Verbose( newItem.Name, newItem.ItemID, newItem.ParentPartID);
"DATASTORE",
"Adding item {0}, {1} to prim ID {2}", DataRow newItemRow = dbItems.NewRow();
newItem.Name, newItem.ItemID, newItem.ParentPartID); fillItemRow(newItemRow, newItem);
dbItems.Rows.Add(newItemRow);
DataRow newItemRow = dbItems.NewRow(); }
fillItemRow(newItemRow, newItem);
dbItems.Rows.Add(newItemRow);
} }
} }