Пример #1
0
 def _fetch_version(self, key):
     versioned = self.get(key)
     if versioned:
         version = versioned[0][1]
     else:
         version = protocol.VectorClock()
         version.timestamp = int(time.time() * 1000)
     return version
Пример #2
0
    def _increment(self, clock):
        new_clock = protocol.VectorClock()
        new_clock.MergeFrom(clock)

        # See if we already have a version for this guy, if so increment it
        for entry in new_clock.entries:
            if entry.node_id == self.node_id:
                entry.version += 1
                return new_clock

        # Otherwise add a version
        entry = new_clock.entries.add()
        entry.node_id = self.node_id
        entry.version = 1
        new_clock.timestamp = int(time.time() * 1000)

        return new_clock