simpledb

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package simpledb implements a one-table version of LevelDB

It buffers all writes in memory; to make data durable, call Compact(). This operation re-writes all of the data in the database (including in-memory writes) in a crash-safe manner. Keys in the table are cached for efficient reads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(db Database)

Close closes an open database cleanly, flushing any in-memory writes.

db should not be used afterward

func CloseTable

func CloseTable(t Table)

CloseTable frees up the fd held by a table.

func Compact

func Compact(db Database)

Compact persists in-memory writes to a new table.

This simple database design must re-write all data to combine in-memory writes with existing writes.

func DecodeUInt64

func DecodeUInt64(p []byte) (uint64, uint64)

DecodeUInt64 is a Decoder(uint64)

All decoders have the shape func(p []byte) (T, uint64)

The uint64 represents the number of bytes consumed; if 0, then decoding failed, and the value of type T should be ignored.

func EncodeSlice

func EncodeSlice(data []byte, p []byte) []byte

EncodeSlice is an Encoder([]byte)

func EncodeUInt64

func EncodeUInt64(x uint64, p []byte) []byte

EncodeUInt64 is an Encoder(uint64)

func Read

func Read(db Database, k uint64) ([]byte, bool)

Read gets a key from the database.

Returns a boolean indicating if the k was found and a non-nil slice with the value if k was in the database.

Reflects any completed in-memory writes.

func Shutdown

func Shutdown(db Database)

Shutdown immediately closes the database.

Discards any uncommitted in-memory writes; similar to a crash except for cleanly closing any open files.

func UseMarshal added in v0.4.5

func UseMarshal()

func Write

func Write(db Database, k uint64, v []byte)

Write sets a key to a new value.

Creates a new key-value mapping if k is not in the database and overwrites the previous value if k is present.

The new value is buffered in memory. To persist it, call db.Compact().

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database is a handle to an open database.

func NewDb

func NewDb() Database

NewDb initializes a new database on top of an empty filesys.

func Recover

func Recover() Database

Recover restores a previously created database after a crash or shutdown.

type Entry

type Entry struct {
	Key   uint64
	Value []byte
}

Entry represents a (key, value) pair.

func DecodeEntry

func DecodeEntry(data []byte) (Entry, uint64)

DecodeEntry is a Decoder(Entry)

type Table

type Table struct {
	Index map[uint64]uint64
	File  filesys.File
}

A Table provides access to an immutable copy of data on the filesystem, along with an index for fast random access.

func CreateTable

func CreateTable(p string) Table

CreateTable creates a new, empty table.

func RecoverTable

func RecoverTable(p string) Table

RecoverTable restores a table from disk on startup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL