Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_SYNCABLE_H_ | |
| 6 #define BLIMP_NET_HELIUM_SYNCABLE_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "blimp/common/proto/helium.pb.h" | |
| 12 | |
| 13 #include "vector_clock.h" | |
|
CJ
2016/09/29 20:36:55
Nit: I think you want to give the full path to vec
scf
2016/09/29 23:13:39
Done.
| |
| 14 | |
| 15 namespace blimp { | |
| 16 | |
| 17 // SyncableObject and Syncable are conceptually very similar. Both are objects | |
|
Sriram
2016/09/29 18:52:21
Not to bikeshed with names but I find SyncableObje
Brian Goldman
2016/09/29 19:31:28
Seconded that it's confusing. For me it's because
scf
2016/09/29 23:13:38
Not bikeshed at all. I was not super happy with th
| |
| 18 // that will be synchronized between client server. | |
|
Brian Goldman
2016/09/29 19:31:28
Maybe a little more detail here on what it means t
scf
2016/09/29 23:13:39
Done.
| |
| 19 // | |
| 20 // The main difference is that SyncableObject owns its lifetime, whereas | |
|
Kevin M
2016/09/29 20:01:16
The lifetime is managed by an arbitrary entity whi
scf
2016/09/29 23:13:39
I find this a bit vague. Not entirely sure what yo
| |
| 21 // Syncable depends on its SyncableObject parent. | |
| 22 // | |
| 23 // An example for GeoLocation would be: | |
| 24 // GeoLocation : SyncableObject { | |
| 25 // * Frequency : Syncable | |
| 26 // * Position : Syncable | |
| 27 // } | |
| 28 // | |
| 29 // VectorClocks from a Syncable can be compared with the vector clock from | |
|
CJ
2016/09/29 20:36:55
This a bit confusing as well. Is the vector clock
scf
2016/09/29 23:13:39
Done.
| |
| 30 // the SyncableObject. This reduces the amount of state that can be kept. | |
| 31 | |
| 32 class SyncableObject { | |
|
Sriram
2016/09/29 18:52:21
A SyncableObject does not control how often it is
scf
2016/09/29 23:13:39
There will be a notification mechanism to tell the
| |
| 33 public: | |
| 34 using CreateChangesetCallback = | |
| 35 base::Callback<void(std::unique_ptr<helium::Changeset> changeset)>; | |
|
Kevin M
2016/09/29 20:01:16
In general we don't specify parameter names in fun
scf
2016/09/29 23:13:38
Done.
| |
| 36 | |
| 37 explicit SyncableObject(const VectorClock& clock) : clock_(clock) {} | |
| 38 | |
| 39 virtual ~SyncableObject(){} | |
| 40 | |
| 41 // Constructs a changeset between the |from| revision and its current state. | |
| 42 // The Sync layer will encapsulate the changeset with details since |from|, | |
| 43 // but the Object is responsible for including any revision information | |
| 44 // additional to that expressed by the VectorClocks, that is necessary to | |
| 45 // detect and resolve conflicts. | |
| 46 // The computed changeset is returned asynchronously via |response_callback|. | |
| 47 virtual void CreateChangesetToCurrent( | |
|
Kevin M
2016/09/29 20:01:16
Shouldn't these be overrides of Syncable instead o
scf
2016/09/29 23:13:38
I thought about making the interfaces different as
| |
| 48 const VectorClock& from, | |
| 49 const CreateChangesetCallback& response_callback) = 0; | |
| 50 | |
| 51 // Applies a |changeset| given as parameter to the contents of the | |
| 52 // Object. The VectorClocks |from| and |to| can be used to detect and resolve | |
|
CJ
2016/09/29 20:36:55
Not following when u say "the Object". If you mean
scf
2016/09/29 23:13:38
Done.
| |
| 53 // concurrent change conflicts. | |
| 54 // The closure |done| its called when the state is applied. | |
| 55 virtual void ApplyChangeset(const VectorClock& from, | |
| 56 const VectorClock& to, | |
| 57 const helium::Changeset& changeset, | |
| 58 const base::Closure& done) = 0; | |
| 59 | |
| 60 // This call is an optimization that allows the source of the change | |
|
Kevin M
2016/09/29 20:01:16
* This isn't a mere optimization; it's actually qu
scf
2016/09/29 23:13:39
Done.
| |
| 61 // delete anything before a given checkpoint. Lets say we know the receiver | |
| 62 // already received the change for VectorClock (2,3). The source now can | |
| 63 // delete any state that it needed to create a changeset from x to (2,3). | |
| 64 virtual void ReleaseCheckpointsBefore(const VectorClock& checkpoint) = 0; | |
| 65 | |
| 66 VectorClock get_clock() { return clock_; } | |
|
scf
2016/09/29 18:26:53
This is needed in order for the |Syncacle| objects
Kevin M
2016/09/29 20:01:16
You are returning the clock by-value, which means
CJ
2016/09/29 20:36:55
Maybe put a little of this rationale in a comment,
scf
2016/09/29 23:13:39
Done.
| |
| 67 | |
| 68 protected: | |
| 69 VectorClock clock_; | |
| 70 }; | |
| 71 | |
| 72 template <class ChangesetType> | |
| 73 class Syncable { | |
| 74 public: | |
| 75 explicit Syncable(VectorClock* parent_clock) : parent_clock_(parent_clock) {} | |
|
Kevin M
2016/09/29 20:01:16
There's a circular dependency in that we have a "p
scf
2016/09/29 23:13:39
completely agree
| |
| 76 virtual ~Syncable(){} | |
| 77 | |
| 78 // Returns true if the object have been modified since |from| | |
| 79 virtual bool ModifiedSince(const VectorClock& from) = 0; | |
| 80 | |
| 81 // See above definition in |SyncableObject|, the only difference is that | |
| 82 // this is a blocking call | |
|
Kevin M
2016/09/29 20:01:16
Why are these all blocking?
scf
2016/09/29 23:13:39
I should have checked with you offline before I wr
| |
| 83 virtual void CreateChangesetToCurrent(const VectorClock& from, | |
| 84 ChangesetType* changeset) = 0; | |
| 85 | |
| 86 // See above definition in |SyncableObject|, the only difference is that | |
| 87 // this is a blocking call | |
| 88 virtual void ApplyChangeset(const VectorClock& from, | |
| 89 const VectorClock& to, | |
| 90 const ChangesetType& changeset) = 0; | |
| 91 | |
| 92 // See above definition in |SyncableObject|, the only difference is that | |
| 93 // this is a blocking call | |
| 94 virtual void ReleaseCheckpointsBefore(const VectorClock& checkpoint) = 0; | |
| 95 | |
| 96 protected: | |
| 97 // Increments the parent clock and returns the new value. Should be used | |
| 98 // whenever a Syncable updates its state. | |
| 99 VectorClock IncrementParentClock() { | |
| 100 parent_clock_->IncrementLocal(); | |
| 101 return *parent_clock_; | |
| 102 } | |
| 103 | |
| 104 VectorClock parent_clock() { return *parent_clock_; } | |
|
Kevin M
2016/09/29 20:01:16
Should return a pointer
scf
2016/09/29 23:13:39
Done.
| |
| 105 | |
| 106 private: | |
| 107 VectorClock* parent_clock_; | |
| 108 }; | |
| 109 | |
| 110 } // namespace blimp | |
| 111 | |
| 112 #endif // BLIMP_NET_HELIUM_SYNCABLE_H_ | |
| OLD | NEW |