Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: blimp/net/helium/vector_clock.h

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: Missed one feedback (s/r/Conflicts/Conflict) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BLIMP_NET_HELIUM_VECTOR_CLOCK_H_
6 #define BLIMP_NET_HELIUM_VECTOR_CLOCK_H_
7
8 #include <stdint.h>
9
10 #include "blimp/net/blimp_net_export.h"
11
12 namespace blimp {
13
14 // From wikipedia:
15 // A vector clock is an algorithm for generating a partial ordering of events
16 // in a distributed system and detecting causality violations.
17 // Just as in Lamport timestamps, interprocess messages contain the state of
18 // the sending process's logical clock. A vector clock of a system of
19 // N processes is an array/vector of N logical clocks, one clock per process
Kevin M 2016/09/27 21:36:09 A summary description and a link to Wikipedia migh
scf 2016/09/27 23:23:10 Done.
20 //
21 // In the particular case where N=2 (Client and Engine). So we can optimize to
Kevin M 2016/09/27 21:36:09 Sentence doesn't parse.
scf 2016/09/27 23:23:11 Done.
22 // store the 2 fields directly.
23 class BLIMP_NET_EXPORT VectorClock {
24 public:
Kevin M 2016/09/27 21:36:09 Add a type alias for Revision (uint32_t) and use t
scf 2016/09/27 23:23:10 Done.
25 enum class Comparison { LessThan, EqualTo, GreaterThan, Conflict };
26
27 VectorClock(int32_t local_revision, int32_t remote_revision);
28 VectorClock();
29
30 // Compares two vector clocks. There are 4 possibilities for the result:
31 // * LessThan: One revision is equal and for the other is smaller.
32 // (1,0).CompareTo((2, 0));
33 // * EqualTo: Both revisions are equals.
Kevin M 2016/09/27 21:36:09 equals = equal What about "the same", so we don't
scf 2016/09/27 23:23:11 Done.
34 // * GreaterThan: One revision is equal and for the other is greater.
35 // (2,0).CompareTo((1, 0));
36 // * Conflict: Both revisions are different. (1,0).CompareTo(0,1)
37 Comparison CompareTo(const VectorClock& other) const;
38
39 // Merges two vector clocks, this is useful/used after we merge the client
Kevin M 2016/09/27 21:36:09 The "why" should be more generalized, so that we p
scf 2016/09/27 23:23:10 Done.
40 // and server data and need to combine the clocks from both local and remote.
41 VectorClock MergeWith(const VectorClock& other) const;
42
43 // Increments one to the local_revision_. This is used when something changes
Kevin M 2016/09/27 21:36:09 Active voice: "Increments local_revision_ by one."
scf 2016/09/27 23:23:10 Done.
44 // in the local host like setting a property or applying a change set.
Kevin M 2016/09/27 21:36:09 Does applying changesets modify the local revision
Kevin M 2016/09/27 21:36:09 local state
scf 2016/09/27 23:23:11 I think if we follow the vector clock definition y
scf 2016/09/27 23:23:11 Done.
Kevin M 2016/09/28 01:23:15 Wouldn't this necessarily be a conflicting state,
45 void IncrementLocal();
46
47 int32_t local_revision() const { return local_revision_; }
48 void set_local_revision(int32_t local_revision) {
Kevin M 2016/09/27 21:36:09 Why will we need to support a setter?
scf 2016/09/27 23:23:10 Done.
49 local_revision_ = local_revision;
50 }
51 int32_t remote_revision() const { return remote_revision_; }
52
53 private:
54 int32_t local_revision_;
55 int32_t remote_revision_;
56 };
57
58 } // namespace blimp
59
60 #endif // BLIMP_NET_HELIUM_VECTOR_CLOCK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698