summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-04-01 11:06:50 -0400
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-04-01 11:06:50 -0400
commit43bcf032e6989430463907cc5cabeb6fcdb21648 (patch)
tree38e57b40e4becff60fc3707f4fe219754bc7fac6
parentc26b623447e14b81f42136b79ad88b1c9b24e207 (diff)
Now combox.silo.ComboxSilo reloads db from disk before reading/writing.
modified: combox/events.py modified: combox/silo.py
-rw-r--r--combox/events.py24
-rw-r--r--combox/silo.py19
2 files changed, 13 insertions, 30 deletions
diff --git a/combox/events.py b/combox/events.py
index 3ef4386..91be1a4 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -54,13 +54,6 @@ class ComboxDirMonitor(LoggingEventHandler):
self.housekeep()
- def silo_update(self):
- """
- Re-reads the silo from disk.
- """
- self.silo.reload()
-
-
def housekeep(self):
"""Recursively traverses combox directory, discovers changes and updates silo and node directories.
@@ -76,7 +69,6 @@ class ComboxDirMonitor(LoggingEventHandler):
updated and the file's shards are updated.
"""
- self.silo_update()
print "combox is housekeeping."
print "Please don't make any changes to combox directory now."
print "Thanks for your patience."
@@ -119,7 +111,6 @@ class ComboxDirMonitor(LoggingEventHandler):
def on_moved(self, event):
super(ComboxDirMonitor, self).on_moved(event)
- self.silo_update()
if event.is_directory:
# creates a corresponding directory at the node dirs.
@@ -134,7 +125,6 @@ class ComboxDirMonitor(LoggingEventHandler):
def on_created(self, event):
super(ComboxDirMonitor, self).on_created(event)
- self.silo_update()
file_node_path = node_path(event.src_path, self.config,
not event.is_directory)
@@ -152,7 +142,6 @@ class ComboxDirMonitor(LoggingEventHandler):
def on_deleted(self, event):
super(ComboxDirMonitor, self).on_deleted(event)
- self.silo_update()
file_node_path = node_path(event.src_path, self.config,
not event.is_directory)
@@ -170,7 +159,6 @@ class ComboxDirMonitor(LoggingEventHandler):
def on_modified(self, event):
super(ComboxDirMonitor, self).on_modified(event)
- self.silo_update()
if event.is_directory:
# do nothing
@@ -201,13 +189,6 @@ class NodeDirMonitor(LoggingEventHandler):
self.silo = ComboxSilo(self.config, dblock)
- def silo_update(self):
- """
- Re-reads the silo from disk.
- """
- self.silo.reload()
-
-
def shardp(self, path):
"""Returns True if `path' is a shard
@@ -234,7 +215,6 @@ class NodeDirMonitor(LoggingEventHandler):
location in the combox directory.
"""
- self.silo_update()
print "combox node monitor is housekeeping."
print "Please don't make any changes to combox directory now."
@@ -289,7 +269,6 @@ class NodeDirMonitor(LoggingEventHandler):
def on_moved(self, event):
super(NodeDirMonitor, self).on_moved(event)
- self.silo_update()
src_cb_path = cb_path(event.src_path, self.config)
dest_cb_path = cb_path(event.dest_path, self.config)
@@ -309,7 +288,6 @@ class NodeDirMonitor(LoggingEventHandler):
def on_created(self, event):
super(NodeDirMonitor, self).on_created(event)
- self.silo_update()
if not self.shardp(event.src_path) and not event.is_directory:
# the file created can be ignored as it is not a shard or
@@ -336,7 +314,6 @@ class NodeDirMonitor(LoggingEventHandler):
def on_deleted(self, event):
super(NodeDirMonitor, self).on_deleted(event)
- self.silo_update()
if not self.shardp(event.src_path) and not event.is_directory:
# the file created can be ignored as it is not a shard or
@@ -357,7 +334,6 @@ class NodeDirMonitor(LoggingEventHandler):
def on_modified(self, event):
super(NodeDirMonitor, self).on_modified(event)
- self.silo_update()
if not self.shardp(event.src_path) and not event.is_directory:
# the file created can be ignored as it is not a shard or
diff --git a/combox/silo.py b/combox/silo.py
index f391d2e..a6abce5 100644
--- a/combox/silo.py
+++ b/combox/silo.py
@@ -65,6 +65,7 @@ class ComboxSilo(object):
filep: path to the file in combox directory.
"""
+ self.reload()
with self.lock:
fhash = hash_file(filep)
return self.db.set(filep, fhash)
@@ -74,6 +75,7 @@ class ComboxSilo(object):
"""Returns a list of all keys in db."""
# this is why Redis or some other key-value DB should be used
# instead of PickleDB
+ self.reload()
with self.lock:
return self.db.db.keys()
@@ -85,6 +87,7 @@ class ComboxSilo(object):
"""
try:
+ self.reload()
with self.lock:
return self.db.rem(filep)
except KeyError, e:
@@ -100,7 +103,7 @@ class ComboxSilo(object):
filep: path to the file in combox directory.
"""
-
+ self.reload()
with self.lock:
if self.db.get(filep) is None:
return False
@@ -121,6 +124,7 @@ class ComboxSilo(object):
if not fhash:
fhash = hash_file(filep)
+ self.reload()
with self.lock:
fhash_in_db = self.db.get(filep)
@@ -147,6 +151,7 @@ class ComboxSilo(object):
file_: path of the file_ in combox directory.
"""
+ self.reload()
with self.lock:
try:
num = self.db.dget(type_, file_)
@@ -164,8 +169,10 @@ class ComboxSilo(object):
type_: 'shard_created', 'shard_modified', 'shard_moved', 'shard_deleted'
file_: path of the file_ in combox directory.
"""
- try:
- return self.db.dget(type_, file_)
- except KeyError, e:
- # file_ info not there under type_ dict.
- return None
+ self.reload()
+ with self.lock:
+ try:
+ return self.db.dget(type_, file_)
+ except KeyError, e:
+ # file_ info not there under type_ dict.
+ return None