Remove go-datastore from Godeps
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jun 11, 2016 at 16:11 UTC
6217e1f141534576768aa792bc96b2df07d8b25f
88 files changed
+84
-4054
Godeps/Godeps.json
-4
@@ -29,10 +29,6 @@
29
"ImportPath": "github.com/hashicorp/golang-lru",
30
"Rev": "253b2dc1ca8bae42c3b5b6e53dd2eab1a7551116"
31
},
32
- {
33
- "ImportPath": "github.com/ipfs/go-datastore",
34
- "Rev": "e63957b6da369d986ef3e7a3f249779ba3f56c7e"
35
- },
32
{
33
"ImportPath": "github.com/jbenet/go-detect-race",
34
"Rev": "3463798d9574bd0b7eca275dccc530804ff5216f"
Godeps/_workspace/src/github.com/ipfs/go-datastore/.travis.yml
deleted
-11
@@ -1,11 +0,0 @@
1
-language: go
2
-
3
-go:
4
- - 1.3
5
- - release
6
- - tip
7
-
8
-script:
9
- - make test
10
-
11
-env: TEST_NO_FUSE=1 TEST_VERBOSE=1
Godeps/_workspace/src/github.com/ipfs/go-datastore/Godeps/Godeps.json
deleted
-76
@@ -1,76 +0,0 @@
1
-{
2
- "ImportPath": "github.com/jbenet/go-datastore",
3
- "GoVersion": "go1.5",
4
- "Packages": [
5
- "./..."
6
- ],
7
- "Deps": [
8
- {
9
- "ImportPath": "github.com/Sirupsen/logrus",
10
- "Comment": "v0.8.3-37-g418b41d",
11
- "Rev": "418b41d23a1bf978c06faea5313ba194650ac088"
12
- },
13
- {
14
- "ImportPath": "github.com/codahale/blake2",
15
- "Rev": "3fa823583afba430e8fc7cdbcc670dbf90bfacc4"
16
- },
17
- {
18
- "ImportPath": "github.com/codahale/hdrhistogram",
19
- "Rev": "5fd85ec0b4e2dd5d4158d257d943f2e586d86b62"
20
- },
21
- {
22
- "ImportPath": "github.com/codahale/metrics",
23
- "Rev": "7d3beb1b480077e77c08a6f6c65ea969f6e91420"
24
- },
25
- {
26
- "ImportPath": "github.com/dustin/randbo",
27
- "Rev": "7f1b564ca7242d22bcc6e2128beb90d9fa38b9f0"
28
- },
29
- {
30
- "ImportPath": "github.com/fzzy/radix/redis",
31
- "Comment": "v0.5.1",
32
- "Rev": "27a863cdffdb0998d13e1e11992b18489aeeaa25"
33
- },
34
- {
35
- "ImportPath": "github.com/hashicorp/golang-lru",
36
- "Rev": "4dfff096c4973178c8f35cf6dd1a732a0a139370"
37
- },
38
- {
39
- "ImportPath": "github.com/ipfs/go-log",
40
- "Rev": "ee5cb9834b33bcf29689183e0323e328c8b8de29"
41
- },
42
- {
43
- "ImportPath": "github.com/jbenet/go-os-rename",
44
- "Rev": "2d93ae970ba96c41f717036a5bf5494faf1f38c0"
45
- },
46
- {
47
- "ImportPath": "github.com/jbenet/goprocess",
48
- "Rev": "5b02f8d275a2dd882fb06f8bbdf74347795ff3b1"
49
- },
50
- {
51
- "ImportPath": "github.com/mattbaird/elastigo/api",
52
- "Rev": "041b88c1fcf6489a5721ede24378ce1253b9159d"
53
- },
54
- {
55
- "ImportPath": "github.com/mattbaird/elastigo/core",
56
- "Rev": "041b88c1fcf6489a5721ede24378ce1253b9159d"
57
- },
58
- {
59
- "ImportPath": "github.com/syndtr/gosnappy/snappy",
60
- "Rev": "ce8acff4829e0c2458a67ead32390ac0a381c862"
61
- },
62
- {
63
- "ImportPath": "golang.org/x/net/context",
64
- "Rev": "dfcbca9c45aeabb8971affa4f76b2d40f6f72328"
65
- },
66
- {
67
- "ImportPath": "gopkg.in/check.v1",
68
- "Rev": "91ae5f88a67b14891cfd43895b01164f6c120420"
69
- },
70
- {
71
- "ImportPath": "launchpad.net/gocheck",
72
- "Comment": "87",
73
- "Rev": "gustavo@niemeyer.net-20140225173054-xu9zlkf9kxhvow02"
74
- }
75
- ]
76
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/Godeps/Readme
deleted
-5
@@ -1,5 +0,0 @@
1
-This directory tree is generated automatically by godep.
2
-
3
-Please do not edit.
4
-
5
-See https://github.com/tools/godep for more information.
Godeps/_workspace/src/github.com/ipfs/go-datastore/LICENSE
deleted
-21
@@ -1,21 +0,0 @@
1
-The MIT License
2
-
3
-Copyright (c) 2014 Juan Batiz-Benet
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in
13
-all copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
-THE SOFTWARE.
Godeps/_workspace/src/github.com/ipfs/go-datastore/Makefile
deleted
-24
@@ -1,24 +0,0 @@
1
-build:
2
- go build
3
-
4
-test: build
5
- go test -race -cpu=5 -v ./...
6
-
7
-# saves/vendors third-party dependencies to Godeps/_workspace
8
-# -r flag rewrites import paths to use the vendored path
9
-# ./... performs operation on all packages in tree
10
-vendor: godep
11
- godep save -r ./...
12
-
13
-deps:
14
- go get ./...
15
-
16
-watch:
17
- -make
18
- @echo "[watching *.go; for recompilation]"
19
- # for portability, use watchmedo -- pip install watchmedo
20
- @watchmedo shell-command --patterns="*.go;" --recursive \
21
- --command='make' .
22
-
23
-godep:
24
- go get github.com/tools/godep
Godeps/_workspace/src/github.com/ipfs/go-datastore/README.md
deleted
-15
@@ -1,15 +0,0 @@
1
-# datastore interface
2
-
3
-datastore is a generic layer of abstraction for data store and database access. It is a simple API with the aim to enable application development in a datastore-agnostic way, allowing datastores to be swapped seamlessly without changing application code. Thus, one can leverage different datastores with different strengths without committing the application to one datastore throughout its lifetime.
4
-
5
-In addition, grouped datastores significantly simplify interesting data access patterns (such as caching and sharding).
6
-
7
-Based on [datastore.py](https://github.com/datastore/datastore).
8
-
9
-### Documentation
10
-
11
-https://godoc.org/github.com/jbenet/go-datastore
12
-
13
-### License
14
-
15
-MIT
Godeps/_workspace/src/github.com/ipfs/go-datastore/basic_ds.go
deleted
-189
@@ -1,189 +0,0 @@
1
-package datastore
2
-
3
-import (
4
- "io"
5
- "log"
6
-
7
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
8
-)
9
-
10
-// Here are some basic datastore implementations.
11
-
12
-type keyMap map[Key]interface{}
13
-
14
-// MapDatastore uses a standard Go map for internal storage.
15
-type MapDatastore struct {
16
- values keyMap
17
-}
18
-
19
-// NewMapDatastore constructs a MapDatastore
20
-func NewMapDatastore() (d *MapDatastore) {
21
- return &MapDatastore{
22
- values: keyMap{},
23
- }
24
-}
25
-
26
-// Put implements Datastore.Put
27
-func (d *MapDatastore) Put(key Key, value interface{}) (err error) {
28
- d.values[key] = value
29
- return nil
30
-}
31
-
32
-// Get implements Datastore.Get
33
-func (d *MapDatastore) Get(key Key) (value interface{}, err error) {
34
- val, found := d.values[key]
35
- if !found {
36
- return nil, ErrNotFound
37
- }
38
- return val, nil
39
-}
40
-
41
-// Has implements Datastore.Has
42
-func (d *MapDatastore) Has(key Key) (exists bool, err error) {
43
- _, found := d.values[key]
44
- return found, nil
45
-}
46
-
47
-// Delete implements Datastore.Delete
48
-func (d *MapDatastore) Delete(key Key) (err error) {
49
- if _, found := d.values[key]; !found {
50
- return ErrNotFound
51
- }
52
- delete(d.values, key)
53
- return nil
54
-}
55
-
56
-// Query implements Datastore.Query
57
-func (d *MapDatastore) Query(q dsq.Query) (dsq.Results, error) {
58
- re := make([]dsq.Entry, 0, len(d.values))
59
- for k, v := range d.values {
60
- re = append(re, dsq.Entry{Key: k.String(), Value: v})
61
- }
62
- r := dsq.ResultsWithEntries(q, re)
63
- r = dsq.NaiveQueryApply(q, r)
64
- return r, nil
65
-}
66
-
67
-func (d *MapDatastore) Batch() (Batch, error) {
68
- return NewBasicBatch(d), nil
69
-}
70
-
71
-func (d *MapDatastore) Close() error {
72
- return nil
73
-}
74
-
75
-// NullDatastore stores nothing, but conforms to the API.
76
-// Useful to test with.
77
-type NullDatastore struct {
78
-}
79
-
80
-// NewNullDatastore constructs a null datastoe
81
-func NewNullDatastore() *NullDatastore {
82
- return &NullDatastore{}
83
-}
84
-
85
-// Put implements Datastore.Put
86
-func (d *NullDatastore) Put(key Key, value interface{}) (err error) {
87
- return nil
88
-}
89
-
90
-// Get implements Datastore.Get
91
-func (d *NullDatastore) Get(key Key) (value interface{}, err error) {
92
- return nil, nil
93
-}
94
-
95
-// Has implements Datastore.Has
96
-func (d *NullDatastore) Has(key Key) (exists bool, err error) {
97
- return false, nil
98
-}
99
-
100
-// Delete implements Datastore.Delete
101
-func (d *NullDatastore) Delete(key Key) (err error) {
102
- return nil
103
-}
104
-
105
-// Query implements Datastore.Query
106
-func (d *NullDatastore) Query(q dsq.Query) (dsq.Results, error) {
107
- return dsq.ResultsWithEntries(q, nil), nil
108
-}
109
-
110
-func (d *NullDatastore) Batch() (Batch, error) {
111
- return NewBasicBatch(d), nil
112
-}
113
-
114
-func (d *NullDatastore) Close() error {
115
- return nil
116
-}
117
-
118
-// LogDatastore logs all accesses through the datastore.
119
-type LogDatastore struct {
120
- Name string
121
- child Datastore
122
-}
123
-
124
-// Shim is a datastore which has a child.
125
-type Shim interface {
126
- Datastore
127
-
128
- Children() []Datastore
129
-}
130
-
131
-// NewLogDatastore constructs a log datastore.
132
-func NewLogDatastore(ds Datastore, name string) *LogDatastore {
133
- if len(name) < 1 {
134
- name = "LogDatastore"
135
- }
136
- return &LogDatastore{Name: name, child: ds}
137
-}
138
-
139
-// Children implements Shim
140
-func (d *LogDatastore) Children() []Datastore {
141
- return []Datastore{d.child}
142
-}
143
-
144
-// Put implements Datastore.Put
145
-func (d *LogDatastore) Put(key Key, value interface{}) (err error) {
146
- log.Printf("%s: Put %s\n", d.Name, key)
147
- // log.Printf("%s: Put %s ```%s```", d.Name, key, value)
148
- return d.child.Put(key, value)
149
-}
150
-
151
-// Get implements Datastore.Get
152
-func (d *LogDatastore) Get(key Key) (value interface{}, err error) {
153
- log.Printf("%s: Get %s\n", d.Name, key)
154
- return d.child.Get(key)
155
-}
156
-
157
-// Has implements Datastore.Has
158
-func (d *LogDatastore) Has(key Key) (exists bool, err error) {
159
- log.Printf("%s: Has %s\n", d.Name, key)
160
- return d.child.Has(key)
161
-}
162
-
163
-// Delete implements Datastore.Delete
164
-func (d *LogDatastore) Delete(key Key) (err error) {
165
- log.Printf("%s: Delete %s\n", d.Name, key)
166
- return d.child.Delete(key)
167
-}
168
-
169
-// Query implements Datastore.Query
170
-func (d *LogDatastore) Query(q dsq.Query) (dsq.Results, error) {
171
- log.Printf("%s: Query\n", d.Name)
172
- return d.child.Query(q)
173
-}
174
-
175
-func (d *LogDatastore) Batch() (Batch, error) {
176
- log.Printf("%s: Batch\n", d.Name)
177
- if bds, ok := d.child.(Batching); ok {
178
- return bds.Batch()
179
- }
180
- return nil, ErrBatchUnsupported
181
-}
182
-
183
-func (d *LogDatastore) Close() error {
184
- log.Printf("%s: Close\n", d.Name)
185
- if cds, ok := d.child.(io.Closer); ok {
186
- return cds.Close()
187
- }
188
- return nil
189
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/batch.go
deleted
-44
@@ -1,44 +0,0 @@
1
-package datastore
2
-
3
-// basicBatch implements the transaction interface for datastores who do
4
-// not have any sort of underlying transactional support
5
-type basicBatch struct {
6
- puts map[Key]interface{}
7
- deletes map[Key]struct{}
8
-
9
- target Datastore
10
-}
11
-
12
-func NewBasicBatch(ds Datastore) Batch {
13
- return &basicBatch{
14
- puts: make(map[Key]interface{}),
15
- deletes: make(map[Key]struct{}),
16
- target: ds,
17
- }
18
-}
19
-
20
-func (bt *basicBatch) Put(key Key, val interface{}) error {
21
- bt.puts[key] = val
22
- return nil
23
-}
24
-
25
-func (bt *basicBatch) Delete(key Key) error {
26
- bt.deletes[key] = struct{}{}
27
- return nil
28
-}
29
-
30
-func (bt *basicBatch) Commit() error {
31
- for k, val := range bt.puts {
32
- if err := bt.target.Put(k, val); err != nil {
33
- return err
34
- }
35
- }
36
-
37
- for k, _ := range bt.deletes {
38
- if err := bt.target.Delete(k); err != nil {
39
- return err
40
- }
41
- }
42
-
43
- return nil
44
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/callback/callback.go
deleted
-42
@@ -1,42 +0,0 @@
1
-package callback
2
-
3
-import (
4
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
5
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
6
-)
7
-
8
-type Datastore struct {
9
- D ds.Datastore
10
- F func()
11
-}
12
-
13
-func Wrap(ds ds.Datastore, f func()) *Datastore {
14
- return &Datastore{ds, f}
15
-}
16
-
17
-func (c *Datastore) SetFunc(f func()) { c.F = f }
18
-
19
-func (c *Datastore) Put(key ds.Key, value interface{}) (err error) {
20
- c.F()
21
- return c.D.Put(key, value)
22
-}
23
-
24
-func (c *Datastore) Get(key ds.Key) (value interface{}, err error) {
25
- c.F()
26
- return c.D.Get(key)
27
-}
28
-
29
-func (c *Datastore) Has(key ds.Key) (exists bool, err error) {
30
- c.F()
31
- return c.D.Has(key)
32
-}
33
-
34
-func (c *Datastore) Delete(key ds.Key) (err error) {
35
- c.F()
36
- return c.D.Delete(key)
37
-}
38
-
39
-func (c *Datastore) Query(q dsq.Query) (dsq.Results, error) {
40
- c.F()
41
- return c.D.Query(q)
42
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/coalesce/coalesce.go
deleted
-140
@@ -1,140 +0,0 @@
1
-package coalesce
2
-
3
-import (
4
- "io"
5
- "sync"
6
-
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
9
-)
10
-
11
-// parent keys
12
-var (
13
- putKey = "put"
14
- getKey = "get"
15
- hasKey = "has"
16
- deleteKey = "delete"
17
-)
18
-
19
-type keySync struct {
20
- op string
21
- k ds.Key
22
- value interface{}
23
-}
24
-
25
-type valSync struct {
26
- val interface{}
27
- err error
28
- done chan struct{}
29
-}
30
-
31
-// Datastore uses golang-lru for internal storage.
32
-type datastore struct {
33
- child ds.Datastore
34
-
35
- reqmu sync.Mutex
36
- req map[keySync]*valSync
37
-}
38
-
39
-// Wrap wraps a given datastore with a coalescing datastore.
40
-// All simultaenous requests which have the same keys will
41
-// yield the exact same result. Note that this shares
42
-// memory. It is not possible to copy a generic interface{}
43
-func Wrap(d ds.Datastore) ds.Datastore {
44
- return &datastore{child: d, req: make(map[keySync]*valSync)}
45
-}
46
-
47
-// sync synchronizes requests for a given key.
48
-func (d *datastore) sync(k keySync) (vs *valSync, found bool) {
49
- d.reqmu.Lock()
50
- vs, found = d.req[k]
51
- if !found {
52
- vs = &valSync{done: make(chan struct{})}
53
- d.req[k] = vs
54
- }
55
- d.reqmu.Unlock()
56
-
57
- // if we did find one, wait till it's done.
58
- if found {
59
- <-vs.done
60
- }
61
- return vs, found
62
-}
63
-
64
-// sync synchronizes requests for a given key.
65
-func (d *datastore) syncDone(k keySync) {
66
-
67
- d.reqmu.Lock()
68
- vs, found := d.req[k]
69
- if !found {
70
- panic("attempt to syncDone non-existent request")
71
- }
72
- delete(d.req, k)
73
- d.reqmu.Unlock()
74
-
75
- // release all the waiters.
76
- close(vs.done)
77
-}
78
-
79
-// Put stores the object `value` named by `key`.
80
-func (d *datastore) Put(key ds.Key, value interface{}) (err error) {
81
- ks := keySync{putKey, key, value}
82
- vs, found := d.sync(ks)
83
- if !found {
84
- vs.err = d.child.Put(key, value)
85
- d.syncDone(ks)
86
- }
87
- return err
88
-}
89
-
90
-// Get retrieves the object `value` named by `key`.
91
-func (d *datastore) Get(key ds.Key) (value interface{}, err error) {
92
- ks := keySync{getKey, key, nil}
93
- vs, found := d.sync(ks)
94
- if !found {
95
- vs.val, vs.err = d.child.Get(key)
96
- d.syncDone(ks)
97
- }
98
- return vs.val, vs.err
99
-}
100
-
101
-// Has returns whether the `key` is mapped to a `value`.
102
-func (d *datastore) Has(key ds.Key) (exists bool, err error) {
103
- ks := keySync{hasKey, key, nil}
104
- vs, found := d.sync(ks)
105
- if !found {
106
- vs.val, vs.err = d.child.Has(key)
107
- d.syncDone(ks)
108
- }
109
- return vs.val.(bool), vs.err
110
-}
111
-
112
-// Delete removes the value for given `key`.
113
-func (d *datastore) Delete(key ds.Key) (err error) {
114
- ks := keySync{deleteKey, key, nil}
115
- vs, found := d.sync(ks)
116
- if !found {
117
- vs.err = d.child.Delete(key)
118
- d.syncDone(ks)
119
- }
120
- return vs.err
121
-}
122
-
123
-// Query returns a list of keys in the datastore
124
-func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
125
- // query not coalesced yet.
126
- return d.child.Query(q)
127
-}
128
-
129
-func (d *datastore) Close() error {
130
- d.reqmu.Lock()
131
- defer d.reqmu.Unlock()
132
-
133
- for _, s := range d.req {
134
- <-s.done
135
- }
136
- if c, ok := d.child.(io.Closer); ok {
137
- return c.Close()
138
- }
139
- return nil
140
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/datastore.go
deleted
-122
@@ -1,122 +0,0 @@
1
-package datastore
2
-
3
-import (
4
- "errors"
5
-
6
- query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
7
-)
8
-
9
-/*
10
-Datastore represents storage for any key-value pair.
11
-
12
-Datastores are general enough to be backed by all kinds of different storage:
13
-in-memory caches, databases, a remote datastore, flat files on disk, etc.
14
-
15
-The general idea is to wrap a more complicated storage facility in a simple,
16
-uniform interface, keeping the freedom of using the right tools for the job.
17
-In particular, a Datastore can aggregate other datastores in interesting ways,
18
-like sharded (to distribute load) or tiered access (caches before databases).
19
-
20
-While Datastores should be written general enough to accept all sorts of
21
-values, some implementations will undoubtedly have to be specific (e.g. SQL
22
-databases where fields should be decomposed into columns), particularly to
23
-support queries efficiently. Moreover, certain datastores may enforce certain
24
-types of values (e.g. requiring an io.Reader, a specific struct, etc) or
25
-serialization formats (JSON, Protobufs, etc).
26
-
27
-IMPORTANT: No Datastore should ever Panic! This is a cross-module interface,
28
-and thus it should behave predictably and handle exceptional conditions with
29
-proper error reporting. Thus, all Datastore calls may return errors, which
30
-should be checked by callers.
31
-*/
32
-type Datastore interface {
33
- // Put stores the object `value` named by `key`.
34
- //
35
- // The generalized Datastore interface does not impose a value type,
36
- // allowing various datastore middleware implementations (which do not
37
- // handle the values directly) to be composed together.
38
- //
39
- // Ultimately, the lowest-level datastore will need to do some value checking
40
- // or risk getting incorrect values. It may also be useful to expose a more
41
- // type-safe interface to your application, and do the checking up-front.
42
- Put(key Key, value interface{}) error
43
-
44
- // Get retrieves the object `value` named by `key`.
45
- // Get will return ErrNotFound if the key is not mapped to a value.
46
- Get(key Key) (value interface{}, err error)
47
-
48
- // Has returns whether the `key` is mapped to a `value`.
49
- // In some contexts, it may be much cheaper only to check for existence of
50
- // a value, rather than retrieving the value itself. (e.g. HTTP HEAD).
51
- // The default implementation is found in `GetBackedHas`.
52
- Has(key Key) (exists bool, err error)
53
-
54
- // Delete removes the value for given `key`.
55
- Delete(key Key) error
56
-
57
- // Query searches the datastore and returns a query result. This function
58
- // may return before the query actually runs. To wait for the query:
59
- //
60
- // result, _ := ds.Query(q)
61
- //
62
- // // use the channel interface; result may come in at different times
63
- // for entry := range result.Entries() { ... }
64
- //
65
- // // or wait for the query to be completely done
66
- // result.Wait()
67
- // result.AllEntries()
68
- //
69
- Query(q query.Query) (query.Results, error)
70
-}
71
-
72
-type Batching interface {
73
- Datastore
74
-
75
- Batch() (Batch, error)
76
-}
77
-
78
-var ErrBatchUnsupported = errors.New("this datastore does not support batching")
79
-
80
-// ThreadSafeDatastore is an interface that all threadsafe datastore should
81
-// implement to leverage type safety checks.
82
-type ThreadSafeDatastore interface {
83
- Datastore
84
- IsThreadSafe()
85
-}
86
-
87
-// Errors
88
-
89
-// ErrNotFound is returned by Get, Has, and Delete when a datastore does not
90
-// map the given key to a value.
91
-var ErrNotFound = errors.New("datastore: key not found")
92
-
93
-// ErrInvalidType is returned by Put when a given value is incopatible with
94
-// the type the datastore supports. This means a conversion (or serialization)
95
-// is needed beforehand.
96
-var ErrInvalidType = errors.New("datastore: invalid type error")
97
-
98
-// GetBackedHas provides a default Datastore.Has implementation.
99
-// It exists so Datastore.Has implementations can use it, like so:
100
-//
101
-// func (*d SomeDatastore) Has(key Key) (exists bool, err error) {
102
-// return GetBackedHas(d, key)
103
-// }
104
-func GetBackedHas(ds Datastore, key Key) (bool, error) {
105
- _, err := ds.Get(key)
106
- switch err {
107
- case nil:
108
- return true, nil
109
- case ErrNotFound:
110
- return false, nil
111
- default:
112
- return false, err
113
- }
114
-}
115
-
116
-type Batch interface {
117
- Put(key Key, val interface{}) error
118
-
119
- Delete(key Key) error
120
-
121
- Commit() error
122
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/elastigo/datastore.go
deleted
-128
@@ -1,128 +0,0 @@
1
-package elastigo
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "net/url"
7
- "strings"
8
-
9
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
- query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
11
-
12
- "github.com/codahale/blake2"
13
- "github.com/mattbaird/elastigo/api"
14
- "github.com/mattbaird/elastigo/core"
15
-)
16
-
17
-// Currently, elastigo does not allow connecting to multiple elasticsearch
18
-// instances. The elastigo API uses global static variables (ugh).
19
-// See https://github.com/mattbaird/elastigo/issues/22
20
-//
21
-// Thus, we use a global static variable (GlobalInstance), and return an
22
-// error if NewDatastore is called twice with different addresses.
23
-var GlobalInstance string
24
-
25
-// Datastore uses a standard Go map for internal storage.
26
-type Datastore struct {
27
- url string
28
- index string
29
-
30
- // Elastic search does not allow slashes in their object ids,
31
- // so we hash the key. By default, we use the provided BlakeKeyHash
32
- KeyHash func(ds.Key) string
33
-}
34
-
35
-func NewDatastore(urlstr string) (*Datastore, error) {
36
- if GlobalInstance != "" && GlobalInstance != urlstr {
37
- return nil, fmt.Errorf("elastigo only allows one client. See godoc.")
38
- }
39
-
40
- uf := "http://<host>:<port>/<index>"
41
- u, err := url.Parse(urlstr)
42
- if err != nil {
43
- return nil, fmt.Errorf("error parsing url: %s (%s)", urlstr, uf)
44
- }
45
-
46
- host := strings.Split(u.Host, ":")
47
- api.Domain = host[0]
48
- if len(host) > 1 {
49
- api.Port = host[1]
50
- }
51
-
52
- index := strings.Trim(u.Path, "/")
53
- if strings.Contains(index, "/") {
54
- e := "elastigo index cannot have slashes: %s (%s -> %s)"
55
- return nil, fmt.Errorf(e, index, urlstr, uf)
56
- }
57
-
58
- GlobalInstance = urlstr
59
- return &Datastore{
60
- url: urlstr,
61
- index: index,
62
- KeyHash: BlakeKeyHash,
63
- }, nil
64
-}
65
-
66
-// Returns the ElasticSearch index for given key. If the datastore specifies
67
-// an index, use that. Else, key.Parent
68
-func (d *Datastore) Index(key ds.Key) string {
69
- if len(d.index) > 0 {
70
- return d.index
71
- }
72
- return key.Parent().BaseNamespace()
73
-}
74
-
75
-// value should be JSON serializable.
76
-func (d *Datastore) Put(key ds.Key, value interface{}) (err error) {
77
- id := d.KeyHash(key)
78
- res, err := core.Index(false, d.Index(key), key.Type(), id, value)
79
- if err != nil {
80
- return err
81
- }
82
- if !res.Ok {
83
- return fmt.Errorf("Elasticsearch response: NOT OK. %v", res)
84
- }
85
- return nil
86
-}
87
-
88
-func (d *Datastore) Get(key ds.Key) (value interface{}, err error) {
89
- id := d.KeyHash(key)
90
- res, err := core.Get(false, d.Index(key), key.Type(), id)
91
- if err != nil {
92
- return nil, err
93
- }
94
- if !res.Ok {
95
- return nil, fmt.Errorf("Elasticsearch response: NOT OK. %v", res)
96
- }
97
- return res.Source, nil
98
-}
99
-
100
-func (d *Datastore) Has(key ds.Key) (exists bool, err error) {
101
- id := d.KeyHash(key)
102
- return core.Exists(false, d.Index(key), key.Type(), id)
103
-}
104
-
105
-func (d *Datastore) Delete(key ds.Key) (err error) {
106
- id := d.KeyHash(key)
107
- res, err := core.Delete(false, d.Index(key), key.Type(), id, 0, "")
108
- if err != nil {
109
- return err
110
- }
111
- if !res.Ok {
112
- return fmt.Errorf("Elasticsearch response: NOT OK. %v", res)
113
- }
114
- return nil
115
-}
116
-
117
-func (d *Datastore) Query(query.Query) (query.Results, error) {
118
- return nil, errors.New("Not yet implemented!")
119
-}
120
-
121
-// Hash a key and return the first 16 hex chars of its blake2b hash.
122
-// basically: Blake2b(key).HexString[:16]
123
-func BlakeKeyHash(key ds.Key) string {
124
- h := blake2.NewBlake2B()
125
- h.Write(key.Bytes())
126
- d := h.Sum(nil)
127
- return fmt.Sprintf("%x", d)[:16]
128
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/flatfs/flatfs.go
deleted
-392
@@ -1,392 +0,0 @@
1
-// Package flatfs is a Datastore implementation that stores all
2
-// objects in a two-level directory structure in the local file
3
-// system, regardless of the hierarchy of the keys.
4
-package flatfs
5
-
6
-import (
7
- "encoding/hex"
8
- "errors"
9
- "io/ioutil"
10
- "os"
11
- "path"
12
- "path/filepath"
13
- "strings"
14
- "time"
15
-
16
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
17
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
18
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-os-rename"
19
-
20
- logging "gx/ipfs/QmYtB7Qge8cJpXc4irsEp8zRqfnZMBeB7aTrMEkPk67DRv/go-log"
21
-)
22
-
23
-var log = logging.Logger("flatfs")
24
-
25
-const (
26
- extension = ".data"
27
- maxPrefixLen = 16
28
-)
29
-
30
-var (
31
- ErrBadPrefixLen = errors.New("bad prefix length")
32
-)
33
-
34
-type Datastore struct {
35
- path string
36
- // length of the dir splay prefix, in bytes of hex digits
37
- hexPrefixLen int
38
-
39
- // sychronize all writes and directory changes for added safety
40
- sync bool
41
-}
42
-
43
-var _ datastore.Datastore = (*Datastore)(nil)
44
-
45
-func New(path string, prefixLen int, sync bool) (*Datastore, error) {
46
- if prefixLen <= 0 || prefixLen > maxPrefixLen {
47
- return nil, ErrBadPrefixLen
48
- }
49
- fs := &Datastore{
50
- path: path,
51
- // convert from binary bytes to bytes of hex encoding
52
- hexPrefixLen: prefixLen * hex.EncodedLen(1),
53
- sync: sync,
54
- }
55
- return fs, nil
56
-}
57
-
58
-var padding = strings.Repeat("_", maxPrefixLen*hex.EncodedLen(1))
59
-
60
-func (fs *Datastore) encode(key datastore.Key) (dir, file string) {
61
- safe := hex.EncodeToString(key.Bytes()[1:])
62
- prefix := (safe + padding)[:fs.hexPrefixLen]
63
- dir = path.Join(fs.path, prefix)
64
- file = path.Join(dir, safe+extension)
65
- return dir, file
66
-}
67
-
68
-func (fs *Datastore) decode(file string) (key datastore.Key, ok bool) {
69
- if path.Ext(file) != extension {
70
- return datastore.Key{}, false
71
- }
72
- name := file[:len(file)-len(extension)]
73
- k, err := hex.DecodeString(name)
74
- if err != nil {
75
- return datastore.Key{}, false
76
- }
77
- return datastore.NewKey(string(k)), true
78
-}
79
-
80
-func (fs *Datastore) makePrefixDir(dir string) error {
81
- if err := fs.makePrefixDirNoSync(dir); err != nil {
82
- return err
83
- }
84
-
85
- // In theory, if we create a new prefix dir and add a file to
86
- // it, the creation of the prefix dir itself might not be
87
- // durable yet. Sync the root dir after a successful mkdir of
88
- // a prefix dir, just to be paranoid.
89
- if fs.sync {
90
- if err := syncDir(fs.path); err != nil {
91
- return err
92
- }
93
- }
94
- return nil
95
-}
96
-
97
-func (fs *Datastore) makePrefixDirNoSync(dir string) error {
98
- if err := os.Mkdir(dir, 0777); err != nil {
99
- // EEXIST is safe to ignore here, that just means the prefix
100
- // directory already existed.
101
- if !os.IsExist(err) {
102
- return err
103
- }
104
- }
105
- return nil
106
-}
107
-
108
-var putMaxRetries = 3
109
-
110
-func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
111
- val, ok := value.([]byte)
112
- if !ok {
113
- return datastore.ErrInvalidType
114
- }
115
-
116
- var err error
117
- for i := 0; i < putMaxRetries; i++ {
118
- err = fs.doPut(key, val)
119
- if err == nil {
120
- return nil
121
- }
122
-
123
- if !strings.Contains(err.Error(), "too many open files") {
124
- return err
125
- }
126
-
127
- log.Error("too many open files, retrying in %dms", 100*i)
128
- time.Sleep(time.Millisecond * 100 * time.Duration(i))
129
- }
130
- return err
131
-}
132
-
133
-func (fs *Datastore) doPut(key datastore.Key, val []byte) error {
134
- dir, path := fs.encode(key)
135
- if err := fs.makePrefixDir(dir); err != nil {
136
- return err
137
- }
138
-
139
- tmp, err := ioutil.TempFile(dir, "put-")
140
- if err != nil {
141
- return err
142
- }
143
- closed := false
144
- removed := false
145
- defer func() {
146
- if !closed {
147
- // silence errcheck
148
- _ = tmp.Close()
149
- }
150
- if !removed {
151
- // silence errcheck
152
- _ = os.Remove(tmp.Name())
153
- }
154
- }()
155
-
156
- if _, err := tmp.Write(val); err != nil {
157
- return err
158
- }
159
- if fs.sync {
160
- if err := tmp.Sync(); err != nil {
161
- return err
162
- }
163
- }
164
- if err := tmp.Close(); err != nil {
165
- return err
166
- }
167
- closed = true
168
-
169
- err = osrename.Rename(tmp.Name(), path)
170
- if err != nil {
171
- return err
172
- }
173
- removed = true
174
-
175
- if fs.sync {
176
- if err := syncDir(dir); err != nil {
177
- return err
178
- }
179
- }
180
- return nil
181
-}
182
-
183
-func (fs *Datastore) putMany(data map[datastore.Key]interface{}) error {
184
- var dirsToSync []string
185
- files := make(map[*os.File]string)
186
-
187
- for key, value := range data {
188
- val, ok := value.([]byte)
189
- if !ok {
190
- return datastore.ErrInvalidType
191
- }
192
- dir, path := fs.encode(key)
193
- if err := fs.makePrefixDirNoSync(dir); err != nil {
194
- return err
195
- }
196
- dirsToSync = append(dirsToSync, dir)
197
-
198
- tmp, err := ioutil.TempFile(dir, "put-")
199
- if err != nil {
200
- return err
201
- }
202
-
203
- if _, err := tmp.Write(val); err != nil {
204
- return err
205
- }
206
-
207
- files[tmp] = path
208
- }
209
-
210
- ops := make(map[*os.File]int)
211
-
212
- defer func() {
213
- for fi, _ := range files {
214
- val, _ := ops[fi]
215
- switch val {
216
- case 0:
217
- _ = fi.Close()
218
- fallthrough
219
- case 1:
220
- _ = os.Remove(fi.Name())
221
- }
222
- }
223
- }()
224
-
225
- // Now we sync everything
226
- // sync and close files
227
- for fi, _ := range files {
228
- if fs.sync {
229
- if err := fi.Sync(); err != nil {
230
- return err
231
- }
232
- }
233
-
234
- if err := fi.Close(); err != nil {
235
- return err
236
- }
237
-
238
- // signify closed
239
- ops[fi] = 1
240
- }
241
-
242
- // move files to their proper places
243
- for fi, path := range files {
244
- if err := osrename.Rename(fi.Name(), path); err != nil {
245
- return err
246
- }
247
-
248
- // signify removed
249
- ops[fi] = 2
250
- }
251
-
252
- // now sync the dirs for those files
253
- if fs.sync {
254
- for _, dir := range dirsToSync {
255
- if err := syncDir(dir); err != nil {
256
- return err
257
- }
258
- }
259
-
260
- // sync top flatfs dir
261
- if err := syncDir(fs.path); err != nil {
262
- return err
263
- }
264
- }
265
-
266
- return nil
267
-}
268
-
269
-func (fs *Datastore) Get(key datastore.Key) (value interface{}, err error) {
270
- _, path := fs.encode(key)
271
- data, err := ioutil.ReadFile(path)
272
- if err != nil {
273
- if os.IsNotExist(err) {
274
- return nil, datastore.ErrNotFound
275
- }
276
- // no specific error to return, so just pass it through
277
- return nil, err
278
- }
279
- return data, nil
280
-}
281
-
282
-func (fs *Datastore) Has(key datastore.Key) (exists bool, err error) {
283
- _, path := fs.encode(key)
284
- switch _, err := os.Stat(path); {
285
- case err == nil:
286
- return true, nil
287
- case os.IsNotExist(err):
288
- return false, nil
289
- default:
290
- return false, err
291
- }
292
-}
293
-
294
-func (fs *Datastore) Delete(key datastore.Key) error {
295
- _, path := fs.encode(key)
296
- switch err := os.Remove(path); {
297
- case err == nil:
298
- return nil
299
- case os.IsNotExist(err):
300
- return datastore.ErrNotFound
301
- default:
302
- return err
303
- }
304
-}
305
-
306
-func (fs *Datastore) Query(q query.Query) (query.Results, error) {
307
- if (q.Prefix != "" && q.Prefix != "/") ||
308
- len(q.Filters) > 0 ||
309
- len(q.Orders) > 0 ||
310
- q.Limit > 0 ||
311
- q.Offset > 0 ||
312
- !q.KeysOnly {
313
- // TODO this is overly simplistic, but the only caller is
314
- // `ipfs refs local` for now, and this gets us moving.
315
- return nil, errors.New("flatfs only supports listing all keys in random order")
316
- }
317
-
318
- reschan := make(chan query.Result)
319
- go func() {
320
- defer close(reschan)
321
- err := filepath.Walk(fs.path, func(path string, info os.FileInfo, err error) error {
322
-
323
- if !info.Mode().IsRegular() || info.Name()[0] == '.' {
324
- return nil
325
- }
326
-
327
- key, ok := fs.decode(info.Name())
328
- if !ok {
329
- log.Warning("failed to decode entry in flatfs")
330
- return nil
331
- }
332
-
333
- reschan <- query.Result{
334
- Entry: query.Entry{
335
- Key: key.String(),
336
- },
337
- }
338
- return nil
339
- })
340
- if err != nil {
341
- log.Warning("walk failed: ", err)
342
- }
343
- }()
344
- return query.ResultsWithChan(q, reschan), nil
345
-}
346
-
347
-func (fs *Datastore) Close() error {
348
- return nil
349
-}
350
-
351
-type flatfsBatch struct {
352
- puts map[datastore.Key]interface{}
353
- deletes map[datastore.Key]struct{}
354
-
355
- ds *Datastore
356
-}
357
-
358
-func (fs *Datastore) Batch() (datastore.Batch, error) {
359
- return &flatfsBatch{
360
- puts: make(map[datastore.Key]interface{}),
361
- deletes: make(map[datastore.Key]struct{}),
362
- ds: fs,
363
- }, nil
364
-}
365
-
366
-func (bt *flatfsBatch) Put(key datastore.Key, val interface{}) error {
367
- bt.puts[key] = val
368
- return nil
369
-}
370
-
371
-func (bt *flatfsBatch) Delete(key datastore.Key) error {
372
- bt.deletes[key] = struct{}{}
373
- return nil
374
-}
375
-
376
-func (bt *flatfsBatch) Commit() error {
377
- if err := bt.ds.putMany(bt.puts); err != nil {
378
- return err
379
- }
380
-
381
- for k, _ := range bt.deletes {
382
- if err := bt.ds.Delete(k); err != nil {
383
- return err
384
- }
385
- }
386
-
387
- return nil
388
-}
389
-
390
-var _ datastore.ThreadSafeDatastore = (*Datastore)(nil)
391
-
392
-func (*Datastore) IsThreadSafe() {}
Godeps/_workspace/src/github.com/ipfs/go-datastore/flatfs/sync_std.go
deleted
-17
@@ -1,17 +0,0 @@
1
-// +build !windows
2
-
3
-package flatfs
4
-
5
-import "os"
6
-
7
-func syncDir(dir string) error {
8
- dirF, err := os.Open(dir)
9
- if err != nil {
10
- return err
11
- }
12
- defer dirF.Close()
13
- if err := dirF.Sync(); err != nil {
14
- return err
15
- }
16
- return nil
17
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/flatfs/sync_windows.go
deleted
-5
@@ -1,5 +0,0 @@
1
-package flatfs
2
-
3
-func syncDir(dir string) error {
4
- return nil
5
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/fs/fs.go
deleted
-159
@@ -1,159 +0,0 @@
1
-// Package fs is a simple Datastore implementation that stores keys
2
-// are directories and files, mirroring the key. That is, the key
3
-// "/foo/bar" is stored as file "PATH/foo/bar/.dsobject".
4
-//
5
-// This means key some segments will not work. For example, the
6
-// following keys will result in unwanted behavior:
7
-//
8
-// - "/foo/./bar"
9
-// - "/foo/../bar"
10
-// - "/foo\x00bar"
11
-//
12
-// Keys that only differ in case may be confused with each other on
13
-// case insensitive file systems, for example in OS X.
14
-//
15
-// This package is intended for exploratory use, where the user would
16
-// examine the file system manually, and should only be used with
17
-// human-friendly, trusted keys. You have been warned.
18
-package fs
19
-
20
-import (
21
- "fmt"
22
- "io/ioutil"
23
- "os"
24
- "path/filepath"
25
- "strings"
26
-
27
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
28
- query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
29
-)
30
-
31
-var ObjectKeySuffix = ".dsobject"
32
-
33
-// Datastore uses a uses a file per key to store values.
34
-type Datastore struct {
35
- path string
36
-}
37
-
38
-// NewDatastore returns a new fs Datastore at given `path`
39
-func NewDatastore(path string) (ds.Datastore, error) {
40
- if !isDir(path) {
41
- return nil, fmt.Errorf("Failed to find directory at: %v (file? perms?)", path)
42
- }
43
-
44
- return &Datastore{path: path}, nil
45
-}
46
-
47
-// KeyFilename returns the filename associated with `key`
48
-func (d *Datastore) KeyFilename(key ds.Key) string {
49
- return filepath.Join(d.path, key.String(), ObjectKeySuffix)
50
-}
51
-
52
-// Put stores the given value.
53
-func (d *Datastore) Put(key ds.Key, value interface{}) (err error) {
54
-
55
- // TODO: maybe use io.Readers/Writers?
56
- // r, err := dsio.CastAsReader(value)
57
- // if err != nil {
58
- // return err
59
- // }
60
-
61
- val, ok := value.([]byte)
62
- if !ok {
63
- return ds.ErrInvalidType
64
- }
65
-
66
- fn := d.KeyFilename(key)
67
-
68
- // mkdirall above.
69
- err = os.MkdirAll(filepath.Dir(fn), 0755)
70
- if err != nil {
71
- return err
72
- }
73
-
74
- return ioutil.WriteFile(fn, val, 0666)
75
-}
76
-
77
-// Get returns the value for given key
78
-func (d *Datastore) Get(key ds.Key) (value interface{}, err error) {
79
- fn := d.KeyFilename(key)
80
- if !isFile(fn) {
81
- return nil, ds.ErrNotFound
82
- }
83
-
84
- return ioutil.ReadFile(fn)
85
-}
86
-
87
-// Has returns whether the datastore has a value for a given key
88
-func (d *Datastore) Has(key ds.Key) (exists bool, err error) {
89
- return ds.GetBackedHas(d, key)
90
-}
91
-
92
-// Delete removes the value for given key
93
-func (d *Datastore) Delete(key ds.Key) (err error) {
94
- fn := d.KeyFilename(key)
95
- if !isFile(fn) {
96
- return ds.ErrNotFound
97
- }
98
-
99
- return os.Remove(fn)
100
-}
101
-
102
-// Query implements Datastore.Query
103
-func (d *Datastore) Query(q query.Query) (query.Results, error) {
104
-
105
- results := make(chan query.Result)
106
-
107
- walkFn := func(path string, info os.FileInfo, err error) error {
108
- // remove ds path prefix
109
- if strings.HasPrefix(path, d.path) {
110
- path = path[len(d.path):]
111
- }
112
-
113
- if !info.IsDir() {
114
- if strings.HasSuffix(path, ObjectKeySuffix) {
115
- path = path[:len(path)-len(ObjectKeySuffix)]
116
- }
117
- key := ds.NewKey(path)
118
- entry := query.Entry{Key: key.String(), Value: query.NotFetched}
119
- results <- query.Result{Entry: entry}
120
- }
121
- return nil
122
- }
123
-
124
- go func() {
125
- filepath.Walk(d.path, walkFn)
126
- close(results)
127
- }()
128
- r := query.ResultsWithChan(q, results)
129
- r = query.NaiveQueryApply(q, r)
130
- return r, nil
131
-}
132
-
133
-// isDir returns whether given path is a directory
134
-func isDir(path string) bool {
135
- finfo, err := os.Stat(path)
136
- if err != nil {
137
- return false
138
- }
139
-
140
- return finfo.IsDir()
141
-}
142
-
143
-// isFile returns whether given path is a file
144
-func isFile(path string) bool {
145
- finfo, err := os.Stat(path)
146
- if err != nil {
147
- return false
148
- }
149
-
150
- return !finfo.IsDir()
151
-}
152
-
153
-func (d *Datastore) Close() error {
154
- return nil
155
-}
156
-
157
-func (d *Datastore) Batch() (ds.Batch, error) {
158
- return ds.NewBasicBatch(d), nil
159
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/key.go
deleted
-252
@@ -1,252 +0,0 @@
1
-package datastore
2
-
3
-import (
4
- "path"
5
- "strings"
6
-
7
- "gx/ipfs/QmcyaFHbyiZfoX5GTpcqqCPYmbjYNAhRDekXSJPFHdYNSV/go.uuid"
8
-
9
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
-)
11
-
12
-/*
13
-A Key represents the unique identifier of an object.
14
-Our Key scheme is inspired by file systems and Google App Engine key model.
15
-
16
-Keys are meant to be unique across a system. Keys are hierarchical,
17
-incorporating more and more specific namespaces. Thus keys can be deemed
18
-'children' or 'ancestors' of other keys::
19
-
20
- Key("/Comedy")
21
- Key("/Comedy/MontyPython")
22
-
23
-Also, every namespace can be parametrized to embed relevant object
24
-information. For example, the Key `name` (most specific namespace) could
25
-include the object type::
26
-
27
- Key("/Comedy/MontyPython/Actor:JohnCleese")
28
- Key("/Comedy/MontyPython/Sketch:CheeseShop")
29
- Key("/Comedy/MontyPython/Sketch:CheeseShop/Character:Mousebender")
30
-
31
-*/
32
-type Key struct {
33
- string
34
-}
35
-
36
-// NewKey constructs a key from string. it will clean the value.
37
-func NewKey(s string) Key {
38
- k := Key{s}
39
- k.Clean()
40
- return k
41
-}
42
-
43
-// KeyWithNamespaces constructs a key out of a namespace slice.
44
-func KeyWithNamespaces(ns []string) Key {
45
- return NewKey(strings.Join(ns, "/"))
46
-}
47
-
48
-// Clean up a Key, using path.Clean.
49
-func (k *Key) Clean() {
50
- k.string = path.Clean("/" + k.string)
51
-}
52
-
53
-// Strings is the string value of Key
54
-func (k Key) String() string {
55
- return k.string
56
-}
57
-
58
-// Bytes returns the string value of Key as a []byte
59
-func (k Key) Bytes() []byte {
60
- return []byte(k.string)
61
-}
62
-
63
-// Equal checks equality of two keys
64
-func (k Key) Equal(k2 Key) bool {
65
- return k.string == k2.string
66
-}
67
-
68
-// Less checks whether this key is sorted lower than another.
69
-func (k Key) Less(k2 Key) bool {
70
- list1 := k.List()
71
- list2 := k2.List()
72
- for i, c1 := range list1 {
73
- if len(list2) < (i + 1) {
74
- return false
75
- }
76
-
77
- c2 := list2[i]
78
- if c1 < c2 {
79
- return true
80
- } else if c1 > c2 {
81
- return false
82
- }
83
- // c1 == c2, continue
84
- }
85
-
86
- // list1 is shorter or exactly the same.
87
- return len(list1) < len(list2)
88
-}
89
-
90
-// List returns the `list` representation of this Key.
91
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").List()
92
-// ["Comedy", "MontyPythong", "Actor:JohnCleese"]
93
-func (k Key) List() []string {
94
- return strings.Split(k.string, "/")[1:]
95
-}
96
-
97
-// Reverse returns the reverse of this Key.
98
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").Reverse()
99
-// NewKey("/Actor:JohnCleese/MontyPython/Comedy")
100
-func (k Key) Reverse() Key {
101
- l := k.List()
102
- r := make([]string, len(l), len(l))
103
- for i, e := range l {
104
- r[len(l)-i-1] = e
105
- }
106
- return KeyWithNamespaces(r)
107
-}
108
-
109
-// Namespaces returns the `namespaces` making up this Key.
110
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").List()
111
-// ["Comedy", "MontyPythong", "Actor:JohnCleese"]
112
-func (k Key) Namespaces() []string {
113
- return k.List()
114
-}
115
-
116
-// BaseNamespace returns the "base" namespace of this key (path.Base(filename))
117
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").BaseNamespace()
118
-// "Actor:JohnCleese"
119
-func (k Key) BaseNamespace() string {
120
- n := k.Namespaces()
121
- return n[len(n)-1]
122
-}
123
-
124
-// Type returns the "type" of this key (value of last namespace).
125
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").List()
126
-// "Actor"
127
-func (k Key) Type() string {
128
- return NamespaceType(k.BaseNamespace())
129
-}
130
-
131
-// Name returns the "name" of this key (field of last namespace).
132
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").List()
133
-// "Actor"
134
-func (k Key) Name() string {
135
- return NamespaceValue(k.BaseNamespace())
136
-}
137
-
138
-// Instance returns an "instance" of this type key (appends value to namespace).
139
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").List()
140
-// "JohnCleese"
141
-func (k Key) Instance(s string) Key {
142
- return NewKey(k.string + ":" + s)
143
-}
144
-
145
-// Path returns the "path" of this key (parent + type).
146
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").Path()
147
-// NewKey("/Comedy/MontyPython/Actor")
148
-func (k Key) Path() Key {
149
- s := k.Parent().string + "/" + NamespaceType(k.BaseNamespace())
150
- return NewKey(s)
151
-}
152
-
153
-// Parent returns the `parent` Key of this Key.
154
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese").Parent()
155
-// NewKey("/Comedy/MontyPython")
156
-func (k Key) Parent() Key {
157
- n := k.List()
158
- if len(n) == 1 {
159
- return NewKey("/")
160
- }
161
- return NewKey(strings.Join(n[:len(n)-1], "/"))
162
-}
163
-
164
-// Child returns the `child` Key of this Key.
165
-// NewKey("/Comedy/MontyPython").Child("Actor:JohnCleese")
166
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese")
167
-func (k Key) Child(k2 Key) Key {
168
- return NewKey(k.string + "/" + k2.string)
169
-}
170
-
171
-// ChildString returns the `child` Key of this Key -- string helper.
172
-// NewKey("/Comedy/MontyPython").Child("Actor:JohnCleese")
173
-// NewKey("/Comedy/MontyPython/Actor:JohnCleese")
174
-func (k Key) ChildString(s string) Key {
175
- return NewKey(k.string + "/" + s)
176
-}
177
-
178
-// IsAncestorOf returns whether this key is a prefix of `other`
179
-// NewKey("/Comedy").IsAncestorOf("/Comedy/MontyPython")
180
-// true
181
-func (k Key) IsAncestorOf(other Key) bool {
182
- if other.string == k.string {
183
- return false
184
- }
185
- return strings.HasPrefix(other.string, k.string)
186
-}
187
-
188
-// IsDescendantOf returns whether this key contains another as a prefix.
189
-// NewKey("/Comedy/MontyPython").IsDescendantOf("/Comedy")
190
-// true
191
-func (k Key) IsDescendantOf(other Key) bool {
192
- if other.string == k.string {
193
- return false
194
- }
195
- return strings.HasPrefix(k.string, other.string)
196
-}
197
-
198
-// IsTopLevel returns whether this key has only one namespace.
199
-func (k Key) IsTopLevel() bool {
200
- return len(k.List()) == 1
201
-}
202
-
203
-// RandomKey returns a randomly (uuid) generated key.
204
-// RandomKey()
205
-// NewKey("/f98719ea086343f7b71f32ea9d9d521d")
206
-func RandomKey() Key {
207
- return NewKey(strings.Replace(uuid.NewV4().String(), "-", "", -1))
208
-}
209
-
210
-/*
211
-A Key Namespace is like a path element.
212
-A namespace can optionally include a type (delimited by ':')
213
-
214
- > NamespaceValue("Song:PhilosopherSong")
215
- PhilosopherSong
216
- > NamespaceType("Song:PhilosopherSong")
217
- Song
218
- > NamespaceType("Music:Song:PhilosopherSong")
219
- Music:Song
220
-*/
221
-
222
-// NamespaceType is the first component of a namespace. `foo` in `foo:bar`
223
-func NamespaceType(namespace string) string {
224
- parts := strings.Split(namespace, ":")
225
- if len(parts) < 2 {
226
- return ""
227
- }
228
- return strings.Join(parts[0:len(parts)-1], ":")
229
-}
230
-
231
-// NamespaceValue returns the last component of a namespace. `baz` in `f:b:baz`
232
-func NamespaceValue(namespace string) string {
233
- parts := strings.Split(namespace, ":")
234
- return parts[len(parts)-1]
235
-}
236
-
237
-// KeySlice attaches the methods of sort.Interface to []Key,
238
-// sorting in increasing order.
239
-type KeySlice []Key
240
-
241
-func (p KeySlice) Len() int { return len(p) }
242
-func (p KeySlice) Less(i, j int) bool { return p[i].Less(p[j]) }
243
-func (p KeySlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
244
-
245
-// EntryKeys
246
-func EntryKeys(e []dsq.Entry) []Key {
247
- ks := make([]Key, len(e))
248
- for i, e := range e {
249
- ks[i] = NewKey(e.Key)
250
- }
251
- return ks
252
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/keytransform/doc.go
deleted
-25
@@ -1,25 +0,0 @@
1
-// Package keytransform introduces a Datastore Shim that transforms keys before
2
-// passing them to its child. It can be used to manipulate what keys look like
3
-// to the user, for example namespacing keys, reversing them, etc.
4
-//
5
-// Use the Wrap function to wrap a datastore with any KeyTransform.
6
-// A KeyTransform is simply an interface with two functions, a conversion and
7
-// its inverse. For example:
8
-//
9
-// import (
10
-// ktds "github.com/ipfs/go-datastore/keytransform"
11
-// ds "github.com/ipfs/go-datastore"
12
-// )
13
-//
14
-// func reverseKey(k ds.Key) ds.Key {
15
-// return k.Reverse()
16
-// }
17
-//
18
-// func invertKeys(d ds.Datastore) {
19
-// return ktds.Wrap(d, &ktds.Pair{
20
-// Convert: reverseKey,
21
-// Invert: reverseKey, // reverse is its own inverse.
22
-// })
23
-// }
24
-//
25
-package keytransform
Godeps/_workspace/src/github.com/ipfs/go-datastore/keytransform/interface.go
deleted
-34
@@ -1,34 +0,0 @@
1
-package keytransform
2
-
3
-import ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
4
-
5
-// KeyMapping is a function that maps one key to annother
6
-type KeyMapping func(ds.Key) ds.Key
7
-
8
-// KeyTransform is an object with a pair of functions for (invertibly)
9
-// transforming keys
10
-type KeyTransform interface {
11
- ConvertKey(ds.Key) ds.Key
12
- InvertKey(ds.Key) ds.Key
13
-}
14
-
15
-// Datastore is a keytransform.Datastore
16
-type Datastore interface {
17
- ds.Shim
18
- KeyTransform
19
-}
20
-
21
-// Wrap wraps a given datastore with a KeyTransform function.
22
-// The resulting wrapped datastore will use the transform on all Datastore
23
-// operations.
24
-func Wrap(child ds.Datastore, t KeyTransform) *ktds {
25
- if t == nil {
26
- panic("t (KeyTransform) is nil")
27
- }
28
-
29
- if child == nil {
30
- panic("child (ds.Datastore) is nil")
31
- }
32
-
33
- return &ktds{child: child, KeyTransform: t}
34
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/keytransform/keytransform.go
deleted
-118
@@ -1,118 +0,0 @@
1
-package keytransform
2
-
3
-import (
4
- "io"
5
-
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
8
-)
9
-
10
-type Pair struct {
11
- Convert KeyMapping
12
- Invert KeyMapping
13
-}
14
-
15
-func (t *Pair) ConvertKey(k ds.Key) ds.Key {
16
- return t.Convert(k)
17
-}
18
-
19
-func (t *Pair) InvertKey(k ds.Key) ds.Key {
20
- return t.Invert(k)
21
-}
22
-
23
-// ktds keeps a KeyTransform function
24
-type ktds struct {
25
- child ds.Datastore
26
-
27
- KeyTransform
28
-}
29
-
30
-// Children implements ds.Shim
31
-func (d *ktds) Children() []ds.Datastore {
32
- return []ds.Datastore{d.child}
33
-}
34
-
35
-// Put stores the given value, transforming the key first.
36
-func (d *ktds) Put(key ds.Key, value interface{}) (err error) {
37
- return d.child.Put(d.ConvertKey(key), value)
38
-}
39
-
40
-// Get returns the value for given key, transforming the key first.
41
-func (d *ktds) Get(key ds.Key) (value interface{}, err error) {
42
- return d.child.Get(d.ConvertKey(key))
43
-}
44
-
45
-// Has returns whether the datastore has a value for a given key, transforming
46
-// the key first.
47
-func (d *ktds) Has(key ds.Key) (exists bool, err error) {
48
- return d.child.Has(d.ConvertKey(key))
49
-}
50
-
51
-// Delete removes the value for given key
52
-func (d *ktds) Delete(key ds.Key) (err error) {
53
- return d.child.Delete(d.ConvertKey(key))
54
-}
55
-
56
-// Query implements Query, inverting keys on the way back out.
57
-func (d *ktds) Query(q dsq.Query) (dsq.Results, error) {
58
- qr, err := d.child.Query(q)
59
- if err != nil {
60
- return nil, err
61
- }
62
-
63
- ch := make(chan dsq.Result)
64
- go func() {
65
- defer close(ch)
66
- defer qr.Close()
67
-
68
- for r := range qr.Next() {
69
- if r.Error == nil {
70
- r.Entry.Key = d.InvertKey(ds.NewKey(r.Entry.Key)).String()
71
- }
72
- ch <- r
73
- }
74
- }()
75
-
76
- return dsq.DerivedResults(qr, ch), nil
77
-}
78
-
79
-func (d *ktds) Close() error {
80
- if c, ok := d.child.(io.Closer); ok {
81
- return c.Close()
82
- }
83
- return nil
84
-}
85
-
86
-func (d *ktds) Batch() (ds.Batch, error) {
87
- bds, ok := d.child.(ds.Batching)
88
- if !ok {
89
- return nil, ds.ErrBatchUnsupported
90
- }
91
-
92
- childbatch, err := bds.Batch()
93
- if err != nil {
94
- return nil, err
95
- }
96
- return &transformBatch{
97
- dst: childbatch,
98
- f: d.ConvertKey,
99
- }, nil
100
-}
101
-
102
-type transformBatch struct {
103
- dst ds.Batch
104
-
105
- f KeyMapping
106
-}
107
-
108
-func (t *transformBatch) Put(key ds.Key, val interface{}) error {
109
- return t.dst.Put(t.f(key), val)
110
-}
111
-
112
-func (t *transformBatch) Delete(key ds.Key) error {
113
- return t.dst.Delete(t.f(key))
114
-}
115
-
116
-func (t *transformBatch) Commit() error {
117
- return t.dst.Commit()
118
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/leveldb/datastore.go
deleted
-155
@@ -1,155 +0,0 @@
1
-package leveldb
2
-
3
-import (
4
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
5
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
6
- "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb"
7
- "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/opt"
8
- "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/util"
9
-
10
- "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
11
-)
12
-
13
-type datastore struct {
14
- DB *leveldb.DB
15
-}
16
-
17
-type Options opt.Options
18
-
19
-func NewDatastore(path string, opts *Options) (*datastore, error) {
20
- var nopts opt.Options
21
- if opts != nil {
22
- nopts = opt.Options(*opts)
23
- }
24
- db, err := leveldb.OpenFile(path, &nopts)
25
- if err != nil {
26
- return nil, err
27
- }
28
-
29
- return &datastore{
30
- DB: db,
31
- }, nil
32
-}
33
-
34
-// Returns ErrInvalidType if value is not of type []byte.
35
-//
36
-// NOTE: Using sync = false.
37
-// see http://godoc.org/github.com/syndtr/goleveldb/leveldb/opt#WriteOptions
38
-func (d *datastore) Put(key ds.Key, value interface{}) (err error) {
39
- val, ok := value.([]byte)
40
- if !ok {
41
- return ds.ErrInvalidType
42
- }
43
- return d.DB.Put(key.Bytes(), val, nil)
44
-}
45
-
46
-func (d *datastore) Get(key ds.Key) (value interface{}, err error) {
47
- val, err := d.DB.Get(key.Bytes(), nil)
48
- if err != nil {
49
- if err == leveldb.ErrNotFound {
50
- return nil, ds.ErrNotFound
51
- }
52
- return nil, err
53
- }
54
- return val, nil
55
-}
56
-
57
-func (d *datastore) Has(key ds.Key) (exists bool, err error) {
58
- return d.DB.Has(key.Bytes(), nil)
59
-}
60
-
61
-func (d *datastore) Delete(key ds.Key) (err error) {
62
- err = d.DB.Delete(key.Bytes(), nil)
63
- if err == leveldb.ErrNotFound {
64
- return ds.ErrNotFound
65
- }
66
- return err
67
-}
68
-
69
-func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
70
-
71
- // we can use multiple iterators concurrently. see:
72
- // https://godoc.org/github.com/syndtr/goleveldb/leveldb#DB.NewIterator
73
- // advance the iterator only if the reader reads
74
- //
75
- // run query in own sub-process tied to Results.Process(), so that
76
- // it waits for us to finish AND so that clients can signal to us
77
- // that resources should be reclaimed.
78
- qrb := dsq.NewResultBuilder(q)
79
- qrb.Process.Go(func(worker goprocess.Process) {
80
- d.runQuery(worker, qrb)
81
- })
82
-
83
- // go wait on the worker (without signaling close)
84
- go qrb.Process.CloseAfterChildren()
85
-
86
- // Now, apply remaining things (filters, order)
87
- qr := qrb.Results()
88
- for _, f := range q.Filters {
89
- qr = dsq.NaiveFilter(qr, f)
90
- }
91
- for _, o := range q.Orders {
92
- qr = dsq.NaiveOrder(qr, o)
93
- }
94
- return qr, nil
95
-}
96
-
97
-func (d *datastore) runQuery(worker goprocess.Process, qrb *dsq.ResultBuilder) {
98
-
99
- var rnge *util.Range
100
- if qrb.Query.Prefix != "" {
101
- rnge = util.BytesPrefix([]byte(qrb.Query.Prefix))
102
- }
103
- i := d.DB.NewIterator(rnge, nil)
104
- defer i.Release()
105
-
106
- // advance iterator for offset
107
- if qrb.Query.Offset > 0 {
108
- for j := 0; j < qrb.Query.Offset; j++ {
109
- i.Next()
110
- }
111
- }
112
-
113
- // iterate, and handle limit, too
114
- for sent := 0; i.Next(); sent++ {
115
- // end early if we hit the limit
116
- if qrb.Query.Limit > 0 && sent >= qrb.Query.Limit {
117
- break
118
- }
119
-
120
- k := ds.NewKey(string(i.Key())).String()
121
- e := dsq.Entry{Key: k}
122
-
123
- if !qrb.Query.KeysOnly {
124
- buf := make([]byte, len(i.Value()))
125
- copy(buf, i.Value())
126
- e.Value = buf
127
- }
128
-
129
- select {
130
- case qrb.Output <- dsq.Result{Entry: e}: // we sent it out
131
- case <-worker.Closing(): // client told us to end early.
132
- break
133
- }
134
- }
135
-
136
- if err := i.Error(); err != nil {
137
- select {
138
- case qrb.Output <- dsq.Result{Error: err}: // client read our error
139
- case <-worker.Closing(): // client told us to end.
140
- return
141
- }
142
- }
143
-}
144
-
145
-func (d *datastore) Batch() (ds.Batch, error) {
146
- // TODO: implement batch on leveldb
147
- return nil, ds.ErrBatchUnsupported
148
-}
149
-
150
-// LevelDB needs to be closed.
151
-func (d *datastore) Close() (err error) {
152
- return d.DB.Close()
153
-}
154
-
155
-func (d *datastore) IsThreadSafe() {}
Godeps/_workspace/src/github.com/ipfs/go-datastore/lru/datastore.go
deleted
-64
@@ -1,64 +0,0 @@
1
-package lru
2
-
3
-import (
4
- "errors"
5
-
6
- lru "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/hashicorp/golang-lru"
7
-
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
-)
11
-
12
-// Datastore uses golang-lru for internal storage.
13
-type Datastore struct {
14
- cache *lru.Cache
15
-}
16
-
17
-// NewDatastore constructs a new LRU Datastore with given capacity.
18
-func NewDatastore(capacity int) (*Datastore, error) {
19
- cache, err := lru.New(capacity)
20
- if err != nil {
21
- return nil, err
22
- }
23
-
24
- return &Datastore{cache: cache}, nil
25
-}
26
-
27
-// Put stores the object `value` named by `key`.
28
-func (d *Datastore) Put(key ds.Key, value interface{}) (err error) {
29
- d.cache.Add(key, value)
30
- return nil
31
-}
32
-
33
-// Get retrieves the object `value` named by `key`.
34
-func (d *Datastore) Get(key ds.Key) (value interface{}, err error) {
35
- val, ok := d.cache.Get(key)
36
- if !ok {
37
- return nil, ds.ErrNotFound
38
- }
39
- return val, nil
40
-}
41
-
42
-// Has returns whether the `key` is mapped to a `value`.
43
-func (d *Datastore) Has(key ds.Key) (exists bool, err error) {
44
- return ds.GetBackedHas(d, key)
45
-}
46
-
47
-// Delete removes the value for given `key`.
48
-func (d *Datastore) Delete(key ds.Key) (err error) {
49
- d.cache.Remove(key)
50
- return nil
51
-}
52
-
53
-// KeyList returns a list of keys in the datastore
54
-func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) {
55
- return nil, errors.New("KeyList not implemented.")
56
-}
57
-
58
-func (d *Datastore) Close() error {
59
- return nil
60
-}
61
-
62
-func (d *Datastore) Batch() (ds.Batch, error) {
63
- return nil, ds.ErrBatchUnsupported
64
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/measure/measure.go
deleted
-248
@@ -1,248 +0,0 @@
1
-// Package measure provides a Datastore wrapper that records metrics
2
-// using github.com/codahale/metrics.
3
-package measure
4
-
5
-import (
6
- "io"
7
- "time"
8
-
9
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/codahale/metrics"
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
11
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
12
-)
13
-
14
-// Histogram measurements exceeding these limits are dropped. TODO
15
-// maybe it would be better to cap the value? Should we keep track of
16
-// drops?
17
-const (
18
- maxLatency = int64(1 * time.Second)
19
- maxSize = int64(1 << 32)
20
-)
21
-
22
-// New wraps the datastore, providing metrics on the operations. The
23
-// metrics are registered with names starting with prefix and a dot.
24
-//
25
-// If prefix is not unique, New will panic. Call Close to release the
26
-// prefix.
27
-func New(prefix string, ds datastore.Datastore) *measure {
28
- m := &measure{
29
- backend: ds,
30
-
31
- putNum: metrics.Counter(prefix + ".Put.num"),
32
- putErr: metrics.Counter(prefix + ".Put.err"),
33
- putLatency: metrics.NewHistogram(prefix+".Put.latency", 0, maxLatency, 3),
34
- putSize: metrics.NewHistogram(prefix+".Put.size", 0, maxSize, 3),
35
-
36
- getNum: metrics.Counter(prefix + ".Get.num"),
37
- getErr: metrics.Counter(prefix + ".Get.err"),
38
- getLatency: metrics.NewHistogram(prefix+".Get.latency", 0, maxLatency, 3),
39
- getSize: metrics.NewHistogram(prefix+".Get.size", 0, maxSize, 3),
40
-
41
- hasNum: metrics.Counter(prefix + ".Has.num"),
42
- hasErr: metrics.Counter(prefix + ".Has.err"),
43
- hasLatency: metrics.NewHistogram(prefix+".Has.latency", 0, maxLatency, 3),
44
-
45
- deleteNum: metrics.Counter(prefix + ".Delete.num"),
46
- deleteErr: metrics.Counter(prefix + ".Delete.err"),
47
- deleteLatency: metrics.NewHistogram(prefix+".Delete.latency", 0, maxLatency, 3),
48
-
49
- queryNum: metrics.Counter(prefix + ".Query.num"),
50
- queryErr: metrics.Counter(prefix + ".Query.err"),
51
- queryLatency: metrics.NewHistogram(prefix+".Query.latency", 0, maxLatency, 3),
52
- }
53
- return m
54
-}
55
-
56
-type measure struct {
57
- backend datastore.Datastore
58
-
59
- putNum metrics.Counter
60
- putErr metrics.Counter
61
- putLatency *metrics.Histogram
62
- putSize *metrics.Histogram
63
-
64
- getNum metrics.Counter
65
- getErr metrics.Counter
66
- getLatency *metrics.Histogram
67
- getSize *metrics.Histogram
68
-
69
- hasNum metrics.Counter
70
- hasErr metrics.Counter
71
- hasLatency *metrics.Histogram
72
-
73
- deleteNum metrics.Counter
74
- deleteErr metrics.Counter
75
- deleteLatency *metrics.Histogram
76
-
77
- queryNum metrics.Counter
78
- queryErr metrics.Counter
79
- queryLatency *metrics.Histogram
80
-}
81
-
82
-var _ datastore.Datastore = (*measure)(nil)
83
-
84
-func recordLatency(h *metrics.Histogram, start time.Time) {
85
- elapsed := time.Now().Sub(start) / time.Microsecond
86
- _ = h.RecordValue(int64(elapsed))
87
-}
88
-
89
-func (m *measure) Put(key datastore.Key, value interface{}) error {
90
- defer recordLatency(m.putLatency, time.Now())
91
- m.putNum.Add()
92
- if b, ok := value.([]byte); ok {
93
- _ = m.putSize.RecordValue(int64(len(b)))
94
- }
95
- err := m.backend.Put(key, value)
96
- if err != nil {
97
- m.putErr.Add()
98
- }
99
- return err
100
-}
101
-
102
-func (m *measure) Get(key datastore.Key) (value interface{}, err error) {
103
- defer recordLatency(m.getLatency, time.Now())
104
- m.getNum.Add()
105
- value, err = m.backend.Get(key)
106
- if err != nil {
107
- m.getErr.Add()
108
- } else {
109
- if b, ok := value.([]byte); ok {
110
- _ = m.getSize.RecordValue(int64(len(b)))
111
- }
112
- }
113
- return value, err
114
-}
115
-
116
-func (m *measure) Has(key datastore.Key) (exists bool, err error) {
117
- defer recordLatency(m.hasLatency, time.Now())
118
- m.hasNum.Add()
119
- exists, err = m.backend.Has(key)
120
- if err != nil {
121
- m.hasErr.Add()
122
- }
123
- return exists, err
124
-}
125
-
126
-func (m *measure) Delete(key datastore.Key) error {
127
- defer recordLatency(m.deleteLatency, time.Now())
128
- m.deleteNum.Add()
129
- err := m.backend.Delete(key)
130
- if err != nil {
131
- m.deleteErr.Add()
132
- }
133
- return err
134
-}
135
-
136
-func (m *measure) Query(q query.Query) (query.Results, error) {
137
- defer recordLatency(m.queryLatency, time.Now())
138
- m.queryNum.Add()
139
- res, err := m.backend.Query(q)
140
- if err != nil {
141
- m.queryErr.Add()
142
- }
143
- return res, err
144
-}
145
-
146
-type measuredBatch struct {
147
- puts int
148
- deletes int
149
-
150
- putts datastore.Batch
151
- delts datastore.Batch
152
-
153
- m *measure
154
-}
155
-
156
-func (m *measure) Batch() (datastore.Batch, error) {
157
- bds, ok := m.backend.(datastore.Batching)
158
- if !ok {
159
- return nil, datastore.ErrBatchUnsupported
160
- }
161
- pb, err := bds.Batch()
162
- if err != nil {
163
- return nil, err
164
- }
165
-
166
- db, err := bds.Batch()
167
- if err != nil {
168
- return nil, err
169
- }
170
-
171
- return &measuredBatch{
172
- putts: pb,
173
- delts: db,
174
-
175
- m: m,
176
- }, nil
177
-}
178
-
179
-func (mt *measuredBatch) Put(key datastore.Key, val interface{}) error {
180
- mt.puts++
181
- valb, ok := val.([]byte)
182
- if !ok {
183
- return datastore.ErrInvalidType
184
- }
185
- _ = mt.m.putSize.RecordValue(int64(len(valb)))
186
- return mt.putts.Put(key, val)
187
-}
188
-
189
-func (mt *measuredBatch) Delete(key datastore.Key) error {
190
- mt.deletes++
191
- return mt.delts.Delete(key)
192
-}
193
-
194
-func (mt *measuredBatch) Commit() error {
195
- err := logBatchCommit(mt.delts, mt.deletes, mt.m.deleteNum, mt.m.deleteErr, mt.m.deleteLatency)
196
- if err != nil {
197
- return err
198
- }
199
-
200
- err = logBatchCommit(mt.putts, mt.puts, mt.m.putNum, mt.m.putErr, mt.m.putLatency)
201
- if err != nil {
202
- return err
203
- }
204
-
205
- return nil
206
-}
207
-
208
-func logBatchCommit(b datastore.Batch, n int, num, errs metrics.Counter, lat *metrics.Histogram) error {
209
- if n > 0 {
210
- before := time.Now()
211
- err := b.Commit()
212
- took := int(time.Now().Sub(before)/time.Microsecond) / n
213
- num.AddN(uint64(n))
214
- for i := 0; i < n; i++ {
215
- _ = lat.RecordValue(int64(took))
216
- }
217
- if err != nil {
218
- errs.Add()
219
- return err
220
- }
221
- }
222
- return nil
223
-}
224
-
225
-func (m *measure) Close() error {
226
- m.putNum.Remove()
227
- m.putErr.Remove()
228
- m.putLatency.Remove()
229
- m.putSize.Remove()
230
- m.getNum.Remove()
231
- m.getErr.Remove()
232
- m.getLatency.Remove()
233
- m.getSize.Remove()
234
- m.hasNum.Remove()
235
- m.hasErr.Remove()
236
- m.hasLatency.Remove()
237
- m.deleteNum.Remove()
238
- m.deleteErr.Remove()
239
- m.deleteLatency.Remove()
240
- m.queryNum.Remove()
241
- m.queryErr.Remove()
242
- m.queryLatency.Remove()
243
-
244
- if c, ok := m.backend.(io.Closer); ok {
245
- return c.Close()
246
- }
247
- return nil
248
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/mount/mount.go
deleted
-188
@@ -1,188 +0,0 @@
1
-// Package mount provides a Datastore that has other Datastores
2
-// mounted at various key prefixes.
3
-package mount
4
-
5
-import (
6
- "errors"
7
- "io"
8
- "strings"
9
-
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
11
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/keytransform"
12
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
13
-)
14
-
15
-var (
16
- ErrNoMount = errors.New("no datastore mounted for this key")
17
-)
18
-
19
-type Mount struct {
20
- Prefix datastore.Key
21
- Datastore datastore.Datastore
22
-}
23
-
24
-func New(mounts []Mount) *Datastore {
25
- // make a copy so we're sure it doesn't mutate
26
- m := make([]Mount, len(mounts))
27
- for i, v := range mounts {
28
- m[i] = v
29
- }
30
- return &Datastore{mounts: m}
31
-}
32
-
33
-type Datastore struct {
34
- mounts []Mount
35
-}
36
-
37
-var _ datastore.Datastore = (*Datastore)(nil)
38
-
39
-func (d *Datastore) lookup(key datastore.Key) (ds datastore.Datastore, mountpoint, rest datastore.Key) {
40
- for _, m := range d.mounts {
41
- if m.Prefix.Equal(key) || m.Prefix.IsAncestorOf(key) {
42
- s := strings.TrimPrefix(key.String(), m.Prefix.String())
43
- k := datastore.NewKey(s)
44
- return m.Datastore, m.Prefix, k
45
- }
46
- }
47
- return nil, datastore.NewKey("/"), key
48
-}
49
-
50
-func (d *Datastore) Put(key datastore.Key, value interface{}) error {
51
- ds, _, k := d.lookup(key)
52
- if ds == nil {
53
- return ErrNoMount
54
- }
55
- return ds.Put(k, value)
56
-}
57
-
58
-func (d *Datastore) Get(key datastore.Key) (value interface{}, err error) {
59
- ds, _, k := d.lookup(key)
60
- if ds == nil {
61
- return nil, datastore.ErrNotFound
62
- }
63
- return ds.Get(k)
64
-}
65
-
66
-func (d *Datastore) Has(key datastore.Key) (exists bool, err error) {
67
- ds, _, k := d.lookup(key)
68
- if ds == nil {
69
- return false, nil
70
- }
71
- return ds.Has(k)
72
-}
73
-
74
-func (d *Datastore) Delete(key datastore.Key) error {
75
- ds, _, k := d.lookup(key)
76
- if ds == nil {
77
- return datastore.ErrNotFound
78
- }
79
- return ds.Delete(k)
80
-}
81
-
82
-func (d *Datastore) Query(q query.Query) (query.Results, error) {
83
- if len(q.Filters) > 0 ||
84
- len(q.Orders) > 0 ||
85
- q.Limit > 0 ||
86
- q.Offset > 0 {
87
- // TODO this is overly simplistic, but the only caller is
88
- // `ipfs refs local` for now, and this gets us moving.
89
- return nil, errors.New("mount only supports listing all prefixed keys in random order")
90
- }
91
- key := datastore.NewKey(q.Prefix)
92
- ds, mount, k := d.lookup(key)
93
- if ds == nil {
94
- return nil, errors.New("mount only supports listing a mount point")
95
- }
96
- // TODO support listing cross mount points too
97
-
98
- // delegate the query to the mounted datastore, while adjusting
99
- // keys in and out
100
- q2 := q
101
- q2.Prefix = k.String()
102
- wrapDS := keytransform.Wrap(ds, &keytransform.Pair{
103
- Convert: func(datastore.Key) datastore.Key {
104
- panic("this should never be called")
105
- },
106
- Invert: func(k datastore.Key) datastore.Key {
107
- return mount.Child(k)
108
- },
109
- })
110
-
111
- r, err := wrapDS.Query(q2)
112
- if err != nil {
113
- return nil, err
114
- }
115
- r = query.ResultsReplaceQuery(r, q)
116
- return r, nil
117
-}
118
-
119
-func (d *Datastore) Close() error {
120
- for _, d := range d.mounts {
121
- if c, ok := d.Datastore.(io.Closer); ok {
122
- err := c.Close()
123
- if err != nil {
124
- return err
125
- }
126
- }
127
- }
128
- return nil
129
-}
130
-
131
-type mountBatch struct {
132
- mounts map[string]datastore.Batch
133
-
134
- d *Datastore
135
-}
136
-
137
-func (d *Datastore) Batch() (datastore.Batch, error) {
138
- return &mountBatch{
139
- mounts: make(map[string]datastore.Batch),
140
- d: d,
141
- }, nil
142
-}
143
-
144
-func (mt *mountBatch) lookupBatch(key datastore.Key) (datastore.Batch, datastore.Key, error) {
145
- child, loc, rest := mt.d.lookup(key)
146
- t, ok := mt.mounts[loc.String()]
147
- if !ok {
148
- bds, ok := child.(datastore.Batching)
149
- if !ok {
150
- return nil, datastore.NewKey(""), datastore.ErrBatchUnsupported
151
- }
152
- var err error
153
- t, err = bds.Batch()
154
- if err != nil {
155
- return nil, datastore.NewKey(""), err
156
- }
157
- mt.mounts[loc.String()] = t
158
- }
159
- return t, rest, nil
160
-}
161
-
162
-func (mt *mountBatch) Put(key datastore.Key, val interface{}) error {
163
- t, rest, err := mt.lookupBatch(key)
164
- if err != nil {
165
- return err
166
- }
167
-
168
- return t.Put(rest, val)
169
-}
170
-
171
-func (mt *mountBatch) Delete(key datastore.Key) error {
172
- t, rest, err := mt.lookupBatch(key)
173
- if err != nil {
174
- return err
175
- }
176
-
177
- return t.Delete(rest)
178
-}
179
-
180
-func (mt *mountBatch) Commit() error {
181
- for _, t := range mt.mounts {
182
- err := t.Commit()
183
- if err != nil {
184
- return err
185
- }
186
- }
187
- return nil
188
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/namespace/doc.go
deleted
-24
@@ -1,24 +0,0 @@
1
-// Package namespace introduces a namespace Datastore Shim, which basically
2
-// mounts the entire child datastore under a prefix.
3
-//
4
-// Use the Wrap function to wrap a datastore with any Key prefix. For example:
5
-//
6
-// import (
7
-// "fmt"
8
-//
9
-// ds "github.com/ipfs/go-datastore"
10
-// nsds "github.com/ipfs/go-datastore/namespace"
11
-// )
12
-//
13
-// func main() {
14
-// mp := ds.NewMapDatastore()
15
-// ns := nsds.Wrap(mp, ds.NewKey("/foo/bar"))
16
-//
17
-// // in the Namespace Datastore:
18
-// ns.Put(ds.NewKey("/beep"), "boop")
19
-// v2, _ := ns.Get(ds.NewKey("/beep")) // v2 == "boop"
20
-//
21
-// // and, in the underlying MapDatastore:
22
-// v3, _ := mp.Get(ds.NewKey("/foo/bar/beep")) // v3 == "boop"
23
-// }
24
-package namespace
Godeps/_workspace/src/github.com/ipfs/go-datastore/namespace/namespace.go
deleted
-91
@@ -1,91 +0,0 @@
1
-package namespace
2
-
3
-import (
4
- "fmt"
5
- "strings"
6
-
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
- ktds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/keytransform"
9
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
-)
11
-
12
-// PrefixTransform constructs a KeyTransform with a pair of functions that
13
-// add or remove the given prefix key.
14
-//
15
-// Warning: Will panic if prefix not found when it should be there. This is
16
-// to avoid insidious data inconsistency errors.
17
-func PrefixTransform(prefix ds.Key) ktds.KeyTransform {
18
- return &ktds.Pair{
19
-
20
- // Convert adds the prefix
21
- Convert: func(k ds.Key) ds.Key {
22
- return prefix.Child(k)
23
- },
24
-
25
- // Invert removes the prefix. panics if prefix not found.
26
- Invert: func(k ds.Key) ds.Key {
27
- if !prefix.IsAncestorOf(k) {
28
- fmt.Errorf("Expected prefix (%s) in key (%s)", prefix, k)
29
- panic("expected prefix not found")
30
- }
31
-
32
- s := strings.TrimPrefix(k.String(), prefix.String())
33
- return ds.NewKey(s)
34
- },
35
- }
36
-}
37
-
38
-// Wrap wraps a given datastore with a key-prefix.
39
-func Wrap(child ds.Datastore, prefix ds.Key) *datastore {
40
- if child == nil {
41
- panic("child (ds.Datastore) is nil")
42
- }
43
-
44
- d := ktds.Wrap(child, PrefixTransform(prefix))
45
- return &datastore{Datastore: d, raw: child, prefix: prefix}
46
-}
47
-
48
-type datastore struct {
49
- prefix ds.Key
50
- raw ds.Datastore
51
- ktds.Datastore
52
-}
53
-
54
-// Query implements Query, inverting keys on the way back out.
55
-func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
56
- qr, err := d.raw.Query(q)
57
- if err != nil {
58
- return nil, err
59
- }
60
-
61
- ch := make(chan dsq.Result)
62
- go func() {
63
- defer close(ch)
64
- defer qr.Close()
65
-
66
- for r := range qr.Next() {
67
- if r.Error != nil {
68
- ch <- r
69
- continue
70
- }
71
-
72
- k := ds.NewKey(r.Entry.Key)
73
- if !d.prefix.IsAncestorOf(k) {
74
- continue
75
- }
76
-
77
- r.Entry.Key = d.Datastore.InvertKey(k).String()
78
- ch <- r
79
- }
80
- }()
81
-
82
- return dsq.DerivedResults(qr, ch), nil
83
-}
84
-
85
-func (d *datastore) Batch() (ds.Batch, error) {
86
- if bds, ok := d.Datastore.(ds.Batching); ok {
87
- return bds.Batch()
88
- }
89
-
90
- return nil, ds.ErrBatchUnsupported
91
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/panic/panic.go
deleted
-120
@@ -1,120 +0,0 @@
1
-package sync
2
-
3
-import (
4
- "fmt"
5
- "io"
6
- "os"
7
-
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
-)
11
-
12
-type datastore struct {
13
- child ds.Datastore
14
-}
15
-
16
-// Wrap shims a datastore such than _any_ operation failing triggers a panic
17
-// This is useful for debugging invariants.
18
-func Wrap(d ds.Datastore) ds.Shim {
19
- return &datastore{child: d}
20
-}
21
-
22
-func (d *datastore) Children() []ds.Datastore {
23
- return []ds.Datastore{d.child}
24
-}
25
-
26
-func (d *datastore) Put(key ds.Key, value interface{}) error {
27
- err := d.child.Put(key, value)
28
- if err != nil {
29
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
30
- panic("panic datastore: Put failed")
31
- }
32
- return nil
33
-}
34
-
35
-func (d *datastore) Get(key ds.Key) (interface{}, error) {
36
- val, err := d.child.Get(key)
37
- if err != nil {
38
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
39
- panic("panic datastore: Get failed")
40
- }
41
- return val, nil
42
-}
43
-
44
-func (d *datastore) Has(key ds.Key) (bool, error) {
45
- e, err := d.child.Has(key)
46
- if err != nil {
47
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
48
- panic("panic datastore: Has failed")
49
- }
50
- return e, nil
51
-}
52
-
53
-func (d *datastore) Delete(key ds.Key) error {
54
- err := d.child.Delete(key)
55
- if err != nil {
56
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
57
- panic("panic datastore: Delete failed")
58
- }
59
- return nil
60
-}
61
-
62
-func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
63
- r, err := d.child.Query(q)
64
- if err != nil {
65
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
66
- panic("panic datastore: Query failed")
67
- }
68
- return r, nil
69
-}
70
-
71
-func (d *datastore) Close() error {
72
- if c, ok := d.child.(io.Closer); ok {
73
- err := c.Close()
74
- if err != nil {
75
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
76
- panic("panic datastore: Close failed")
77
- }
78
- }
79
- return nil
80
-}
81
-
82
-func (d *datastore) Batch() (ds.Batch, error) {
83
- b, err := d.child.(ds.Batching).Batch()
84
- if err != nil {
85
- return nil, err
86
- }
87
-
88
- return &panicBatch{b}, nil
89
-}
90
-
91
-type panicBatch struct {
92
- t ds.Batch
93
-}
94
-
95
-func (p *panicBatch) Put(key ds.Key, val interface{}) error {
96
- err := p.t.Put(key, val)
97
- if err != nil {
98
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
99
- panic("panic datastore: transaction put failed")
100
- }
101
- return nil
102
-}
103
-
104
-func (p *panicBatch) Delete(key ds.Key) error {
105
- err := p.t.Delete(key)
106
- if err != nil {
107
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
108
- panic("panic datastore: transaction delete failed")
109
- }
110
- return nil
111
-}
112
-
113
-func (p *panicBatch) Commit() error {
114
- err := p.t.Commit()
115
- if err != nil {
116
- fmt.Fprintf(os.Stdout, "panic datastore: %s", err)
117
- panic("panic datastore: transaction commit failed")
118
- }
119
- return nil
120
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/query/filter.go
deleted
-86
@@ -1,86 +0,0 @@
1
-package query
2
-
3
-import (
4
- "fmt"
5
- "reflect"
6
- "strings"
7
-)
8
-
9
-// Filter is an object that tests ResultEntries
10
-type Filter interface {
11
- // Filter returns whether an entry passes the filter
12
- Filter(e Entry) bool
13
-}
14
-
15
-// Op is a comparison operator
16
-type Op string
17
-
18
-var (
19
- Equal = Op("==")
20
- NotEqual = Op("!=")
21
- GreaterThan = Op(">")
22
- GreaterThanOrEqual = Op(">=")
23
- LessThan = Op("<")
24
- LessThanOrEqual = Op("<=")
25
-)
26
-
27
-// FilterValueCompare is used to signal to datastores they
28
-// should apply internal comparisons. unfortunately, there
29
-// is no way to apply comparisons* to interface{} types in
30
-// Go, so if the datastore doesnt have a special way to
31
-// handle these comparisons, you must provided the
32
-// TypedFilter to actually do filtering.
33
-//
34
-// [*] other than == and !=, which use reflect.DeepEqual.
35
-type FilterValueCompare struct {
36
- Op Op
37
- Value interface{}
38
- TypedFilter Filter
39
-}
40
-
41
-func (f FilterValueCompare) Filter(e Entry) bool {
42
- if f.TypedFilter != nil {
43
- return f.TypedFilter.Filter(e)
44
- }
45
-
46
- switch f.Op {
47
- case Equal:
48
- return reflect.DeepEqual(f.Value, e.Value)
49
- case NotEqual:
50
- return !reflect.DeepEqual(f.Value, e.Value)
51
- default:
52
- panic(fmt.Errorf("cannot apply op '%s' to interface{}.", f.Op))
53
- }
54
-}
55
-
56
-type FilterKeyCompare struct {
57
- Op Op
58
- Key string
59
-}
60
-
61
-func (f FilterKeyCompare) Filter(e Entry) bool {
62
- switch f.Op {
63
- case Equal:
64
- return e.Key == f.Key
65
- case NotEqual:
66
- return e.Key != f.Key
67
- case GreaterThan:
68
- return e.Key > f.Key
69
- case GreaterThanOrEqual:
70
- return e.Key >= f.Key
71
- case LessThan:
72
- return e.Key < f.Key
73
- case LessThanOrEqual:
74
- return e.Key <= f.Key
75
- default:
76
- panic(fmt.Errorf("unknown op '%s'", f.Op))
77
- }
78
-}
79
-
80
-type FilterKeyPrefix struct {
81
- Prefix string
82
-}
83
-
84
-func (f FilterKeyPrefix) Filter(e Entry) bool {
85
- return strings.HasPrefix(e.Key, f.Prefix)
86
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/query/order.go
deleted
-66
@@ -1,66 +0,0 @@
1
-package query
2
-
3
-import (
4
- "sort"
5
-)
6
-
7
-// Order is an object used to order objects
8
-type Order interface {
9
-
10
- // Sort sorts the Entry slice according to
11
- // the Order criteria.
12
- Sort([]Entry)
13
-}
14
-
15
-// OrderByValue is used to signal to datastores they
16
-// should apply internal orderings. unfortunately, there
17
-// is no way to apply order comparisons to interface{} types
18
-// in Go, so if the datastore doesnt have a special way to
19
-// handle these comparisons, you must provide an Order
20
-// implementation that casts to the correct type.
21
-type OrderByValue struct {
22
- TypedOrder Order
23
-}
24
-
25
-func (o OrderByValue) Sort(res []Entry) {
26
- if o.TypedOrder == nil {
27
- panic("cannot order interface{} by value. see query docs.")
28
- }
29
- o.TypedOrder.Sort(res)
30
-}
31
-
32
-// OrderByValueDescending is used to signal to datastores they
33
-// should apply internal orderings. unfortunately, there
34
-// is no way to apply order comparisons to interface{} types
35
-// in Go, so if the datastore doesnt have a special way to
36
-// handle these comparisons, you are SOL.
37
-type OrderByValueDescending struct {
38
- TypedOrder Order
39
-}
40
-
41
-func (o OrderByValueDescending) Sort(res []Entry) {
42
- if o.TypedOrder == nil {
43
- panic("cannot order interface{} by value. see query docs.")
44
- }
45
- o.TypedOrder.Sort(res)
46
-}
47
-
48
-// OrderByKey
49
-type OrderByKey struct{}
50
-
51
-func (o OrderByKey) Sort(res []Entry) {
52
- sort.Stable(reByKey(res))
53
-}
54
-
55
-// OrderByKeyDescending
56
-type OrderByKeyDescending struct{}
57
-
58
-func (o OrderByKeyDescending) Sort(res []Entry) {
59
- sort.Stable(sort.Reverse(reByKey(res)))
60
-}
61
-
62
-type reByKey []Entry
63
-
64
-func (s reByKey) Len() int { return len(s) }
65
-func (s reByKey) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
66
-func (s reByKey) Less(i, j int) bool { return s[i].Key < s[j].Key }
Godeps/_workspace/src/github.com/ipfs/go-datastore/query/query.go
deleted
-250
@@ -1,250 +0,0 @@
1
-package query
2
-
3
-import (
4
- goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
5
-)
6
-
7
-/*
8
-Query represents storage for any key-value pair.
9
-
10
-tl;dr:
11
-
12
- queries are supported across datastores.
13
- Cheap on top of relational dbs, and expensive otherwise.
14
- Pick the right tool for the job!
15
-
16
-In addition to the key-value store get and set semantics, datastore
17
-provides an interface to retrieve multiple records at a time through
18
-the use of queries. The datastore Query model gleans a common set of
19
-operations performed when querying. To avoid pasting here years of
20
-database research, let’s summarize the operations datastore supports.
21
-
22
-Query Operations:
23
-
24
- * namespace - scope the query, usually by object type
25
- * filters - select a subset of values by applying constraints
26
- * orders - sort the results by applying sort conditions
27
- * limit - impose a numeric limit on the number of results
28
- * offset - skip a number of results (for efficient pagination)
29
-
30
-datastore combines these operations into a simple Query class that allows
31
-applications to define their constraints in a simple, generic, way without
32
-introducing datastore specific calls, languages, etc.
33
-
34
-Of course, different datastores provide relational query support across a
35
-wide spectrum, from full support in traditional databases to none at all in
36
-most key-value stores. Datastore aims to provide a common, simple interface
37
-for the sake of application evolution over time and keeping large code bases
38
-free of tool-specific code. It would be ridiculous to claim to support high-
39
-performance queries on architectures that obviously do not. Instead, datastore
40
-provides the interface, ideally translating queries to their native form
41
-(e.g. into SQL for MySQL).
42
-
43
-However, on the wrong datastore, queries can potentially incur the high cost
44
-of performing the aforemantioned query operations on the data set directly in
45
-Go. It is the client’s responsibility to select the right tool for the job:
46
-pick a data storage solution that fits the application’s needs now, and wrap
47
-it with a datastore implementation. As the needs change, swap out datastore
48
-implementations to support your new use cases. Some applications, particularly
49
-in early development stages, can afford to incurr the cost of queries on non-
50
-relational databases (e.g. using a FSDatastore and not worry about a database
51
-at all). When it comes time to switch the tool for performance, updating the
52
-application code can be as simple as swapping the datastore in one place, not
53
-all over the application code base. This gain in engineering time, both at
54
-initial development and during later iterations, can significantly offset the
55
-cost of the layer of abstraction.
56
-
57
-*/
58
-type Query struct {
59
- Prefix string // namespaces the query to results whose keys have Prefix
60
- Filters []Filter // filter results. apply sequentially
61
- Orders []Order // order results. apply sequentially
62
- Limit int // maximum number of results
63
- Offset int // skip given number of results
64
- KeysOnly bool // return only keys.
65
-}
66
-
67
-// NotFetched is a special type that signals whether or not the value
68
-// of an Entry has been fetched or not. This is needed because
69
-// datastore implementations get to decide whether Query returns values
70
-// or only keys. nil is not a good signal, as real values may be nil.
71
-const NotFetched int = iota
72
-
73
-// Entry is a query result entry.
74
-type Entry struct {
75
- Key string // cant be ds.Key because circular imports ...!!!
76
- Value interface{}
77
-}
78
-
79
-// Result is a special entry that includes an error, so that the client
80
-// may be warned about internal errors.
81
-type Result struct {
82
- Entry
83
-
84
- Error error
85
-}
86
-
87
-// Results is a set of Query results. This is the interface for clients.
88
-// Example:
89
-//
90
-// qr, _ := myds.Query(q)
91
-// for r := range qr.Next() {
92
-// if r.Error != nil {
93
-// // handle.
94
-// break
95
-// }
96
-//
97
-// fmt.Println(r.Entry.Key, r.Entry.Value)
98
-// }
99
-//
100
-// or, wait on all results at once:
101
-//
102
-// qr, _ := myds.Query(q)
103
-// es, _ := qr.Rest()
104
-// for _, e := range es {
105
-// fmt.Println(e.Key, e.Value)
106
-// }
107
-//
108
-type Results interface {
109
- Query() Query // the query these Results correspond to
110
- Next() <-chan Result // returns a channel to wait for the next result
111
- Rest() ([]Entry, error) // waits till processing finishes, returns all entries at once.
112
- Close() error // client may call Close to signal early exit
113
-
114
- // Process returns a goprocess.Process associated with these results.
115
- // most users will not need this function (Close is all they want),
116
- // but it's here in case you want to connect the results to other
117
- // goprocess-friendly things.
118
- Process() goprocess.Process
119
-}
120
-
121
-// results implements Results
122
-type results struct {
123
- query Query
124
- proc goprocess.Process
125
- res <-chan Result
126
-}
127
-
128
-func (r *results) Next() <-chan Result {
129
- return r.res
130
-}
131
-
132
-func (r *results) Rest() ([]Entry, error) {
133
- var es []Entry
134
- for e := range r.res {
135
- if e.Error != nil {
136
- return es, e.Error
137
- }
138
- es = append(es, e.Entry)
139
- }
140
- <-r.proc.Closed() // wait till the processing finishes.
141
- return es, nil
142
-}
143
-
144
-func (r *results) Process() goprocess.Process {
145
- return r.proc
146
-}
147
-
148
-func (r *results) Close() error {
149
- return r.proc.Close()
150
-}
151
-
152
-func (r *results) Query() Query {
153
- return r.query
154
-}
155
-
156
-// ResultBuilder is what implementors use to construct results
157
-// Implementors of datastores and their clients must respect the
158
-// Process of the Request:
159
-//
160
-// * clients must call r.Process().Close() on an early exit, so
161
-// implementations can reclaim resources.
162
-// * if the Entries are read to completion (channel closed), Process
163
-// should be closed automatically.
164
-// * datastores must respect <-Process.Closing(), which intermediates
165
-// an early close signal from the client.
166
-//
167
-type ResultBuilder struct {
168
- Query Query
169
- Process goprocess.Process
170
- Output chan Result
171
-}
172
-
173
-// Results returns a Results to to this builder.
174
-func (rb *ResultBuilder) Results() Results {
175
- return &results{
176
- query: rb.Query,
177
- proc: rb.Process,
178
- res: rb.Output,
179
- }
180
-}
181
-
182
-func NewResultBuilder(q Query) *ResultBuilder {
183
- b := &ResultBuilder{
184
- Query: q,
185
- Output: make(chan Result),
186
- }
187
- b.Process = goprocess.WithTeardown(func() error {
188
- close(b.Output)
189
- return nil
190
- })
191
- return b
192
-}
193
-
194
-// ResultsWithChan returns a Results object from a channel
195
-// of Result entries. Respects its own Close()
196
-func ResultsWithChan(q Query, res <-chan Result) Results {
197
- b := NewResultBuilder(q)
198
-
199
- // go consume all the entries and add them to the results.
200
- b.Process.Go(func(worker goprocess.Process) {
201
- for {
202
- select {
203
- case <-worker.Closing(): // client told us to close early
204
- return
205
- case e, more := <-res:
206
- if !more {
207
- return
208
- }
209
-
210
- select {
211
- case b.Output <- e:
212
- case <-worker.Closing(): // client told us to close early
213
- return
214
- }
215
- }
216
- }
217
- return
218
- })
219
-
220
- go b.Process.CloseAfterChildren()
221
- return b.Results()
222
-}
223
-
224
-// ResultsWithEntries returns a Results object from a list of entries
225
-func ResultsWithEntries(q Query, res []Entry) Results {
226
- b := NewResultBuilder(q)
227
-
228
- // go consume all the entries and add them to the results.
229
- b.Process.Go(func(worker goprocess.Process) {
230
- for _, e := range res {
231
- select {
232
- case b.Output <- Result{Entry: e}:
233
- case <-worker.Closing(): // client told us to close early
234
- return
235
- }
236
- }
237
- return
238
- })
239
-
240
- go b.Process.CloseAfterChildren()
241
- return b.Results()
242
-}
243
-
244
-func ResultsReplaceQuery(r Results, q Query) Results {
245
- return &results{
246
- query: q,
247
- proc: r.Process(),
248
- res: r.Next(),
249
- }
250
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/query/query_impl.go
deleted
-127
@@ -1,127 +0,0 @@
1
-package query
2
-
3
-func DerivedResults(qr Results, ch <-chan Result) Results {
4
- return &results{
5
- query: qr.Query(),
6
- proc: qr.Process(),
7
- res: ch,
8
- }
9
-}
10
-
11
-// NaiveFilter applies a filter to the results.
12
-func NaiveFilter(qr Results, filter Filter) Results {
13
- ch := make(chan Result)
14
- go func() {
15
- defer close(ch)
16
- defer qr.Close()
17
-
18
- for e := range qr.Next() {
19
- if e.Error != nil || filter.Filter(e.Entry) {
20
- ch <- e
21
- }
22
- }
23
- }()
24
-
25
- return DerivedResults(qr, ch)
26
-}
27
-
28
-// NaiveLimit truncates the results to a given int limit
29
-func NaiveLimit(qr Results, limit int) Results {
30
- ch := make(chan Result)
31
- go func() {
32
- defer close(ch)
33
- defer qr.Close()
34
-
35
- l := 0
36
- for e := range qr.Next() {
37
- if e.Error != nil {
38
- ch <- e
39
- continue
40
- }
41
- ch <- e
42
- l++
43
- if limit > 0 && l >= limit {
44
- break
45
- }
46
- }
47
- }()
48
-
49
- return DerivedResults(qr, ch)
50
-}
51
-
52
-// NaiveOffset skips a given number of results
53
-func NaiveOffset(qr Results, offset int) Results {
54
- ch := make(chan Result)
55
- go func() {
56
- defer close(ch)
57
- defer qr.Close()
58
-
59
- sent := 0
60
- for e := range qr.Next() {
61
- if e.Error != nil {
62
- ch <- e
63
- }
64
-
65
- if sent < offset {
66
- sent++
67
- continue
68
- }
69
- ch <- e
70
- }
71
- }()
72
-
73
- return DerivedResults(qr, ch)
74
-}
75
-
76
-// NaiveOrder reorders results according to given Order.
77
-// WARNING: this is the only non-stream friendly operation!
78
-func NaiveOrder(qr Results, o Order) Results {
79
- ch := make(chan Result)
80
- var entries []Entry
81
- go func() {
82
- defer close(ch)
83
- defer qr.Close()
84
-
85
- for e := range qr.Next() {
86
- if e.Error != nil {
87
- ch <- e
88
- }
89
-
90
- entries = append(entries, e.Entry)
91
- }
92
-
93
- o.Sort(entries)
94
- for _, e := range entries {
95
- ch <- Result{Entry: e}
96
- }
97
- }()
98
-
99
- return DerivedResults(qr, ch)
100
-}
101
-
102
-func NaiveQueryApply(q Query, qr Results) Results {
103
- if q.Prefix != "" {
104
- qr = NaiveFilter(qr, FilterKeyPrefix{q.Prefix})
105
- }
106
- for _, f := range q.Filters {
107
- qr = NaiveFilter(qr, f)
108
- }
109
- for _, o := range q.Orders {
110
- qr = NaiveOrder(qr, o)
111
- }
112
- if q.Offset != 0 {
113
- qr = NaiveOffset(qr, q.Offset)
114
- }
115
- if q.Limit != 0 {
116
- qr = NaiveLimit(qr, q.Offset)
117
- }
118
- return qr
119
-}
120
-
121
-func ResultEntriesFrom(keys []string, vals []interface{}) []Entry {
122
- re := make([]Entry, len(keys))
123
- for i, k := range keys {
124
- re[i] = Entry{Key: k, Value: vals[i]}
125
- }
126
- return re
127
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/redis/redis.go
deleted
-92
@@ -1,92 +0,0 @@
1
-package redis
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "sync"
7
- "time"
8
-
9
- "github.com/fzzy/radix/redis"
10
- datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
11
- query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
12
-)
13
-
14
-var _ datastore.Datastore = &Datastore{}
15
-var _ datastore.ThreadSafeDatastore = &Datastore{}
16
-
17
-var ErrInvalidType = errors.New("redis datastore: invalid type error. this datastore only supports []byte values")
18
-
19
-func NewExpiringDatastore(client *redis.Client, ttl time.Duration) (*Datastore, error) {
20
- return &Datastore{
21
- client: client,
22
- ttl: ttl,
23
- }, nil
24
-}
25
-
26
-func NewDatastore(client *redis.Client) (*Datastore, error) {
27
- return &Datastore{
28
- client: client,
29
- }, nil
30
-}
31
-
32
-type Datastore struct {
33
- mu sync.Mutex
34
- client *redis.Client
35
- ttl time.Duration
36
-}
37
-
38
-func (ds *Datastore) Put(key datastore.Key, value interface{}) error {
39
- ds.mu.Lock()
40
- defer ds.mu.Unlock()
41
-
42
- data, ok := value.([]byte)
43
- if !ok {
44
- return ErrInvalidType
45
- }
46
-
47
- ds.client.Append("SET", key.String(), data)
48
- if ds.ttl != 0 {
49
- ds.client.Append("EXPIRE", key.String(), ds.ttl.Seconds())
50
- }
51
- if err := ds.client.GetReply().Err; err != nil {
52
- return fmt.Errorf("failed to put value: %s", err)
53
- }
54
- if ds.ttl != 0 {
55
- if err := ds.client.GetReply().Err; err != nil {
56
- return fmt.Errorf("failed to set expiration: %s", err)
57
- }
58
- }
59
- return nil
60
-}
61
-
62
-func (ds *Datastore) Get(key datastore.Key) (value interface{}, err error) {
63
- ds.mu.Lock()
64
- defer ds.mu.Unlock()
65
- return ds.client.Cmd("GET", key.String()).Bytes()
66
-}
67
-
68
-func (ds *Datastore) Has(key datastore.Key) (exists bool, err error) {
69
- ds.mu.Lock()
70
- defer ds.mu.Unlock()
71
- return ds.client.Cmd("EXISTS", key.String()).Bool()
72
-}
73
-
74
-func (ds *Datastore) Delete(key datastore.Key) (err error) {
75
- ds.mu.Lock()
76
- defer ds.mu.Unlock()
77
- return ds.client.Cmd("DEL", key.String()).Err
78
-}
79
-
80
-func (ds *Datastore) Query(q query.Query) (query.Results, error) {
81
- return nil, errors.New("TODO implement query for redis datastore?")
82
-}
83
-
84
-func (ds *Datastore) IsThreadSafe() {}
85
-
86
-func (ds *Datastore) Batch() (datastore.Batch, error) {
87
- return nil, datastore.ErrBatchUnsupported
88
-}
89
-
90
-func (ds *Datastore) Close() error {
91
- return ds.client.Close()
92
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/sync/sync.go
deleted
-116
@@ -1,116 +0,0 @@
1
-package sync
2
-
3
-import (
4
- "io"
5
- "sync"
6
-
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
9
-)
10
-
11
-// MutexDatastore contains a child datastire and a mutex.
12
-// used for coarse sync
13
-type MutexDatastore struct {
14
- sync.RWMutex
15
-
16
- child ds.Datastore
17
-}
18
-
19
-// MutexWrap constructs a datastore with a coarse lock around
20
-// the entire datastore, for every single operation
21
-func MutexWrap(d ds.Datastore) *MutexDatastore {
22
- return &MutexDatastore{child: d}
23
-}
24
-
25
-// Children implements Shim
26
-func (d *MutexDatastore) Children() []ds.Datastore {
27
- return []ds.Datastore{d.child}
28
-}
29
-
30
-// IsThreadSafe implements ThreadSafeDatastore
31
-func (d *MutexDatastore) IsThreadSafe() {}
32
-
33
-// Put implements Datastore.Put
34
-func (d *MutexDatastore) Put(key ds.Key, value interface{}) (err error) {
35
- d.Lock()
36
- defer d.Unlock()
37
- return d.child.Put(key, value)
38
-}
39
-
40
-// Get implements Datastore.Get
41
-func (d *MutexDatastore) Get(key ds.Key) (value interface{}, err error) {
42
- d.RLock()
43
- defer d.RUnlock()
44
- return d.child.Get(key)
45
-}
46
-
47
-// Has implements Datastore.Has
48
-func (d *MutexDatastore) Has(key ds.Key) (exists bool, err error) {
49
- d.RLock()
50
- defer d.RUnlock()
51
- return d.child.Has(key)
52
-}
53
-
54
-// Delete implements Datastore.Delete
55
-func (d *MutexDatastore) Delete(key ds.Key) (err error) {
56
- d.Lock()
57
- defer d.Unlock()
58
- return d.child.Delete(key)
59
-}
60
-
61
-// KeyList implements Datastore.KeyList
62
-func (d *MutexDatastore) Query(q dsq.Query) (dsq.Results, error) {
63
- d.RLock()
64
- defer d.RUnlock()
65
- return d.child.Query(q)
66
-}
67
-
68
-func (d *MutexDatastore) Batch() (ds.Batch, error) {
69
- d.RLock()
70
- defer d.RUnlock()
71
- bds, ok := d.child.(ds.Batching)
72
- if !ok {
73
- return nil, ds.ErrBatchUnsupported
74
- }
75
-
76
- b, err := bds.Batch()
77
- if err != nil {
78
- return nil, err
79
- }
80
- return &syncBatch{
81
- batch: b,
82
- mds: d,
83
- }, nil
84
-}
85
-
86
-func (d *MutexDatastore) Close() error {
87
- d.RWMutex.Lock()
88
- defer d.RWMutex.Unlock()
89
- if c, ok := d.child.(io.Closer); ok {
90
- return c.Close()
91
- }
92
- return nil
93
-}
94
-
95
-type syncBatch struct {
96
- batch ds.Batch
97
- mds *MutexDatastore
98
-}
99
-
100
-func (b *syncBatch) Put(key ds.Key, val interface{}) error {
101
- b.mds.Lock()
102
- defer b.mds.Unlock()
103
- return b.batch.Put(key, val)
104
-}
105
-
106
-func (b *syncBatch) Delete(key ds.Key) error {
107
- b.mds.Lock()
108
- defer b.mds.Unlock()
109
- return b.batch.Delete(key)
110
-}
111
-
112
-func (b *syncBatch) Commit() error {
113
- b.mds.Lock()
114
- defer b.mds.Unlock()
115
- return b.batch.Commit()
116
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/syncmount/mount.go
deleted
-198
@@ -1,198 +0,0 @@
1
-// Package mount provides a Datastore that has other Datastores
2
-// mounted at various key prefixes and is threadsafe
3
-package syncmount
4
-
5
-import (
6
- "errors"
7
- "io"
8
- "strings"
9
- "sync"
10
-
11
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
12
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/keytransform"
13
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
14
-)
15
-
16
-var (
17
- ErrNoMount = errors.New("no datastore mounted for this key")
18
-)
19
-
20
-type Mount struct {
21
- Prefix ds.Key
22
- Datastore ds.Datastore
23
-}
24
-
25
-func New(mounts []Mount) *Datastore {
26
- // make a copy so we're sure it doesn't mutate
27
- m := make([]Mount, len(mounts))
28
- for i, v := range mounts {
29
- m[i] = v
30
- }
31
- return &Datastore{mounts: m}
32
-}
33
-
34
-type Datastore struct {
35
- mounts []Mount
36
- lk sync.Mutex
37
-}
38
-
39
-var _ ds.Datastore = (*Datastore)(nil)
40
-
41
-func (d *Datastore) lookup(key ds.Key) (ds.Datastore, ds.Key, ds.Key) {
42
- d.lk.Lock()
43
- defer d.lk.Unlock()
44
- for _, m := range d.mounts {
45
- if m.Prefix.Equal(key) || m.Prefix.IsAncestorOf(key) {
46
- s := strings.TrimPrefix(key.String(), m.Prefix.String())
47
- k := ds.NewKey(s)
48
- return m.Datastore, m.Prefix, k
49
- }
50
- }
51
- return nil, ds.NewKey("/"), key
52
-}
53
-
54
-func (d *Datastore) Put(key ds.Key, value interface{}) error {
55
- cds, _, k := d.lookup(key)
56
- if cds == nil {
57
- return ErrNoMount
58
- }
59
- return cds.Put(k, value)
60
-}
61
-
62
-func (d *Datastore) Get(key ds.Key) (value interface{}, err error) {
63
- cds, _, k := d.lookup(key)
64
- if cds == nil {
65
- return nil, ds.ErrNotFound
66
- }
67
- return cds.Get(k)
68
-}
69
-
70
-func (d *Datastore) Has(key ds.Key) (exists bool, err error) {
71
- cds, _, k := d.lookup(key)
72
- if cds == nil {
73
- return false, nil
74
- }
75
- return cds.Has(k)
76
-}
77
-
78
-func (d *Datastore) Delete(key ds.Key) error {
79
- cds, _, k := d.lookup(key)
80
- if cds == nil {
81
- return ds.ErrNotFound
82
- }
83
- return cds.Delete(k)
84
-}
85
-
86
-func (d *Datastore) Query(q query.Query) (query.Results, error) {
87
- if len(q.Filters) > 0 ||
88
- len(q.Orders) > 0 ||
89
- q.Limit > 0 ||
90
- q.Offset > 0 {
91
- // TODO this is overly simplistic, but the only caller is
92
- // `ipfs refs local` for now, and this gets us moving.
93
- return nil, errors.New("mount only supports listing all prefixed keys in random order")
94
- }
95
- key := ds.NewKey(q.Prefix)
96
- cds, mount, k := d.lookup(key)
97
- if cds == nil {
98
- return nil, errors.New("mount only supports listing a mount point")
99
- }
100
- // TODO support listing cross mount points too
101
-
102
- // delegate the query to the mounted datastore, while adjusting
103
- // keys in and out
104
- q2 := q
105
- q2.Prefix = k.String()
106
- wrapDS := keytransform.Wrap(cds, &keytransform.Pair{
107
- Convert: func(ds.Key) ds.Key {
108
- panic("this should never be called")
109
- },
110
- Invert: func(k ds.Key) ds.Key {
111
- return mount.Child(k)
112
- },
113
- })
114
-
115
- r, err := wrapDS.Query(q2)
116
- if err != nil {
117
- return nil, err
118
- }
119
- r = query.ResultsReplaceQuery(r, q)
120
- return r, nil
121
-}
122
-
123
-func (d *Datastore) IsThreadSafe() {}
124
-
125
-func (d *Datastore) Close() error {
126
- for _, d := range d.mounts {
127
- if c, ok := d.Datastore.(io.Closer); ok {
128
- err := c.Close()
129
- if err != nil {
130
- return err
131
- }
132
- }
133
- }
134
- return nil
135
-}
136
-
137
-type mountBatch struct {
138
- mounts map[string]ds.Batch
139
- lk sync.Mutex
140
-
141
- d *Datastore
142
-}
143
-
144
-func (d *Datastore) Batch() (ds.Batch, error) {
145
- return &mountBatch{
146
- mounts: make(map[string]ds.Batch),
147
- d: d,
148
- }, nil
149
-}
150
-
151
-func (mt *mountBatch) lookupBatch(key ds.Key) (ds.Batch, ds.Key, error) {
152
- mt.lk.Lock()
153
- defer mt.lk.Unlock()
154
-
155
- child, loc, rest := mt.d.lookup(key)
156
- t, ok := mt.mounts[loc.String()]
157
- if !ok {
158
- bds, ok := child.(ds.Batching)
159
- if !ok {
160
- return nil, ds.NewKey(""), ds.ErrBatchUnsupported
161
- }
162
- var err error
163
- t, err = bds.Batch()
164
- if err != nil {
165
- return nil, ds.NewKey(""), err
166
- }
167
- mt.mounts[loc.String()] = t
168
- }
169
- return t, rest, nil
170
-}
171
-
172
-func (mt *mountBatch) Put(key ds.Key, val interface{}) error {
173
- t, rest, err := mt.lookupBatch(key)
174
- if err != nil {
175
- return err
176
- }
177
-
178
- return t.Put(rest, val)
179
-}
180
-
181
-func (mt *mountBatch) Delete(key ds.Key) error {
182
- t, rest, err := mt.lookupBatch(key)
183
- if err != nil {
184
- return err
185
- }
186
-
187
- return t.Delete(rest)
188
-}
189
-
190
-func (mt *mountBatch) Commit() error {
191
- for _, t := range mt.mounts {
192
- err := t.Commit()
193
- if err != nil {
194
- return err
195
- }
196
- }
197
- return nil
198
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/test/assert.go
deleted
-25
@@ -1,25 +0,0 @@
1
-package dstest
2
-
3
-import "testing"
4
-
5
-func Nil(err error, t *testing.T, msgs ...string) {
6
- if err != nil {
7
- t.Fatal(msgs, "error:", err)
8
- }
9
-}
10
-
11
-func True(v bool, t *testing.T, msgs ...string) {
12
- if !v {
13
- t.Fatal(msgs)
14
- }
15
-}
16
-
17
-func False(v bool, t *testing.T, msgs ...string) {
18
- True(!v, t, msgs...)
19
-}
20
-
21
-func Err(err error, t *testing.T, msgs ...string) {
22
- if err == nil {
23
- t.Fatal(msgs, "error:", err)
24
- }
25
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/test/test_util.go
deleted
-99
@@ -1,99 +0,0 @@
1
-package dstest
2
-
3
-import (
4
- "bytes"
5
- "encoding/base32"
6
- "testing"
7
-
8
- rand "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/randbo"
9
- dstore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
-)
11
-
12
-func RunBatchTest(t *testing.T, ds dstore.Batching) {
13
- batch, err := ds.Batch()
14
- if err != nil {
15
- t.Fatal(err)
16
- }
17
-
18
- r := rand.New()
19
- var blocks [][]byte
20
- var keys []dstore.Key
21
- for i := 0; i < 20; i++ {
22
- blk := make([]byte, 256*1024)
23
- r.Read(blk)
24
- blocks = append(blocks, blk)
25
-
26
- key := dstore.NewKey(base32.StdEncoding.EncodeToString(blk[:8]))
27
- keys = append(keys, key)
28
-
29
- err := batch.Put(key, blk)
30
- if err != nil {
31
- t.Fatal(err)
32
- }
33
- }
34
-
35
- // Ensure they are not in the datastore before comitting
36
- for _, k := range keys {
37
- _, err := ds.Get(k)
38
- if err == nil {
39
- t.Fatal("should not have found this block")
40
- }
41
- }
42
-
43
- // commit, write them to the datastore
44
- err = batch.Commit()
45
- if err != nil {
46
- t.Fatal(err)
47
- }
48
-
49
- for i, k := range keys {
50
- blk, err := ds.Get(k)
51
- if err != nil {
52
- t.Fatal(err)
53
- }
54
-
55
- if !bytes.Equal(blk.([]byte), blocks[i]) {
56
- t.Fatal("blocks not correct!")
57
- }
58
- }
59
-}
60
-
61
-func RunBatchDeleteTest(t *testing.T, ds dstore.Batching) {
62
- r := rand.New()
63
- var keys []dstore.Key
64
- for i := 0; i < 20; i++ {
65
- blk := make([]byte, 16)
66
- r.Read(blk)
67
-
68
- key := dstore.NewKey(base32.StdEncoding.EncodeToString(blk[:8]))
69
- keys = append(keys, key)
70
-
71
- err := ds.Put(key, blk)
72
- if err != nil {
73
- t.Fatal(err)
74
- }
75
- }
76
-
77
- batch, err := ds.Batch()
78
- if err != nil {
79
- t.Fatal(err)
80
- }
81
-
82
- for _, k := range keys {
83
- err := batch.Delete(k)
84
- if err != nil {
85
- t.Fatal(err)
86
- }
87
- }
88
- err = batch.Commit()
89
- if err != nil {
90
- t.Fatal(err)
91
- }
92
-
93
- for _, k := range keys {
94
- _, err := ds.Get(k)
95
- if err == nil {
96
- t.Fatal("shouldnt have found block")
97
- }
98
- }
99
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/tiered/tiered.go
deleted
-94
@@ -1,94 +0,0 @@
1
-package tiered
2
-
3
-import (
4
- "fmt"
5
- "sync"
6
-
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
9
-)
10
-
11
-type tiered []ds.Datastore
12
-
13
-// New returns a tiered datastore. Puts and Deletes will write-through to
14
-// all datastores, Has and Get will try each datastore sequentially, and
15
-// Query will always try the last one (most complete) first.
16
-func New(dses ...ds.Datastore) tiered {
17
- return tiered(dses)
18
-}
19
-
20
-// Put stores the object `value` named by `key`.
21
-func (d tiered) Put(key ds.Key, value interface{}) (err error) {
22
- errs := make(chan error, len(d))
23
-
24
- var wg sync.WaitGroup
25
- for _, cd := range d {
26
- wg.Add(1)
27
- go func(cd ds.Datastore) {
28
- defer wg.Done()
29
- if err := cd.Put(key, value); err != nil {
30
- errs <- err
31
- }
32
- }(cd)
33
- }
34
- wg.Wait()
35
-
36
- close(errs)
37
- for err := range errs {
38
- return err
39
- }
40
- return nil
41
-}
42
-
43
-// Get retrieves the object `value` named by `key`.
44
-func (d tiered) Get(key ds.Key) (value interface{}, err error) {
45
- err = fmt.Errorf("no datastores")
46
- for _, cd := range d {
47
- value, err = cd.Get(key)
48
- if err == nil {
49
- break
50
- }
51
- }
52
- return
53
-}
54
-
55
-// Has returns whether the `key` is mapped to a `value`.
56
-func (d tiered) Has(key ds.Key) (exists bool, err error) {
57
- err = fmt.Errorf("no datastores")
58
- for _, cd := range d {
59
- exists, err = cd.Has(key)
60
- if err == nil && exists {
61
- break
62
- }
63
- }
64
- return
65
-}
66
-
67
-// Delete removes the value for given `key`.
68
-func (d tiered) Delete(key ds.Key) (err error) {
69
- errs := make(chan error, len(d))
70
-
71
- var wg sync.WaitGroup
72
- for _, cd := range d {
73
- wg.Add(1)
74
- go func(cd ds.Datastore) {
75
- defer wg.Done()
76
- if err := cd.Delete(key); err != nil {
77
- errs <- err
78
- }
79
- }(cd)
80
- }
81
- wg.Wait()
82
-
83
- close(errs)
84
- for err := range errs {
85
- return err
86
- }
87
- return nil
88
-}
89
-
90
-// Query returns a list of keys in the datastore
91
-func (d tiered) Query(q dsq.Query) (dsq.Results, error) {
92
- // query always the last (most complete) one
93
- return d[len(d)-1].Query(q)
94
-}
Godeps/_workspace/src/github.com/ipfs/go-datastore/timecache/timecache.go
deleted
-104
@@ -1,104 +0,0 @@
1
-package timecache
2
-
3
-import (
4
- "io"
5
- "sync"
6
- "time"
7
-
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
-)
11
-
12
-// op keys
13
-var (
14
- putKey = "put"
15
- getKey = "get"
16
- hasKey = "has"
17
- deleteKey = "delete"
18
-)
19
-
20
-type datastore struct {
21
- cache ds.Datastore
22
- ttl time.Duration
23
-
24
- ttlmu sync.Mutex
25
- ttls map[ds.Key]time.Time
26
-}
27
-
28
-func WithTTL(ttl time.Duration) *datastore {
29
- return WithCache(ds.NewMapDatastore(), ttl)
30
-}
31
-
32
-// WithCache wraps a given datastore as a timecache.
33
-// Get + Has requests are considered expired after a TTL.
34
-func WithCache(d ds.Datastore, ttl time.Duration) *datastore {
35
- return &datastore{cache: d, ttl: ttl, ttls: make(map[ds.Key]time.Time)}
36
-}
37
-
38
-func (d *datastore) gc() {
39
- var now = time.Now()
40
- var del []ds.Key
41
-
42
- // remove all expired ttls.
43
- d.ttlmu.Lock()
44
- for k, ttl := range d.ttls {
45
- if now.After(ttl) {
46
- delete(d.ttls, k)
47
- del = append(del, k)
48
- }
49
- }
50
- d.ttlmu.Unlock()
51
-
52
- for _, k := range del {
53
- d.cache.Delete(k)
54
- }
55
-}
56
-
57
-func (d *datastore) ttlPut(key ds.Key) {
58
- d.ttlmu.Lock()
59
- d.ttls[key] = time.Now().Add(d.ttl)
60
- d.ttlmu.Unlock()
61
-}
62
-
63
-func (d *datastore) ttlDelete(key ds.Key) {
64
- d.ttlmu.Lock()
65
- delete(d.ttls, key)
66
- d.ttlmu.Unlock()
67
-}
68
-
69
-// Put stores the object `value` named by `key`.
70
-func (d *datastore) Put(key ds.Key, value interface{}) (err error) {
71
- err = d.cache.Put(key, value)
72
- d.ttlPut(key)
73
- return err
74
-}
75
-
76
-// Get retrieves the object `value` named by `key`.
77
-func (d *datastore) Get(key ds.Key) (value interface{}, err error) {
78
- d.gc()
79
- return d.cache.Get(key)
80
-}
81
-
82
-// Has returns whether the `key` is mapped to a `value`.
83
-func (d *datastore) Has(key ds.Key) (exists bool, err error) {
84
- d.gc()
85
- return d.cache.Has(key)
86
-}
87
-
88
-// Delete removes the value for given `key`.
89
-func (d *datastore) Delete(key ds.Key) (err error) {
90
- d.ttlDelete(key)
91
- return d.cache.Delete(key)
92
-}
93
-
94
-// Query returns a list of keys in the datastore
95
-func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
96
- return d.cache.Query(q)
97
-}
98
-
99
-func (d *datastore) Close() error {
100
- if c, ok := d.cache.(io.Closer); ok {
101
- return c.Close()
102
- }
103
- return nil
104
-}
blocks/blockstore/blockstore.go
+3
-3
@@ -7,9 +7,9 @@ import (
7
"sync"
8
"sync/atomic"
9
10
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
11
- dsns "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/namespace"
12
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
+ ds "github.com/ipfs/go-datastore"
11
+ dsns "github.com/ipfs/go-datastore/namespace"
12
+ dsq "github.com/ipfs/go-datastore/query"
13
blocks "github.com/ipfs/go-ipfs/blocks"
14
key "github.com/ipfs/go-ipfs/blocks/key"
15
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
blocks/blockstore/blockstore_test.go
+3
-3
@@ -5,9 +5,9 @@ import (
5
"fmt"
6
"testing"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
10
- ds_sync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
8
+ ds "github.com/ipfs/go-datastore"
9
+ dsq "github.com/ipfs/go-datastore/query"
10
+ ds_sync "github.com/ipfs/go-datastore/sync"
11
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
12
13
blocks "github.com/ipfs/go-ipfs/blocks"
blocks/blockstore/write_cache_test.go
+3
-3
@@ -3,9 +3,9 @@ package blockstore
3
import (
4
"testing"
5
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
8
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
6
+ ds "github.com/ipfs/go-datastore"
7
+ dsq "github.com/ipfs/go-datastore/query"
8
+ syncds "github.com/ipfs/go-datastore/sync"
9
"github.com/ipfs/go-ipfs/blocks"
10
)
11
blocks/key/key.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"encoding/json"
5
"fmt"
6
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
+ ds "github.com/ipfs/go-datastore"
8
b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58"
9
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
10
)
blockservice/test/blocks_test.go
+2
-2
@@ -5,8 +5,8 @@ import (
5
"testing"
6
"time"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
8
+ ds "github.com/ipfs/go-datastore"
9
+ dssync "github.com/ipfs/go-datastore/sync"
10
blocks "github.com/ipfs/go-ipfs/blocks"
11
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
12
blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
core/builder.go
+2
-2
@@ -5,8 +5,8 @@ import (
5
"encoding/base64"
6
"errors"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dsync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
8
+ ds "github.com/ipfs/go-datastore"
9
+ dsync "github.com/ipfs/go-datastore/sync"
10
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
11
key "github.com/ipfs/go-ipfs/blocks/key"
12
bserv "github.com/ipfs/go-ipfs/blockservice"
core/core.go
+1
-1
@@ -16,7 +16,7 @@ import (
16
"net"
17
"time"
18
19
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
19
+ ds "github.com/ipfs/go-datastore"
20
diag "github.com/ipfs/go-ipfs/diagnostics"
21
peer "gx/ipfs/QmQGwpJy9P4yXZySmqkZEXCmbBpJUb8xntCv8Ca4taZwDC/go-libp2p-peer"
22
discovery "gx/ipfs/QmQkQP7WmeT9FRJDsEzAaGYDparttDiB6mCpVBrq2MuWQS/go-libp2p/p2p/discovery"
core/corerouting/core.go
+1
-1
@@ -3,7 +3,7 @@ package corerouting
3
import (
4
"errors"
5
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
6
+ ds "github.com/ipfs/go-datastore"
7
core "github.com/ipfs/go-ipfs/core"
8
repo "github.com/ipfs/go-ipfs/repo"
9
routing "github.com/ipfs/go-ipfs/routing"
core/coreunix/add.go
+2
-2
@@ -7,8 +7,8 @@ import (
7
"os"
8
gopath "path"
9
10
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
11
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
10
+ ds "github.com/ipfs/go-datastore"
11
+ syncds "github.com/ipfs/go-datastore/sync"
12
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
13
key "github.com/ipfs/go-ipfs/blocks/key"
14
bserv "github.com/ipfs/go-ipfs/blockservice"
core/coreunix/metadata_test.go
+2
-2
@@ -5,8 +5,8 @@ import (
5
"io/ioutil"
6
"testing"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
8
+ ds "github.com/ipfs/go-datastore"
9
+ dssync "github.com/ipfs/go-datastore/sync"
10
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
11
12
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
core/mock/mock.go
+2
-2
@@ -3,8 +3,8 @@ package coremock
3
import (
4
"net"
5
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
6
+ "github.com/ipfs/go-datastore"
7
+ syncds "github.com/ipfs/go-datastore/sync"
8
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
9
10
commands "github.com/ipfs/go-ipfs/commands"
exchange/bitswap/decision/engine_test.go
+2
-2
@@ -8,8 +8,8 @@ import (
8
"sync"
9
"testing"
10
11
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
12
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
11
+ ds "github.com/ipfs/go-datastore"
12
+ dssync "github.com/ipfs/go-datastore/sync"
13
blocks "github.com/ipfs/go-ipfs/blocks"
14
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
15
message "github.com/ipfs/go-ipfs/exchange/bitswap/message"
exchange/bitswap/testnet/peernet.go
+1
-1
@@ -1,7 +1,7 @@
1
package bitswap
2
3
import (
4
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
4
+ ds "github.com/ipfs/go-datastore"
5
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
6
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
7
testutil "github.com/ipfs/go-ipfs/thirdparty/testutil"
exchange/bitswap/testutils.go
+2
-2
@@ -3,8 +3,8 @@ package bitswap
3
import (
4
"time"
5
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- ds_sync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
6
+ ds "github.com/ipfs/go-datastore"
7
+ ds_sync "github.com/ipfs/go-datastore/sync"
8
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
9
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
10
datastore2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
exchange/offline/offline_test.go
+2
-2
@@ -3,8 +3,8 @@ package offline
3
import (
4
"testing"
5
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- ds_sync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
6
+ ds "github.com/ipfs/go-datastore"
7
+ ds_sync "github.com/ipfs/go-datastore/sync"
8
blocks "github.com/ipfs/go-ipfs/blocks"
9
"github.com/ipfs/go-ipfs/blocks/blockstore"
10
"github.com/ipfs/go-ipfs/blocks/blocksutil"
exchange/reprovide/reprovide_test.go
+2
-2
@@ -3,8 +3,8 @@ package reprovide_test
3
import (
4
"testing"
5
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
6
+ ds "github.com/ipfs/go-datastore"
7
+ dssync "github.com/ipfs/go-datastore/sync"
8
blocks "github.com/ipfs/go-ipfs/blocks"
9
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
10
mock "github.com/ipfs/go-ipfs/routing/mock"
merkledag/merkledag_test.go
+2
-2
@@ -10,8 +10,8 @@ import (
10
"sync"
11
"testing"
12
13
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
14
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
13
+ ds "github.com/ipfs/go-datastore"
14
+ dssync "github.com/ipfs/go-datastore/sync"
15
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
16
key "github.com/ipfs/go-ipfs/blocks/key"
17
bserv "github.com/ipfs/go-ipfs/blockservice"
merkledag/test/utils.go
+2
-2
@@ -1,8 +1,8 @@
1
package mdutils
2
3
import (
4
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
5
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
4
+ ds "github.com/ipfs/go-datastore"
5
+ dssync "github.com/ipfs/go-datastore/sync"
6
"github.com/ipfs/go-ipfs/blocks/blockstore"
7
bsrv "github.com/ipfs/go-ipfs/blockservice"
8
"github.com/ipfs/go-ipfs/exchange/offline"
merkledag/utils/utils.go
+2
-2
@@ -3,8 +3,8 @@ package dagutils
3
import (
4
"errors"
5
6
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
6
+ ds "github.com/ipfs/go-datastore"
7
+ syncds "github.com/ipfs/go-datastore/sync"
8
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
9
10
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
mfs/mfs_test.go
+2
-2
@@ -13,8 +13,8 @@ import (
13
"testing"
14
"time"
15
16
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
17
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
16
+ ds "github.com/ipfs/go-datastore"
17
+ dssync "github.com/ipfs/go-datastore/sync"
18
"github.com/ipfs/go-ipfs/path"
19
randbo "gx/ipfs/QmYvsG72GsfLgUeSojXArjnU6L4Wmwk7wuAxtNLuyXcc1T/randbo"
20
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
namesys/namesys.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"strings"
5
"time"
6
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
+ ds "github.com/ipfs/go-datastore"
8
path "github.com/ipfs/go-ipfs/path"
9
routing "github.com/ipfs/go-ipfs/routing"
10
ci "gx/ipfs/QmUEUu1CM8bxBJxc3ZLojAi8evhTr4byQogWstABet79oY/go-libp2p-crypto"
namesys/publisher.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"fmt"
7
"time"
8
9
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
+ ds "github.com/ipfs/go-datastore"
10
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
11
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
12
namesys/republisher/repub.go
+1
-1
@@ -12,7 +12,7 @@ import (
12
"github.com/ipfs/go-ipfs/routing"
13
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
14
15
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
15
+ ds "github.com/ipfs/go-datastore"
16
peer "gx/ipfs/QmQGwpJy9P4yXZySmqkZEXCmbBpJUb8xntCv8Ca4taZwDC/go-libp2p-peer"
17
goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
18
gpctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context"
namesys/resolve_test.go
+2
-2
@@ -5,8 +5,8 @@ import (
5
"testing"
6
"time"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
8
+ ds "github.com/ipfs/go-datastore"
9
+ dssync "github.com/ipfs/go-datastore/sync"
10
key "github.com/ipfs/go-ipfs/blocks/key"
11
path "github.com/ipfs/go-ipfs/path"
12
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
pin/pin.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"sync"
8
"time"
9
10
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
+ ds "github.com/ipfs/go-datastore"
11
key "github.com/ipfs/go-ipfs/blocks/key"
12
"github.com/ipfs/go-ipfs/blocks/set"
13
mdag "github.com/ipfs/go-ipfs/merkledag"
pin/pin_test.go
+2
-2
@@ -6,8 +6,8 @@ import (
6
7
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
8
9
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
9
+ ds "github.com/ipfs/go-datastore"
10
+ dssync "github.com/ipfs/go-datastore/sync"
11
"github.com/ipfs/go-ipfs/blocks/blockstore"
12
key "github.com/ipfs/go-ipfs/blocks/key"
13
bs "github.com/ipfs/go-ipfs/blockservice"
pin/set_test.go
+2
-2
@@ -4,8 +4,8 @@ import (
4
"testing"
5
"testing/quick"
6
7
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
7
+ "github.com/ipfs/go-datastore"
8
+ dssync "github.com/ipfs/go-datastore/sync"
9
"github.com/ipfs/go-ipfs/blocks/blockstore"
10
"github.com/ipfs/go-ipfs/blocks/key"
11
"github.com/ipfs/go-ipfs/blockservice"
repo/fsrepo/defaultds.go
+5
-5
@@ -4,11 +4,11 @@ import (
4
"fmt"
5
"path"
6
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/flatfs"
9
- levelds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/leveldb"
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/measure"
11
- mount "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/syncmount"
7
+ ds "github.com/ipfs/go-datastore"
8
+ "github.com/ipfs/go-datastore/flatfs"
9
+ levelds "github.com/ipfs/go-datastore/leveldb"
10
+ "github.com/ipfs/go-datastore/measure"
11
+ mount "github.com/ipfs/go-datastore/syncmount"
12
repo "github.com/ipfs/go-ipfs/repo"
13
config "github.com/ipfs/go-ipfs/repo/config"
14
"github.com/ipfs/go-ipfs/thirdparty/dir"
repo/fsrepo/fsrepo.go
+1
-1
@@ -10,7 +10,7 @@ import (
10
"strings"
11
"sync"
12
13
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/measure"
13
+ "github.com/ipfs/go-datastore/measure"
14
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
15
repo "github.com/ipfs/go-ipfs/repo"
16
"github.com/ipfs/go-ipfs/repo/common"
repo/fsrepo/fsrepo_test.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"path/filepath"
8
"testing"
9
10
- datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
+ datastore "github.com/ipfs/go-datastore"
11
"github.com/ipfs/go-ipfs/repo/config"
12
"github.com/ipfs/go-ipfs/thirdparty/assert"
13
)
repo/repo.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"io"
6
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
+ ds "github.com/ipfs/go-datastore"
8
config "github.com/ipfs/go-ipfs/repo/config"
9
)
10
routing/dht/dht.go
+1
-1
@@ -15,7 +15,7 @@ import (
15
kb "github.com/ipfs/go-ipfs/routing/kbucket"
16
record "github.com/ipfs/go-ipfs/routing/record"
17
18
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
18
+ ds "github.com/ipfs/go-datastore"
19
peer "gx/ipfs/QmQGwpJy9P4yXZySmqkZEXCmbBpJUb8xntCv8Ca4taZwDC/go-libp2p-peer"
20
host "gx/ipfs/QmQkQP7WmeT9FRJDsEzAaGYDparttDiB6mCpVBrq2MuWQS/go-libp2p/p2p/host"
21
protocol "gx/ipfs/QmQkQP7WmeT9FRJDsEzAaGYDparttDiB6mCpVBrq2MuWQS/go-libp2p/p2p/protocol"
routing/dht/dht_test.go
+2
-2
@@ -9,8 +9,8 @@ import (
9
"testing"
10
"time"
11
12
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
13
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
12
+ ds "github.com/ipfs/go-datastore"
13
+ dssync "github.com/ipfs/go-datastore/sync"
14
key "github.com/ipfs/go-ipfs/blocks/key"
15
routing "github.com/ipfs/go-ipfs/routing"
16
record "github.com/ipfs/go-ipfs/routing/record"
routing/dht/ext_test.go
+2
-2
@@ -6,8 +6,8 @@ import (
6
"testing"
7
"time"
8
9
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
9
+ ds "github.com/ipfs/go-datastore"
10
+ dssync "github.com/ipfs/go-datastore/sync"
11
key "github.com/ipfs/go-ipfs/blocks/key"
12
routing "github.com/ipfs/go-ipfs/routing"
13
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/dht/handlers.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"fmt"
6
"time"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
+ ds "github.com/ipfs/go-datastore"
9
key "github.com/ipfs/go-ipfs/blocks/key"
10
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
11
lgbl "github.com/ipfs/go-ipfs/thirdparty/loggables"
routing/mock/centralized_client.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"time"
6
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
+ ds "github.com/ipfs/go-datastore"
8
key "github.com/ipfs/go-ipfs/blocks/key"
9
routing "github.com/ipfs/go-ipfs/routing"
10
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/mock/centralized_server.go
+2
-2
@@ -5,8 +5,8 @@ import (
5
"sync"
6
"time"
7
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
8
+ ds "github.com/ipfs/go-datastore"
9
+ dssync "github.com/ipfs/go-datastore/sync"
10
key "github.com/ipfs/go-ipfs/blocks/key"
11
"github.com/ipfs/go-ipfs/thirdparty/testutil"
12
routing/mock/dht.go
+2
-2
@@ -1,8 +1,8 @@
1
package mockrouting
2
3
import (
4
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
5
- sync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
4
+ ds "github.com/ipfs/go-datastore"
5
+ sync "github.com/ipfs/go-datastore/sync"
6
dht "github.com/ipfs/go-ipfs/routing/dht"
7
"github.com/ipfs/go-ipfs/thirdparty/testutil"
8
mocknet "gx/ipfs/QmQkQP7WmeT9FRJDsEzAaGYDparttDiB6mCpVBrq2MuWQS/go-libp2p/p2p/net/mock"
routing/mock/interface.go
+1
-1
@@ -5,7 +5,7 @@
5
package mockrouting
6
7
import (
8
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
8
+ ds "github.com/ipfs/go-datastore"
9
key "github.com/ipfs/go-ipfs/blocks/key"
10
routing "github.com/ipfs/go-ipfs/routing"
11
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
routing/offline/offline.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"time"
6
7
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
+ ds "github.com/ipfs/go-datastore"
8
key "github.com/ipfs/go-ipfs/blocks/key"
9
routing "github.com/ipfs/go-ipfs/routing"
10
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/supernode/server.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"fmt"
6
7
- datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
7
+ datastore "github.com/ipfs/go-datastore"
8
key "github.com/ipfs/go-ipfs/blocks/key"
9
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
10
record "github.com/ipfs/go-ipfs/routing/record"
routing/supernode/server_test.go
+1
-1
@@ -3,7 +3,7 @@ package supernode
3
import (
4
"testing"
5
6
- datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
6
+ datastore "github.com/ipfs/go-datastore"
7
key "github.com/ipfs/go-ipfs/blocks/key"
8
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
9
)
test/integration/grandcentral_test.go
+2
-2
@@ -8,8 +8,8 @@ import (
8
"math"
9
"testing"
10
11
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
12
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
11
+ "github.com/ipfs/go-datastore"
12
+ syncds "github.com/ipfs/go-datastore/sync"
13
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
14
15
key "github.com/ipfs/go-ipfs/blocks/key"
test/supernode_client/main.go
+2
-2
@@ -12,8 +12,8 @@ import (
12
gopath "path"
13
"time"
14
15
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
16
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
15
+ "github.com/ipfs/go-datastore"
16
+ syncds "github.com/ipfs/go-datastore/sync"
17
random "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
18
commands "github.com/ipfs/go-ipfs/commands"
19
core "github.com/ipfs/go-ipfs/core"
thirdparty/datastore2/datastore_closer.go
+1
-1
@@ -3,7 +3,7 @@ package datastore2
3
import (
4
"io"
5
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
6
+ "github.com/ipfs/go-datastore"
7
)
8
9
type ThreadSafeDatastoreCloser interface {
thirdparty/datastore2/delayed.go
+2
-2
@@ -1,8 +1,8 @@
1
package datastore2
2
3
import (
4
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
5
- dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/query"
4
+ ds "github.com/ipfs/go-datastore"
5
+ dsq "github.com/ipfs/go-datastore/query"
6
7
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
8
)
thirdparty/datastore2/threadsafe.go
+1
-1
@@ -3,7 +3,7 @@ package datastore2
3
import (
4
"io"
5
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
6
+ "github.com/ipfs/go-datastore"
7
)
8
9
// ClaimThreadSafe claims that a Datastore is threadsafe, even when
thirdparty/testutil/datastore.go
+2
-2
@@ -1,8 +1,8 @@
1
package testutil
2
3
import (
4
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
5
- syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
4
+ "github.com/ipfs/go-datastore"
5
+ syncds "github.com/ipfs/go-datastore/sync"
6
ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
7
)
8
unixfs/mod/dagmodifier_test.go
+2
-2
@@ -7,7 +7,7 @@ import (
7
"os"
8
"testing"
9
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
10
+ "github.com/ipfs/go-datastore/sync"
11
"github.com/ipfs/go-ipfs/blocks/blockstore"
12
bs "github.com/ipfs/go-ipfs/blockservice"
13
"github.com/ipfs/go-ipfs/exchange/offline"
@@ -20,7 +20,7 @@ import (
20
uio "github.com/ipfs/go-ipfs/unixfs/io"
21
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
22
23
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
23
+ ds "github.com/ipfs/go-datastore"
24
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
25
)
26