[sldev-commits] r50 - trunk/certified_http

which.linden at svn.secondlife.com which.linden at svn.secondlife.com
Thu Nov 15 09:07:11 PST 2007


Author: which.linden
Date: 2007-11-15 11:07:10 -0600 (Thu, 15 Nov 2007)
New Revision: 50

Modified:
   trunk/certified_http/file_persist.py
   trunk/certified_http/mysql_persist.py
   trunk/certified_http/oplog.py
   trunk/certified_http/persist_test.py
Trac: http://svn.secondlife.com/trac/certified_http/changeset/50
Log:
Added creation times to the oplogs and LogStorages.  This will be useful for expiration.

Modified: trunk/certified_http/file_persist.py
===================================================================
--- trunk/certified_http/file_persist.py	2007-11-15 00:25:45 UTC (rev 49)
+++ trunk/certified_http/file_persist.py	2007-11-15 17:07:10 UTC (rev 50)
@@ -17,11 +17,12 @@
 limitations under the License.
 """
 
-import traceback
+import oplog
 import os
 import pickle
+import time
+import traceback
 import uuid
-import oplog
 
 class Persistence(oplog.Persistence):
     def __init__(self, directory):
@@ -86,6 +87,7 @@
 
 class LogStorage(object):
     def __init__(self, directory, mid=None, restore = False):
+        self._created = time.time()
         self._stored = []
         self._last = None
         if restore:
@@ -130,7 +132,11 @@
         return len(self._stored)
 
     def reset(self):
+        # *NOTE: not quite a perfect approximation of creation time on UNIX
+        self._created = os.path.getctime(self._filename)
         fp = open(self._filename, "r")
         self._last, self._stored = pickle.load(fp)
         fp.close()
-        
+
+    def created(self):
+        return self._created

Modified: trunk/certified_http/mysql_persist.py
===================================================================
--- trunk/certified_http/mysql_persist.py	2007-11-15 00:25:45 UTC (rev 49)
+++ trunk/certified_http/mysql_persist.py	2007-11-15 17:07:10 UTC (rev 50)
@@ -23,6 +23,7 @@
 import uuid
 import oplog
 import MySQLdb
+import time
 from MySQLdb.cursors import DictCursor
 
 named_queries = {
@@ -37,7 +38,8 @@
     'set-last-index': "update lrt set last = %s where id = %s",
     'all-oplog-entries': "select entry from lrtlog where id = %s order by pos asc",
     'count-oplog-entries': "select count(entry) as count from lrtlog where id = %s",
-    'insert-oplog-entry': "insert into lrtlog(id, pos, entry) values (%s, %s, %s)"
+    'insert-oplog-entry': "insert into lrtlog(id, pos, entry) values (%s, %s, %s)",
+    'get-created': "select created from lrt where id = %s"
     }
 
 class DBMgr(object):
@@ -117,9 +119,6 @@
         db = dbmgr.connect()
         self._db = db
         self._dbmgr = dbmgr
-        def run(name,params):
-            return dbmgr.run(db,name,params)
-        self.run = run
         assert(mid or not restore)
         if mid is None:
             assert(not restore)
@@ -134,7 +133,11 @@
         else:
             self._id = mid
             self.reset()
+        self._created = self.run('get-created', [self._id])[0]['created']
 
+    def run(self,name,params):
+        return self._dbmgr.run(self._db,name,params)
+
     def __del__(self):
         if hasattr(self,'_db'):
             self._db.close()
@@ -195,6 +198,9 @@
     def length(self):
         return self._num_stored
 
+    def created(self):
+        return time.mktime(self._created.timetuple())
+
 def _teardown(host=None, user=None, passwd=None, db=None, verbose=False):
     assert(host and user and db and (passwd is not None))
     db = MySQLdb.connect(host=host,user=user,passwd=passwd,db=db)
@@ -213,6 +219,7 @@
     id varchar(128) not null unique,
     last int,
     resumable int not null,
+    created timestamp default current_timestamp,
     primary key (id)
 )
     """)

Modified: trunk/certified_http/oplog.py
===================================================================
--- trunk/certified_http/oplog.py	2007-11-15 00:25:45 UTC (rev 49)
+++ trunk/certified_http/oplog.py	2007-11-15 17:07:10 UTC (rev 50)
@@ -121,4 +121,8 @@
         if self._still_restoring():
             self._main = self._restore_next()
 
+    def created(self):
+        """ Returns the date (in seconds since epoch) of creation of this oplog."""
+        return self._persister.created()
 
+

Modified: trunk/certified_http/persist_test.py
===================================================================
--- trunk/certified_http/persist_test.py	2007-11-15 00:25:45 UTC (rev 49)
+++ trunk/certified_http/persist_test.py	2007-11-15 17:07:10 UTC (rev 50)
@@ -77,3 +77,11 @@
         del fp
         fp2 = self.restore(mid)
         assert_properties(fp2)
+
+    def test_created(self):
+        import time
+        tm = time.time()
+        fp = self.creater()
+        # same second == teh samez
+        self.assertEquals(int(tm), int(fp.created()))
+        



More information about the sldev-commits mailing list