Exemplo n.º 1
0
    def chunk_reader(self, roff):
        index = roff / CHUNKSIZE
        offset = roff % CHUNKSIZE
        chunk = self.get_chunk(index)
        length = min(self.length - index * CHUNKSIZE, CHUNKSIZE)
        if offset > length:
            return

        local_ip = socket.gethostbyname(socket.gethostname())
        if any(ip == local_ip for ip, port in chunk.addrs):
            for block in read_chunk_from_local(chunk.id, chunk.version,
                                               length - offset, offset):
                yield block
                offset += len(block)
                if offset >= length:
                    return

        for host, port in chunk.addrs:
            # give up after two continuous errors
            nerror = 0
            while nerror < 2:
                try:
                    for block in read_chunk(host, port, chunk.id,
                                            chunk.version, length - offset,
                                            offset):
                        yield block
                        offset += len(block)
                        if offset >= length:
                            return
                        nerror = 0
                    break
                except IOError, e:
                    #print 'read chunk error from ', host, port, chunk.id, chunk.version, offset, e
                    nerror += 1
Exemplo n.º 2
0
    def chunk_reader(self, roff):
        index = roff / CHUNKSIZE
        offset = roff % CHUNKSIZE
        chunk = self.get_chunk(index)
        length = min(self.length - index * CHUNKSIZE, CHUNKSIZE)
        if offset > length:
            return

        local_ip = socket.gethostbyname(socket.gethostname())
        if any(ip == local_ip for ip, port in chunk.addrs):
            try:
                if _local_aware:
                    for block in read_chunk_from_local(chunk.id,
                                                       chunk.version,
                                                       length-offset,
                                                       offset):
                        yield block
                        offset += len(block)
                        if offset >= length:
                            return
                for i in range(len(chunk.addrs)):
                    ip, port = chunk.addrs[i]
                    if ip == local_ip:
                        if i != 0:
                            chunk.addrs[0], chunk.addrs[i] = chunk.addrs[i], chunk.addrs[0]
                        break
            except Exception, e:
                logger.warning("fail to read chunk %d of %s from local, \
                                exception: %s",
                               chunk.id, self.path, e)
Exemplo n.º 3
0
    def chunk_reader(self, roff):
        index = roff / CHUNKSIZE
        offset = roff % CHUNKSIZE
        chunk = self.get_chunk(index)
        length = min(self.length - index * CHUNKSIZE, CHUNKSIZE)
        if offset > length:
            return
        
        local_ip = socket.gethostbyname(socket.gethostname())
        if any(ip == local_ip for ip,port in chunk.addrs):
            for block in read_chunk_from_local(chunk.id,
                    chunk.version, length-offset, offset):
                yield block
                offset += len(block)
                if offset >= length:
                    return

        for host, port in chunk.addrs:
            # give up after two continuous errors
            nerror = 0
            while nerror < 2:
                try:
                    for block in read_chunk(host, port, chunk.id,
                        chunk.version, length-offset, offset):
                        yield block
                        offset += len(block)
                        if offset >= length:
                            return
                        nerror = 0
                    break
                except IOError, e:
                    #print 'read chunk error from ', host, port, chunk.id, chunk.version, offset, e
                    nerror += 1
Exemplo n.º 4
0
    def chunk_reader(self, roff):
        index = roff / CHUNKSIZE
        offset = roff % CHUNKSIZE
        chunk = self.get_chunk(index)
        length = min(self.length - index * CHUNKSIZE, CHUNKSIZE)
        if offset > length:
            return

        local_ip = socket.gethostbyname(socket.gethostname())
        if any(ip == local_ip for ip, port in chunk.addrs):
            try:
                for block in read_chunk_from_local(chunk.id, chunk.version, length - offset, offset):
                    yield block
                    offset += len(block)
                    if offset >= length:
                        return
            except Exception, e:
                logger.warning("read chunk %d from local: %s", chunk.id, e)
Exemplo n.º 5
0
    def chunk_reader(self, roff):
        index = roff / CHUNKSIZE
        offset = roff % CHUNKSIZE
        chunk = self.get_chunk(index)
        length = min(self.length - index * CHUNKSIZE, CHUNKSIZE)
        if offset > length:
            return

        local_ip = socket.gethostbyname(socket.gethostname())
        if any(ip == local_ip for ip, port in chunk.addrs):
            try:
                for block in read_chunk_from_local(chunk.id, chunk.version,
                                                   length - offset, offset):
                    yield block
                    offset += len(block)
                    if offset >= length:
                        return
            except Exception, e:
                logger.warning("read chunk %d from local: %s", chunk.id, e)