From 7ca8e28a9a518e5ff646676713a7be46ba172ca3 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 21 Jan 2008 15:12:00 +0000 Subject: Properly lock new separate database accesses --- OpenSim/Framework/Data.MySQL/MySQLDataStore.cs | 121 +++++++++++----------- OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs | 107 +++++++++---------- 2 files changed, 117 insertions(+), 111 deletions(-) diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs index 698569a..a752236 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs @@ -1203,72 +1203,75 @@ namespace OpenSim.Framework.Data.MySQL MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID); - // Find all existing inventory rows for this prim - DataTable dbItems = m_itemsTable; - - String sql = String.Format("primID = '{0}'", primID); - DataRow[] dbItemRows = dbItems.Select(sql); - - // Build structures for manipulation purposes - IDictionary dbItemsToRemove = new Dictionary(); - ICollection itemsToAdd = new List(); - - foreach (DataRow row in dbItemRows) - { -// MainLog.Instance.Verbose( -// "DATASTORE", -// "Found item {0}, {1} in prim id {2}", -// row["name"], row["itemID"], primID); + lock (m_dataSet) + { + // Find all existing inventory rows for this prim + DataTable dbItems = m_itemsTable; + + String sql = String.Format("primID = '{0}'", primID); + DataRow[] dbItemRows = dbItems.Select(sql); - 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) + // Build structures for manipulation purposes + IDictionary dbItemsToRemove = new Dictionary(); + ICollection itemsToAdd = new List(); + + foreach (DataRow row in dbItemRows) { - 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( -// "DATASTORE", -// "Discarding item {0}, {1} from remove candidates for prim id {2}", -// items[itemId].Name, rawItemId, primID); + String rawItemId = itemId.ToString(); - 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)) + { + // MainLog.Instance.Verbose( + // "DATASTORE", + // "Discarding item {0}, {1} from remove candidates for prim id {2}", + // items[itemId].Name, rawItemId, primID); + + dbItemsToRemove.Remove(rawItemId); + } + else + { + itemsToAdd.Add(items[itemId]); + } + } + } - row.Delete(); - } - - // Insert items not already present - foreach (TaskInventoryItem newItem in itemsToAdd) - { - MainLog.Instance.Verbose( - "DATASTORE", - "Adding item {0}, {1} to prim ID {2}", - newItem.Name, newItem.ItemID, newItem.ParentPartID); + // 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(); + } - DataRow newItemRow = dbItems.NewRow(); - fillItemRow(newItemRow, newItem); - dbItems.Rows.Add(newItemRow); + // Insert items not already present + foreach (TaskInventoryItem newItem in itemsToAdd) + { + 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); + } } } diff --git a/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs b/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs index 76848cf..ba50dca 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs @@ -1258,63 +1258,66 @@ namespace OpenSim.Framework.Data.SQLite MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID); - // Find all existing inventory rows for this prim - DataTable dbItems = ds.Tables["primitems"]; - - String sql = String.Format("primID = '{0}'", primID); - DataRow[] dbItemRows = dbItems.Select(sql); - - // Build structures for manipulation purposes - IDictionary dbItemsToRemove = new Dictionary(); - ICollection itemsToAdd - = new List(); - - foreach (DataRow row in dbItemRows) - { - 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) + lock (ds) { - foreach (LLUUID itemId in items.Keys) + // Find all existing inventory rows for this prim + DataTable dbItems = ds.Tables["primitems"]; + + String sql = String.Format("primID = '{0}'", primID); + DataRow[] dbItemRows = dbItems.Select(sql); + + // Build structures for manipulation purposes + IDictionary dbItemsToRemove = new Dictionary(); + ICollection itemsToAdd + = new List(); + + foreach (DataRow row in dbItemRows) { - String rawItemId = itemId.ToString(); - - if (dbItemsToRemove.ContainsKey(rawItemId)) - { - dbItemsToRemove.Remove(rawItemId); - } - else + 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) { - 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"]); + String rawItemId = itemId.ToString(); + + if (dbItemsToRemove.ContainsKey(rawItemId)) + { + dbItemsToRemove.Remove(rawItemId); + } + else + { + itemsToAdd.Add(items[itemId]); + } + } + } - row.Delete(); - } - - // Insert items not already present - foreach (TaskInventoryItem newItem in itemsToAdd) - { - MainLog.Instance.Verbose( - "DATASTORE", - "Adding item {0}, {1} to prim ID {2}", - newItem.Name, newItem.ItemID, newItem.ParentPartID); + // 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(); + } - DataRow newItemRow = dbItems.NewRow(); - fillItemRow(newItemRow, newItem); - dbItems.Rows.Add(newItemRow); + // Insert items not already present + foreach (TaskInventoryItem newItem in itemsToAdd) + { + 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); + } } } -- cgit v1.1