diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-04-01 22:57:55 -0400 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-04-01 22:57:55 -0400 |
commit | 132921d3c42327012857a9a595963758837c9aa7 (patch) | |
tree | e3d6b5398114f41a16f3d73c294cfe26cde4ac37 /combox/events.py | |
parent | 110e515a51c9d97affcbb283f7a5f1c02a2231bd (diff) |
[golden commit]: rewrote combox.events.NodeDirMonitor.on_created method.
- Now the the node monitor waits for all shards of the file, which
was created on a remote computer, to arrive on this computer, before
it re-constructs the file into the respective location in the combox
directory.
- Tests for it is at tests.events_test.TestEvents.test_NDM_oncreate
method.
- The main test method, tests.events_test.TestEvents.test_NDM, was
disabled by renaming it to tests.events_test.TestEvents.test_NDM.
- Now the NodeDirMonitor requires passing the 'node monitor lock' when
creating an instance of it.
:~(
modified: combox/events.py
modified: tests/events_test.py
Diffstat (limited to 'combox/events.py')
-rw-r--r-- | combox/events.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/combox/events.py b/combox/events.py index 359aa03..efdbc53 100644 --- a/combox/events.py +++ b/combox/events.py @@ -175,12 +175,15 @@ class NodeDirMonitor(LoggingEventHandler): """ - def __init__(self, config, dblock): + def __init__(self, config, dblock, nodem_lock): """ config: a dictinary which contains combox configuration. + dblock: Lock for the ComboxSilo. + nodem_lock: Lock for NodeDirMonitors. """ super(NodeDirMonitor, self).__init__() + self.lock = nodem_lock logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') @@ -302,16 +305,25 @@ class NodeDirMonitor(LoggingEventHandler): # means, the directory was created on another computer # (also running combox). so, create this directory # under the combox directory - os.mkdir(file_cb_path) + with self.lock: + self.silo.node_set('file_created', file_cb_path) + num = self.silo.node_get('file_created', file_cb_path) + + if num == self.num_nodes: + os.mkdir(file_cb_path) elif (not event.is_directory) and (not path.exists(file_cb_path)): # shard created. # means, file was created on another computer (also # running combox). so, reconstruct the file and put it # in the combox directory. - decrypt_and_glue(file_cb_path, self.config) - # update db. - self.silo.update(file_cb_path) + with self.lock: + self.silo.node_set('file_created', file_cb_path) + num = self.silo.node_get('file_created', file_cb_path) + if num == self.num_nodes: + decrypt_and_glue(file_cb_path, self.config) + # update db. + self.silo.update(file_cb_path) def on_deleted(self, event): |