aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL')
-rw-r--r--OpenSim/Data/MySQL/MySQLAssetData.cs305
1 files changed, 144 insertions, 161 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs
index f03e322..5d8da17 100644
--- a/OpenSim/Data/MySQL/MySQLAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLAssetData.cs
@@ -45,7 +45,6 @@ namespace OpenSim.Data.MySQL
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 private string m_connectionString; 47 private string m_connectionString;
48 private object m_dbLock = new object();
49 48
50 protected virtual Assembly Assembly 49 protected virtual Assembly Assembly
51 { 50 {
@@ -107,47 +106,46 @@ namespace OpenSim.Data.MySQL
107 override public AssetBase GetAsset(UUID assetID) 106 override public AssetBase GetAsset(UUID assetID)
108 { 107 {
109 AssetBase asset = null; 108 AssetBase asset = null;
110 lock (m_dbLock) 109
110 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
111 { 111 {
112 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 112 dbcon.Open();
113
114 using (MySqlCommand cmd = new MySqlCommand(
115 "SELECT name, description, assetType, local, temporary, asset_flags, CreatorID, data FROM assets WHERE id=?id",
116 dbcon))
113 { 117 {
114 dbcon.Open(); 118 cmd.Parameters.AddWithValue("?id", assetID.ToString());
115 119
116 using (MySqlCommand cmd = new MySqlCommand( 120 try
117 "SELECT name, description, assetType, local, temporary, asset_flags, CreatorID, data FROM assets WHERE id=?id",
118 dbcon))
119 { 121 {
120 cmd.Parameters.AddWithValue("?id", assetID.ToString()); 122 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
121
122 try
123 { 123 {
124 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 124 if (dbReader.Read())
125 { 125 {
126 if (dbReader.Read()) 126 asset = new AssetBase(assetID, (string)dbReader["name"], (sbyte)dbReader["assetType"], dbReader["CreatorID"].ToString());
127 { 127 asset.Data = (byte[])dbReader["data"];
128 asset = new AssetBase(assetID, (string)dbReader["name"], (sbyte)dbReader["assetType"], dbReader["CreatorID"].ToString()); 128 asset.Description = (string)dbReader["description"];
129 asset.Data = (byte[])dbReader["data"]; 129
130 asset.Description = (string)dbReader["description"]; 130 string local = dbReader["local"].ToString();
131 131 if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase))
132 string local = dbReader["local"].ToString(); 132 asset.Local = true;
133 if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase)) 133 else
134 asset.Local = true; 134 asset.Local = false;
135 else 135
136 asset.Local = false; 136 asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
137 137 asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
138 asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
139 asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
140 }
141 } 138 }
142 } 139 }
143 catch (Exception e) 140 }
144 { 141 catch (Exception e)
145 m_log.Error( 142 {
146 string.Format("[ASSETS DB]: MySql failure fetching asset {0}. Exception ", assetID), e); 143 m_log.Error(
147 } 144 string.Format("[ASSETS DB]: MySql failure fetching asset {0}. Exception ", assetID), e);
148 } 145 }
149 } 146 }
150 } 147 }
148
151 return asset; 149 return asset;
152 } 150 }
153 151
@@ -158,100 +156,94 @@ namespace OpenSim.Data.MySQL
158 /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> 156 /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks>
159 override public void StoreAsset(AssetBase asset) 157 override public void StoreAsset(AssetBase asset)
160 { 158 {
161 lock (m_dbLock) 159 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
162 { 160 {
163 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 161 dbcon.Open();
162
163 using (MySqlCommand cmd =
164 new MySqlCommand(
165 "replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, asset_flags, CreatorID, data)" +
166 "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?CreatorID, ?data)",
167 dbcon))
164 { 168 {
165 dbcon.Open(); 169 string assetName = asset.Name;
170 if (asset.Name.Length > AssetBase.MAX_ASSET_NAME)
171 {
172 assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME);
173 m_log.WarnFormat(
174 "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add",
175 asset.Name, asset.ID, asset.Name.Length, assetName.Length);
176 }
166 177
167 using (MySqlCommand cmd = 178 string assetDescription = asset.Description;
168 new MySqlCommand( 179 if (asset.Description.Length > AssetBase.MAX_ASSET_DESC)
169 "replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, asset_flags, CreatorID, data)" +
170 "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?CreatorID, ?data)",
171 dbcon))
172 { 180 {
173 string assetName = asset.Name; 181 assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC);
174 if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) 182 m_log.WarnFormat(
175 { 183 "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add",
176 assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); 184 asset.Description, asset.ID, asset.Description.Length, assetDescription.Length);
177 m_log.WarnFormat( 185 }
178 "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", 186
179 asset.Name, asset.ID, asset.Name.Length, assetName.Length); 187 try
180 } 188 {
181 189 using (cmd)
182 string assetDescription = asset.Description;
183 if (asset.Description.Length > AssetBase.MAX_ASSET_DESC)
184 {
185 assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC);
186 m_log.WarnFormat(
187 "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add",
188 asset.Description, asset.ID, asset.Description.Length, assetDescription.Length);
189 }
190
191 try
192 {
193 using (cmd)
194 {
195 // create unix epoch time
196 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
197 cmd.Parameters.AddWithValue("?id", asset.ID);
198 cmd.Parameters.AddWithValue("?name", assetName);
199 cmd.Parameters.AddWithValue("?description", assetDescription);
200 cmd.Parameters.AddWithValue("?assetType", asset.Type);
201 cmd.Parameters.AddWithValue("?local", asset.Local);
202 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
203 cmd.Parameters.AddWithValue("?create_time", now);
204 cmd.Parameters.AddWithValue("?access_time", now);
205 cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID);
206 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
207 cmd.Parameters.AddWithValue("?data", asset.Data);
208 cmd.ExecuteNonQuery();
209 }
210 }
211 catch (Exception e)
212 { 190 {
213 m_log.Error( 191 // create unix epoch time
214 string.Format( 192 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
215 "[ASSET DB]: MySQL failure creating asset {0} with name {1}. Exception ", 193 cmd.Parameters.AddWithValue("?id", asset.ID);
216 asset.FullID, asset.Name) 194 cmd.Parameters.AddWithValue("?name", assetName);
217 , e); 195 cmd.Parameters.AddWithValue("?description", assetDescription);
196 cmd.Parameters.AddWithValue("?assetType", asset.Type);
197 cmd.Parameters.AddWithValue("?local", asset.Local);
198 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
199 cmd.Parameters.AddWithValue("?create_time", now);
200 cmd.Parameters.AddWithValue("?access_time", now);
201 cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID);
202 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
203 cmd.Parameters.AddWithValue("?data", asset.Data);
204 cmd.ExecuteNonQuery();
218 } 205 }
219 } 206 }
207 catch (Exception e)
208 {
209 m_log.Error(
210 string.Format(
211 "[ASSET DB]: MySQL failure creating asset {0} with name {1}. Exception ",
212 asset.FullID, asset.Name)
213 , e);
214 }
220 } 215 }
221 } 216 }
222 } 217 }
223 218
224 private void UpdateAccessTime(AssetBase asset) 219 private void UpdateAccessTime(AssetBase asset)
225 { 220 {
226 lock (m_dbLock) 221 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
227 { 222 {
228 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 223 dbcon.Open();
229 {
230 dbcon.Open();
231 224
232 using (MySqlCommand cmd 225 using (MySqlCommand cmd
233 = new MySqlCommand("update assets set access_time=?access_time where id=?id", dbcon)) 226 = new MySqlCommand("update assets set access_time=?access_time where id=?id", dbcon))
227 {
228 try
234 { 229 {
235 try 230 using (cmd)
236 {
237 using (cmd)
238 {
239 // create unix epoch time
240 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
241 cmd.Parameters.AddWithValue("?id", asset.ID);
242 cmd.Parameters.AddWithValue("?access_time", now);
243 cmd.ExecuteNonQuery();
244 }
245 }
246 catch (Exception e)
247 { 231 {
248 m_log.Error( 232 // create unix epoch time
249 string.Format( 233 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
250 "[ASSETS DB]: Failure updating access_time for asset {0} with name {1}. Exception ", 234 cmd.Parameters.AddWithValue("?id", asset.ID);
251 asset.FullID, asset.Name), 235 cmd.Parameters.AddWithValue("?access_time", now);
252 e); 236 cmd.ExecuteNonQuery();
253 } 237 }
254 } 238 }
239 catch (Exception e)
240 {
241 m_log.Error(
242 string.Format(
243 "[ASSETS DB]: Failure updating access_time for asset {0} with name {1}. Exception ",
244 asset.FullID, asset.Name),
245 e);
246 }
255 } 247 }
256 } 248 }
257 } 249 }
@@ -271,20 +263,17 @@ namespace OpenSim.Data.MySQL
271 string ids = "'" + string.Join("','", uuids) + "'"; 263 string ids = "'" + string.Join("','", uuids) + "'";
272 string sql = string.Format("SELECT id FROM assets WHERE id IN ({0})", ids); 264 string sql = string.Format("SELECT id FROM assets WHERE id IN ({0})", ids);
273 265
274 lock (m_dbLock) 266 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
275 { 267 {
276 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 268 dbcon.Open();
269 using (MySqlCommand cmd = new MySqlCommand(sql, dbcon))
277 { 270 {
278 dbcon.Open(); 271 using (MySqlDataReader dbReader = cmd.ExecuteReader())
279 using (MySqlCommand cmd = new MySqlCommand(sql, dbcon))
280 { 272 {
281 using (MySqlDataReader dbReader = cmd.ExecuteReader()) 273 while (dbReader.Read())
282 { 274 {
283 while (dbReader.Read()) 275 UUID id = DBGuid.FromDB(dbReader["id"]);
284 { 276 exist.Add(id);
285 UUID id = DBGuid.FromDB(dbReader["id"]);
286 exist.Add(id);
287 }
288 } 277 }
289 } 278 }
290 } 279 }
@@ -309,50 +298,47 @@ namespace OpenSim.Data.MySQL
309 { 298 {
310 List<AssetMetadata> retList = new List<AssetMetadata>(count); 299 List<AssetMetadata> retList = new List<AssetMetadata>(count);
311 300
312 lock (m_dbLock) 301 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
313 { 302 {
314 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 303 dbcon.Open();
304
305 using (MySqlCommand cmd
306 = new MySqlCommand(
307 "SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count",
308 dbcon))
315 { 309 {
316 dbcon.Open(); 310 cmd.Parameters.AddWithValue("?start", start);
311 cmd.Parameters.AddWithValue("?count", count);
317 312
318 using (MySqlCommand cmd 313 try
319 = new MySqlCommand(
320 "SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count",
321 dbcon))
322 { 314 {
323 cmd.Parameters.AddWithValue("?start", start); 315 using (MySqlDataReader dbReader = cmd.ExecuteReader())
324 cmd.Parameters.AddWithValue("?count", count);
325
326 try
327 { 316 {
328 using (MySqlDataReader dbReader = cmd.ExecuteReader()) 317 while (dbReader.Read())
329 { 318 {
330 while (dbReader.Read()) 319 AssetMetadata metadata = new AssetMetadata();
331 { 320 metadata.Name = (string)dbReader["name"];
332 AssetMetadata metadata = new AssetMetadata(); 321 metadata.Description = (string)dbReader["description"];
333 metadata.Name = (string)dbReader["name"]; 322 metadata.Type = (sbyte)dbReader["assetType"];
334 metadata.Description = (string)dbReader["description"]; 323 metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct.
335 metadata.Type = (sbyte)dbReader["assetType"]; 324 metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
336 metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct. 325 metadata.FullID = DBGuid.FromDB(dbReader["id"]);
337 metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); 326 metadata.CreatorID = dbReader["CreatorID"].ToString();
338 metadata.FullID = DBGuid.FromDB(dbReader["id"]); 327
339 metadata.CreatorID = dbReader["CreatorID"].ToString(); 328 // Current SHA1s are not stored/computed.
340 329 metadata.SHA1 = new byte[] { };
341 // Current SHA1s are not stored/computed. 330
342 metadata.SHA1 = new byte[] { }; 331 retList.Add(metadata);
343
344 retList.Add(metadata);
345 }
346 } 332 }
347 } 333 }
348 catch (Exception e) 334 }
349 { 335 catch (Exception e)
350 m_log.Error( 336 {
351 string.Format( 337 m_log.Error(
352 "[ASSETS DB]: MySql failure fetching asset set from {0}, count {1}. Exception ", 338 string.Format(
353 start, count), 339 "[ASSETS DB]: MySql failure fetching asset set from {0}, count {1}. Exception ",
354 e); 340 start, count),
355 } 341 e);
356 } 342 }
357 } 343 }
358 } 344 }
@@ -362,17 +348,14 @@ namespace OpenSim.Data.MySQL
362 348
363 public override bool Delete(string id) 349 public override bool Delete(string id)
364 { 350 {
365 lock (m_dbLock) 351 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
366 { 352 {
367 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 353 dbcon.Open();
368 {
369 dbcon.Open();
370 354
371 using (MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id", dbcon)) 355 using (MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id", dbcon))
372 { 356 {
373 cmd.Parameters.AddWithValue("?id", id); 357 cmd.Parameters.AddWithValue("?id", id);
374 cmd.ExecuteNonQuery(); 358 cmd.ExecuteNonQuery();
375 }
376 } 359 }
377 } 360 }
378 361