Changes
[iotcloud.git] / version2 / doc / iotcloud.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
2 % Short Sectioned Assignment\r
3 % LaTeX Template\r
4 % Version 1.0 (5/5/12)\r
5 %\r
6 % This template has been downloaded from:\r
7 % http://www.LaTeXTemplates.com\r
8 %\r
9 % Original author:\r
10 % Frits Wenneker (http://www.howtotex.com)\r
11 %\r
12 % License:\r
13 % CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)\r
14 %\r
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
16 \r
17 %----------------------------------------------------------------------------------------\r
18 %   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS\r
19 %----------------------------------------------------------------------------------------\r
20 \r
21 \documentclass[paper=letter, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size\r
22 \r
23 \usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs\r
24 \usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default\r
25 \usepackage[english]{babel} % English language/hyphenation\r
26 \usepackage{amsmath,amsfonts,amsthm} % Math packages\r
27 \usepackage{graphicx}\r
28 \usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template\r
29 \usepackage{hyperref}\r
30 \usepackage{amssymb}\r
31 \usepackage{listings}\r
32 \usepackage[]{algorithm2e}\r
33 \usepackage{algpseudocode}\r
34 \usepackage{enumerate}\r
35 \usepackage[table,xcdraw]{xcolor}\r
36 \usepackage{sectsty} % Allows customizing section commands\r
37 \usepackage{float}\r
38 \usepackage{caption}\r
39 \usepackage{gensymb} % to used degree symbol \r
40 \usepackage{siunitx} \r
41 \usepackage{enumitem}\r
42 \r
43 \usepackage[sc]{mathpazo}\r
44 \allsectionsfont{ \normalfont\scshape} % Make all sections the default font and small caps\r
45 \usepackage{fancyhdr} % Custom headers and footers\r
46 \pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers\r
47 \fancyhead{} % No page header - if you want one, create it in the same way as the footers below\r
48 \fancyfoot[L]{} % Empty left footer\r
49 \fancyfoot[C]{} % Empty center footer\r
50 \fancyfoot[R]{\thepage} % Page numbering for right footer\r
51 \renewcommand{\headrulewidth}{0pt} % Remove header underlines\r
52 \renewcommand{\footrulewidth}{0pt} % Remove footer underlines\r
53 \setlength{\headheight}{13.6pt} % Customize the height of the header\r
54 \r
55 \numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\r
56 \numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\r
57 \numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)\r
58 \r
59 \setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text\r
60 \r
61 %----------------------------------------------------------------------------------------\r
62 %   TITLE SECTION\r
63 %----------------------------------------------------------------------------------------\r
64 \newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height\r
65 \r
66 \title{ \r
67 \normalfont \normalsize \r
68 \textsc{University of California Irvine} \\  % Your university, school and/or department name(s)\r
69 \textsc{Prgramming Language Research Group} \\ [25pt]\r
70 \horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule\r
71 \huge IoTCloud Version 2.0\\ % The assignment title\r
72 \horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule\r
73 }\r
74 \r
75 \author{Authors} % Your name\r
76 \r
77 \r
78 \date{\normalsize\today} % Today's date or a custom date\r
79 \r
80 \begin{document}\r
81 \r
82 \maketitle % Print the title\r
83 \r
84 \r
85 \r
86 \r
87 %---------------------------------------------------------------------------------------\r
88 % Custom Stuff\r
89 %---------------------------------------------------------------------------------------\r
90 \newcommand{\tab}[1]{\hspace{.2\textwidth}\rlap{#1}}\r
91 \r
92 \r
93 \r
94 \r
95 \section{\textbf{Introduction}}\r
96 \r
97 \section{\textbf{Device Approach}}\r
98 \r
99 \subsection{\textbf{Records}}\r
100 Each record has the following information included in it:\r
101 \begin{itemize}\r
102     \item Machine ID of the device creating the record\r
103     \item The vector clock using the largest clock values from each device it knows and its own largest clock value incremented by 1.\r
104     \item Data payload\r
105     \item HMAC of the record.\r
106 \end{itemize}\r
107     \r
108 Records can be identified by the machine ID and the local machine clock, hereby referred to as the record ID.\r
109 \r
110 \subsubsection{\textbf{Types of Payloads}}\r
111 The different types of record payloads are:\r
112 \begin{itemize}\r
113 \r
114     \item Transactions\r
115         \begin{itemize}\r
116             \item Contains:\r
117             \begin{itemize}\r
118                 \item Transaction ID\r
119                 \item key-value pair gets (reads)\r
120                 \item A guard condition (boolean condition) that can be evaluated on the key-value gets.\r
121                 \item A set of key-value pairs that are to be updated if the guard condition is met.\r
122                 \item Can only get and set key-value pairs that are from 1 arbitrator.  Getting and/or setting key-value pairs from more than 1 arbitrator causes the transaction to be invalid and dead.\r
123             \end{itemize}\r
124         \end{itemize}\r
125     \item Commit notifications\r
126         \begin{itemize}\r
127             \item Contains the commit of a single transaction, the whole transaction.\r
128             \item There is 1 commit per transaction.\r
129             \item Generated by the arbitrator for the set of key-value gets and sets in the transaction.\r
130         \end{itemize}\r
131     \item Abort notifications\r
132         \begin{itemize}\r
133             \item Contains a transaction ID of an aborted transaction and the machine ID of the device that created that transaction.\r
134             \item Causes a transaction to be aborted, key-values not used in updates.\r
135         \end{itemize}\r
136     \item Data structure re-size notifications\r
137         \begin{itemize}\r
138             \item Contains new size of data structure (number of record allowed in the data structure or something like that).\r
139         \end{itemize}\r
140     \item Server sequence number confirmations.\r
141         \begin{itemize}\r
142             \item Contains a record ID and the server sequence number for that record that the server reported.\r
143             \item Created by any device if that device finds a record with a server sequence number that does not have a server sequence number conformation yet.\r
144         \end{itemize}\r
145     \item Delete notifications\r
146         \begin{itemize}\r
147             \item Contain the server sequence number of the record that was deleted.\r
148             \item Generated when a device deletes a record.\r
149         \end{itemize}\r
150     \item New Key notification\r
151         \begin{itemize}\r
152             \item Contains the name of a new key and the machine ID of the machine that is to arbitrate\r
153             \item Generated when a device generates a new (never used) key-value pair.\r
154         \end{itemize}\r
155 \end{itemize}\r
156 \r
157 \subsection{\textbf{Pulling the data structure}}\r
158 To pull the latest version of the data structure the following is done:\r
159 \begin{enumerate}\r
160     \item Make a pull request to the server and get all the records sent back.\r
161     \item Separate the records by machine ID.\r
162     \item For each machine ID, order the records based on that machine IDs clock within each of the records.\r
163     \item Check the data structure for any malicious activity (discussed below)\r
164 \end{enumerate}\r
165 \r
166 \subsection{\textbf{Updates}}\r
167 Updates take place as follows:\r
168 \begin{enumerate}\r
169     \item A device pulls the latest version of the data structure.  If the device cannot pull the latest version because of network connectivity or some other issues then that device will just work using the local copy of the data structure it has.\r
170     \item Check the pulled data structure for any malicious activity (as stated in a section below) if not done already.\r
171     \item Check if any records in the current server need to be deleted (have delete notifications in data structure but the delete never took place), if so then delete them.\r
172     \item Check that the size of the data structure will not exceed the max size when the new record is inserted.  If it does then prepare to delete records by inserting delete payloads in the new record (discussed below).\r
173     \item The device makes a record as follows:\r
174         \begin{enumerate}\r
175             \item Adds its machine ID.\r
176             \item Creates a vector clock using the largest clock values from each device it knows and its own largest clock value incremented by 1.\r
177             \item Fill the record payload section with the transactions and other types of payloads.\r
178             \item Fill the empty space of the record payload with server sequence number confirmations for records that have yet to have their server sequence numbers confirmed.\r
179             \item Fill the empty space of the record payload with rescued key-value pairs, transactions, ext (Discussed later).\r
180             \item Pad the record to be the same size for all records.\r
181             \item Calculate the HMAC of the record and add that to the record\r
182             \item Encrypt the record.\r
183         \end{enumerate}\r
184     \item Send the record to the server for insertion into the device's queue.\r
185     \item Issue any server commands such as deletes to the server.\r
186 \end{enumerate}\r
187 \r
188 If there is a connectivity issue then all the records will be held by the local device until connection is resumed then pushed to the server in the order which they occurred.  Also the device can only delete records for which there is a server sequence number.  At some point the device could run out of records to delete (it hasn't connected to the server in a while) in which case the device will not be able to delete any records.\r
189 \r
190 \subsection{\textbf{Deletions}}\r
191 When deciding which records to delete the following is to be done:\r
192 \begin{enumerate}\r
193     \item Order all the records in order based on their server sequence numbers\r
194     \item Calculate the difference between the current size of the data structure and the minimum size of the data structure (lets call this $m$). Note: count newly inserted records towards the total size of the data structure if doing deletes while doing updates.\r
195     \item Delete the oldest m records based on the ordering from step 1. \r
196     \begin{itemize}\r
197         \item If a record to be deleted has live data in it then the whole data structure needs to be re-sized.\r
198     \end{itemize}\r
199 \end{enumerate}\r
200 \r
201 Note this makes that size of the data structure be bounded:\r
202 If there are $n$ devices and the data structure has a minimum size of $m$.  Then the max size of the data structure is given by $m + n -1$ for the case when all the devices make an update at the same time.   \r
203 \r
204 \subsection{\textbf{Reading a key-value pair}}\r
205 When getting a key-value pair the following is done:\r
206 \begin{enumerate}\r
207     \item A device pulls the latest version of the data structure.  If the device cannot pull the latest version because of network connectivity or some other issues then that device will just work using the local copy of the data structure it has.\r
208     \item Check the pulled data structure for any malicious activity (as stated in a section below) if not done already.\r
209     \item Find the transaction with the largest server sequence number that contains the key-value pair of interest (this is the latest value).\r
210 \end{enumerate}\r
211 \r
212 \subsection{\textbf{Rescuing Transactions, Commits, Aborts, Ext}}\r
213 Data should be proactively rescued from the "oldest" records currently in the data structure.  Unused space in new records should be used to rescue data from old records so that when it comes time to delete the old records, there are no live pieces of data that need to be rescued.  When a piece of data is rescued, it is rescued with its vector clock as well (so that the time of that data can be saved).\\\r
214 \r
215 When rescuing transactions and commits: only keep the key-value pair sets that do not have a newer key-value pair set (no other transaction/commits sets that key-value pair later in the future).  This means that transactions/commits can shrink in size.\\\r
216 \r
217 When rescuing Key Value notifications: save the vector clock and the server sequence number of the notification in the rescued data.\r
218 \r
219 When deciding which data to rescue the following is to be done:\r
220 \begin{enumerate}\r
221     \item Order all the records in order based on their server sequence numbers\r
222     \item Create an ordered list of currently live transactions, commits, aborts, ext from the oldest $n$ records from step one where the order is based on the age of the data (how old the record is).\r
223     \item Randomly select from the list of live transactions, commits, aborts, ext to save.  Save as much as can fit in the current new record.  The random selection could give higher probability to transactions, commits, aborts, ext from records that are to be deleted sooner.\r
224 \end{enumerate}\r
225 \r
226 \subsection{\textbf{Checking the Data Structure}}\r
227 Checking the data structure for consistency is done as follows:\r
228 \begin{enumerate}\r
229     \item Verify that each record in the data structure has an HMAC that matches the data in the record.\r
230     \item Verify that the oldest record the server sent has a server sequence number that is equal to or less than the server sequence number in the most recent delete notification (currently live delete notification) + 1.\r
231     \item Make sure that for each device queue the difference between the vector clock value of the device queues clock is at most 1 between 2 consecutive messages for all records with server sequence numbers above the last deleted records server sequence numbers.\r
232     \item Verify that no currently live data Structure re-size notification is smaller than the last known data structure size.  Data structure can only grow in size.\r
233     \item Verify that all the server sequence numbers for the records that are currently present have unique numbers.\r
234     \item Verify that all the server sequence numbers for the records have a difference of 1 (no gaps) for all records with server sequence numbers above the last deleted records server sequence numbers.\r
235     \item Verify record server sequence numbers against the stated server sequence numbers in the server sequence number notification payloads (make sure the server is not changing the sequence number on the fly).\r
236 \end{enumerate}\r
237 \r
238 \subsection{\textbf{The Arbitrator}}\r
239 The arbitrator can:\r
240 \begin{enumerate}\r
241     \item Send Commits\r
242     \item Send Aborts\r
243 \end{enumerate}\r
244 \r
245 \subsubsection{\textbf{Commits}}\r
246 Commits have the following properties\r
247 \begin{itemize}\r
248     \item Agree with the ordering of the server sequence numbers most of the time.\r
249     \item Cannot commit an already aborted transaction.\r
250     \item Commits state the ordering of key-value pairs.\r
251     \item Can disagree with the ordering of server sequence numbers if arbitrator decides to do so.\r
252     \item Should occur frequently as to make sure that the commit order matches the server sequence ordering as closely as possible (prevent large divergence of the 2 orderings)\r
253 \end{itemize}\r
254     \r
255 \subsubsection{\textbf{Aborts}}\r
256 \r
257 \begin{itemize}\r
258     \item Aborts are used to show which transactions have been aborted based on the arbitrators decision.\r
259     \item Aborts are considered live until an abort acknowledgement is presented.\r
260 \end{itemize}\r
261  \r
262 \subsection{\textbf{Setting Up New Keys (Choosing the Arbitrator)}}\r
263 Setting up new keys is done as follows:\r
264 \begin{enumerate}\r
265     \item Device wishes to generate new key\r
266     \item Device inserts a New Key notification into the data structure.\r
267 \end{enumerate}\r
268 In the case where multiple devices are creating the same key, the key with the smallest vector clock is the only valid one.  In the case of a concurrent vector clock, the smallest server sequence number notification is the valid one.\r
269     \r
270 \subsection{\textbf{Live Status}}\r
271 Live Status of entries:\r
272 \begin{enumerate}\r
273 \r
274     \item Delete notifications\r
275         \begin{itemize}\r
276             \item Live if it deleted the largest known server sequence number to be deleted (most recent delete).\r
277         \end{itemize}\r
278     \r
279     \item Commit notifications\r
280         \begin{itemize}\r
281             \item Live until all the key-value pair sets in the transaction commit are dead.\r
282                 \begin{itemize}\r
283                     \item key-value pairs are dead when a commit for a transaction that sets the same key-value pair occurs with a larger vector clock.\r
284                 \end{itemize}\r
285         \end{itemize}\r
286     \r
287     \item Abort notifications\r
288         \begin{itemize}\r
289             \item Live until the device whos machine ID is in the abort notification makes an update to the data structure that contains a vector clock that is more in the future than the vector clock for this abort notification.\r
290         \end{itemize}\r
291     \r
292     \item Data structure re-size notifications\r
293         \begin{itemize}\r
294             \item Live if it contains the largest target size of the data structure.\r
295         \end{itemize}\r
296     \r
297     \item Server sequence number confirmations.\r
298          \begin{itemize}\r
299             \item Live until the record that this notification is reporting on is deleted.\r
300         \end{itemize}\r
301         \r
302     \item Transactions\r
303         \begin{itemize}\r
304             \item Is dead if it is invalid (contains keys-values for multiple arbitrators)\r
305             \item Live until a commit or abort notification for this transaction is generated.\r
306         \end{itemize}\r
307         \r
308     \item New Key notification\r
309         \begin{itemize}\r
310             \item Is dead if there exists a New Key notification that has a server sequence number that is smaller and the same key name.\r
311         \end{itemize}\r
312     \r
313 \end{enumerate}\r
314 \r
315 \section{\textbf{Server Approach}}\r
316 \r
317 The servers view of the system is in terms of data slots where each data slot holds a single record, has a monotonically increasing number associated with it (server sequence number) for the record that currently is present in that data slot and can be set or deleted.  A server may have a finite amount of memory which it can partition into slots, reusing memory that newly deleted slots used to occupy.\r
318 \r
319 There are 3 types of requests from a device that the server must respond to:\r
320 \begin{enumerate}\r
321     \item Pull all current slots.\r
322     \item Put a new record in a slot.\r
323     \item Delete a slot.\r
324 \end{enumerate}\r
325 \r
326 \subsection{\textbf{Pull all current slots}}\r
327 In this case the server will simply send back all active slots (slots that have data) in any order along with each slots server sequence number.  It is the job of the devices to order the slots.\r
328 \r
329 \subsection{\textbf{Put a new record in a slot}}\r
330 In this case the server will:\r
331 \begin{enumerate}\r
332     \item Receive a record data from a device.\r
333     \item Put this record data in an empty slot.\r
334     \item Assign the just received record the next number in the server sequence numbers.\r
335 \end{enumerate}\r
336 If more than 1 put request is made at the same time, the server is free to order the requests however it wishes.\r
337 \r
338 \subsection{\textbf{Delete a slot}}\r
339 In this case the server will delete the data in the slot that has the server sequence number that matches the server sequence number in the delete request.  The server could delay the delete if it wishes (if it has plenty of space for new slots).\r
340 \r
341 \section{\textbf{System Guarantees}}\r
342 \begin{itemize}\r
343     \item Server cannot view data inside records\r
344     \item Server cannot forge or modify or create any records\r
345     \item Server cannot withhold any records\r
346     \item Server cannot reorder records that could not have been ordered differently due to network latency\r
347     \item Server cannot delete records unless told to do so.\r
348     \item There will always be an obvious key-value pair that is the latest key value pair.\r
349     \item The data structure is bounded in size such that $m$ is the minimum size of the data structure,  $n$ is the number of devices in the system and $s$ is the current size of the data structure: $m \leq s \leq (m+n-1)$\r
350     \item Data structure can only grow when there are too may key-value pairs (and aborts) than what fit in the current data structure size within reason.\r
351     \item No currently valid data can be lost by the system and go undetected.\r
352     \item Devices can operate offline and re-sync with the system and get a consistent view of the system\r
353     \item If the server tries to hold a device on an older version of the data structure, that device can eventually rejoin the main data structure without problems.\r
354     \item Devices that have a transaction aborted will be able to be notified about the abort indefinitely (no time frame when notification must be accepted).\r
355     \item Server cannot hold a device on an old version of the data structure and then move them to a newer version of the data structure without being detected (The server sequence numbers would reveal conflicts or gaps or both).\r
356 \r
357 \end{itemize}\r
358     \r
359 \section{System Correctness}\r
360 \r
361 \end{document}