Skip to content

Commit

Permalink
Change API to accept request to verify empty sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Oct 9, 2013
1 parent a455149 commit 90a0ec3
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 310 deletions.
196 changes: 0 additions & 196 deletions api.go

This file was deleted.

14 changes: 5 additions & 9 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func (c *collections) get(coll, key string) ([]byte, bool) {
return val, ok
}

func (c *collections) getCollection(coll string) ([][]byte, error) {
func (c *collections) getCollection(coll string) [][]byte {
c.RLock()
m, ok := c.members[coll]
c.RUnlock()

if !ok {
return nil, errorNoSuchColl(coll)
return nil
}

return m.getMembers(), nil
return m.getMembers()
}

func (c *collections) put(coll, key string, value []byte) {
Expand Down Expand Up @@ -80,7 +80,7 @@ func (c *collections) deleteKey(coll, key string) error {
return nil
}

func (c *collections) deleteCollection(coll string) error {
func (c *collections) deleteCollection(coll string) {
c.RLock()
_, ok := c.members[coll]
c.RUnlock()
Expand All @@ -92,16 +92,12 @@ func (c *collections) deleteCollection(coll string) error {
c.Unlock()
// Was deleted in between our read-lock and the current write-lock
if !ok {
return errorNoSuchColl(coll)
return
}

// TODO : This is not really necessary, can just delete the folder
// at once and save some IO.
m.deleteAll()
jan.deleteFolder(m)
} else {
return errorNoSuchColl(coll)
}

return nil
}
68 changes: 68 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
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"
*/
package dskvs

0 comments on commit 90a0ec3

Please sign in to comment.