2 sys.path.append('/tmp/dnet/lib')
3 sys.path.append('/tmp/test/history.2')
5 from libelliptics_python import *
7 # groups used in metadata write
8 pohmelfs_groups = [1, 2, 3]
9 pohmelfs_log_file = '/tmp/test/history.2/python.log'
11 log = elliptics_log_file(pohmelfs_log_file, 10)
12 n = elliptics_node_python(log)
13 # we should only add own local group, since we do not want all updates to be repeated for all groups
15 n.add_remote('172.16.239.1', 1025)
17 __return_data = 'unused'
22 from sstable2 import sstable
25 FORMAT = "%(asctime)-15s %(process)d %(script)s %(dentry_name)s %(message)s"
26 logging.basicConfig(filename=pohmelfs_log_file, level=logging.DEBUG, format=FORMAT)
31 #pohmelfs_ioflags_read = 256
32 pohmelfs_ioflags_read = 0
33 pohmelfs_ioflags_write = 0
34 # do not lock operation, since we are 'inside' DNET_CMD_EXEC command already
37 pohmelfs_link_number_column = 2
38 pohmelfs_inode_info_column = 3
41 def pohmelfs_write(parent_id, content):
42 n.write_data(parent_id, content, pohmelfs_offset, pohmelfs_aflags, pohmelfs_ioflags_write)
43 n.write_metadata(parent_id, '', pohmelfs_groups, pohmelfs_aflags)
50 # 4 bytes: number of chunks inside
53 # Chunk header format:
54 # 2 bytes: length in chunks
55 # 2 bytes: current chunk
57 # 2 bytes: payload size
58 chunk_header_fmt = "<HHHH"
63 header = struct.unpack_from(header_fmt, buffer, position)
64 position += struct.calcsize(header_fmt)
66 header_chunk_size = header[2]
67 header_count = header[3]
68 header_strings_start = position
71 #print "chunk size:", header_chunk_size, ", chunks count:", header_count, ", strings start at", header_strings_start
74 offset = header_strings_start
75 while offset < header_strings_start + header_count * header_chunk_size:
76 chunk_header = struct.unpack_from(chunk_header_fmt, buffer, offset)
77 if chunk_header[1] > 0:
78 offset -= chunk_header[1]*header_chunk_size
80 chunk_header = struct.unpack_from(chunk_header_fmt, buffer, offset)
82 key_len = chunk_header[2]
83 payload_len = chunk_header[3]
89 for i in xrange(0, chunk_header[0]):
94 key_size = header_chunk_size - chunk_header_size
95 if key_len < key_size:
98 key_offset = offset + rec_offset + chunk_header_size
99 key += buffer[key_offset:(key_offset + key_size)]
102 # Get payload from chunks
103 if key_len == 0 and payload_len > 0:
104 payload_size = header_chunk_size - chunk_header_size - key_size
105 if payload_len < payload_size:
106 payload_size = payload_len
108 payload_offset = offset + rec_offset + chunk_header_size + key_size
109 payload += buffer[payload_offset:(payload_offset + payload_size)]
110 payload_len -= payload_size
112 rec_offset += header_chunk_size
115 offset += chunk_header[0]*header_chunk_size