summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-04-30 15:02:36 -0400
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-04-30 15:02:36 -0400
commit2925bf8cacfd7716639e0177f444140928ed0c9a (patch)
tree7bf4db3bef5208746a9f95ff26bc8a22fb5da04a
parentbcf127e0472aec90a1569c4bfd9f1c86db88283e (diff)
Updated combox.events.NodeDirMonitor.housekeep's delete functionality.
- Now the housekeep method deletes the file in the combox directory only if all of its shards are missing in the respective node directories -- meaning it was deleted on another computer (running combox). - If it finds only some of all the shards of a file missing, it stores this information in the `file_deleted' dict inside the silo. - tests.events_tests.TestEvents.test_NDM_housekeep_delete tests the delete functionality of combox.events.NodeDirMonitor.housekeep method. modified: combox/events.py modified: tests/events_test.py
-rw-r--r--combox/events.py26
-rw-r--r--tests/events_test.py31
2 files changed, 45 insertions, 12 deletions
diff --git a/combox/events.py b/combox/events.py
index 7026756..e15ea70 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -232,16 +232,22 @@ class NodeDirMonitor(LoggingEventHandler):
fpaths = filter(fpath_filter, self.silo.keys())
for fpath in fpaths:
- fshards = node_paths(fpath, self.config, True)
-
- for fshard in fshards:
- if not path.exists(fshard):
- # remove the file from combox directory.
- rm_path(fpath)
- print fpath, "was deleted on another computer. Removing it."
- # update silo.
- self.silo.remove(fpath)
- break
+ del_num = 0
+ fshards = node_paths(fpath, self.config, True)
+
+ for fshard in fshards:
+ if not path.exists(fshard):
+ del_num += 1
+
+ if del_num == self.num_nodes:
+ # remove the file from combox directory.
+ rm_path(fpath)
+ print fpath, "was deleted on another computer. Removing it."
+ # update silo.
+ self.silo.remove(fpath)
+ self.silo.node_rem('file_deleted', fpath)
+ elif del_num > 0:
+ self.silo.node_set('file_deleted', fpath, del_num)
for root, dirs, files in os.walk(get_nodedirs(self.config)[0]):
for f in files:
diff --git a/tests/events_test.py b/tests/events_test.py
index 5d65709..abb490a 100644
--- a/tests/events_test.py
+++ b/tests/events_test.py
@@ -35,7 +35,7 @@ from combox.events import ComboxDirMonitor, NodeDirMonitor
from combox.file import (relative_path, purge_dir, hash_file,
read_file, write_file, move_shards,
rm_shards, mk_nodedir, rm_nodedir,
- move_nodedir)
+ move_nodedir, node_paths)
from combox.silo import ComboxSilo
from tests.utils import (get_config, shardedp, dirp, renamedp,
@@ -572,7 +572,34 @@ class TestEvents(object):
observers[i].join()
- def test_NDM_housekeep(self):
+ def test_NDM_housekeep_delete(self):
+ """Testing NodeDirMonitor's housekeep method's delete functionality."""
+ # files for testing deletion.
+ testf1 = path.join(self.FILES_DIR, 'hitchhikers.png')
+ testf2 = path.join(self.FILES_DIR, 'lorem.housekeep')
+ copyfile(self.TEST_FILE, testf1)
+ copyfile(self.lorem, testf2)
+
+ split_and_encrypt(testf2, self.config)
+ testf2_shard0 = node_paths(testf2, self.config, True)[0]
+ remove(testf2_shard0)
+
+ silo = ComboxSilo(self.config, self.silo_lock)
+ silo.update(testf1)
+ silo.update(testf2)
+
+ ndm = NodeDirMonitor(self.config, self.silo_lock,
+ self.nodem_lock)
+ ndm.housekeep()
+
+ assert not path.exists(testf1)
+ assert path.exists(testf2)
+
+ self.purge_list.append(testf1)
+ self.purge_list.append(testf2)
+
+
+ def untest_NDM_housekeep(self):
"""Testing NodeDirMonitor's housekeep method."""
# files for testing deletion.