YACDB
Yet Another C(rappy) Database
diskio.h File Reference

Interactions with the disk and cache. More...

#include <assert.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "db_structs.h"
#include "../../schema/include/record.h"
Include dependency graph for diskio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  linked_overflow
 
struct  key_value
 
struct  node
 The basic structure stored in memory. More...
 
struct  cached_node
 A struct for holding cached nodes. More...
 

Macros

#define ORDER   4
 

Typedefs

typedef unsigned long Key
 A key to a record. More...
 

Functions

bool is_leaf (struct node *node)
 Verifies if the node is a leaf.
 
struct noderead_node (Page addr)
 Reads a node from disk at a given address. More...
 
int write_node (struct node *node, Page addr)
 Writes a node to disk (or cache) at a given address. If an error occurs returns -1.
 
int remove_node (Page addr)
 Removes a node from disk at a given address. If an error occurs returns -1.
 
Page create_addr ()
 Creates an address for a new node. If an error occurs returns -1. More...
 
int init_db ()
 initializes the database
 
struct nodecreate_node ()
 
int add_to_cache (struct node *node, Page addr)
 Adds a node to the beginning of the linked list that is cache. If the size of cache is greater than the max cache size, the last node of the list is removed. More...
 
struct nodeget_from_cache (Page addr)
 Get a node from the cache. This node will be a copy of the node in the cache. More...
 
int remove_node_from_cache (struct cached_node *last_node)
 Removes a node from cache, erasing it permanently.
 
void free_node (struct node *node)
 Free's a node.
 

Variables

struct yacdb db
 The database.
 

Detailed Description

Interactions with the disk and cache.

Author
Jack Royer
Date
2022-05-29

Typedef Documentation

◆ Key

Key

A key to a record.

This type is mainly used for auto-documentation, in order to better destinguish keys from addresses.

Function Documentation

◆ add_to_cache()

int add_to_cache ( struct node node,
Page  addr 
)

Adds a node to the beginning of the linked list that is cache. If the size of cache is greater than the max cache size, the last node of the list is removed.

Adds a node to the beginning of the linked list that is cache. If the size of cache is greater than the max cache size, the last node of the list is removed.

◆ create_addr()

Page create_addr ( )

Creates an address for a new node. If an error occurs returns -1.

Creates an address for a new node. If an error occurs returns -1.

TODO: Cache optimization

Returns
the page number or -1 if an error occurred.

◆ get_from_cache()

struct node * get_from_cache ( Page  addr)

Get a node from the cache. This node will be a copy of the node in the cache.

If no node is found or an error occurs, returns NULL.

Get a node from the cache. This node will be a copy of the node in the cache.

◆ read_node()

struct node * read_node ( Page  addr)

Reads a node from disk at a given address.

Parameters
addrThe page number of the node
Returns
a pointer to the node.
Exceptions
ReturnsNULL if an error occurred