Move the key expiring to the checkpoint function.
authorCameron Dale <camrdale@gmail.com>
Fri, 22 Feb 2008 19:33:50 +0000 (11:33 -0800)
committerCameron Dale <camrdale@gmail.com>
Fri, 22 Feb 2008 19:33:50 +0000 (11:33 -0800)
apt-dht.conf
apt_dht/apt_dht_conf.py
apt_dht_Khashmir/DHT.py
apt_dht_Khashmir/actions.py
apt_dht_Khashmir/khashmir.py
debian/apt-dht.conf.sgml
test.py

index 7f42e4d..709a0d3 100644 (file)
@@ -82,14 +82,8 @@ MIN_PING_INTERVAL = 15m
 # refresh buckets that haven't been touched in this long
 BUCKET_STALENESS = 1h
 
-# time before expirer starts running
-KEINITIAL_DELAY = 15s
-
-# time between expirer runs
-KE_DELAY = 20m
-
-# expire entries older than this
-KE_AGE = 1h
+# expire unrefreshed entries older than this
+KEY_EXPIRE = 1h
 
 # whether to spew info about the requests/responses in the protocol
 SPEW = no
index 16f10c1..931d46c 100644 (file)
@@ -86,15 +86,8 @@ DHT_DEFAULTS = {
     # refresh buckets that haven't been touched in this long
     'BUCKET_STALENESS': '1h', # one hour
     
-    ###  KEY EXPIRER
-    # time before expirer starts running
-    'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db
-    
-    # time between expirer runs
-    'KE_DELAY': '20m', # 20 minutes
-    
     # expire entries older than this
-    'KE_AGE': '1h', # 60 minutes
+    'KEY_EXPIRE': '1h', # 60 minutes
     
     # whether to spew info about the requests/responses in the protocol
     'SPEW': 'yes',
index e62f304..ab206d2 100644 (file)
@@ -49,7 +49,7 @@ class DHT:
                      'MAX_FAILURES', 'PORT']:
                 self.config[k] = self.config_parser.getint(section, k)
             elif k in ['CHECKPOINT_INTERVAL', 'MIN_PING_INTERVAL', 
-                       'BUCKET_STALENESS', 'KEINITIAL_DELAY', 'KE_DELAY', 'KE_AGE']:
+                       'BUCKET_STALENESS', 'KEY_EXPIRE']:
                 self.config[k] = self.config_parser.gettime(section, k)
             elif k in ['SPEW']:
                 self.config[k] = self.config_parser.getboolean(section, k)
@@ -186,8 +186,7 @@ class TestSimpleDHT(unittest.TestCase):
                     'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
                     'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3,
                     'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
-                    'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200,
-                    'KE_AGE': 3600, 'SPEW': False, }
+                    'KEY_EXPIRE': 3600, 'SPEW': False, }
 
     def setUp(self):
         self.a = DHT()
@@ -279,8 +278,7 @@ class TestMultiDHT(unittest.TestCase):
                     'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
                     'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3,
                     'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
-                    'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200,
-                    'KE_AGE': 3600, 'SPEW': False, }
+                    'KEY_EXPIRE': 3600, 'SPEW': False, }
 
     def setUp(self):
         self.l = []
index 7822579..05349d4 100644 (file)
@@ -236,20 +236,3 @@ class StoreValue(ActionBase):
         self.nodes = nodes
         self.nodes.sort(self.sort)
         self.schedule()
-
-
-class KeyExpirer:
-    def __init__(self, store, config):
-        self.store = store
-        self.config = config
-        self.next_expire = reactor.callLater(self.config['KEINITIAL_DELAY'], self.doExpire)
-    
-    def doExpire(self):
-        self.store.expireValues(self.config['KE_AGE'])
-        self.next_expire = reactor.callLater(self.config['KE_DELAY'], self.doExpire)
-        
-    def shutdown(self):
-        try:
-            self.next_expire.cancel()
-        except:
-            pass
index d3479e6..a9a7867 100644 (file)
@@ -17,7 +17,7 @@ from db import DB
 from ktable import KTable
 from knode import KNodeBase, KNodeRead, KNodeWrite, NULL_ID
 from khash import newID, newIDInRange
-from actions import FindNode, GetValue, KeyExpirer, StoreValue
+from actions import FindNode, GetValue, StoreValue
 import krpc
 
 # this is the base class, has base functionality and find node, no key-value mappings
@@ -39,7 +39,6 @@ class KhashmirBase(protocol.Factory):
         self.udp.protocol = krpc.KRPC
         self.listenport = reactor.listenUDP(self.port, self.udp)
         self._loadRoutingTable()
-        self.expirer = KeyExpirer(self.store, config)
         self.refreshTable(force=1)
         self.next_checkpoint = reactor.callLater(60, self.checkpoint, (1,))
 
@@ -65,6 +64,7 @@ class KhashmirBase(protocol.Factory):
             self.token_secrets.pop()
         self.store.saveSelfNode(self.node.id)
         self.store.dumpRoutingTable(self.table.buckets)
+        self.store.expireValues(self.config['KEY_EXPIRE'])
         self.refreshTable()
         if auto:
             self.next_checkpoint = reactor.callLater(randrange(int(self.config['CHECKPOINT_INTERVAL'] * .9), 
@@ -196,7 +196,6 @@ class KhashmirBase(protocol.Factory):
             self.next_checkpoint.cancel()
         except:
             pass
-        self.expirer.shutdown()
         self.store.close()
 
     #### Remote Interface - called by remote nodes
@@ -301,8 +300,7 @@ class SimpleTests(unittest.TestCase):
                     'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
                     'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3,
                     'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
-                    'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200,
-                    'KE_AGE': 3600, 'SPEW': False, }
+                    'KEY_EXPIRE': 3600, 'SPEW': False, }
 
     def setUp(self):
         krpc.KRPC.noisy = 0
@@ -375,8 +373,7 @@ class MultiTest(unittest.TestCase):
                     'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
                     'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3,
                     'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
-                    'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200,
-                    'KE_AGE': 3600, 'SPEW': False, }
+                    'KEY_EXPIRE': 3600, 'SPEW': False, }
 
     def _done(self, val):
         self.done = 1
index 6b7762d..b481193 100644 (file)
            </listitem>
          </varlistentry>
          <varlistentry>
-           <term><option>KEINITIAL_DELAY = <replaceable>time</replaceable></option></term>
-            <listitem>
-             <para>The <replaceable>time</replaceable> to wait after startup before starting the key expirer.
-                 (Default is 15 seconds.)</para>
-           </listitem>
-         </varlistentry>
-         <varlistentry>
-           <term><option>KE_DELAY = <replaceable>time</replaceable></option></term>
-            <listitem>
-             <para>The <replaceable>time</replaceable> to wait between runs of the key expirer.
-                 (Default is 20 minutes.)</para>
-           </listitem>
-         </varlistentry>
-         <varlistentry>
-           <term><option>KE_AGE = <replaceable>time</replaceable></option></term>
+           <term><option>KEY_EXPIRE = <replaceable>time</replaceable></option></term>
             <listitem>
              <para>The <replaceable>time</replaceable> to wait before expiring unrefreshed keys.
                  (Default is 1 hour.)</para>
diff --git a/test.py b/test.py
index cfac85b..66f0fc6 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -376,14 +376,8 @@ MIN_PING_INTERVAL = 15m
 # refresh buckets that haven't been touched in this long
 BUCKET_STALENESS = 1h
 
-# time before expirer starts running
-KEINITIAL_DELAY = 15s
-
-# time between expirer runs
-KE_DELAY = 20m
-
 # expire entries older than this
-KE_AGE = 1h
+KEY_EXPIRE = 1h
 
 # whether to spew info about the requests/responses in the protocol
 SPEW = yes