diff options
author | Justin Clark-Casey (justincc) | 2013-03-15 23:17:54 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-03-15 23:17:54 +0000 |
commit | e9f3cd1a60bfc5e936d1029495ada2c2bff99430 (patch) | |
tree | 10e065b2eda5f37d9cae6248ef205130fb26bc73 /OpenSim/Data/MySQL | |
parent | refactor: Reuse Get() method in AssetService to eliminate some copy/paste in ... (diff) | |
download | opensim-SC-e9f3cd1a60bfc5e936d1029495ada2c2bff99430.zip opensim-SC-e9f3cd1a60bfc5e936d1029495ada2c2bff99430.tar.gz opensim-SC-e9f3cd1a60bfc5e936d1029495ada2c2bff99430.tar.bz2 opensim-SC-e9f3cd1a60bfc5e936d1029495ada2c2bff99430.tar.xz |
Implement access time updates on assets for XAssetService.
This only happens if access time is older than 30 days currently, in order to reduce database updates.
The idea is to give some idea of assets which haven't been accessed for a very, very long time.
These might conceivably be deleteable, though this will be a risk due to caching at other points in the chain.
This is actually currently much less useable on the xasset service since access time is on metadata rather than the data itself.
And many metadata entries may point to the same data. Probably need to address this.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLXAssetData.cs | 95 |
1 files changed, 57 insertions, 38 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs index c2282c8..273fbca 100644 --- a/OpenSim/Data/MySQL/MySQLXAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs | |||
@@ -50,6 +50,11 @@ namespace OpenSim.Data.MySQL | |||
50 | get { return GetType().Assembly; } | 50 | get { return GetType().Assembly; } |
51 | } | 51 | } |
52 | 52 | ||
53 | /// <summary> | ||
54 | /// Number of days that must pass before we update the access time on an asset when it has been fetched. | ||
55 | /// </summary> | ||
56 | private const int DaysBetweenAccessTimeUpdates = 30; | ||
57 | |||
53 | private bool m_enableCompression = false; | 58 | private bool m_enableCompression = false; |
54 | private string m_connectionString; | 59 | private string m_connectionString; |
55 | private object m_dbLock = new object(); | 60 | private object m_dbLock = new object(); |
@@ -133,7 +138,7 @@ namespace OpenSim.Data.MySQL | |||
133 | dbcon.Open(); | 138 | dbcon.Open(); |
134 | 139 | ||
135 | using (MySqlCommand cmd = new MySqlCommand( | 140 | using (MySqlCommand cmd = new MySqlCommand( |
136 | "SELECT name, description, asset_type, local, temporary, asset_flags, creator_id, data FROM xassetsmeta JOIN xassetsdata ON xassetsmeta.hash = xassetsdata.hash WHERE id=?id", | 141 | "SELECT name, description, access_time, asset_type, local, temporary, asset_flags, creator_id, data FROM xassetsmeta JOIN xassetsdata ON xassetsmeta.hash = xassetsdata.hash WHERE id=?id", |
137 | dbcon)) | 142 | dbcon)) |
138 | { | 143 | { |
139 | cmd.Parameters.AddWithValue("?id", assetID.ToString()); | 144 | cmd.Parameters.AddWithValue("?id", assetID.ToString()); |
@@ -171,12 +176,14 @@ namespace OpenSim.Data.MySQL | |||
171 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | 176 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); |
172 | } | 177 | } |
173 | } | 178 | } |
179 | |||
180 | UpdateAccessTime(asset.Metadata, (int)dbReader["access_time"]); | ||
174 | } | 181 | } |
175 | } | 182 | } |
176 | } | 183 | } |
177 | catch (Exception e) | 184 | catch (Exception e) |
178 | { | 185 | { |
179 | m_log.Error("[MYSQL XASSET DATA]: MySql failure fetching asset " + assetID + ": " + e.Message); | 186 | m_log.Error("[MYSQL XASSET DATA]: Failure fetching asset " + assetID + ": " + e.Message); |
180 | } | 187 | } |
181 | } | 188 | } |
182 | } | 189 | } |
@@ -303,41 +310,49 @@ namespace OpenSim.Data.MySQL | |||
303 | } | 310 | } |
304 | } | 311 | } |
305 | 312 | ||
306 | // private void UpdateAccessTime(AssetBase asset) | 313 | /// <summary> |
307 | // { | 314 | /// Updates the access time of the asset if it was accessed above a given threshhold amount of time. |
308 | // lock (m_dbLock) | 315 | /// </summary> |
309 | // { | 316 | /// <remarks> |
310 | // using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 317 | /// This gives us some insight into assets which haven't ben accessed for a long period. This is only done |
311 | // { | 318 | /// over the threshold time to avoid excessive database writes as assets are fetched. |
312 | // dbcon.Open(); | 319 | /// </remarks> |
313 | // MySqlCommand cmd = | 320 | /// <param name='asset'></param> |
314 | // new MySqlCommand("update assets set access_time=?access_time where id=?id", | 321 | /// <param name='accessTime'></param> |
315 | // dbcon); | 322 | private void UpdateAccessTime(AssetMetadata assetMetadata, int accessTime) |
316 | // | 323 | { |
317 | // // need to ensure we dispose | 324 | DateTime now = DateTime.UtcNow; |
318 | // try | 325 | |
319 | // { | 326 | if ((now - Utils.UnixTimeToDateTime(accessTime)).TotalDays < DaysBetweenAccessTimeUpdates) |
320 | // using (cmd) | 327 | return; |
321 | // { | 328 | |
322 | // // create unix epoch time | 329 | lock (m_dbLock) |
323 | // int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); | 330 | { |
324 | // cmd.Parameters.AddWithValue("?id", asset.ID); | 331 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
325 | // cmd.Parameters.AddWithValue("?access_time", now); | 332 | { |
326 | // cmd.ExecuteNonQuery(); | 333 | dbcon.Open(); |
327 | // cmd.Dispose(); | 334 | MySqlCommand cmd = |
328 | // } | 335 | new MySqlCommand("update assets set access_time=?access_time where id=?id", dbcon); |
329 | // } | 336 | |
330 | // catch (Exception e) | 337 | try |
331 | // { | 338 | { |
332 | // m_log.ErrorFormat( | 339 | using (cmd) |
333 | // "[ASSETS DB]: " + | 340 | { |
334 | // "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString() | 341 | // create unix epoch time |
335 | // + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name); | 342 | cmd.Parameters.AddWithValue("?id", assetMetadata.ID); |
336 | // } | 343 | cmd.Parameters.AddWithValue("?access_time", (int)Utils.DateTimeToUnixTime(now)); |
337 | // } | 344 | cmd.ExecuteNonQuery(); |
338 | // } | 345 | } |
339 | // | 346 | } |
340 | // } | 347 | catch (Exception e) |
348 | { | ||
349 | m_log.ErrorFormat( | ||
350 | "[XASSET MYSQL DB]: Failure updating access_time for asset {0} with name {1}", | ||
351 | assetMetadata.ID, assetMetadata.Name); | ||
352 | } | ||
353 | } | ||
354 | } | ||
355 | } | ||
341 | 356 | ||
342 | /// <summary> | 357 | /// <summary> |
343 | /// We assume we already have the m_dbLock. | 358 | /// We assume we already have the m_dbLock. |
@@ -422,6 +437,8 @@ namespace OpenSim.Data.MySQL | |||
422 | return assetExists; | 437 | return assetExists; |
423 | } | 438 | } |
424 | 439 | ||
440 | |||
441 | |||
425 | /// <summary> | 442 | /// <summary> |
426 | /// Returns a list of AssetMetadata objects. The list is a subset of | 443 | /// Returns a list of AssetMetadata objects. The list is a subset of |
427 | /// the entire data set offset by <paramref name="start" /> containing | 444 | /// the entire data set offset by <paramref name="start" /> containing |
@@ -439,7 +456,7 @@ namespace OpenSim.Data.MySQL | |||
439 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 456 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
440 | { | 457 | { |
441 | dbcon.Open(); | 458 | dbcon.Open(); |
442 | MySqlCommand cmd = new MySqlCommand("SELECT name,description,asset_type,temporary,id,asset_flags,creator_id FROM xassetsmeta LIMIT ?start, ?count", dbcon); | 459 | MySqlCommand cmd = new MySqlCommand("SELECT name,description,access_time,asset_type,temporary,id,asset_flags,creator_id FROM xassetsmeta LIMIT ?start, ?count", dbcon); |
443 | cmd.Parameters.AddWithValue("?start", start); | 460 | cmd.Parameters.AddWithValue("?start", start); |
444 | cmd.Parameters.AddWithValue("?count", count); | 461 | cmd.Parameters.AddWithValue("?count", count); |
445 | 462 | ||
@@ -461,6 +478,8 @@ namespace OpenSim.Data.MySQL | |||
461 | // We'll ignore this for now - it appears unused! | 478 | // We'll ignore this for now - it appears unused! |
462 | // metadata.SHA1 = dbReader["hash"]); | 479 | // metadata.SHA1 = dbReader["hash"]); |
463 | 480 | ||
481 | UpdateAccessTime(metadata, (int)dbReader["access_time"]); | ||
482 | |||
464 | retList.Add(metadata); | 483 | retList.Add(metadata); |
465 | } | 484 | } |
466 | } | 485 | } |