Exemplo n.º 1
0
        def replication(self, filename, to_addr):
            to_channel = channel.DRDFSChannel()
            to_channel.connect(to_addr, conf.dataport)

            f = open(os.path.join(self.rootpath, filename), 'r')
            f_size = os.fstat(f.fileno()).st_size
            senddata = ['recv_repl', filename, f_size]
            to_channel._send_header(senddata)
            send_size = 0

            while send_size < f_size:
                buf = f.read(conf.blsize)
                print len(buf)
                to_channel.sock.sendall(buf)
                send_size += len(buf)
            assert (send_size == f_size)

            print "finish send data of file"
            (ans, dist_filename) = to_channel.recv_header()
            print "recv answer"

            if ans == 0:
                ans = (0, dist_filename, f_size)
                self.c_channel.send_header(ans)
            to_channel.brk_channel()
Exemplo n.º 2
0
    def __init__(self, metaaddr, rootpath, dddfs_dir):
        """initialize DDDFS's data server daemon
        """
        self.metaaddr = metaaddr
        self.rootpath = os.path.abspath(rootpath)
        self.dddfs_dir = dddfs_dir
        """Check directory for data files.
        """
        assert os.access(self.rootpath, os.R_OK and os.W_OK and os.X_OK)
        """Initialize Log
        """
        DRDFSLog.init("data", DRDFSLog.DEBUG)
        """At first, connect to metadata server and send request to attend.
        """
        mchannel = channel.DRDFSChannel()
        mchannel.connect(self.metaaddr, conf.metaport)

        DRDFSLog.debug("Success in creating connection to metadata server")
        senddata = ['dataadd', self.rootpath]

        ans = mchannel.send_recv_flow(senddata)
        if ans == -1:
            e = system.DDDFSSystemError()
            raise e
        mchannel.brk_channel()

        DRDFSLog.debug("Init complete!!")
Exemplo n.º 3
0
Arquivo: meta.py Projeto: nukamu/dddfs
 def send_delete_request(self, IP, files):
     senddata = ['filedel', files]
     ch = channel.DRDFSChannel()
     ch.connect(IP, conf.dataport)
     ans = ch.send_recv_flow(senddata)
     senddata = ['close']
     ch.send_header(senddata)
     ch.brk_channel()
Exemplo n.º 4
0
    def finalize(self, ):
        """remove myself from data servers' list
        """
        mchannel = channel.DRDFSChannel()
        mchannel.connect(self.metaaddr, conf.metaport)
        senddata = ['datadel']

        mchannel.send_header(senddata)
        mchannel.brk_channel()
Exemplo n.º 5
0
        def __init__(self, path, flags, *mode):
            DRDFSLog.debug("** open ** path = %s, flag = %s, mode = %s" %
                           (path, str(flags), str(mode)))
            senddata = ['open', path, flags, mode]

            ans = m_channel.send_recv_flow(senddata)
            DRDFSLog.debug("open ans (from meta)" + str(ans))
            self.dist = ans[1]
            self.metafd = ans[2]
            self.path = path
            self.size = ans[3]
            path_data = ans[4]
            self.created = ans[5]

            DRDFSLog.debug("This file size is %d bytes" % (self.size, ))

            self.d_channel = channel.DRDFSChannel()
            self.d_channel.connect(self.dist, conf.dataport)

            senddata = ['open', path_data, flags, mode]
            ans = self.d_channel.send_recv_flow(senddata)
            DRDFSLog.debug("open ans (from data)" + str(ans))
            if ans[0] != 0:
                print "open error!!"
                e = IOError()
                e.errno = ans[0]
                raise e
            self.datafd = ans[1]
            """Initialize the write buffer
            """
            self.r_buflock = threading.Lock()
            self.w_buflock = threading.Lock()
            self.writelist = []
            self.writedata = cStringIO.StringIO()
            self.writelen = 0

            self.blnum = self.size / conf.blsize
            if self.size % conf.blsize != 0:
                self.blnum += 1
            if self.size == 0:
                self.bldata = tuple([tips.DRDFSBlock()])
            else:
                self.bldata = tuple(
                    [tips.DRDFSBlock() for i in range(self.blnum + 1)])
            DRDFSLog.debug("len of bldata = %d" % (len(self.bldata)))
            DRDFSLog.debug("create bldata 0-%d block" % (len(self.bldata) - 1))
Exemplo n.º 6
0
Arquivo: meta.py Projeto: nukamu/dddfs
        def run(self, ):
            while True:
                # check tasks of replication
                try:
                    (rep_from, rep_filename, rep_to,
                     org_filename) = self.repq.get(timeout=1)
                    rep_ch = channel.DRDFSChannel()
                    rep_ch.connect(rep_from, conf.dataport)
                    senddata = ['do_repl', rep_filename, rep_to]
                    rep_ch.send_header(senddata)
                    self.sock_list.append(rep_ch.sock.fileno())
                    self.sock_dict[rep_ch.sock.fileno()] = (rep_ch,
                                                            org_filename,
                                                            rep_from, rep_to)
                except Queue.Empty:
                    pass

                # check messages of replication ends
                ch_list = select.select(self.sock_list, [], [], 1)[0]
                for socknum in ch_list:
                    ch = self.sock_dict[socknum][0]
                    org_filename = self.sock_dict[socknum][1]
                    org_dist = self.sock_dict[socknum][2]
                    new_dist = self.sock_dict[socknum][3]
                    (ans, dist_filename, size) = ch.recv_header()
                    if ans == 0:
                        # add new location of the file
                        f = open(self.rootpath + org_filename, 'a')
                        buf = "%s,%s,%d,%s\n" % (new_dist, dist_filename, size,
                                                 org_dist)
                        f.write(buf)
                        f.close()
                        print "*** add replication ****"
                        self.access_info.add_dest(org_filename, new_dist)
                    self.sock_list.remove(ch.sock.fileno())
                    del self.sock_dict[ch.sock.fileno()]
                    senddata = [
                        'close',
                    ]
                    ch.send_header(senddata)
                    ch.brk_channel()
Exemplo n.º 7
0
    def truncate(self, path, len):
        senddata = ['truncate', path, len]
        DRDFSLog.debug('*** truncate ***' + path + str(len))

        ans = m_channel.send_recv_flow(senddata)
        if ans[0] != 0:
            return -ans[0]
        ans[1] = filedist_info_list
        DRDFSLog.debug("send request to data server: path=%s, len=%d" %
                       (path, len))
        for filedist_info in filedist_info_list:
            dist = filedist_info[0]
            filename = filedist_info[1]
            senddata = ['truncate', filename, len]
            ch = channel.DRDFSChannel()
            ch.connect(dist, conf.dataport)
            ans = ch.send_recv_flow(senddata)
            ch.brk_channel()
            if ans != 0:
                return -ans
        return 0
Exemplo n.º 8
0
    def run(self, ):
        """Connected from clients
        """
        self.lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.lsock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.lsock.bind(("0.0.0.0", conf.dataport))
        self.lsock.listen(10)

        daemons = []
        collector_thread = self.thread_collector(daemons)
        collector_thread.start()
        threads_count = 0

        while True:
            (csock, address) = self.lsock.accept()
            c_channel = channel.DRDFSChannel()
            c_channel.set_channel_from_sock(csock)
            datad = self.handler(c_channel, self.rootpath)
            datad.name = "D%d" % (threads_count)
            threads_count += 1
            datad.start()
            daemons.append(datad)
Exemplo n.º 9
0
Arquivo: meta.py Projeto: nukamu/dddfs
    def run(self, ):
        """Connected from a client
        """
        self.lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.lsock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.lsock.bind(("0.0.0.0", conf.metaport))
        self.lsock.listen(10)

        DRDFSLog.debug("Listening at the port " + str(conf.metaport))
        daemons = []
        collector_thread = self.thread_collector(daemons)
        collector_thread.start()
        threads_count = 0

        delete_files_thread = self.delete_files(self.delfiles_q)
        delete_files_thread.start()
        replicator_thread = self.replicator(self.repq, self.access_info,
                                            self.rootpath)
        replicator_thread.start()
        delete_replica_thread = self.del_repl(self.repl_info, self.delfiles_q,
                                              self.rootpath)
        delete_replica_thread.start()

        while True:
            (csock, address) = self.lsock.accept()
            c_channel = channel.DRDFSChannel()
            c_channel.set_channel_from_sock(csock)
            DRDFSLog.debug("accept connnect from %s" % (str(address[0])))
            metad = self.handler(c_channel, self.rootpath, self.delfiles_q,
                                 self.datalist, self.repq, self.repl_info,
                                 self.access_info, self.cluster_info)
            threads_count += 1
            metad.start()
            daemons.append(metad)

            DRDFSLog.debug("Created thread name = " + metad.getName())
Exemplo n.º 10
0
fuse.fuse_python_api = (0, 2)
import os, sys, os.path

sys.path.append(os.pardir)

from conf import conf
from libs import channel, dbmng, system, tips
from libs.system import DRDFSLog

import stat, errno, re
import socket, cPickle
import cStringIO, threading
import string, time, select

m_channel = channel.DRDFSChannel()
daemons = []


class DRDFS(Fuse):
    """Class for DRDFS's clients
    """
    def __init__(self, meta_server, *args, **kw):
        Fuse.__init__(self, *args, **kw)
        self.meta_server = meta_server
        self.parse(errex=1)
        m_channel.connect(self.meta_server, conf.metaport)

    def fsinit(self):
        """Called before fs.main() called.
        """