def encode_key(self, path, original_versionstamp, deleted_versionstamp=None): """ Encodes a key for a deleted version index entry. Args: path: A tuple or protobuf path object. original_versionstamp: A 10-byte string specifying the entity version's original commit versionstamp. deleted_versionstamp: A 10-byte string specifying the entity version's delete versionstamp or None. Returns: A string containing an FDB key. If deleted_versionstamp was None, the key should be used with set_versionstamped_key. """ if not isinstance(path, tuple): path = Path.flatten(path) scatter_byte = hash_tuple(path) key = b''.join([ self.directory.rawPrefix, scatter_byte, deleted_versionstamp or b'\x00' * VERSIONSTAMP_SIZE, Path.pack(path), original_versionstamp ]) if not deleted_versionstamp: versionstamp_index = len( self.directory.rawPrefix) + len(scatter_byte) key += encode_versionstamp_index(versionstamp_index) return key
def encode_key(self, path, commit_versionstamp): key = b''.join([self.directory.rawPrefix, Path.pack(path), commit_versionstamp or b'\x00' * VERSIONSTAMP_SIZE]) if not commit_versionstamp: key += encode_versionstamp_index(len(key) - VERSIONSTAMP_SIZE) return key
def encode_start_key(self, scatter_val, commit_versionstamp=None): key = b''.join([self.directory.rawPrefix, six.int2byte(scatter_val), commit_versionstamp or b'\x00' * VERSIONSTAMP_SIZE]) if not commit_versionstamp: key += encode_versionstamp_index(len(key) - VERSIONSTAMP_SIZE) return key
def _encode_chunks(self, section_prefix, value): full_prefix = section_prefix + b'\x00' * VERSIONSTAMP_SIZE versionstamp_index = encode_versionstamp_index(len(section_prefix)) chunk_count = int(math.ceil(len(value) / self._CHUNK_SIZE)) return tuple( (full_prefix + six.int2byte(index) + versionstamp_index, value[index * self._CHUNK_SIZE:(index + 1) * self._CHUNK_SIZE]) for index in sm.range(chunk_count))
def encode_key(self, ancestor_path, encoded_values, remaining_path, commit_versionstamp): ancestor_path = Path.pack(ancestor_path) if ancestor_path else b'' remaining_path = Path.pack(remaining_path) key = b''.join( (self.directory.rawPrefix, ancestor_path) + tuple(encoded_values) + (remaining_path, commit_versionstamp or b'\x00' * VERSIONSTAMP_SIZE)) if not commit_versionstamp: key += encode_versionstamp_index(len(key) - VERSIONSTAMP_SIZE) return key
def encode(self, path): """ Creates a Key-Value tuple for updating a group's commit versionstamp. Args: path: A tuple or protobuf path object. Returns: A (key, value) tuple suitable for set_versionstamped_value. """ if not isinstance(path, tuple): path = Path.flatten(path) group_path = path[:2] return (self.encode_key(group_path), b'\x00' * VERSIONSTAMP_SIZE + encode_versionstamp_index(0))
def put_entries(self, tr, old_version_entry, new_entity): old_key_stats = IndexStatsSummary() if old_version_entry.has_entity: old_keys, old_key_stats = yield self._get_index_keys( tr, old_version_entry.decoded, old_version_entry.commit_versionstamp) for key in old_keys: # Set deleted versionstamp. tr.set_versionstamped_value( key, b'\x00' * VERSIONSTAMP_SIZE + encode_versionstamp_index(0)) new_key_stats = IndexStatsSummary() if new_entity is not None: new_keys, new_key_stats = yield self._get_index_keys( tr, new_entity) for key in new_keys: tr.set_versionstamped_key(key, b'') raise gen.Return(new_key_stats - old_key_stats)
def encode_key(self, path, commit_versionstamp, index): """ Encodes a key for the given version entry. Args: path: A tuple or protobuf path object. commit_versionstamp: A 10-byte string specifying the version's commit versionstamp or None. index: An integer specifying the chunk index. Returns: A string containing an FDB key. If commit_versionstamp was None, the key should be used with set_versionstamped_key. """ encoded_key = b''.join([self._encode_path_prefix(path), commit_versionstamp or b'\x00' * VERSIONSTAMP_SIZE, six.int2byte(index)]) if not commit_versionstamp: versionstamp_index = (len(encoded_key) - (VERSIONSTAMP_SIZE + self._INDEX_SIZE)) encoded_key += encode_versionstamp_index(versionstamp_index) return encoded_key