# Part 0: Skeleton Code

![Data x-ray](/files/-MJf0sWTySoRpQ59STxi)

Read through all of the code in the `concurrency` directory (including the classes that you are not touching - they may contain useful methods or information pertinent to the project). Many comments contain critical information on how you must implement certain functions.

Try to understand how each class fits in: what is each class responsible for, what are all the methods you have to implement, and how does each one manipulate the internal state. Trying to code one method at a time without understanding how all the parts of the lock manager work often results in having to rewrite significant amounts of code.

## Layers

![](/files/-MJf0sWUPPSPlPQX4uYp)

The skeleton code divides multigranularity locking into three layers.

* The `LockManager` object manages all the locks, treating each resource as independent (it doesn't consider the resource hierarchy at all). This level is responsible queuing logic, blocking/unblocking transactions as necessary, and is the single source of authority on whether a transaction has a certain lock. If the `LockManager` says T1 has X(database), then T1 has X(database).
* A collection of `LockContext` objects, which each represent a single lockable object (e.g. a page or a table) lies on top of the `LockManager`. The `LockContext` objects are connected according to the hierarchy (e.g. a `LockContext` for a table has the database context as its parent, and its pages' contexts as children). The `LockContext` objects all share a single `LockManager`, and each context enforces multigranularity constraints on its methods (e.g. an exception will be thrown if a transaction attempts to request X(table) without IX(database)).
* A declarative layer lies on top of the collection of `LockContext` objects, and is responsible for acquiring all the intent locks needed for each S or X request that the database uses (e.g. if S(page) is requested, this layer would be responsible for requesting IS(database), IS(table) if necessary).

In Part 1, you will be implementing the bottom layer (`LockManager`) and lock types. In Part 2, you will be implementing the middle and top layer (`LockContext` and `LockUtil`), and integrate your changes into the database.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cs186.gitbook.io/project/assignments/proj4/skeleton-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
