aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLInventoryData.cs
diff options
context:
space:
mode:
authorJohn Hurliman2009-11-02 11:19:55 -0800
committerJohn Hurliman2009-11-02 11:19:55 -0800
commit6309fcc5b4b42102b5bb901dbbdf44846f5643f2 (patch)
tree9f71f2801c6ed6eaa40fe637b0cda520a9e5894f /OpenSim/Data/MySQL/MySQLInventoryData.cs
parentFix an invalid argument exception in the remote admin module when. (diff)
downloadopensim-SC_OLD-6309fcc5b4b42102b5bb901dbbdf44846f5643f2.zip
opensim-SC_OLD-6309fcc5b4b42102b5bb901dbbdf44846f5643f2.tar.gz
opensim-SC_OLD-6309fcc5b4b42102b5bb901dbbdf44846f5643f2.tar.bz2
opensim-SC_OLD-6309fcc5b4b42102b5bb901dbbdf44846f5643f2.tar.xz
Reverting the memory leak patch for MySQL. Problems have been reported with the grid server after running for several hours
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLInventoryData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLInventoryData.cs335
1 files changed, 169 insertions, 166 deletions
diff --git a/OpenSim/Data/MySQL/MySQLInventoryData.cs b/OpenSim/Data/MySQL/MySQLInventoryData.cs
index 598971d..0eecf06 100644
--- a/OpenSim/Data/MySQL/MySQLInventoryData.cs
+++ b/OpenSim/Data/MySQL/MySQLInventoryData.cs
@@ -135,30 +135,30 @@ namespace OpenSim.Data.MySQL
135 135
136 database.CheckConnection(); 136 database.CheckConnection();
137 137
138 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", 138 MySqlCommand result =
139 database.Connection)) 139 new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
140 database.Connection);
141 result.Parameters.AddWithValue("?uuid", folderID.ToString());
142 MySqlDataReader reader = result.ExecuteReader();
143
144 while (reader.Read())
140 { 145 {
141 result.Parameters.AddWithValue("?uuid", folderID.ToString()); 146 // A null item (because something went wrong) breaks everything in the folder
147 InventoryItemBase item = readInventoryItem(reader);
148 if (item != null)
149 items.Add(item);
150 }
142 151
143 using (MySqlDataReader reader = result.ExecuteReader()) 152 reader.Close();
144 { 153 result.Dispose();
145 while (reader.Read())
146 {
147 // A null item (because something went wrong) breaks everything in the folder
148 InventoryItemBase item = readInventoryItem(reader);
149 if (item != null)
150 items.Add(item);
151 }
152 154
153 return items; 155 return items;
154 }
155 }
156 } 156 }
157 } 157 }
158 catch (Exception e) 158 catch (Exception e)
159 { 159 {
160 database.Reconnect(); 160 database.Reconnect();
161 m_log.Error(e.Message, e); 161 m_log.Error(e.ToString());
162 return null; 162 return null;
163 } 163 }
164 } 164 }
@@ -176,28 +176,29 @@ namespace OpenSim.Data.MySQL
176 { 176 {
177 database.CheckConnection(); 177 database.CheckConnection();
178 178
179 using (MySqlCommand result = new MySqlCommand( 179 MySqlCommand result =
180 "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", 180 new MySqlCommand(
181 database.Connection)) 181 "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
182 { 182 database.Connection);
183 result.Parameters.AddWithValue("?uuid", user.ToString()); 183 result.Parameters.AddWithValue("?uuid", user.ToString());
184 result.Parameters.AddWithValue("?zero", UUID.Zero.ToString()); 184 result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
185 MySqlDataReader reader = result.ExecuteReader();
185 186
186 using (MySqlDataReader reader = result.ExecuteReader()) 187 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
187 { 188 while (reader.Read())
188 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 189 items.Add(readInventoryFolder(reader));
189 while (reader.Read())
190 items.Add(readInventoryFolder(reader));
191 190
192 return items; 191
193 } 192 reader.Close();
194 } 193 result.Dispose();
194
195 return items;
195 } 196 }
196 } 197 }
197 catch (Exception e) 198 catch (Exception e)
198 { 199 {
199 database.Reconnect(); 200 database.Reconnect();
200 m_log.Error(e.Message, e); 201 m_log.Error(e.ToString());
201 return null; 202 return null;
202 } 203 }
203 } 204 }
@@ -216,38 +217,41 @@ namespace OpenSim.Data.MySQL
216 { 217 {
217 database.CheckConnection(); 218 database.CheckConnection();
218 219
219 using (MySqlCommand result = new MySqlCommand( 220 MySqlCommand result =
220 "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", 221 new MySqlCommand(
221 database.Connection)) 222 "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
222 { 223 database.Connection);
223 result.Parameters.AddWithValue("?uuid", user.ToString()); 224 result.Parameters.AddWithValue("?uuid", user.ToString());
224 result.Parameters.AddWithValue("?zero", UUID.Zero.ToString()); 225 result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
225 226
226 using (MySqlDataReader reader = result.ExecuteReader()) 227 MySqlDataReader reader = result.ExecuteReader();
227 {
228 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
229 while (reader.Read())
230 items.Add(readInventoryFolder(reader));
231 228
232 InventoryFolderBase rootFolder = null; 229 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
230 while (reader.Read())
231 items.Add(readInventoryFolder(reader));
233 232
234 // There should only ever be one root folder for a user. However, if there's more 233 InventoryFolderBase rootFolder = null;
235 // than one we'll simply use the first one rather than failing. It would be even
236 // nicer to print some message to this effect, but this feels like it's too low a
237 // to put such a message out, and it's too minor right now to spare the time to
238 // suitably refactor.
239 if (items.Count > 0)
240 rootFolder = items[0];
241 234
242 return rootFolder; 235 // There should only ever be one root folder for a user. However, if there's more
243 } 236 // than one we'll simply use the first one rather than failing. It would be even
237 // nicer to print some message to this effect, but this feels like it's too low a
238 // to put such a message out, and it's too minor right now to spare the time to
239 // suitably refactor.
240 if (items.Count > 0)
241 {
242 rootFolder = items[0];
244 } 243 }
244
245 reader.Close();
246 result.Dispose();
247
248 return rootFolder;
245 } 249 }
246 } 250 }
247 catch (Exception e) 251 catch (Exception e)
248 { 252 {
249 database.Reconnect(); 253 database.Reconnect();
250 m_log.Error(e.Message, e); 254 m_log.Error(e.ToString());
251 return null; 255 return null;
252 } 256 }
253 } 257 }
@@ -267,26 +271,27 @@ namespace OpenSim.Data.MySQL
267 { 271 {
268 database.CheckConnection(); 272 database.CheckConnection();
269 273
270 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", 274 MySqlCommand result =
271 database.Connection)) 275 new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
272 { 276 database.Connection);
273 result.Parameters.AddWithValue("?uuid", parentID.ToString()); 277 result.Parameters.AddWithValue("?uuid", parentID.ToString());
274 using (MySqlDataReader reader = result.ExecuteReader()) 278 MySqlDataReader reader = result.ExecuteReader();
275 {
276 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
277 279
278 while (reader.Read()) 280 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
279 items.Add(readInventoryFolder(reader));
280 281
281 return items; 282 while (reader.Read())
282 } 283 items.Add(readInventoryFolder(reader));
283 } 284
285 reader.Close();
286 result.Dispose();
287
288 return items;
284 } 289 }
285 } 290 }
286 catch (Exception e) 291 catch (Exception e)
287 { 292 {
288 database.Reconnect(); 293 database.Reconnect();
289 m_log.Error(e.Message, e); 294 m_log.Error(e.ToString());
290 return null; 295 return null;
291 } 296 }
292 } 297 }
@@ -365,25 +370,25 @@ namespace OpenSim.Data.MySQL
365 { 370 {
366 database.CheckConnection(); 371 database.CheckConnection();
367 372
368 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection)) 373 MySqlCommand result =
369 { 374 new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
370 result.Parameters.AddWithValue("?uuid", itemID.ToString()); 375 result.Parameters.AddWithValue("?uuid", itemID.ToString());
376 MySqlDataReader reader = result.ExecuteReader();
371 377
372 using (MySqlDataReader reader = result.ExecuteReader()) 378 InventoryItemBase item = null;
373 { 379 if (reader.Read())
374 InventoryItemBase item = null; 380 item = readInventoryItem(reader);
375 if (reader.Read())
376 item = readInventoryItem(reader);
377 381
378 return item; 382 reader.Close();
379 } 383 result.Dispose();
380 } 384
385 return item;
381 } 386 }
382 } 387 }
383 catch (Exception e) 388 catch (Exception e)
384 { 389 {
385 database.Reconnect(); 390 database.Reconnect();
386 m_log.Error(e.Message, e); 391 m_log.Error(e.ToString());
387 } 392 }
388 return null; 393 return null;
389 } 394 }
@@ -408,7 +413,7 @@ namespace OpenSim.Data.MySQL
408 } 413 }
409 catch (Exception e) 414 catch (Exception e)
410 { 415 {
411 m_log.Error(e.Message, e); 416 m_log.Error(e.ToString());
412 } 417 }
413 418
414 return null; 419 return null;
@@ -428,25 +433,24 @@ namespace OpenSim.Data.MySQL
428 { 433 {
429 database.CheckConnection(); 434 database.CheckConnection();
430 435
431 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection)) 436 MySqlCommand result =
432 { 437 new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
433 result.Parameters.AddWithValue("?uuid", folderID.ToString()); 438 result.Parameters.AddWithValue("?uuid", folderID.ToString());
439 MySqlDataReader reader = result.ExecuteReader();
434 440
435 using (MySqlDataReader reader = result.ExecuteReader()) 441 InventoryFolderBase folder = null;
436 { 442 if (reader.Read())
437 InventoryFolderBase folder = null; 443 folder = readInventoryFolder(reader);
438 if (reader.Read()) 444 reader.Close();
439 folder = readInventoryFolder(reader); 445 result.Dispose();
440 446
441 return folder; 447 return folder;
442 }
443 }
444 } 448 }
445 } 449 }
446 catch (Exception e) 450 catch (Exception e)
447 { 451 {
448 database.Reconnect(); 452 database.Reconnect();
449 m_log.Error(e.Message, e); 453 m_log.Error(e.ToString());
450 return null; 454 return null;
451 } 455 }
452 } 456 }
@@ -694,73 +698,69 @@ namespace OpenSim.Data.MySQL
694 try 698 try
695 { 699 {
696 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 700 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
697 Dictionary<UUID, List<InventoryFolderBase>> hashtable = new Dictionary<UUID, List<InventoryFolderBase>>(); ; 701 Dictionary<UUID, List<InventoryFolderBase>> hashtable
702 = new Dictionary<UUID, List<InventoryFolderBase>>(); ;
698 List<InventoryFolderBase> parentFolder = new List<InventoryFolderBase>(); 703 List<InventoryFolderBase> parentFolder = new List<InventoryFolderBase>();
699 bool buildResultsFromHashTable = false;
700
701 lock (database) 704 lock (database)
702 { 705 {
706 MySqlCommand result;
707 MySqlDataReader reader;
708 bool buildResultsFromHashTable = false;
709
703 database.CheckConnection(); 710 database.CheckConnection();
704 711
705 /* Fetch the parent folder from the database to determine the agent ID, and if 712 /* Fetch the parent folder from the database to determine the agent ID, and if
706 * we're querying the root of the inventory folder tree */ 713 * we're querying the root of the inventory folder tree */
707 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection)) 714 result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid",
708 { 715 database.Connection);
709 result.Parameters.AddWithValue("?uuid", parentID.ToString()); 716 result.Parameters.AddWithValue("?uuid", parentID.ToString());
710 717 reader = result.ExecuteReader();
711 using (MySqlDataReader reader = result.ExecuteReader()) 718 while (reader.Read()) // Should be at most 1 result
712 { 719 parentFolder.Add(readInventoryFolder(reader));
713 // Should be at most 1 result 720 reader.Close();
714 while (reader.Read()) 721 result.Dispose();
715 parentFolder.Add(readInventoryFolder(reader));
716 }
717 }
718 722
719 if (parentFolder.Count >= 1) // No result means parent folder does not exist 723 if (parentFolder.Count >= 1) // No result means parent folder does not exist
720 { 724 {
721 if (parentFolder[0].ParentID == UUID.Zero) // We are querying the root folder 725 if (parentFolder[0].ParentID == UUID.Zero) // We are querying the root folder
722 { 726 {
723 /* Get all of the agent's folders from the database, put them in a list and return it */ 727 /* Get all of the agent's folders from the database, put them in a list and return it */
724 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection)) 728 result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid",
729 database.Connection);
730 result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
731 reader = result.ExecuteReader();
732 while (reader.Read())
725 { 733 {
726 result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString()); 734 InventoryFolderBase curFolder = readInventoryFolder(reader);
727 735 if (curFolder.ID != parentID) // Do not need to add the root node of the tree to the list
728 using (MySqlDataReader reader = result.ExecuteReader()) 736 folders.Add(curFolder);
729 {
730 while (reader.Read())
731 {
732 InventoryFolderBase curFolder = readInventoryFolder(reader);
733 if (curFolder.ID != parentID) // Do not need to add the root node of the tree to the list
734 folders.Add(curFolder);
735 }
736 }
737 } 737 }
738 reader.Close();
739 result.Dispose();
738 } // if we are querying the root folder 740 } // if we are querying the root folder
739 else // else we are querying a subtree of the inventory folder tree 741 else // else we are querying a subtree of the inventory folder tree
740 { 742 {
741 /* Get all of the agent's folders from the database, put them all in a hash table 743 /* Get all of the agent's folders from the database, put them all in a hash table
742 * indexed by their parent ID */ 744 * indexed by their parent ID */
743 using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection)) 745 result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid",
746 database.Connection);
747 result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
748 reader = result.ExecuteReader();
749 while (reader.Read())
744 { 750 {
745 result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString()); 751 InventoryFolderBase curFolder = readInventoryFolder(reader);
746 752 if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling
747 using (MySqlDataReader reader = result.ExecuteReader()) 753 hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list
754 else // else current folder has no known (yet) siblings
748 { 755 {
749 while (reader.Read()) 756 List<InventoryFolderBase> siblingList = new List<InventoryFolderBase>();
750 { 757 siblingList.Add(curFolder);
751 InventoryFolderBase curFolder = readInventoryFolder(reader); 758 // Current folder has no known (yet) siblings
752 if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling 759 hashtable.Add(curFolder.ParentID, siblingList);
753 hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list
754 else // else current folder has no known (yet) siblings
755 {
756 List<InventoryFolderBase> siblingList = new List<InventoryFolderBase>();
757 siblingList.Add(curFolder);
758 // Current folder has no known (yet) siblings
759 hashtable.Add(curFolder.ParentID, siblingList);
760 }
761 } // while more items to read from the database
762 } 760 }
763 } 761 } // while more items to read from the database
762 reader.Close();
763 result.Dispose();
764 764
765 // Set flag so we know we need to build the results from the hash table after 765 // Set flag so we know we need to build the results from the hash table after
766 // we unlock the database 766 // we unlock the database
@@ -781,13 +781,12 @@ namespace OpenSim.Data.MySQL
781 folders.AddRange(hashtable[folders[i].ID]); 781 folders.AddRange(hashtable[folders[i].ID]);
782 } 782 }
783 } // lock (database) 783 } // lock (database)
784
785 return folders; 784 return folders;
786 } 785 }
787 catch (Exception e) 786 catch (Exception e)
788 { 787 {
789 database.Reconnect(); 788 database.Reconnect();
790 m_log.Error(e.Message, e); 789 m_log.Error(e.ToString());
791 return null; 790 return null;
792 } 791 }
793 } 792 }
@@ -802,18 +801,19 @@ namespace OpenSim.Data.MySQL
802 { 801 {
803 database.CheckConnection(); 802 database.CheckConnection();
804 803
805 using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection)) 804 MySqlCommand cmd =
806 { 805 new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
807 cmd.Parameters.AddWithValue("?uuid", folderID.ToString()); 806 cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
808 807
809 lock (database) 808 lock (database)
810 cmd.ExecuteNonQuery(); 809 {
810 cmd.ExecuteNonQuery();
811 } 811 }
812 } 812 }
813 catch (MySqlException e) 813 catch (MySqlException e)
814 { 814 {
815 database.Reconnect(); 815 database.Reconnect();
816 m_log.Error(e.Message, e); 816 m_log.Error(e.ToString());
817 } 817 }
818 } 818 }
819 819
@@ -827,12 +827,13 @@ namespace OpenSim.Data.MySQL
827 { 827 {
828 database.CheckConnection(); 828 database.CheckConnection();
829 829
830 using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection)) 830 MySqlCommand cmd =
831 { 831 new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
832 cmd.Parameters.AddWithValue("?uuid", folderID.ToString()); 832 cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
833 833
834 lock (database) 834 lock (database)
835 cmd.ExecuteNonQuery(); 835 {
836 cmd.ExecuteNonQuery();
836 } 837 }
837 } 838 }
838 catch (MySqlException e) 839 catch (MySqlException e)
@@ -864,38 +865,40 @@ namespace OpenSim.Data.MySQL
864 865
865 public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) 866 public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
866 { 867 {
868 MySqlDataReader result = null;
869 MySqlCommand sqlCmd = null;
867 lock (database) 870 lock (database)
868 { 871 {
869 try 872 try
870 { 873 {
871 database.CheckConnection(); 874 database.CheckConnection();
872 875 sqlCmd = new MySqlCommand(
873 using (MySqlCommand sqlCmd = new MySqlCommand(
874 "SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1", 876 "SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1",
875 database.Connection)) 877 database.Connection);
876 { 878 sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString());
877 sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString()); 879 sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture);
878 sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture); 880 result = sqlCmd.ExecuteReader();
879 881
880 using (MySqlDataReader result = sqlCmd.ExecuteReader()) 882 List<InventoryItemBase> list = new List<InventoryItemBase>();
881 { 883 while (result.Read())
882 List<InventoryItemBase> list = new List<InventoryItemBase>(); 884 {
883 while (result.Read()) 885 InventoryItemBase item = readInventoryItem(result);
884 { 886 if (item != null)
885 InventoryItemBase item = readInventoryItem(result); 887 list.Add(item);
886 if (item != null)
887 list.Add(item);
888 }
889 return list;
890 }
891 } 888 }
889 return list;
892 } 890 }
893 catch (Exception e) 891 catch (Exception e)
894 { 892 {
895 database.Reconnect(); 893 database.Reconnect();
896 m_log.Error(e.Message, e); 894 m_log.Error(e.ToString());
897 return null; 895 return null;
898 } 896 }
897 finally
898 {
899 if (result != null) result.Close();
900 if (sqlCmd != null) sqlCmd.Dispose();
901 }
899 } 902 }
900 } 903 }
901 } 904 }