Documentation ¶
Overview ¶
Package dskvs is an embedded, in memory key value store following the REST convention of adressing resources as being 'collections' and 'members'.
The main features of dskvs are:
- very high read performance
- high write performance
- safe for concurrent use by multiple readers/writers.
- every read/write is done in memory. Writes are persisted asynchronously
- remains usable under heavy concurrent usage, although throughput is not-optimal
- can load []byte values of any size
- persisted files are always verified for consistency
In dskvs, a collection contains many members, a member contains a value. A full key is a combination of both the collection and member identifiers to a value.
Example:
fullkey := "artist" + CollKeySep + "Daft Punk"
In this example, 'artist' is a collection that contains many artists. 'Daft Punk' is one of those artists.
Example:
fullkey := "artist" + CollKeySep + "Daft Punk" + CollKeySep + "Discovery.."
A fullkey can contain many CollKeySep; only the first encountered is considered for the collection name.
Every entry of dskvs is saved as a file under a path. If you tell dskvs to use the base path "$HOME/dskvs", it will prepare a filename for your key such as :
colletion := "This Collection" key := "Is the Greatest!!!" escapedKey := filepathSafe(key) // escapes all dangerous characters truncatedKey := escapedKey[:40] // truncate the key to 40 runes member := truncatedKey + sha1(key) // append the truncated key to the SHA1 of // the original key to prevent collisions
dskvs will then write the entry at the path :
$HOME/dskvs/<collection>/<member>
Example:
fullkey := "artist" + CollKeySep + "Daft Punk" + CollKeySep + "Discovery.." collection := "artist" member := "Daft+Punk%2FDiscovery..446166742050756e6b2f446973636f766572792e2eda39a3ee5e6b4b0d3255bfef95601890afd80709"
Given that keys have their value escaped, you can safely use any key:
fullkey := "My Collection/../../"
Will yield :
collection == "My Collection" member == "..%2F..%2F2e2e2f2e2e2fda39a3ee5e6b4b0d3255bfef95601890afd80709"
Index ¶
Constants ¶
const ( // MajorVersion is used to ensure that incompatible fileformat versions are // not loaded in memory. MajorVersion uint16 = 0 // MinorVersion is used to differentiate between fileformat versions. It might // be used for migrations if a future change to dskvs breaks the original // fileformat contract MinorVersion uint16 = 4 // PatchVersion is used for the same reasons as MinorVersion PatchVersion uint64 = 2 )
const ( FILE_PERM = 0640 DIR_PERM = 0740 )
Variables ¶
var ( // CollKeySep is the value used by dskvs to separate the // collection part of the full key from the member part. This is usually // '/' on Unix systems. CollKeySep = string(filepath.Separator) )
Functions ¶
This section is empty.
Types ¶
type KeyError ¶
A KeyError is returned when the key you provided is either not a valid key due to its nature, or is not appropriate for the method on which you use it.
type PathError ¶
A PathError is returned when the path you provided is not suitable for storage, either because of its intrisic nature or because it is already in use by another storage. In the latter case, you should verify your code to ensure that you are not forgetting a storage instance somewhere.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides methods to manipulate the data held in memory and on disk at the path that was specified when you instantiated it. Every store instance points at a different path location on disk. Beware if you create a store that lives within the tree of another store. There's no garantee to what will happen, aside perhaps a garantee that things will go wrong.
func Open ¶
Open creates a new store then retrieves previously persisted entries and load them in memory. If there are no such entries, it returns an empty store.
Every entry file is checked for consistency with a SHA1 checksum. A file that is not consistent will be ignored, a log message emitted and an error returned. This call will block until all collections have been replenished.
func (*Store) Close ¶
Close finishes writing dirty updates and closes all the files. It reports any error that occured doing so. This call will block until the writes are completed.
func (Store) Get ¶
Get returns the value referenced by the `fullKey` given in argument. A `fullKey` is a string that has a collection identifier and a member identifier, separated by `CollKeySep`, Ex:
val, ok, err := store.Get("artists/daft_punk")
will get the value attached to Daft Punk, from within the Artists collection. If the value doesn't exist in the store, ok will be false.
ATTENTION : do not modify the value of the slices that are returned to you.
func (Store) GetAll ¶
GetAll returns all the members in the collection `coll`.
ATTENTION : do not modify the value of the slices that are returned to you.
type StoreError ¶
type StoreError struct {
What string
}
A StoreError is returned when the store you try to use is not properly setup.
func (StoreError) Error ¶
func (e StoreError) Error() string