Switch '.' and '~' in new token format

pull/8439/head
Erik Johnston 2020-10-06 11:58:53 +01:00
parent 93c8091145
commit a321252e33
1 changed files with 7 additions and 7 deletions

View File

@ -408,13 +408,13 @@ class RoomStreamToken:
The format of the token in such case is an initial integer min position, The format of the token in such case is an initial integer min position,
followed by the mapping of instance ID to position separated by '.' and '~': followed by the mapping of instance ID to position separated by '.' and '~':
m{min_pos}.{writer1}~{pos1}.{writer2}~{pos2}. ... m{min_pos}~{writer1}.{pos1}~{writer2}.{pos2}. ...
The `min_pos` corresponds to the minimum position all writers have persisted The `min_pos` corresponds to the minimum position all writers have persisted
up to, and then only writers that are ahead of that position need to be up to, and then only writers that are ahead of that position need to be
encoded. An example token is: encoded. An example token is:
m56.2~58.3~59 m56~2.58~3.59
Which corresponds to a set of three (or more writers) where instances 2 and Which corresponds to a set of three (or more writers) where instances 2 and
3 (these are instance IDs that can be looked up in the DB to fetch the more 3 (these are instance IDs that can be looked up in the DB to fetch the more
@ -454,12 +454,12 @@ class RoomStreamToken:
parts = string[1:].split("-", 1) parts = string[1:].split("-", 1)
return cls(topological=int(parts[0]), stream=int(parts[1])) return cls(topological=int(parts[0]), stream=int(parts[1]))
if string[0] == "m": if string[0] == "m":
parts = string[1:].split(".") parts = string[1:].split("~")
stream = int(parts[0]) stream = int(parts[0])
instance_map = {} instance_map = {}
for part in parts[1:]: for part in parts[1:]:
key, value = part.split("~") key, value = part.split(".")
instance_id = int(key) instance_id = int(key)
pos = int(value) pos = int(value)
@ -539,10 +539,10 @@ class RoomStreamToken:
entries = [] entries = []
for name, pos in self.instance_map.items(): for name, pos in self.instance_map.items():
instance_id = await store.get_id_for_instance(name) instance_id = await store.get_id_for_instance(name)
entries.append("{}~{}".format(instance_id, pos)) entries.append("{}.{}".format(instance_id, pos))
encoded_map = ".".join(entries) encoded_map = "~".join(entries)
return "m{}.{}".format(self.stream, encoded_map) return "m{}~{}".format(self.stream, encoded_map)
else: else:
return "s%d" % (self.stream,) return "s%d" % (self.stream,)