Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-datastore
Commits
507733cb
Unverified
Commit
507733cb
authored
Aug 21, 2019
by
Steven Allen
Committed by
GitHub
Aug 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #132 from ipfs/feat/idempotent-delete
feat: make delete idempotent
parents
9f8f4730
49d30a71
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
13 additions
and
20 deletions
+13
-20
autobatch/autobatch.go
autobatch/autobatch.go
+0
-4
basic_ds.go
basic_ds.go
+0
-3
batch.go
batch.go
+0
-5
datastore.go
datastore.go
+4
-3
examples/fs.go
examples/fs.go
+6
-2
mount/mount.go
mount/mount.go
+1
-1
mount/mount_test.go
mount/mount_test.go
+2
-2
No files found.
autobatch/autobatch.go
View file @
507733cb
...
...
@@ -75,10 +75,6 @@ func (d *Datastore) Flush() error {
var
err
error
if
o
.
delete
{
err
=
b
.
Delete
(
k
)
if
err
==
ds
.
ErrNotFound
{
// Ignore these, let delete be idempotent.
err
=
nil
}
}
else
{
err
=
b
.
Put
(
k
,
o
.
value
)
}
...
...
basic_ds.go
View file @
507733cb
...
...
@@ -53,9 +53,6 @@ func (d *MapDatastore) GetSize(key Key) (size int, err error) {
// Delete implements Datastore.Delete
func
(
d
*
MapDatastore
)
Delete
(
key
Key
)
(
err
error
)
{
if
_
,
found
:=
d
.
values
[
key
];
!
found
{
return
ErrNotFound
}
delete
(
d
.
values
,
key
)
return
nil
}
...
...
batch.go
View file @
507733cb
...
...
@@ -35,11 +35,6 @@ func (bt *basicBatch) Commit() error {
for
k
,
op
:=
range
bt
.
ops
{
if
op
.
delete
{
err
=
bt
.
target
.
Delete
(
k
)
// We could try to do something smarter but I really
// don't care. Delete should be idempotent anyways.
if
err
==
ErrNotFound
{
err
=
nil
}
}
else
{
err
=
bt
.
target
.
Put
(
k
,
op
.
value
)
}
...
...
datastore.go
View file @
507733cb
...
...
@@ -50,7 +50,8 @@ type Write interface {
// type-safe interface to your application, and do the checking up-front.
Put
(
key
Key
,
value
[]
byte
)
error
// Delete removes the value for given `key`.
// Delete removes the value for given `key`. If the key is not in the
// datastore, this method returns no error.
Delete
(
key
Key
)
error
}
...
...
@@ -191,8 +192,8 @@ type TxnDatastore interface {
// Errors
// ErrNotFound is returned by Get
, Has, and Delet
e when a datastore does not
//
map the
given key to a value.
// ErrNotFound is returned by Get
and GetSiz
e when a datastore does not
map the
// given key to a value.
var
ErrNotFound
=
errors
.
New
(
"datastore: key not found"
)
// ErrInvalidType is returned by Put when a given value is incopatible with
...
...
examples/fs.go
View file @
507733cb
...
...
@@ -86,10 +86,14 @@ func (d *Datastore) GetSize(key ds.Key) (size int, err error) {
func
(
d
*
Datastore
)
Delete
(
key
ds
.
Key
)
(
err
error
)
{
fn
:=
d
.
KeyFilename
(
key
)
if
!
isFile
(
fn
)
{
return
ds
.
ErrNotFound
return
nil
}
return
os
.
Remove
(
fn
)
err
=
os
.
Remove
(
fn
)
if
os
.
IsNotExist
(
err
)
{
err
=
nil
// idempotent
}
return
err
}
// Query implements Datastore.Query
...
...
mount/mount.go
View file @
507733cb
...
...
@@ -216,7 +216,7 @@ func (d *Datastore) GetSize(key ds.Key) (size int, err error) {
func
(
d
*
Datastore
)
Delete
(
key
ds
.
Key
)
error
{
cds
,
_
,
k
:=
d
.
lookup
(
key
)
if
cds
==
nil
{
return
ds
.
ErrNotFound
return
nil
}
return
cds
.
Delete
(
k
)
}
...
...
mount/mount_test.go
View file @
507733cb
...
...
@@ -171,8 +171,8 @@ func TestDeleteNotFound(t *testing.T) {
})
err
:=
m
.
Delete
(
datastore
.
NewKey
(
"/quux/thud"
))
if
g
,
e
:=
err
,
datastore
.
ErrNotFound
;
g
!=
e
{
t
.
Fatalf
(
"expected
ErrNotFound
, got: %v
\n
"
,
g
)
if
err
!=
nil
{
t
.
Fatalf
(
"expected
nil
, got: %v
\n
"
,
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment