-
Notifications
You must be signed in to change notification settings - Fork 0
/
DbFile.java
87 lines (78 loc) · 3.2 KB
/
DbFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package simpledb;
import java.util.*;
import java.io.*;
/**
* The interface for database files on disk. Each table is represented by a
* single DbFile. DbFiles can fetch pages and iterate through tuples. Each
* file has a unique id used to store metadata about the table in the Catalog.
* DbFiles are generally accessed through the buffer pool, rather than directly
* by operators.
*/
public interface DbFile {
/**
* Read the specified page from disk.
*
* @throws IllegalArgumentException if the page does not exist in this file.
*/
public Page readPage(PageId id);
/**
* Push the specified page to disk.
*
* @param p The page to write. page.getId().pageno() specifies the offset into the file where the page should be written.
* @throws IOException if the write fails
*
*/
public void writePage(Page p) throws IOException;
/**
* Adds the specified tuple to the file on behalf of transaction.
* This method will acquire a lock on the affected pages of the file, and
* may block until the lock can be acquired.
*
* @param tid The transaction performing the update
* @param t The tuple to add. This tuple should be updated to reflect that
* it is now stored in this file.
* @return An ArrayList contain the pages that were modified
* @throws DbException if the tuple cannot be added
* @throws IOException if the needed file can't be read/written
*/
public ArrayList<Page> addTuple(TransactionId tid, Tuple t)
throws DbException, IOException, TransactionAbortedException;
/**
* Removes the specifed tuple from the file on behalf of the specified
* transaction.
* This method will acquire a lock on the affected pages of the file, and
* may block until the lock can be acquired.
*
* @throws DbException if the tuple cannot be deleted or is not a member
* of the file
*/
public Page deleteTuple(TransactionId tid, Tuple t)
throws DbException, TransactionAbortedException;
/**
* Returns an iterator over all the tuples stored in this DbFile. The
* iterator must use {@link BufferPool#getPage}, rather than
* {@link #readPage} to iterate through the pages.
*
* @return an iterator over all the tuples stored in this DbFile.
*/
public DbFileIterator iterator(TransactionId tid);
/**
* Returns a unique ID used to identify this DbFile in the Catalog. This id
* can be used to look up the table via {@link Catalog#getDbFile} and
* {@link Catalog#getTupleDesc}.
* <p>
* Implementation note: you will need to generate this tableid somewhere,
* ensure that each HeapFile has a "unique id," and that you always
* return the same value for a particular HeapFile. A simple implementation
* is to use the hash code of the absolute path of the file underlying
* the HeapFile, i.e. <code>f.getAbsoluteFile().hashCode()</code>.
*
* @return an ID uniquely identifying this HeapFile.
*/
public int getId();
/**
* Returns the TupleDesc of the table stored in this DbFile.
* @return TupleDesc of this DbFile.
*/
public TupleDesc getTupleDesc();
}