aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs118
1 files changed, 101 insertions, 17 deletions
diff --git a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
index fdab254..2bfa597 100644
--- a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
@@ -30,6 +30,7 @@ using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO; 31using System.IO;
32using System.Reflection; 32using System.Reflection;
33using System.Timers;
33using Nini.Config; 34using Nini.Config;
34using OpenSim.Framework; 35using OpenSim.Framework;
35using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
@@ -47,7 +48,9 @@ namespace OpenSim.Services.Connectors
47 48
48 private string m_ServerURI = String.Empty; 49 private string m_ServerURI = String.Empty;
49 private IImprovedAssetCache m_Cache = null; 50 private IImprovedAssetCache m_Cache = null;
50 51 private int m_retryCounter;
52 private Dictionary<int, List<AssetBase>> m_retryQueue = new Dictionary<int, List<AssetBase>>();
53 private Timer m_retryTimer;
51 private delegate void AssetRetrievedEx(AssetBase asset); 54 private delegate void AssetRetrievedEx(AssetBase asset);
52 55
53 // Keeps track of concurrent requests for the same asset, so that it's only loaded once. 56 // Keeps track of concurrent requests for the same asset, so that it's only loaded once.
@@ -91,6 +94,55 @@ namespace OpenSim.Services.Connectors
91 MainConsole.Instance.Commands.AddCommand("asset", false, "dump asset", 94 MainConsole.Instance.Commands.AddCommand("asset", false, "dump asset",
92 "dump asset <id> <file>", 95 "dump asset <id> <file>",
93 "dump one cached asset", HandleDumpAsset); 96 "dump one cached asset", HandleDumpAsset);
97
98 m_retryTimer = new Timer();
99 m_retryTimer.Elapsed += new ElapsedEventHandler(retryCheck);
100 m_retryTimer.Interval = 60000;
101 }
102
103 protected void retryCheck(object source, ElapsedEventArgs e)
104 {
105 m_retryCounter++;
106 if (m_retryCounter > 60) m_retryCounter -= 60;
107 List<int> keys = new List<int>();
108 foreach (int a in m_retryQueue.Keys)
109 {
110 keys.Add(a);
111 }
112 foreach (int a in keys)
113 {
114 //We exponentially fall back on frequency until we reach one attempt per hour
115 //The net result is that we end up in the queue for roughly 24 hours..
116 //24 hours worth of assets could be a lot, so the hope is that the region admin
117 //will have gotten the asset connector back online quickly!
118
119 int timefactor = a ^ 2;
120 if (timefactor > 60)
121 {
122 timefactor = 60;
123 }
124
125 //First, find out if we care about this timefactor
126 if (timefactor % a == 0)
127 {
128 //Yes, we do!
129 List<AssetBase> retrylist = m_retryQueue[a];
130 m_retryQueue.Remove(a);
131
132 foreach(AssetBase ass in retrylist)
133 {
134 Store(ass); //Store my ass. This function will put it back in the dictionary if it fails
135 }
136 }
137 }
138
139 if (m_retryQueue.Count == 0)
140 {
141 //It might only be one tick per minute, but I have
142 //repented and abandoned my wasteful ways
143 m_retryCounter = 0;
144 m_retryTimer.Stop();
145 }
94 } 146 }
95 147
96 protected void SetCache(IImprovedAssetCache cache) 148 protected void SetCache(IImprovedAssetCache cache)
@@ -105,8 +157,8 @@ namespace OpenSim.Services.Connectors
105 AssetBase asset = null; 157 AssetBase asset = null;
106 if (m_Cache != null) 158 if (m_Cache != null)
107 asset = m_Cache.Get(id); 159 asset = m_Cache.Get(id);
108 160
109 if (asset == null) 161 if (asset == null || asset.Data == null || asset.Data.Length == 0)
110 { 162 {
111 asset = SynchronousRestObjectRequester. 163 asset = SynchronousRestObjectRequester.
112 MakeRequest<int, AssetBase>("GET", uri, 0); 164 MakeRequest<int, AssetBase>("GET", uri, 0);
@@ -183,7 +235,7 @@ namespace OpenSim.Services.Connectors
183 if (m_Cache != null) 235 if (m_Cache != null)
184 asset = m_Cache.Get(id); 236 asset = m_Cache.Get(id);
185 237
186 if (asset == null) 238 if (asset == null || asset.Data == null || asset.Data.Length == 0)
187 { 239 {
188 lock (m_AssetHandlers) 240 lock (m_AssetHandlers)
189 { 241 {
@@ -243,11 +295,10 @@ namespace OpenSim.Services.Connectors
243 295
244 public string Store(AssetBase asset) 296 public string Store(AssetBase asset)
245 { 297 {
298 if (m_Cache != null)
299 m_Cache.Cache(asset);
246 if (asset.Temporary || asset.Local) 300 if (asset.Temporary || asset.Local)
247 { 301 {
248 if (m_Cache != null)
249 m_Cache.Cache(asset);
250
251 return asset.ID; 302 return asset.ID;
252 } 303 }
253 304
@@ -257,24 +308,57 @@ namespace OpenSim.Services.Connectors
257 try 308 try
258 { 309 {
259 newID = SynchronousRestObjectRequester. 310 newID = SynchronousRestObjectRequester.
260 MakeRequest<AssetBase, string>("POST", uri, asset); 311 MakeRequest<AssetBase, string>("POST", uri, asset, 25);
312 if (newID == null || newID == "")
313 {
314 newID = UUID.Zero.ToString();
315 }
261 } 316 }
262 catch (Exception e) 317 catch (Exception e)
263 { 318 {
264 m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message); 319 newID = UUID.Zero.ToString();
265 } 320 }
266 321
267 if (newID != String.Empty) 322 if (newID == UUID.Zero.ToString())
323 {
324 //The asset upload failed, put it in a queue for later
325 asset.UploadAttempts++;
326 if (asset.UploadAttempts > 30)
327 {
328 //By this stage we've been in the queue for a good few hours;
329 //We're going to drop the asset.
330 m_log.ErrorFormat("[Assets] Dropping asset {0} - Upload has been in the queue for too long.", asset.ID.ToString());
331 }
332 else
333 {
334 if (!m_retryQueue.ContainsKey(asset.UploadAttempts))
335 {
336 m_retryQueue.Add(asset.UploadAttempts, new List<AssetBase>());
337 }
338 List<AssetBase> m_queue = m_retryQueue[asset.UploadAttempts];
339 m_queue.Add(asset);
340 m_log.WarnFormat("[Assets] Upload failed: {0} - Requeuing asset for another run.", asset.ID.ToString());
341 m_retryTimer.Start();
342 }
343 }
344 else
268 { 345 {
269 // Placing this here, so that this work with old asset servers that don't send any reply back 346 if (asset.UploadAttempts > 0)
270 // SynchronousRestObjectRequester returns somethins that is not an empty string 347 {
271 if (newID != null) 348 m_log.InfoFormat("[Assets] Upload of {0} succeeded after {1} failed attempts", asset.ID.ToString(), asset.UploadAttempts.ToString());
272 asset.ID = newID; 349 }
350 if (newID != String.Empty)
351 {
352 // Placing this here, so that this work with old asset servers that don't send any reply back
353 // SynchronousRestObjectRequester returns somethins that is not an empty string
354 if (newID != null)
355 asset.ID = newID;
273 356
274 if (m_Cache != null) 357 if (m_Cache != null)
275 m_Cache.Cache(asset); 358 m_Cache.Cache(asset);
359 }
276 } 360 }
277 return newID; 361 return asset.ID;
278 } 362 }
279 363
280 public bool UpdateContent(string id, byte[] data) 364 public bool UpdateContent(string id, byte[] data)