[sldev-commits] r84 - trunk/certified_http

which.linden at svn.secondlife.com which.linden at svn.secondlife.com
Tue Dec 4 16:51:30 PST 2007


Author: which.linden
Date: 2007-12-04 18:51:30 -0600 (Tue, 04 Dec 2007)
New Revision: 84

Modified:
   trunk/certified_http/mysql_persist.py
   trunk/certified_http/oplog.py
   trunk/certified_http/oplog_test.py
   trunk/certified_http/server_test.py
Trac: http://svn.secondlife.com/trac/certified_http/changeset/84
Log:
Tombstoning doesn't remove oplog parent any more, it just nukes the entries and sets a flag.  Also bit(1) -> tinyint because the MySQLdb interface to bit(1) blows.

Modified: trunk/certified_http/mysql_persist.py
===================================================================
--- trunk/certified_http/mysql_persist.py	2007-12-04 23:49:05 UTC (rev 83)
+++ trunk/certified_http/mysql_persist.py	2007-12-05 00:51:30 UTC (rev 84)
@@ -39,6 +39,7 @@
     'oplog-version': "select version from oplog where id = %s",
     'delete-oplog-parent': "delete from oplog where id = %s",
     'delete-oplog-entries':"delete from oplog_entries where id = %s",
+    'set-tombstoned': "update oplog set tombstoned = %s where id = %s",
     'count-oplogs-by-id':"select count(*) as count from oplog where id = %s",
     'last-index': "select last_entry from oplog where id = %s",
     'set-last-index': "update oplog set last_entry = %s where id = %s",
@@ -49,10 +50,11 @@
     'get-fullid': "select full_id from oplog where id = %s",
     'get-date': "select date from oplog where id = %s",
     'get-replays': "select unix_timestamp(replayed) as replayed, replays from oplog where id = %s",
+    'get-tombstoned': "select tombstoned from oplog where id = %s",
     'increment-replays': 'update oplog set replays = replays+1 , replayed = from_unixtime(%s) where id = %s',
     }
 
-_debug = 0
+_debug = False
 
 class BaseDBMgr(object):
     def __init__(self, auth, named_queries=None,debug=False):
@@ -121,18 +123,26 @@
         db = None
         try:
             db = self.connect()
-            rs = self.run(db, 'oplog-exists',[mid])
-            if len(rs) > 0:
-                self.run(db, 'delete-oplog-parent', [mid])
+            rs = self.run(db, 'get-tombstoned',[mid])
+            was_alive = len(rs) > 0 and (not rs[0].get('tombstoned', False))
+            if was_alive:
                 self.run(db, 'delete-oplog-entries', [mid])
+                self.run(db, 'set-tombstoned', [1, mid])
                 db.commit()
             else:
-                print "WARNING: message-id %s does not exist for tombstone-ing" % (mid,)
+                if len(rs) == 0:
+                    print "WARNING: id %s does not exist for tombstone-ing" % (mid)
         finally:
             if db: self.dbmgr.close(db)
 
-        return bool(len(rs) > 0)
+        # tombstone the in-memory copy
+        if op is None:
+            op = self._active_oplogs.get(mid)
+        if op:
+            op._persister._tombstoned = True
 
+        return was_alive
+
     def open_oplogs(self):
         db = None
         try:
@@ -147,7 +157,7 @@
         fullid = str(uuid.uuid4())
         date = httpdate.format_date_time(time.time())
         mid = fullid
-        storage = LogStorage(self.dbmgr, mid=mid, fullid=fullid, date=date, resumable=True)
+        storage = LogStorage(self.dbmgr, mid=mid, fullid=fullid, date=date,  resumable=True)
         _oplog = oplog.Oplog(storage, method, *args, **kwargs)
         self.register_oplog(_oplog)
         return _oplog
@@ -195,6 +205,7 @@
                 self._fullid = fullid
                 self._date = date
                 self._version = version
+                self._tombstoned = False
                 try:
                     self.run(db, 'create-oplog',[str(self._id), fullid, date, self._version, int(resumable), now, now])
                 except IntegrityError:
@@ -237,6 +248,8 @@
             self._created = self.run(db, 'get-created', [self._id])[0]['created']
             self._fullid = self.run(db, 'get-fullid', [self._id])[0]['full_id']
             self._date = self.run(db, 'get-date', [self._id])[0]['date']
+            ts = self.run(db, 'get-tombstoned', [self._id])
+            self._tombstoned = bool(ts[0]['tombstoned'])
             self.run(db, 'increment-replays', [time.time(), self._id])
             self._replayed,self._replays = self._replays_from_db(db)
             rs = self.run(db, 'oplog-version', [self._id])
@@ -302,7 +315,7 @@
                 rv = [pickle.loads(r['entry']) for r in rs]
             else:
                 rv = []
-            assert(len(rv) == self._num_stored)
+            assert(self._tombstoned or len(rv) == self._num_stored)
             return rv
         finally:
             if db: self._dbmgr.close(db)
@@ -325,6 +338,9 @@
     def version(self):
         return self._version
 
+    def tombstoned(self):
+        return self._tombstoned
+
 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)
@@ -345,10 +361,11 @@
   version int not null,
   id char(40) not null unique,
   last_entry int,
-  resumable bit(1) not null,
+  resumable tinyint not null,
   replays int not null default 0,
   replayed datetime not null,
   created datetime not null,
+  tombstoned tinyint not null default 0,
   primary key (id)
 ) Engine=InnoDB
     """)

Modified: trunk/certified_http/oplog.py
===================================================================
--- trunk/certified_http/oplog.py	2007-12-04 23:49:05 UTC (rev 83)
+++ trunk/certified_http/oplog.py	2007-12-05 00:51:30 UTC (rev 84)
@@ -378,9 +378,14 @@
         return self._persister.replays()
 
     def version(self):
+        """ Version number.  Represents the semantics of the code using the oplog.  If the code changes, the version should be as well."""
         return self._persister.version()
 
+    def tombstoned(self):
+        """ Returns true if the oplog has been tombstoned. """
+        return self._persister.tombstoned()
 
+
 def _test():
     import doctest
     doctest.testmod()

Modified: trunk/certified_http/oplog_test.py
===================================================================
--- trunk/certified_http/oplog_test.py	2007-12-04 23:49:05 UTC (rev 83)
+++ trunk/certified_http/oplog_test.py	2007-12-05 00:51:30 UTC (rev 84)
@@ -133,9 +133,15 @@
         c = self.persister.get_oplog(mid)
         initial = test_nondeterministic(c)
         self.assert_(self.persister.tombstone(c))
+        self.assert_(c.tombstoned())
+
+        # check that it's still the same after a refresh, and that the oplogs are 
         self.refresh_persister()
-        ops = self.persister.open_oplogs()
-        self.assertEqual(len(ops), 0)
+        c = self.persister.get_oplog(mid)
+        self.assert_(c.tombstoned())
+        self.assert_(not self.persister.tombstone(c))
+
+        # tombstoning something that doesn't exist should return false
         self.assert_(not self.persister.tombstone(mid="nonexistant"))
 
     def test_reset(self):

Modified: trunk/certified_http/server_test.py
===================================================================
--- trunk/certified_http/server_test.py	2007-12-04 23:49:05 UTC (rev 83)
+++ trunk/certified_http/server_test.py	2007-12-05 00:51:30 UTC (rev 84)
@@ -162,7 +162,7 @@
         # second should fail
         self.assertRaises(httpc.NotFound, httpc.delete, headers['x-message-url'])
         # make sure the oplog is gone
-        self.assert_(not self.persist.get_oplog(msgid)._still_restoring())
+        self.assert_(not self.persist.get_oplog(oplog.simple_sha1(msgid + date))._still_restoring())
 
     def test_message_id_haxxing(self):
         date = httpdate.format_date_time(time.time())



More information about the sldev-commits mailing list