Homework 6

Q1 20pts Below is a log of a transactional database.

LOG

<Start T1>
<T1, A, 5>
<T1, B, 9>
<Start T3>
<Start T2>
<T2, C, 1>
<Commit T1>
<Abort T2>
<Start T4>
<T4, B, 90>
<Commit T4>
<T3, A, 3>
crash

a. Suppose this was an UNDO-log. What are the values of A, B, and C after recovery? Write “NA” if that value is unknowable from this log.

b. Suppose this was a REDO-log. What are the values of A, B, and C after recovery? Write “NA” if that value is unknowable from this log.


Q2 15pts Use 2 phase locking (2PL) to enforce a serializable schedule of two interleaved transactions shown below  (use read, write, lock, unlock):

T1 = READ(A,t);    t := t+12;    WRITE(A,t);  READ(B,t);    t := t+2;    WRITE(B,t);
T2 = READ(B,t);    t := t*4;     WRITE(B,t); 
TxActiontMem AMem B
T1lock1(A)1442

Q3: 30pts MapReduce on Databases is the magic behind BigData processing. One important note is that there is usually lots of metadata in the tuple that was not included on the board exercises. In this problem, metadata of a tuple is indicated as a sub-tuple. For example: v = ((1,A), Kansas, 6) means that this tuple has a primary key 1, and lives in table A. We can access it with v.meta.table = ‘A’ and v.meta.key = 1, and we can access the tuple data with v.state = ‘Kansas’ and v.x = 6.

Relations A and B have the same schema with three columns (key, state, x). Write map and reduce code to perform an inner join between relation A and B on the key-columns.

Server1			       Server2			        Server3
(1, ((1,A), Kansas, 6))       (4, ((4,B), Washington, 12))	(3, ((3,A), Idaho, 4))
(2, ((2,A), Indiana, 11))     (3, ((3,B), New York, 29)) 	(2, ((2,B), Illinois, 20))
			      (1, ((1,B), Vermont, 3))
public void map(key k, tuple v):



public void reduce(key k, list v):



Q4: 20pts Say there are 3 mappers over three servers and 1 reducer. For the data and code in Q3 show the actual values that are:

a. output from each the 3 mappers
b. input to the reducer
c. output from the reducer

Write the data, be verbose.


Q5: 15pts SQL Injection attacks are an enormous problem in Web application development: https://en.wikipedia.org/wiki/SQL_injection

Read up on it and its details.

Now, say I have some PHP code that looks like this:

$uname = $_POST['username'];
$passwd = $_POST['password'];

$sql = “SELECT id FROM users WHERE username='" . $uname . "' AND password='" . $passwd . "'";

$result = mysql_query($db, $sql)

from a Web form that looks like this:

a. Explain why this code is vulnerable to SQL injection attacks.
b. Design a SQL injection attack that drops the user table.
c. Fix this vulnerable PHP code so that it is no longer susceptible to SQL injection.


Q6: 1pt Extra Credit – Give Relation A and Relation B from Q3 appropriate names. What does this data represent?