c = self.conn.cursor()
c.execute("DELETE FROM nodes WHERE id NOT NULL")
for bucket in buckets:
- for node in bucket.l:
+ for node in bucket.nodes:
c.execute("INSERT INTO nodes VALUES (?, ?, ?)", (khash(node.id), node.host, node.port))
self.conn.commit()
c.execute("DELETE FROM kv WHERE last_refresh < ?", (t, ))
self.conn.commit()
+ def keyStats(self):
+ """Count the total number of keys and values in the database.
+ @rtype: (C{int}, C{int})
+ @return: the number of distinct keys and total values in the database
+ """
+ c = self.conn.cursor()
+ c.execute("SELECT COUNT(value) as num_values FROM kv")
+ values = 0
+ row = c.fetchone()
+ if row:
+ values = row[0]
+ c.execute("SELECT COUNT(key) as num_keys FROM (SELECT DISTINCT key FROM kv)")
+ keys = 0
+ row = c.fetchone()
+ if row:
+ keys = row[0]
+ return keys, values
+
class TestDB(unittest.TestCase):
"""Tests for the khashmir database."""
def test_Value(self):
self.store.storeValue(self.key, self.key)
+ self.failUnlessEqual(self.store.countValues(self.key), 1)
val = self.store.retrieveValues(self.key)
self.failUnlessEqual(len(val), 1)
self.failUnlessEqual(val[0], self.key)
dummy2.port = 12345
class bl:
def __init__(self):
- self.l = []
+ self.nodes = []
bl1 = bl()
- bl1.l.append(dummy())
+ bl1.nodes.append(dummy())
bl2 = bl()
- bl2.l.append(dummy2)
+ bl2.nodes.append(dummy2)
buckets = [bl1, bl2]
self.store.dumpRoutingTable(buckets)
rt = self.store.getRoutingTable()