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
1702774c
Commit
1702774c
authored
Jun 26, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename Transaction to Batch
parent
c3fa34b4
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
78 additions
and
78 deletions
+78
-78
basic_ds.go
basic_ds.go
+7
-7
callback/callback.go
callback/callback.go
+2
-2
coalesce/coalesce.go
coalesce/coalesce.go
+2
-2
datastore.go
datastore.go
+3
-3
flatfs/flatfs.go
flatfs/flatfs.go
+6
-6
fs/fs.go
fs/fs.go
+2
-2
keytransform/keytransform.go
keytransform/keytransform.go
+8
-8
leveldb/datastore.go
leveldb/datastore.go
+1
-1
lru/datastore.go
lru/datastore.go
+2
-2
measure/measure.go
measure/measure.go
+10
-10
mount/mount.go
mount/mount.go
+10
-10
panic/panic.go
panic/panic.go
+7
-7
sync/sync.go
sync/sync.go
+2
-2
tiered/tiered.go
tiered/tiered.go
+7
-7
timecache/timecache.go
timecache/timecache.go
+2
-2
transaction.go
transaction.go
+7
-7
No files found.
basic_ds.go
View file @
1702774c
...
...
@@ -63,8 +63,8 @@ func (d *MapDatastore) Query(q dsq.Query) (dsq.Results, error) {
return
r
,
nil
}
func
(
d
*
MapDatastore
)
Start
Batch
Op
()
Transaction
{
return
NewBasic
Transaction
(
d
)
func
(
d
*
MapDatastore
)
Batch
()
Batch
{
return
NewBasic
Batch
(
d
)
}
// NullDatastore stores nothing, but conforms to the API.
...
...
@@ -102,8 +102,8 @@ func (d *NullDatastore) Query(q dsq.Query) (dsq.Results, error) {
return
dsq
.
ResultsWithEntries
(
q
,
nil
),
nil
}
func
(
d
*
NullDatastore
)
Start
Batch
Op
()
Transaction
{
return
NewBasic
Transaction
(
d
)
func
(
d
*
NullDatastore
)
Batch
()
Batch
{
return
NewBasic
Batch
(
d
)
}
// LogDatastore logs all accesses through the datastore.
...
...
@@ -163,7 +163,7 @@ func (d *LogDatastore) Query(q dsq.Query) (dsq.Results, error) {
return
d
.
child
.
Query
(
q
)
}
func
(
d
*
LogDatastore
)
Start
Batch
Op
()
Transaction
{
log
.
Printf
(
"%s:
Start
Batch
Op
\n
"
,
d
.
Name
)
return
d
.
child
.
Start
Batch
Op
()
func
(
d
*
LogDatastore
)
Batch
()
Batch
{
log
.
Printf
(
"%s: Batch
\n
"
,
d
.
Name
)
return
d
.
child
.
Batch
()
}
callback/callback.go
View file @
1702774c
...
...
@@ -41,7 +41,7 @@ func (c *Datastore) Query(q dsq.Query) (dsq.Results, error) {
return
c
.
D
.
Query
(
q
)
}
func
(
c
*
Datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
func
(
c
*
Datastore
)
Batch
()
ds
.
Batch
{
c
.
F
()
return
c
.
D
.
Start
Batch
Op
()
return
c
.
D
.
Batch
()
}
coalesce/coalesce.go
View file @
1702774c
...
...
@@ -125,6 +125,6 @@ func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
return
d
.
child
.
Query
(
q
)
}
func
(
d
*
datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
return
ds
.
NewBasic
Transaction
(
d
)
func
(
d
*
datastore
)
Batch
()
ds
.
Batch
{
return
ds
.
NewBasic
Batch
(
d
)
}
datastore.go
View file @
1702774c
...
...
@@ -68,8 +68,8 @@ type Datastore interface {
//
Query
(
q
query
.
Query
)
(
query
.
Results
,
error
)
//
Start
Batch
Op
begins a datastore transaction
Start
Batch
Op
()
Transaction
// Batch begins a datastore transaction
Batch
()
Batch
}
// ThreadSafeDatastore is an interface that all threadsafe datastore should
...
...
@@ -108,7 +108,7 @@ func GetBackedHas(ds Datastore, key Key) (bool, error) {
}
}
type
Transaction
interface
{
type
Batch
interface
{
Put
(
key
Key
,
val
interface
{})
error
Delete
(
key
Key
)
error
...
...
flatfs/flatfs.go
View file @
1702774c
...
...
@@ -323,32 +323,32 @@ func (fs *Datastore) enumerateKeys(fi os.FileInfo, res []query.Entry) ([]query.E
return
res
,
nil
}
type
flatfs
Transaction
struct
{
type
flatfs
Batch
struct
{
puts
map
[
datastore
.
Key
]
interface
{}
deletes
map
[
datastore
.
Key
]
struct
{}
ds
*
Datastore
}
func
(
fs
*
Datastore
)
Start
Batch
Op
()
datastore
.
Transaction
{
return
&
flatfs
Transaction
{
func
(
fs
*
Datastore
)
Batch
()
datastore
.
Batch
{
return
&
flatfs
Batch
{
puts
:
make
(
map
[
datastore
.
Key
]
interface
{}),
deletes
:
make
(
map
[
datastore
.
Key
]
struct
{}),
ds
:
fs
,
}
}
func
(
bt
*
flatfs
Transaction
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
func
(
bt
*
flatfs
Batch
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
bt
.
puts
[
key
]
=
val
return
nil
}
func
(
bt
*
flatfs
Transaction
)
Delete
(
key
datastore
.
Key
)
error
{
func
(
bt
*
flatfs
Batch
)
Delete
(
key
datastore
.
Key
)
error
{
bt
.
deletes
[
key
]
=
struct
{}{}
return
nil
}
func
(
bt
*
flatfs
Transaction
)
Commit
()
error
{
func
(
bt
*
flatfs
Batch
)
Commit
()
error
{
if
err
:=
bt
.
ds
.
putMany
(
bt
.
puts
);
err
!=
nil
{
return
err
}
...
...
fs/fs.go
View file @
1702774c
...
...
@@ -130,10 +130,10 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
return
r
,
nil
}
func
(
d
*
Datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
func
(
d
*
Datastore
)
Batch
()
ds
.
Batch
{
// just use basic transaction for now, this datastore
// isnt really used in performant code yet
return
ds
.
NewBasic
Transaction
(
d
)
return
ds
.
NewBasic
Batch
(
d
)
}
// isDir returns whether given path is a directory
...
...
keytransform/keytransform.go
View file @
1702774c
...
...
@@ -74,27 +74,27 @@ func (d *ktds) Query(q dsq.Query) (dsq.Results, error) {
return
dsq
.
DerivedResults
(
qr
,
ch
),
nil
}
func
(
d
*
ktds
)
Start
Batch
Op
()
ds
.
Transaction
{
return
&
transform
Transaction
{
dst
:
d
.
child
.
Start
Batch
Op
(),
func
(
d
*
ktds
)
Batch
()
ds
.
Batch
{
return
&
transform
Batch
{
dst
:
d
.
child
.
Batch
(),
f
:
d
.
ConvertKey
,
}
}
type
transform
Transaction
struct
{
dst
ds
.
Transaction
type
transform
Batch
struct
{
dst
ds
.
Batch
f
KeyMapping
}
func
(
t
*
transform
Transaction
)
Put
(
key
ds
.
Key
,
val
interface
{})
error
{
func
(
t
*
transform
Batch
)
Put
(
key
ds
.
Key
,
val
interface
{})
error
{
return
t
.
dst
.
Put
(
t
.
f
(
key
),
val
)
}
func
(
t
*
transform
Transaction
)
Delete
(
key
ds
.
Key
)
error
{
func
(
t
*
transform
Batch
)
Delete
(
key
ds
.
Key
)
error
{
return
t
.
dst
.
Delete
(
t
.
f
(
key
))
}
func
(
t
*
transform
Transaction
)
Commit
()
error
{
func
(
t
*
transform
Batch
)
Commit
()
error
{
return
t
.
dst
.
Commit
()
}
leveldb/datastore.go
View file @
1702774c
...
...
@@ -105,7 +105,7 @@ type ldbBatch struct {
d
*
datastore
}
func
(
d
*
datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
func
(
d
*
datastore
)
Batch
()
ds
.
Batch
{
return
&
ldbBatch
{
b
:
new
(
leveldb
.
Batch
),
d
:
d
,
...
...
lru/datastore.go
View file @
1702774c
...
...
@@ -55,6 +55,6 @@ func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) {
return
nil
,
errors
.
New
(
"KeyList not implemented."
)
}
func
(
d
*
Datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
return
ds
.
NewBasic
Transaction
(
d
)
func
(
d
*
Datastore
)
Batch
()
ds
.
Batch
{
return
ds
.
NewBasic
Batch
(
d
)
}
measure/measure.go
View file @
1702774c
...
...
@@ -148,36 +148,36 @@ func (m *measure) Query(q query.Query) (query.Results, error) {
return
res
,
err
}
type
measured
Transaction
struct
{
type
measured
Batch
struct
{
puts
int
deletes
int
putts
datastore
.
Transaction
delts
datastore
.
Transaction
putts
datastore
.
Batch
delts
datastore
.
Batch
m
*
measure
}
func
(
m
*
measure
)
Start
Batch
Op
()
datastore
.
Transaction
{
return
&
measured
Transaction
{
putts
:
m
.
backend
.
Start
Batch
Op
(),
delts
:
m
.
backend
.
Start
Batch
Op
(),
func
(
m
*
measure
)
Batch
()
datastore
.
Batch
{
return
&
measured
Batch
{
putts
:
m
.
backend
.
Batch
(),
delts
:
m
.
backend
.
Batch
(),
m
:
m
,
}
}
func
(
mt
*
measured
Transaction
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
func
(
mt
*
measured
Batch
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
mt
.
puts
++
return
mt
.
putts
.
Put
(
key
,
val
)
}
func
(
mt
*
measured
Transaction
)
Delete
(
key
datastore
.
Key
)
error
{
func
(
mt
*
measured
Batch
)
Delete
(
key
datastore
.
Key
)
error
{
mt
.
deletes
++
return
mt
.
delts
.
Delete
(
key
)
}
func
(
mt
*
measured
Transaction
)
Commit
()
error
{
func
(
mt
*
measured
Batch
)
Commit
()
error
{
if
mt
.
deletes
>
0
{
before
:=
time
.
Now
()
err
:=
mt
.
delts
.
Commit
()
...
...
mount/mount.go
View file @
1702774c
...
...
@@ -115,42 +115,42 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
return
r
,
nil
}
type
mount
Transaction
struct
{
mounts
map
[
string
]
datastore
.
Transaction
type
mount
Batch
struct
{
mounts
map
[
string
]
datastore
.
Batch
d
*
Datastore
}
func
(
d
*
Datastore
)
Start
Batch
Op
()
datastore
.
Transaction
{
return
&
mount
Transaction
{
mounts
:
make
(
map
[
string
]
datastore
.
Transaction
),
func
(
d
*
Datastore
)
Batch
()
datastore
.
Batch
{
return
&
mount
Batch
{
mounts
:
make
(
map
[
string
]
datastore
.
Batch
),
d
:
d
,
}
}
func
(
mt
*
mount
Transaction
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
func
(
mt
*
mount
Batch
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
child
,
loc
,
rest
:=
mt
.
d
.
lookup
(
key
)
t
,
ok
:=
mt
.
mounts
[
loc
.
String
()]
if
!
ok
{
t
=
child
.
Start
Batch
Op
()
t
=
child
.
Batch
()
mt
.
mounts
[
loc
.
String
()]
=
t
}
return
t
.
Put
(
rest
,
val
)
}
func
(
mt
*
mount
Transaction
)
Delete
(
key
datastore
.
Key
)
error
{
func
(
mt
*
mount
Batch
)
Delete
(
key
datastore
.
Key
)
error
{
child
,
loc
,
rest
:=
mt
.
d
.
lookup
(
key
)
t
,
ok
:=
mt
.
mounts
[
loc
.
String
()]
if
!
ok
{
t
=
child
.
Start
Batch
Op
()
t
=
child
.
Batch
()
mt
.
mounts
[
loc
.
String
()]
=
t
}
return
t
.
Delete
(
rest
)
}
func
(
mt
*
mount
Transaction
)
Commit
()
error
{
func
(
mt
*
mount
Batch
)
Commit
()
error
{
for
_
,
t
:=
range
mt
.
mounts
{
err
:=
t
.
Commit
()
if
err
!=
nil
{
...
...
panic/panic.go
View file @
1702774c
...
...
@@ -67,11 +67,11 @@ func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
return
r
,
nil
}
type
panic
Transaction
struct
{
t
ds
.
Transaction
type
panic
Batch
struct
{
t
ds
.
Batch
}
func
(
p
*
panic
Transaction
)
Put
(
key
ds
.
Key
,
val
interface
{})
error
{
func
(
p
*
panic
Batch
)
Put
(
key
ds
.
Key
,
val
interface
{})
error
{
err
:=
p
.
t
.
Put
(
key
,
val
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
...
...
@@ -80,7 +80,7 @@ func (p *panicTransaction) Put(key ds.Key, val interface{}) error {
return
nil
}
func
(
p
*
panic
Transaction
)
Delete
(
key
ds
.
Key
)
error
{
func
(
p
*
panic
Batch
)
Delete
(
key
ds
.
Key
)
error
{
err
:=
p
.
t
.
Delete
(
key
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
...
...
@@ -89,7 +89,7 @@ func (p *panicTransaction) Delete(key ds.Key) error {
return
nil
}
func
(
p
*
panic
Transaction
)
Commit
()
error
{
func
(
p
*
panic
Batch
)
Commit
()
error
{
err
:=
p
.
t
.
Commit
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
...
...
@@ -98,6 +98,6 @@ func (p *panicTransaction) Commit() error {
return
nil
}
func
(
d
*
datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
return
&
panic
Transaction
{
d
.
child
.
Start
Batch
Op
()}
func
(
d
*
datastore
)
Batch
()
ds
.
Batch
{
return
&
panic
Batch
{
d
.
child
.
Batch
()}
}
sync/sync.go
View file @
1702774c
...
...
@@ -64,8 +64,8 @@ func (d *MutexDatastore) Query(q dsq.Query) (dsq.Results, error) {
return
d
.
child
.
Query
(
q
)
}
func
(
d
*
MutexDatastore
)
Start
Batch
Op
()
ds
.
Transaction
{
func
(
d
*
MutexDatastore
)
Batch
()
ds
.
Batch
{
d
.
RLock
()
defer
d
.
RUnlock
()
return
d
.
child
.
Start
Batch
Op
()
return
d
.
child
.
Batch
()
}
tiered/tiered.go
View file @
1702774c
...
...
@@ -93,17 +93,17 @@ func (d tiered) Query(q dsq.Query) (dsq.Results, error) {
return
d
[
len
(
d
)
-
1
]
.
Query
(
q
)
}
type
tiered
Transaction
[]
ds
.
Transaction
type
tiered
Batch
[]
ds
.
Batch
func
(
d
tiered
)
Start
Batch
Op
()
ds
.
Transaction
{
var
out
tiered
Transaction
func
(
d
tiered
)
Batch
()
ds
.
Batch
{
var
out
tiered
Batch
for
_
,
ds
:=
range
d
{
out
=
append
(
out
,
ds
.
Start
Batch
Op
())
out
=
append
(
out
,
ds
.
Batch
())
}
return
out
}
func
(
t
tiered
Transaction
)
Put
(
key
ds
.
Key
,
val
interface
{})
error
{
func
(
t
tiered
Batch
)
Put
(
key
ds
.
Key
,
val
interface
{})
error
{
for
_
,
ts
:=
range
t
{
err
:=
ts
.
Put
(
key
,
val
)
if
err
!=
nil
{
...
...
@@ -113,7 +113,7 @@ func (t tieredTransaction) Put(key ds.Key, val interface{}) error {
return
nil
}
func
(
t
tiered
Transaction
)
Delete
(
key
ds
.
Key
)
error
{
func
(
t
tiered
Batch
)
Delete
(
key
ds
.
Key
)
error
{
for
_
,
ts
:=
range
t
{
err
:=
ts
.
Delete
(
key
)
if
err
!=
nil
{
...
...
@@ -123,7 +123,7 @@ func (t tieredTransaction) Delete(key ds.Key) error {
return
nil
}
func
(
t
tiered
Transaction
)
Commit
()
error
{
func
(
t
tiered
Batch
)
Commit
()
error
{
for
_
,
ts
:=
range
t
{
err
:=
ts
.
Commit
()
if
err
!=
nil
{
...
...
timecache/timecache.go
View file @
1702774c
...
...
@@ -95,7 +95,7 @@ func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
return
d
.
cache
.
Query
(
q
)
}
func
(
d
*
datastore
)
Start
Batch
Op
()
ds
.
Transaction
{
func
(
d
*
datastore
)
Batch
()
ds
.
Batch
{
// sorry, being lazy here
return
ds
.
NewBasic
Transaction
(
d
)
return
ds
.
NewBasic
Batch
(
d
)
}
transaction.go
View file @
1702774c
package
datastore
// basic
Transaction
implements the transaction interface for datastores who do
// basic
Batch
implements the transaction interface for datastores who do
// not have any sort of underlying transactional support
type
basic
Transaction
struct
{
type
basic
Batch
struct
{
puts
map
[
Key
]
interface
{}
deletes
map
[
Key
]
struct
{}
target
Datastore
}
func
NewBasic
Transaction
(
ds
Datastore
)
Transaction
{
return
&
basic
Transaction
{
func
NewBasic
Batch
(
ds
Datastore
)
Batch
{
return
&
basic
Batch
{
puts
:
make
(
map
[
Key
]
interface
{}),
deletes
:
make
(
map
[
Key
]
struct
{}),
target
:
ds
,
}
}
func
(
bt
*
basic
Transaction
)
Put
(
key
Key
,
val
interface
{})
error
{
func
(
bt
*
basic
Batch
)
Put
(
key
Key
,
val
interface
{})
error
{
bt
.
puts
[
key
]
=
val
return
nil
}
func
(
bt
*
basic
Transaction
)
Delete
(
key
Key
)
error
{
func
(
bt
*
basic
Batch
)
Delete
(
key
Key
)
error
{
bt
.
deletes
[
key
]
=
struct
{}{}
return
nil
}
func
(
bt
*
basic
Transaction
)
Commit
()
error
{
func
(
bt
*
basic
Batch
)
Commit
()
error
{
for
k
,
val
:=
range
bt
.
puts
{
if
err
:=
bt
.
target
.
Put
(
k
,
val
);
err
!=
nil
{
return
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