From aea5d3a84212a236fe1a766131b8e3513f3705a8 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 24 Sep 2013 13:41:44 -0700 Subject: [PATCH] Remove time based terrain storage in SQLite so revision number can be used to denote terrain format revision. Add terrain DB format revision codes to ISimulationDataStore.cs. Setup so legacy compatible terrain storage and fetch is possible while allowing future format extensions. --- OpenSim/Data/MSSQL/MSSQLSimulationData.cs | 2 +- OpenSim/Data/MySQL/MySQLSimulationData.cs | 7 ++++--- OpenSim/Data/SQLite/SQLiteSimulationData.cs | 14 ++----------- .../Interfaces/ISimulationDataStore.cs | 21 +++++++++++++++++++ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs index f41f60ccff..8adddc9c65 100644 --- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs +++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs @@ -576,7 +576,7 @@ ELSE /// regionID. public void StoreTerrain(double[,] terrain, UUID regionID) { - int revision = Util.UnixTimeSinceEpoch(); + int revision = (int)DBTerrainRevision.Legacy256; //Delete old terrain map string sql = "delete from terrain where RegionUUID=@RegionUUID"; diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index b03a9042ba..5751dc8a1c 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -575,6 +575,7 @@ namespace OpenSim.Data.MySQL public void StoreTerrain(double[,] ter, UUID regionID) { m_log.Info("[REGION DB]: Storing terrain"); + int revision = (int)DBTerrainRevision.Legacy256; lock (m_dbLock) { @@ -589,10 +590,10 @@ namespace OpenSim.Data.MySQL ExecuteNonQuery(cmd); - cmd.CommandText = "insert into terrain (RegionUUID, " + - "Revision, Heightfield) values (?RegionUUID, " + - "1, ?Heightfield)"; + cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)" + + "values (?RegionUUID, ?Revision, ?Heightfield)"; + cmd.Parameters.AddWithValue("Revision", revision); cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); ExecuteNonQuery(cmd); diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs index d938b6b03a..b70af6b3e7 100644 --- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs +++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs @@ -828,22 +828,12 @@ namespace OpenSim.Data.SQLite { lock (ds) { - int revision = Util.UnixTimeSinceEpoch(); - - // This is added to get rid of the infinitely growing - // terrain databases which negatively impact on SQLite - // over time. Before reenabling this feature there - // needs to be a limitter put on the number of - // revisions in the database, as this old - // implementation is a DOS attack waiting to happen. + int revision = (int)DBTerrainRevision.Legacy256; using ( - SqliteCommand cmd = - new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision", - m_conn)) + SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn)) { cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); - cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); cmd.ExecuteNonQuery(); } diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs index 3787ca0f36..c936a8478f 100644 --- a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs +++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs @@ -134,5 +134,26 @@ namespace OpenSim.Region.Framework.Interfaces Dictionary GetExtra(UUID regionID); void Shutdown(); + } + + // The terrain is stored as a blob in the database with a 'revision' field. + // Some implementations of terrain storage would fill the revision field with + // the time the terrain was stored. When real revisions were added and this + // feature removed, that left some old entries with the time in the revision + // field. + // Thus, if revision is greater than 'RevisionHigh' then terrain db entry is + // left over and it is presumed to be 'Legacy256'. + // Numbers are arbitrary and are chosen to to reduce possible mis-interpretation. + // If a revision does not match any of these, it is assumed to be Legacy256. + public enum DBTerrainRevision + { + // Terrain is 'double[256,256]' + Legacy256 = 11, + // Terrain is 'int32, int32, float[,]' where the shorts are X and Y dimensions + // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. + Variable2D = 22, + // A revision that is not listed above or any revision greater than this value is 'Legacy256'. + RevisionHigh = 1234 } + }