-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunkserver.py
49 lines (39 loc) · 1.54 KB
/
chunkserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import rpyc
from rpyc.utils.server import ThreadedServer
import os
path = './files/chunk/'
class chunk_service(rpyc.Service):
file_table = {}
def on_connect(self, conn):
print('Connected to the chunk server!')
def on_disconnect(self, conn):
print('Disconnected with the chunk server.')
#--------------------
#initialize
#--------------------
chunkloc = 0
chunktable = {}
# local_filesystem_root = "/gfs/chunks/" + repr(chunkloc)
local_filesystem_root = os.path.expanduser("~")
local_filesystem_root += "./gfs_root/chunks/"+repr(chunkloc)
if not os.access(local_filesystem_root, os.W_OK):
os.makedirs(local_filesystem_root)
print("create chunk root")
def exposed_write(self, chunkuuid, chunk):
local_filename = self.chunk_filename(chunkuuid)
with open(local_filename, "wb") as f:
f.write(chunk)
self.chunktable[chunkuuid] = local_filename
def exposed_read(self, chunkuuid):
data = None
local_filename = self.chunk_filename(chunkuuid)
with open(local_filename, "rb") as f:
data = f.read()
return data
def chunk_filename(self, chunkuuid):
local_filename = self.local_filesystem_root + "/" + str(chunkuuid) + ".gfs"
return local_filename
if __name__ == "__main__":
t = ThreadedServer(chunk_service, port=8888)
t.start()
#& C:/Users/51934/Anaconda3/envs/tensorflow/python.exe c:/Users/51934/Desktop/Python/OST/chunkserver.py