8c11982fa75b9eb640b00b89a6009321f767245e
[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{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 Add a random salt (or nonce) for the encryption safety\r
105     \item Data payload\r
106     \item HMAC of the record.\r
107 \end{itemize}\r
108     \r
109 \r
110 \r
111 \subsubsection{\textbf{Types of Payloads}}\r
112 The different types of record payloads are:\r
113 \begin{itemize}\r
114     \item Delete notifications\r
115         \begin{itemize}\r
116             \item Contains the HMAC of records that were deleted by devices, Their vector clocks and the server sequence numbers.\r
117             \item Generated when a device deletes a record.\r
118             \item The delete notification with the largest server sequence number in its delete payload is the live one (the one that contains the largest server sequence number of the record deleted to date).  \r
119         \end{itemize}\r
120     \item Commit notifications\r
121         \begin{itemize}\r
122             \item Contains list of transactions that are committed in order of commit and the current key-value pair for that key.\r
123             \item Generated by the arbitrator of a key and only the for that key (1 arbitrator per key).\r
124             \item Used in the case that there is a key value pair that needs reordering.\r
125         \end{itemize}\r
126     \item Abort notifications\r
127         \begin{itemize}\r
128             \item Contains a transaction ID of an aborted transaction and the machine ID of the device that created that transaction.\r
129             \item Causes a transaction to be aborted.\r
130         \end{itemize}\r
131     \item Abort acknowledgement notifications\r
132         \begin{itemize}\r
133             \item Contains a transaction ID of an aborted transaction, the machine ID of the device that created that transaction and the abort notification ID that this is acknowledging.\r
134             \item Causes an abort notification to become dead.\r
135             \item Is generated by the device that had created an aborted transaction as an acknowledgement that it saw the aborted transaction notification.\r
136             \item This payload type immediately becomes dead (not live) upon insertion into the data structure.\r
137         \end{itemize}\r
138     \item Data structure re-size notifications\r
139         \begin{itemize}\r
140             \item Contains new size of data structure (number of record allowed in the data structure or something like that).\r
141             \item Causes old data Structure re-size notification to no longer be live.\r
142         \end{itemize}\r
143     \item Server sequence number for a specific record notifications\r
144         \begin{itemize}\r
145             \item Contains a record HMAC and the server sequence number for that record\r
146         \end{itemize}\r
147     \item Transactions\r
148         \begin{itemize}\r
149             \item Contains:\r
150             \begin{itemize}\r
151                 \item Transaction ID\r
152                 \item A guard condition that can be evaluated\r
153                 \item A set of key-value pairs that are to be updated if the guard condition is met.\r
154             \end{itemize}\r
155         \end{itemize}\r
156 \end{itemize}\r
157 \r
158 \r
159 \subsection{\textbf{Updates (Online Updates)}}\r
160 Updates take place as follows:\r
161 \begin{enumerate}\r
162     \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
163     \item The device makes a record as follows:\r
164         \begin{enumerate}\r
165             \item Adds its machine ID.\r
166             \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
167             \item Add a random salt (or nonce) for the encryption safety\r
168             \item Fill the record data section with the transactions, key-value pairs, ext.\r
169             \item Fill the remainder of the data section with rescued key-value pairs, transactions, ext (Discussed later).\r
170             \item Pad the record to be the same size for all records.\r
171             \item Calculate the HMAC of the record and add that to the record\r
172             \item Encrypt the record.\r
173         \end{enumerate}\r
174     \item Send the record to the server for insertion into the device's queue.\r
175     \item Wait for response from server stating the new records (the one just sent) server sequence number.  Save this server sequence number for when creating the next record.\r
176     \item \r
177 \end{enumerate}\r
178 \r
179 \r
180 \subsection{\textbf{Updates when offline}}\r
181 When offline and making updates, the devices should use their local copy of the data structure but do no deletes.  When connection is reestablished the following should take place:\r
182 \r
183 \begin{enumerate}\r
184     \item Pull the latest version of the data structure.\r
185     \item Update local copy of the data structure except for own devices device queue (do deletions as needed)\r
186     \item Calculate many records are "new" to the data structure and pick the same amount to be deleted\r
187     \item Push the updates and the deletes to the server\r
188     \item Wait for sequence numbers for the recently pushed records\r
189     \item Push the sequence numbers for the recently pushed records (using online updates from the section above)\r
190 \end{enumerate}\r
191 \r
192 This kind of update will result in the latest key-value pair being the last pushed record from this update (if no other updates are occurring at the same time).  The arbitrator can then commit or abort as needed but in the mean time the key-value pair may be an old one (but have the largest server sequence number).\r
193 \r
194 \subsection{\textbf{Deletions}}\r
195 When deciding which records to delete the following is to be done:\r
196 \begin{enumerate}\r
197     \item Order all the records in order based on their server sequence numbers\r
198     \item Calculate the difference between the current size of the data structure and the minimum size of the data structure (lets call this $m$)\r
199     \item Delete the oldest m records based on the ordering from step 1. \r
200     \begin{itemize}\r
201         \item If a record to be deleted has live data in it then the whole data structure needs to be resized.\r
202     \end{itemize}\r
203 \end{enumerate}\r
204 \r
205 Note this makes that size of the data structure be bounded.\r
206 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$ for the case when all the devices make an update at the same time.   \r
207 \r
208 \subsection{\textbf{Rescuing Transactions, Commits, Aborts, Ext}}\r
209 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
210 \r
211 When deciding which data to rescue the following is to be done:\r
212 \begin{enumerate}\r
213     \item Order all the records in order based on their server sequence numbers\r
214     \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 .\r
215     \item Randomly select from the list of live data to save.  Save as much as can fit in the current new record.  The random selection could give higher probability to data from records that are to be deleted sooner.\r
216 \end{enumerate}\r
217 \r
218 If a record needs to be deleted but still contains live data then the data structure needs to be resized.  \r
219 \r
220 \subsection{\textbf{Checking the Data Structure}}\r
221 Checking the data structure for consistency is done as follows:\r
222 \begin{enumerate}\r
223     \item Verify that each record in the data structure has an HMAC that matches the data in the record.\r
224     \item Verify that there are at least as many records in the data structure as stated in the largest data structure size record.\r
225     \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.\r
226     \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
227     \item Verify that all the server sequence numbers for the records that are currently present have unique numbers that have a difference of 1 (no gaps).\r
228     \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
229     \item \r
230 \end{enumerate}\r
231 \r
232 \r
233 \subsection{\textbf{The Arbitrator}}\r
234 The arbitrator can:\r
235 \begin{enumerate}\r
236     \item Send Commits\r
237     \item Send Aborts\r
238 \end{enumerate}\r
239     \r
240 \subsubsection{\textbf{Commits}}\r
241 Commits have the following properties\r
242 \begin{itemize}\r
243     \item Agree with the ordering of the server sequence numbers\r
244     \item Once a key-value pair is commited it can not be commited again.\r
245     \item Cannot commit an already aborted transaction.\r
246     \item Commits state the ordering of key-value pairs.\r
247     \item Can disagree with the ordering of server sequence numbers but\r
248     \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
249 \end{itemize}\r
250     \r
251 \subsubsection{\textbf{Aborts}}\r
252 Aborts are used to show which transactions have been aborted and will not be used in the total ordering of the transactions.  Aborts are considered live until an abort acknowledgement is presented.\r
253 When the transaction is aborted then the devices should simply act as if it were never present when evaluating for the latest key-value pair.\r
254     \r
255 \subsection{\textbf{Live Status}}\r
256 Live Status of entries:\r
257 \begin{enumerate}\r
258     \item Key-Value Entry/Data Entry is dead if either:\r
259     \begin{enumerate}\r
260         \item There is a newer key-value pair:\r
261         \begin{itemize}\r
262             \item There is a transaction with a newer vector clock value.\r
263             \item There is a commit that for this key-value pair.\r
264             \item There is an abort for this key-value pair.\r
265         \end{itemize}\r
266         \item It is incomplete.\r
267         \item It is an abort notification that has an abort notification acknowledgment\r
268         \item It is an abort notification acknowledgment (dead on arrival).\r
269     \end{enumerate}\r
270     \item Data is live if there are multiple versions of the same data (key-value pair) in which the vector clock values show concurrency.  All versions are kept live the arbitrator arbitrates.\r
271     \item Multiple versions of the same data (same transaction ID for example) are not all live.  Only the version with the largest server sequence number is live.  \r
272     \r
273 \end{enumerate}\r
274 \r
275     \r
276 \r
277 \end{document}