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-ds-badger
Commits
22c5a172
Unverified
Commit
22c5a172
authored
Oct 09, 2020
by
Steven Allen
Committed by
GitHub
Oct 09, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #108 from ipfs/chore/log-finalizer
Log error if batch not committed or canceled
parents
8a4303f9
78c54b53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
datastore.go
datastore.go
+8
-2
No files found.
datastore.go
View file @
22c5a172
...
@@ -409,7 +409,10 @@ func (d *Datastore) Batch() (ds.Batch, error) {
...
@@ -409,7 +409,10 @@ func (d *Datastore) Batch() (ds.Batch, error) {
b
:=
&
batch
{
d
,
d
.
DB
.
NewWriteBatch
()}
b
:=
&
batch
{
d
,
d
.
DB
.
NewWriteBatch
()}
// Ensure that incomplete transaction resources are cleaned up in case
// Ensure that incomplete transaction resources are cleaned up in case
// batch is abandoned.
// batch is abandoned.
runtime
.
SetFinalizer
(
b
,
func
(
b
*
batch
)
{
b
.
cancel
()
})
runtime
.
SetFinalizer
(
b
,
func
(
b
*
batch
)
{
b
.
cancel
()
log
.
Error
(
"batch not committed or canceled"
)
})
return
b
,
nil
return
b
,
nil
}
}
...
@@ -481,8 +484,10 @@ func (b *batch) commit() error {
...
@@ -481,8 +484,10 @@ func (b *batch) commit() error {
if
err
!=
nil
{
if
err
!=
nil
{
// Discard incomplete transaction held by b.writeBatch
// Discard incomplete transaction held by b.writeBatch
b
.
cancel
()
b
.
cancel
()
return
err
}
}
return
err
runtime
.
SetFinalizer
(
b
,
nil
)
return
nil
}
}
func
(
b
*
batch
)
Cancel
()
error
{
func
(
b
*
batch
)
Cancel
()
error
{
...
@@ -498,6 +503,7 @@ func (b *batch) Cancel() error {
...
@@ -498,6 +503,7 @@ func (b *batch) Cancel() error {
func
(
b
*
batch
)
cancel
()
{
func
(
b
*
batch
)
cancel
()
{
b
.
writeBatch
.
Cancel
()
b
.
writeBatch
.
Cancel
()
runtime
.
SetFinalizer
(
b
,
nil
)
}
}
var
_
ds
.
Datastore
=
(
*
txn
)(
nil
)
var
_
ds
.
Datastore
=
(
*
txn
)(
nil
)
...
...
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