Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
27c144d9
Unverified
Commit
27c144d9
authored
Apr 13, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-program: disk kv store rw lock and docs update
parent
51178b3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
disk.go
op-program/host/kvstore/disk.go
+9
-1
No files found.
op-program/host/kvstore/disk.go
View file @
27c144d9
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"io"
"io"
"os"
"os"
"path"
"path"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
)
)
...
@@ -15,8 +16,11 @@ import (
...
@@ -15,8 +16,11 @@ import (
const
diskPermission
=
0666
const
diskPermission
=
0666
// DiskKV is a disk-backed key-value store, every key-value pair is a hex-encoded .txt file, with the value as content.
// DiskKV is a disk-backed key-value store, every key-value pair is a hex-encoded .txt file, with the value as content.
// DiskKV is safe for concurrent use; Puts may conflict, but write the exact same data anyway.
// DiskKV is safe for concurrent use with a single DiskKV instance.
// DiskKV is not safe for concurrent use between different DiskKV instances of the same disk directory:
// a Put needs to be completed before another DiskKV Get retrieves the values.
type
DiskKV
struct
{
type
DiskKV
struct
{
sync
.
RWMutex
path
string
path
string
}
}
...
@@ -31,6 +35,8 @@ func (d *DiskKV) pathKey(k common.Hash) string {
...
@@ -31,6 +35,8 @@ func (d *DiskKV) pathKey(k common.Hash) string {
}
}
func
(
d
*
DiskKV
)
Put
(
k
common
.
Hash
,
v
[]
byte
)
error
{
func
(
d
*
DiskKV
)
Put
(
k
common
.
Hash
,
v
[]
byte
)
error
{
d
.
Lock
()
defer
d
.
Unlock
()
f
,
err
:=
os
.
OpenFile
(
d
.
pathKey
(
k
),
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_EXCL
|
os
.
O_TRUNC
,
diskPermission
)
f
,
err
:=
os
.
OpenFile
(
d
.
pathKey
(
k
),
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_EXCL
|
os
.
O_TRUNC
,
diskPermission
)
if
err
!=
nil
{
if
err
!=
nil
{
if
errors
.
Is
(
err
,
os
.
ErrExist
)
{
if
errors
.
Is
(
err
,
os
.
ErrExist
)
{
...
@@ -49,6 +55,8 @@ func (d *DiskKV) Put(k common.Hash, v []byte) error {
...
@@ -49,6 +55,8 @@ func (d *DiskKV) Put(k common.Hash, v []byte) error {
}
}
func
(
d
*
DiskKV
)
Get
(
k
common
.
Hash
)
([]
byte
,
error
)
{
func
(
d
*
DiskKV
)
Get
(
k
common
.
Hash
)
([]
byte
,
error
)
{
d
.
RLock
()
defer
d
.
RUnlock
()
f
,
err
:=
os
.
OpenFile
(
d
.
pathKey
(
k
),
os
.
O_RDONLY
,
diskPermission
)
f
,
err
:=
os
.
OpenFile
(
d
.
pathKey
(
k
),
os
.
O_RDONLY
,
diskPermission
)
if
err
!=
nil
{
if
err
!=
nil
{
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
...
...
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