aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-03 01:28:58 +0000
committerJustin Clark-Casey (justincc)2012-03-03 01:28:58 +0000
commit75dc8b1aedbd31f669c657ecc6beb6d8cbc9e037 (patch)
tree0a53797311c558c23465c6f5f0ec7a3dd2cdfe05 /OpenSim/Data
parentIf asset data already exists with the required hash then don't rewrite it (diff)
downloadopensim-SC-75dc8b1aedbd31f669c657ecc6beb6d8cbc9e037.zip
opensim-SC-75dc8b1aedbd31f669c657ecc6beb6d8cbc9e037.tar.gz
opensim-SC-75dc8b1aedbd31f669c657ecc6beb6d8cbc9e037.tar.bz2
opensim-SC-75dc8b1aedbd31f669c657ecc6beb6d8cbc9e037.tar.xz
Implement basic gzip compression for xassetdata
Whether this is worthwhile is debatable since here we are not transmitting data over a network In addition, jpeg2000 (the biggest data hog) is already a compressed image format. May not remain.
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/MySQL/MySQLXAssetData.cs51
1 files changed, 41 insertions, 10 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs
index 748578b..bb03871 100644
--- a/OpenSim/Data/MySQL/MySQLXAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs
@@ -26,9 +26,11 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Data; 30using System.Data;
31using System.IO;
32using System.IO.Compression;
30using System.Reflection; 33using System.Reflection;
31using System.Collections.Generic;
32using System.Text; 34using System.Text;
33using log4net; 35using log4net;
34using MySql.Data.MySqlClient; 36using MySql.Data.MySqlClient;
@@ -139,6 +141,18 @@ namespace OpenSim.Data.MySQL
139 141
140 asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); 142 asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
141 asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); 143 asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
144
145 using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress))
146 {
147 MemoryStream outputStream = new MemoryStream();
148 WebUtil.CopyTo(decompressionStream, outputStream, int.MaxValue);
149// int compressedLength = asset.Data.Length;
150 asset.Data = outputStream.ToArray();
151
152// m_log.DebugFormat(
153// "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}",
154// asset.ID, asset.Name, asset.Data.Length, compressedLength);
155 }
142 } 156 }
143 } 157 }
144 } 158 }
@@ -181,9 +195,24 @@ namespace OpenSim.Data.MySQL
181 assetDescription = asset.Description.Substring(0, 64); 195 assetDescription = asset.Description.Substring(0, 64);
182 m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add"); 196 m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
183 } 197 }
184 198
185 string hash = Util.SHA1Hash(asset.Data); 199 byte[] compressedData;
186 200 MemoryStream outputStream = new MemoryStream();
201
202 using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false))
203 {
204 Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue));
205 // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream.
206 compressionStream.Close();
207 compressedData = outputStream.ToArray();
208 }
209
210 string hash = Util.SHA1Hash(compressedData);
211
212// m_log.DebugFormat(
213// "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}",
214// asset.ID, asset.Name, hash, compressedData.Length);
215
187 try 216 try
188 { 217 {
189 using (MySqlCommand cmd = 218 using (MySqlCommand cmd =
@@ -205,7 +234,6 @@ namespace OpenSim.Data.MySQL
205 cmd.Parameters.AddWithValue("?access_time", now); 234 cmd.Parameters.AddWithValue("?access_time", now);
206 cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID); 235 cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID);
207 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); 236 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
208 cmd.Parameters.AddWithValue("?data", asset.Data);
209 cmd.ExecuteNonQuery(); 237 cmd.ExecuteNonQuery();
210 } 238 }
211 } 239 }
@@ -229,7 +257,7 @@ namespace OpenSim.Data.MySQL
229 dbcon)) 257 dbcon))
230 { 258 {
231 cmd.Parameters.AddWithValue("?hash", hash); 259 cmd.Parameters.AddWithValue("?hash", hash);
232 cmd.Parameters.AddWithValue("?data", asset.Data); 260 cmd.Parameters.AddWithValue("?data", compressedData);
233 cmd.ExecuteNonQuery(); 261 cmd.ExecuteNonQuery();
234 } 262 }
235 } 263 }
@@ -422,16 +450,19 @@ namespace OpenSim.Data.MySQL
422 450
423 public override bool Delete(string id) 451 public override bool Delete(string id)
424 { 452 {
453// m_log.DebugFormat("[XASSETS DB]: Deleting asset {0}", id);
454
425 lock (m_dbLock) 455 lock (m_dbLock)
426 { 456 {
427 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 457 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
428 { 458 {
429 dbcon.Open(); 459 dbcon.Open();
430 MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon);
431 cmd.Parameters.AddWithValue("?id", id);
432 cmd.ExecuteNonQuery();
433 460
434 cmd.Dispose(); 461 using (MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon))
462 {
463 cmd.Parameters.AddWithValue("?id", id);
464 cmd.ExecuteNonQuery();
465 }
435 466
436 // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we 467 // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we
437 // keep a reference count (?) 468 // keep a reference count (?)