aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLSimulationData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLSimulationData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs66
1 files changed, 39 insertions, 27 deletions
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index cc844ae..f910e44 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -48,8 +48,18 @@ namespace OpenSim.Data.MySQL
48 public class MySQLSimulationData : ISimulationDataStore 48 public class MySQLSimulationData : ISimulationDataStore
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[REGION DB MYSQL]";
51 52
52 private string m_connectionString; 53 private string m_connectionString;
54
55 /// <summary>
56 /// This lock was being used to serialize database operations when the connection was shared, but this has
57 /// been unnecessary for a long time after we switched to using MySQL's underlying connection pooling instead.
58 /// FIXME: However, the locks remain in many places since they are effectively providing a level of
59 /// transactionality. This should be replaced by more efficient database transactions which would not require
60 /// unrelated operations to block each other or unrelated operations on the same tables from blocking each
61 /// other.
62 /// </summary>
53 private object m_dbLock = new object(); 63 private object m_dbLock = new object();
54 64
55 protected virtual Assembly Assembly 65 protected virtual Assembly Assembly
@@ -91,7 +101,7 @@ namespace OpenSim.Data.MySQL
91 } 101 }
92 catch (Exception e) 102 catch (Exception e)
93 { 103 {
94 m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message); 104 m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e);
95 throw; 105 throw;
96 } 106 }
97 107
@@ -574,12 +584,16 @@ namespace OpenSim.Data.MySQL
574 } 584 }
575 } 585 }
576 586
577 public virtual void StoreTerrain(double[,] ter, UUID regionID) 587 // Legacy entry point for when terrain was always a 256x256 hieghtmap
588 public void StoreTerrain(double[,] ter, UUID regionID)
589 {
590 StoreTerrain(new HeightmapTerrainData(ter), regionID);
591 }
592
593 public void StoreTerrain(TerrainData terrData, UUID regionID)
578 { 594 {
579 Util.FireAndForget(delegate(object x) 595 Util.FireAndForget(delegate(object x)
580 { 596 {
581 double[,] oldTerrain = LoadTerrain(regionID);
582
583 m_log.Info("[REGION DB]: Storing terrain"); 597 m_log.Info("[REGION DB]: Storing terrain");
584 598
585 lock (m_dbLock) 599 lock (m_dbLock)
@@ -601,8 +615,12 @@ namespace OpenSim.Data.MySQL
601 "Revision, Heightfield) values (?RegionUUID, " + 615 "Revision, Heightfield) values (?RegionUUID, " +
602 "1, ?Heightfield)"; 616 "1, ?Heightfield)";
603 617
604 cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString()); 618 int terrainDBRevision;
605 cmd2.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter, oldTerrain)); 619 Array terrainDBblob;
620 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
621
622 cmd2.Parameters.AddWithValue("Revision", terrainDBRevision);
623 cmd2.Parameters.AddWithValue("Heightfield", terrainDBblob);
606 624
607 ExecuteNonQuery(cmd); 625 ExecuteNonQuery(cmd);
608 ExecuteNonQuery(cmd2); 626 ExecuteNonQuery(cmd2);
@@ -618,9 +636,20 @@ namespace OpenSim.Data.MySQL
618 }); 636 });
619 } 637 }
620 638
639 // Legacy region loading
621 public virtual double[,] LoadTerrain(UUID regionID) 640 public virtual double[,] LoadTerrain(UUID regionID)
622 { 641 {
623 double[,] terrain = null; 642 double[,] ret = null;
643 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
644 if (terrData != null)
645 ret = terrData.GetDoubles();
646 return ret;
647 }
648
649 // Returns 'null' if region not found
650 public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
651 {
652 TerrainData terrData = null;
624 653
625 lock (m_dbLock) 654 lock (m_dbLock)
626 { 655 {
@@ -640,32 +669,15 @@ namespace OpenSim.Data.MySQL
640 while (reader.Read()) 669 while (reader.Read())
641 { 670 {
642 int rev = Convert.ToInt32(reader["Revision"]); 671 int rev = Convert.ToInt32(reader["Revision"]);
643 672 byte[] blob = (byte[])reader["Heightfield"];
644 terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 673 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
645 terrain.Initialize();
646
647 using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
648 {
649 using (BinaryReader br = new BinaryReader(mstr))
650 {
651 for (int x = 0; x < (int)Constants.RegionSize; x++)
652 {
653 for (int y = 0; y < (int)Constants.RegionSize; y++)
654 {
655 terrain[x, y] = br.ReadDouble();
656 }
657 }
658 }
659
660 m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
661 }
662 } 674 }
663 } 675 }
664 } 676 }
665 } 677 }
666 } 678 }
667 679
668 return terrain; 680 return terrData;
669 } 681 }
670 682
671 public virtual void RemoveLandObject(UUID globalID) 683 public virtual void RemoveLandObject(UUID globalID)