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

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

Issue 2382533002: Helium: Initial proto and Syncable interface definition (Closed)
Patch Set: remainder stufft 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_SYNCABLE_H_
6 #define BLIMP_NET_HELIUM_SYNCABLE_H_
7
8 #include <stdint.h>
9 #include <memory>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "blimp/net/helium/vector_clock.h"
14 #include "blimp/net/helium/vector_clock_generator.h"
15
16 namespace blimp {
17
18 namespace proto {
19 class ChangesetMessage;
20 }
21
22 // Syncable is something that supports creating and restoring Changesets.
23 // These objects exchange Changesets between the client and server to keep
24 // their peer counterparts eventually synchronized.
25 //
26 // It provides the following things:
27 // 1. Mapping: There is a one-to-one relationship between instances on the
28 // client and instances on the engine.
29 // 2. Consistency: The values stored in client-engine pairs should eventually be
30 // equal.
31 //
32 // Syncable is a base interface that is used for both self contained
33 // objects (i.e. Simple register) or objects that the actual truth lives
Kevin M 2016/10/05 23:41:30 or => and objects which are disconnected replicas
scf 2016/10/06 19:47:16 Done.
34 // externally.
35 //
36 // Example of self contained objects are the CRDTs for example: LwwRegister,
Kevin M 2016/10/05 23:41:29 Not sure if this is necessary, a cross reference i
scf 2016/10/06 19:47:17 Done.
37 // UniqueSet, Fifo, MutableReplicatedSet, etc.
38 //
39 // Example of an object where the truth resides somewhere else would be:
40 // TabList, TabState, GeoLocation, etc.
41 //
42
43 template <class ChangesetType>
44 class Syncable {
45 public:
46 virtual ~Syncable() {}
47
48 // Constructs a changeset between the |from| revision and its current state.
49 // The Sync layer will encapsulate the changeset with details since |from|,
50 // but the Syncable is responsible for including any revision information
51 // additional to that expressed by the VectorClocks, that is necessary to
52 // detect and resolve conflicts.
53 // The changeset is returned as a return value.
54 virtual std::unique_ptr<ChangesetType> CreateChangesetToCurrent(
55 const VectorClock& from) = 0;
56
57 // Applies a |changeset| given as parameter to the contents of the
58 // Syncable.
59 // The VectorClocks |from| and |to| can be used to detect and resolve
60 // concurrent change conflicts.
61 virtual void ApplyChangeset(const VectorClock& from,
62 const VectorClock& to,
63 std::unique_ptr<ChangesetType> changeset) = 0;
64
65 // Gives a chance for the Syncable to delete any old data previous to the
66 // |checkpoint|. This is a pretty important method that will remove some
Kevin M 2016/10/05 23:41:30 The "pretty important method" sentence reads too c
scf 2016/10/06 19:47:16 Done.
67 // memory pressure for example from the UniqueSet CRDT. They need to keep
68 // a growing list of added/removed elements over time. With this checkpoint
69 // info they can delete those elements prior to the vector clock specified in
70 // |checkpoint|.
71 virtual void ReleaseCheckpointsBefore(const VectorClock& checkpoint) = 0;
72
73 // Returns true if the object have been modified since |from|.
Kevin M 2016/10/05 23:41:29 have => has
scf 2016/10/06 19:47:17 Done.
74 virtual bool ModifiedSince(const VectorClock& from) = 0;
steimel 2016/10/06 17:44:33 Should this be const, or will there be CDRTs for w
scf 2016/10/06 19:47:17 good catch, should be const
75 };
76
77 // Extends the Syncable interface by adding support to synchronize with some
Kevin M 2016/10/05 23:41:29 synchronize => "asynchronously replicate state" ?
scf 2016/10/06 19:47:17 Done.
78 // external entity.
79 //
80 // TwoPhaseSyncable name derives from the fact that the state is both created
81 // and applied in two stages:
82 //
83 // 1. Creation
84 // 1.1) PreCreateChangesetToCurrent is called which retrieves the state
85 // from an external object and saves locally.
86 // 1.2) CreateChangesetToCurrent is called to actually create the changeset.
87 //
88 // 2. Updating
89 // 2.1) ApplyChangeset is called which updates the local state.
90 // 2.2) PostApplyChangeset is called to apply the state from the local
91 // object into the external object.
92 class TwoPhaseSyncable : public Syncable<proto::ChangesetMessage> {
93 public:
94 ~TwoPhaseSyncable() override {}
95
96 // This is before calling CreateChangesetToCurrent to give a change for the
97 // TwoPhaseSyncable to pull the latest changes into its local state.
98 //
99 // The callback |done| should be called once the local instance is ready
100 // to accept the call to CreateChangesetToCurrent.
101 virtual void PreCreateChangesetToCurrent(const VectorClock& from,
102 const base::Closure& done) = 0;
Kevin M 2016/10/05 23:41:30 You can use MandatoryCallback<void(void)> now. Or
Kevin M 2016/10/06 18:16:05 OK, fixed. Now you can take a MandatoryCallback<vo
scf 2016/10/06 19:47:16 Done.
103
104 // This is called after calling ApplyChangeset to allow the changes to
105 // propagate to the actual external object.
106 //
107 // The callback |done| should be called once the external world object is
108 // updated.
109 virtual void PostApplyChangeset(const VectorClock& from,
110 const VectorClock& to,
111 const base::Closure& done) = 0;
Kevin M 2016/10/06 18:16:06 Use MandatoryCallback<void(void)>&&?
112 };
113
114 } // namespace blimp
115
116 #endif // BLIMP_NET_HELIUM_SYNCABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698