This is not the current version of the class.

Synchronization 3: Databases

Overview

In this lecture, we build a correctly-synchronized networked database.

Key-value database

Network API

Clients and servers

WeensyDB server loop

int fd = open_listen_socket(port);
// `fd` doesn’t receive *data*—it receives *new connections*

while (true) {
    struct sockaddr addr;
    socklen_t addrlen = sizeof(addr);

    // Accept connection on listening socket
    int cfd = accept(fd, &addr, &addrlen);
    // `cfd` is a new connection from the computer at `addr`

    // Handle connection
    handle_connection(cfd, unparse_sockaddr(&addr, addrlen));
    // `handle_connection` closes `cfd` when done
}

WeensyDB internals

WeensyDB protocol

kohler@unshare$ telnet cs61 6162
Trying 34.193.34.22...
Connected to cs61.seas.harvard.edu.
Escape character is '^]'.
$get hello
END
$set hello 3          [3 = size of value]
$Hi
STORED #1
$get hello
VALUE hello 3 #1
Hi
END
$delete hello
DELETED #1
$set hello 9
$Hi again
STORED #2
$quit
Connection closed by foreign host.

Synchronization issues

dbmap API