db

package
v0.0.0-...-8699cbc Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2014 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

Coordination between a collection of chunks.

Database is a collection of collections.

Query processor for embedded and HTTP API V2.

Index

Constants

View Source
const (
	HASHTABLE_DIRNAME_MAGIC = "ht_"    // Hash table directory name prefix
	CHUNK_DIRNAME_MAGIC     = "chunk_" // Chunk directory name prefix
	INDEX_PATH_SEP          = ","      // Separator between index path segments
)
View Source
const (
	NUMCHUNKS_FILENAME = "numchunks"
)

Variables

This section is empty.

Functions

func Complement

func Complement(subExprs interface{}, src *Col, result *map[uint64]struct{}) (err error)

Calculate complement of sub query results.

func EvalAllIDs

func EvalAllIDs(src *Col, result *map[uint64]struct{}) (err error)

Put all document IDs into result.

func EvalQuery

func EvalQuery(q interface{}, src *Col, result *map[uint64]struct{}) (err error)

Main entrance to query processor - evaluate a query and put result into result map (as map keys).

func EvalUnion

func EvalUnion(exprs []interface{}, src *Col, result *map[uint64]struct{}) (err error)

Calculate union of sub-query results.

func GetIn

func GetIn(doc interface{}, path []string) (ret []interface{})

Resolve the attribute(s) in the document structure along the given path.

func IntRange

func IntRange(intFrom interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Scan hash table or collection documents using an integer range.

func Intersect

func Intersect(subExprs interface{}, src *Col, result *map[uint64]struct{}) (err error)

Calculate intersection of sub query results.

func Lookup

func Lookup(lookupValue interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Execute value equity check ("attribute == value") using hash lookup or collection scan.

func ParameterizeJSON

func ParameterizeJSON(q string, params ...string) string

Detect ? characters outside of an embedded string, and replace them with the appropriate parameter, which will be encoded as a string. Does not verify that the resulting JSON is valid, but should not allow injecting parameters that change the structure of the source JSON (a la SQL injection). Use this to derive final query strings from any user-supplied input.

ParameterizeJSON(`{"eq": "New Go release", "in": [?]}`, `"thing1","thing2"`) -> {"eq": "New Go release", "in": ["\"thing1\",\"thing2\""]}

func PathExistence

func PathExistence(hasPath interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Execute value existence check.

func RegexpLookup

func RegexpLookup(lookupRegexp interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Execute value match regexp using hash lookup or collection scan.

Types

type Col

type Col struct {
	BaseDir      string // Collection dir path
	Chunks       []*chunk.ChunkCol
	ChunkMutexes []*sync.RWMutex // Synchronize access to chunks
	NumChunks    int             // Total number of chunks
	NumChunksI64 uint64          // Total number of chunks (uint64)

	// Secondary indexes (hashtables)
	SecIndexes map[string][]*chunkfile.HashTable
}

func OpenCol

func OpenCol(baseDir string, numChunks int) (col *Col, err error)

Open a collection (made of chunks).

func (*Col) Close

func (col *Col) Close()

Close the collection.

func (*Col) Delete

func (col *Col) Delete(id uint64)

Delete a document given its unique ID.

func (*Col) DeserializeAll

func (col *Col) DeserializeAll(template interface{}, fun func() bool)
Sequentially deserialize all documents into the template (pointer to struct) and invoke the function on each document (Collection Scan).

The function must not write to this collection.

func (*Col) Flush

func (col *Col) Flush() error

Flush collection data and index files.

func (*Col) ForAll

func (col *Col) ForAll(fun func(id uint64, doc map[string]interface{}) bool)
Sequentially deserialize all documents and invoke the function on each document (Collection Scan).

The function must not write to this collection.

func (*Col) HashScan

func (col *Col) HashScan(htPath string, key, limit uint64) (keys, vals []uint64)

func (*Col) Index

func (col *Col) Index(indexPath []string) error

Create a new index.

func (*Col) Insert

func (col *Col) Insert(doc map[string]interface{}) (id uint64, err error)

Insert a document, return its unique ID.

func (*Col) InsertRecovery

func (col *Col) InsertRecovery(knownID uint64, doc map[string]interface{}) (err error)

Insert a document without allocating a new ID to it. Only for collection recovery operation.

func (*Col) Read

func (col *Col) Read(id uint64, doc interface{}) (physID uint64, err error)

Read a document given its unique ID.

func (*Col) ReadNoLock

func (col *Col) ReadNoLock(id uint64, doc interface{}) (physID uint64, err error)

Read a document given its unique ID (without placing any lock).

func (*Col) Unindex

func (col *Col) Unindex(indexPath []string) (err error)

Remove a secondary index.

func (*Col) Update

func (col *Col) Update(id uint64, newDoc map[string]interface{}) (err error)

Update a document given its unique ID.

type DB

type DB struct {
	BaseDir string          // Database directory path
	StrCol  map[string]*Col // Collection name to collection mapping
}

func OpenDB

func OpenDB(baseDir string) (db *DB, err error)

func (*DB) Close

func (db *DB) Close()

Close all collections.

func (*DB) Create

func (db *DB) Create(name string, numChunks int) (err error)

Create a collection.

func (*DB) Drop

func (db *DB) Drop(name string) (err error)

Drop (delete) a collection.

func (*DB) Flush

func (db *DB) Flush()

Flush all collection data and index files.

func (*DB) Rename

func (db *DB) Rename(oldName, newName string) (err error)

Rename a collection.

func (*DB) Repartition

func (db *DB) Repartition(name string, newNumber int) (counter uint64, err error)

Change the number of partitions in collection

func (*DB) Scrub

func (db *DB) Scrub(name string) (counter uint64, err error)

Compact and repair a collection.

func (*DB) Use

func (db *DB) Use(name string) *Col

Return collection reference by collection name. This function is safe for concurrent use.

Jump to

Keyboard shortcuts

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