Revision b5636704 snf-pithos-backend/pithos/backends/lib/hashfiler/archipelagoblocker.py
b/snf-pithos-backend/pithos/backends/lib/hashfiler/archipelagoblocker.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
from hashlib import new as newhasher |
35 | 35 |
from binascii import hexlify |
36 |
import os, re |
|
36 |
import os |
|
37 |
import re |
|
37 | 38 |
|
38 | 39 |
from context_archipelago import ArchipelagoObject, file_sync_read_chunks |
39 | 40 |
from archipelago.common import ( |
... | ... | |
42 | 43 |
string_at, |
43 | 44 |
) |
44 | 45 |
|
45 |
from pithos.workers import glue, monkey |
|
46 |
from pithos.workers import ( |
|
47 |
glue, |
|
48 |
monkey, |
|
49 |
) |
|
46 | 50 |
|
47 | 51 |
monkey.patch_Request() |
48 | 52 |
|
49 | 53 |
from pithos.api.settings import BACKEND_ARCHIPELAGO_CONF |
50 | 54 |
|
55 |
|
|
51 | 56 |
class ArchipelagoBlocker(object): |
52 | 57 |
"""Blocker. |
53 | 58 |
Required constructor parameters: blocksize, hashtype. |
... | ... | |
61 | 66 |
cfg = {} |
62 | 67 |
bcfg = open(BACKEND_ARCHIPELAGO_CONF).read() |
63 | 68 |
cfg['blockerb'] = re.search('\'blockerb_port\'\s*:\s*\d+', |
64 |
bcfg).group(0).split(':')[1] |
|
69 |
bcfg).group(0).split(':')[1]
|
|
65 | 70 |
blocksize = params['blocksize'] |
66 | 71 |
hashtype = params['hashtype'] |
67 | 72 |
try: |
... | ... | |
85 | 90 |
|
86 | 91 |
def _get_rear_block(self, blkhash, create=0): |
87 | 92 |
name = hexlify(blkhash) |
88 |
return ArchipelagoObject(name, self.ioctx_pool,self.dst_port,create)
|
|
93 |
return ArchipelagoObject(name, self.ioctx_pool, self.dst_port, create)
|
|
89 | 94 |
|
90 | 95 |
def _check_rear_block(self, blkhash): |
91 | 96 |
filename = hexlify(blkhash) |
92 | 97 |
ioctx = self.ioctx_pool.pool_get() |
93 |
req = Request.get_info_request(ioctx,self.dst_port,filename)
|
|
98 |
req = Request.get_info_request(ioctx, self.dst_port, filename)
|
|
94 | 99 |
req.submit() |
95 | 100 |
req.wait() |
96 | 101 |
ret = req.success() |
... | ... | |
182 | 187 |
self.ioctx_pool.pool_put(ioctx) |
183 | 188 |
return blocks |
184 | 189 |
|
185 |
|
|
186 | 190 |
def block_stor(self, blocklist): |
187 | 191 |
"""Store a bunch of blocks and return (hashes, missing). |
188 | 192 |
Hashes is a list of the hashes of the blocks, |
... | ... | |
232 | 236 |
append = hashes.append |
233 | 237 |
block_hash = self.block_hash |
234 | 238 |
|
235 |
for block in file_sync_read_chunks(archipelagoobject, self.blocksize, 1, 0): |
|
239 |
for block in file_sync_read_chunks(archipelagoobject, |
|
240 |
self.blocksize, 1, 0): |
|
236 | 241 |
append(block_hash(block)) |
237 | 242 |
|
238 | 243 |
return hashes |
Also available in: Unified diff