Skip to content

Commit 908b5d9

Browse files
committedOct 1, 2017
Spellcheck
1 parent fe57bef commit 908b5d9

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed
 

‎_parts/part3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ date: 2017-09-01
66
We're going to start small by putting a lot of limitations on our database. For now, it will:
77

88
- support two operations: inserting a row and printing all rows
9-
- reside only in memory (no persistance to disk)
9+
- reside only in memory (no persistence to disk)
1010
- support a single, hard-coded table
1111

1212
Our hard-coded table is going to store users and look like this:

‎_parts/part4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ end
299299
continue;
300300
```
301301

302-
Alright, that's enough testing for now. Next is a very important feature: persistance! We're going to save our database to a file and read it back out again.
302+
Alright, that's enough testing for now. Next is a very important feature: persistence! We're going to save our database to a file and read it back out again.
303303

304304
It's gonna be great.
305305

‎_parts/part5.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131

3232
Like sqlite, we're going to persist records by saving the entire database to a file.
3333

34-
We already set ourselves up to do that by serializing rows into page-sized memory blocks. To add persistance, we can simply write those blocks of memory to a file, and read them back into memory the next time the program starts up.
34+
We already set ourselves up to do that by serializing rows into page-sized memory blocks. To add persistence, we can simply write those blocks of memory to a file, and read them back into memory the next time the program starts up.
3535

3636
To make this easier, we're going to make an abstraction called the pager. We ask the pager for page number `x`, and the pager gives us back a block of memory. It first looks in its cache. On a cache miss, it copies data from disk into memory (by reading the database file).
3737

@@ -255,7 +255,7 @@ Lastly, we need to accept the filename as a command-line argument:
255255
+ Table* table = db_open(filename);
256256
+
257257
```
258-
With these changes, we're able to close then reopen the database, and our records are stil there!
258+
With these changes, we're able to close then reopen the database, and our records are still there!
259259

260260
```
261261
~ ./db mydb.db
@@ -274,23 +274,23 @@ db > .exit
274274
~
275275
```
276276

277-
For extra fun, let's take a look at `mydb.db` to see how our data is being stored. I'll use vim as a hex editior to look at the memory layout of the file:
277+
For extra fun, let's take a look at `mydb.db` to see how our data is being stored. I'll use vim as a hex editor to look at the memory layout of the file:
278278

279279
```
280280
vim mydb.db
281281
:%!xxd
282282
```
283283
{% include image.html url="assets/images/file-format.png" description="Current File Format" %}
284284

285-
The first four bytes are the id of the first row (4 bytes because we store a uint32_t). It's stored in little-endian byte order, so the least signifigant byte comes first (01), followed by the higher-order bytes (00 00 00). We used `memcpy()` to copy bytes from our `Row` struct into the page cache, so that means the struct was laid out in memory in little-endian byte order. That's an attribute of the machine I compiled the program for. If we wanted to write a database file on my machine, then read it on a big-endian machine, we'd have to change our `serialize_row()` and `deserialize_row()` methods to always store and read bytes in the same order.
285+
The first four bytes are the id of the first row (4 bytes because we store a uint32_t). It's stored in little-endian byte order, so the least significant byte comes first (01), followed by the higher-order bytes (00 00 00). We used `memcpy()` to copy bytes from our `Row` struct into the page cache, so that means the struct was laid out in memory in little-endian byte order. That's an attribute of the machine I compiled the program for. If we wanted to write a database file on my machine, then read it on a big-endian machine, we'd have to change our `serialize_row()` and `deserialize_row()` methods to always store and read bytes in the same order.
286286

287-
The next 33 bytes store the username as a null-terminated string. Apparently "cstack" in ASCII hexidecimal is `63 73 74 61 63 6b`, followed by a null character (`00`). The rest of the 33 bytes are unused.
287+
The next 33 bytes store the username as a null-terminated string. Apparently "cstack" in ASCII hexadecimal is `63 73 74 61 63 6b`, followed by a null character (`00`). The rest of the 33 bytes are unused.
288288

289289
The next 256 bytes store the email in the same way. Here we can see some random junk after the terminating null character. This is most likely due to uninitialized memory in our `Row` struct. We copy the entire 256-byte email buffer into the file, including any bytes after the end of the string. Whatever was in memory when we allocated that struct is still there. But since we use a terminating null character, it has no effect on behavior.
290290

291291
## Conclusion
292292

293-
Alright! We've got persistence. It's not the greatest. For example if you kill the program without typing `.exit`, you lose your changes. Additionallly, we're writing all pages back to disk, even pages that haven't changed since we read them from disk. These are issues we can address later. The next thing I think we should work on is implementing the B-tree.
293+
Alright! We've got persistence. It's not the greatest. For example if you kill the program without typing `.exit`, you lose your changes. Additionally, we're writing all pages back to disk, even pages that haven't changed since we read them from disk. These are issues we can address later. The next thing I think we should work on is implementing the B-tree.
294294

295295
Until then!
296296

‎_parts/part7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The picture from above is a B-Tree, which SQLite uses to store indexes. To store
3333
| Number of children per node | Less | More |
3434
| Internal nodes vs. leaf nodes | Same structure | Different structure |
3535

36-
Until we get to implementing indexes, I'm going to talk soley about B+ trees, but I'll just refer to it as a B-tree or a btree.
36+
Until we get to implementing indexes, I'm going to talk solely about B+ trees, but I'll just refer to it as a B-tree or a btree.
3737

3838
Nodes with children are called "internal" nodes. Internal nodes and leaf nodes are structured differently:
3939

0 commit comments

Comments
 (0)
Please sign in to comment.