aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitMeshing
diff options
context:
space:
mode:
authorUbitUmarov2012-10-13 22:30:34 +0100
committerUbitUmarov2012-10-13 22:30:34 +0100
commit5986b4ee3980d27d6e8524c4b8f5ad4c9a701288 (patch)
treecf0f71097277f93aa3927301aa684672a45a36cc /OpenSim/Region/Physics/UbitMeshing
parent retouch mesh ids (diff)
downloadopensim-SC_OLD-5986b4ee3980d27d6e8524c4b8f5ad4c9a701288.zip
opensim-SC_OLD-5986b4ee3980d27d6e8524c4b8f5ad4c9a701288.tar.gz
opensim-SC_OLD-5986b4ee3980d27d6e8524c4b8f5ad4c9a701288.tar.bz2
opensim-SC_OLD-5986b4ee3980d27d6e8524c4b8f5ad4c9a701288.tar.xz
add mesh cache expire on region startup. Expires will be relative to
previus expire (assumed done only once at startup). File 'cntr' on cache folder stores time. Deleting it will force a skip on expire. Default time is 48hours before previus startup to account for failed ones etc.
Diffstat (limited to 'OpenSim/Region/Physics/UbitMeshing')
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs88
1 files changed, 85 insertions, 3 deletions
diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
index 35eabd4..6550b66 100644
--- a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
@@ -76,6 +76,8 @@ namespace OpenSim.Region.Physics.Meshing
76 public bool doMeshFileCache = true; 76 public bool doMeshFileCache = true;
77 77
78 public string cachePath = "MeshCache"; 78 public string cachePath = "MeshCache";
79 public TimeSpan CacheExpire;
80 public bool doCacheExpire = true;
79 81
80// const string baseDir = "rawFiles"; 82// const string baseDir = "rawFiles";
81 private const string baseDir = null; //"rawFiles"; 83 private const string baseDir = null; //"rawFiles";
@@ -92,17 +94,29 @@ namespace OpenSim.Region.Physics.Meshing
92 IConfig start_config = config.Configs["Startup"]; 94 IConfig start_config = config.Configs["Startup"];
93 IConfig mesh_config = config.Configs["Mesh"]; 95 IConfig mesh_config = config.Configs["Mesh"];
94 96
97
98 float fcache = 48.0f;
99// float fcache = 0.02f;
100
95 if(mesh_config != null) 101 if(mesh_config != null)
96 { 102 {
97 useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh); 103 useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh);
98 if(useMeshiesPhysicsMesh) 104 if (useMeshiesPhysicsMesh)
99 { 105 {
100 doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache); 106 doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache);
101 cachePath = mesh_config.GetString("MeshFileCachePath", cachePath); 107 cachePath = mesh_config.GetString("MeshFileCachePath", cachePath);
108 fcache = mesh_config.GetFloat("MeshFileCacheExpireHours", fcache);
109 doCacheExpire = mesh_config.GetBoolean("MeshFileCacheDoExpire", doCacheExpire);
102 } 110 }
103 else 111 else
112 {
104 doMeshFileCache = false; 113 doMeshFileCache = false;
114 doCacheExpire = false;
115 }
105 } 116 }
117
118 CacheExpire = TimeSpan.FromHours(fcache);
119
106 } 120 }
107 121
108 /// <summary> 122 /// <summary>
@@ -1273,6 +1287,7 @@ namespace OpenSim.Region.Physics.Meshing
1273 BinaryFormatter bformatter = new BinaryFormatter(); 1287 BinaryFormatter bformatter = new BinaryFormatter();
1274 1288
1275 mesh = Mesh.FromStream(stream, key); 1289 mesh = Mesh.FromStream(stream, key);
1290
1276 } 1291 }
1277 catch (Exception e) 1292 catch (Exception e)
1278 { 1293 {
@@ -1281,11 +1296,14 @@ namespace OpenSim.Region.Physics.Meshing
1281 "[MESH CACHE]: Failed to get file {0}. Exception {1} {2}", 1296 "[MESH CACHE]: Failed to get file {0}. Exception {1} {2}",
1282 filename, e.Message, e.StackTrace); 1297 filename, e.Message, e.StackTrace);
1283 } 1298 }
1299
1284 if (stream != null) 1300 if (stream != null)
1285 stream.Close(); 1301 stream.Close();
1286 1302
1287 if (mesh == null || !ok) 1303 if (mesh == null || !ok)
1288 File.Delete(filename); 1304 File.Delete(filename);
1305 else
1306 File.SetLastAccessTimeUtc(filename, DateTime.UtcNow);
1289 } 1307 }
1290 } 1308 }
1291 1309
@@ -1326,8 +1344,72 @@ namespace OpenSim.Region.Physics.Meshing
1326 if (stream != null) 1344 if (stream != null)
1327 stream.Close(); 1345 stream.Close();
1328 1346
1329 if (!ok && File.Exists(filename)) 1347 if (File.Exists(filename))
1330 File.Delete(filename); 1348 {
1349 if (ok)
1350 File.SetLastAccessTimeUtc(filename, DateTime.UtcNow);
1351 else
1352 File.Delete(filename);
1353 }
1354 }
1355 }
1356
1357 public void ExpireFileCache()
1358 {
1359 if (!doCacheExpire)
1360 return;
1361
1362 string controlfile = System.IO.Path.Combine(cachePath, "cntr");
1363
1364 lock (diskLock)
1365 {
1366 try
1367 {
1368 if (File.Exists(controlfile))
1369 {
1370 int ndeleted = 0;
1371 int totalfiles = 0;
1372 int ndirs = 0;
1373 DateTime OlderTime = File.GetLastAccessTimeUtc(controlfile) - CacheExpire;
1374 File.SetLastAccessTimeUtc(controlfile, DateTime.UtcNow);
1375
1376 foreach (string dir in Directory.GetDirectories(cachePath))
1377 {
1378 try
1379 {
1380 foreach (string file in Directory.GetFiles(dir))
1381 {
1382 try
1383 {
1384 if (File.GetLastAccessTimeUtc(file) < OlderTime)
1385 {
1386 File.Delete(file);
1387 ndeleted++;
1388 }
1389 }
1390 catch { }
1391 totalfiles++;
1392 }
1393 }
1394 catch { }
1395 ndirs++;
1396 }
1397
1398 if (ndeleted == 0)
1399 m_log.InfoFormat("[MESH CACHE]: {0} Files in {1} cache folders, no expires",
1400 totalfiles,ndirs);
1401 else
1402 m_log.InfoFormat("[MESH CACHE]: {0} Files in {1} cache folders, expired {2} files accessed before {3}",
1403 totalfiles,ndirs, ndeleted, OlderTime.ToString());
1404 }
1405 else
1406 {
1407 m_log.Info("[MESH CACHE]: Expire delayed to next startup");
1408 FileStream fs = File.Create(controlfile,4096,FileOptions.WriteThrough);
1409 fs.Close();
1410 }
1411 }
1412 catch { }
1331 } 1413 }
1332 } 1414 }
1333 } 1415 }