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-dms3
Commits
ee935aba
Commit
ee935aba
authored
Jun 12, 2017
by
Kevin Atkinson
Committed by
Jeromy
Sep 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address p.r. comments
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
2df7727b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
25 deletions
+45
-25
repo/config/init.go
repo/config/init.go
+3
-3
repo/fsrepo/datastores.go
repo/fsrepo/datastores.go
+37
-17
repo/fsrepo/fsrepo_test.go
repo/fsrepo/fsrepo_test.go
+5
-5
No files found.
repo/config/init.go
View file @
ee935aba
...
@@ -39,7 +39,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
...
@@ -39,7 +39,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
Gateway
:
"/ip4/127.0.0.1/tcp/8080"
,
Gateway
:
"/ip4/127.0.0.1/tcp/8080"
,
},
},
Datastore
:
*
datastore
,
Datastore
:
datastore
,
Bootstrap
:
BootstrapPeerStrings
(
bootstrapPeers
),
Bootstrap
:
BootstrapPeerStrings
(
bootstrapPeers
),
Identity
:
identity
,
Identity
:
identity
,
Discovery
:
Discovery
{
MDNS
{
Discovery
:
Discovery
{
MDNS
{
...
@@ -77,8 +77,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
...
@@ -77,8 +77,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
}
}
// DatastoreConfig is an internal function exported to aid in testing.
// DatastoreConfig is an internal function exported to aid in testing.
func
DefaultDatastoreConfig
()
*
Datastore
{
func
DefaultDatastoreConfig
()
Datastore
{
return
&
Datastore
{
return
Datastore
{
StorageMax
:
"10GB"
,
StorageMax
:
"10GB"
,
StorageGCWatermark
:
90
,
// 90%
StorageGCWatermark
:
90
,
// 90%
GCPeriod
:
"1h"
,
GCPeriod
:
"1h"
,
...
...
repo/fsrepo/datastores.go
View file @
ee935aba
package
fsrepo
package
fsrepo
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"path/filepath"
"path/filepath"
...
@@ -20,7 +19,7 @@ func (r *FSRepo) constructDatastore(params map[string]interface{}) (repo.Datasto
...
@@ -20,7 +19,7 @@ func (r *FSRepo) constructDatastore(params map[string]interface{}) (repo.Datasto
case
"mount"
:
case
"mount"
:
mounts
,
ok
:=
params
[
"mounts"
]
.
([]
interface
{})
mounts
,
ok
:=
params
[
"mounts"
]
.
([]
interface
{})
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"mounts field
wasn
t an array"
)
return
nil
,
fmt
.
Errorf
(
"
'
mounts
'
field
is missing or no
t an array"
)
}
}
return
r
.
openMountDatastore
(
mounts
)
return
r
.
openMountDatastore
(
mounts
)
...
@@ -29,19 +28,33 @@ func (r *FSRepo) constructDatastore(params map[string]interface{}) (repo.Datasto
...
@@ -29,19 +28,33 @@ func (r *FSRepo) constructDatastore(params map[string]interface{}) (repo.Datasto
case
"mem"
:
case
"mem"
:
return
ds
.
NewMapDatastore
(),
nil
return
ds
.
NewMapDatastore
(),
nil
case
"log"
:
case
"log"
:
child
,
err
:=
r
.
constructDatastore
(
params
[
"child"
]
.
(
map
[
string
]
interface
{}))
childField
,
ok
:=
params
[
"child"
]
.
(
map
[
string
]
interface
{})
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'child' field is missing or not a map"
)
}
child
,
err
:=
r
.
constructDatastore
(
childField
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
nameField
,
ok
:=
params
[
"name"
]
.
(
string
)
return
ds
.
NewLogDatastore
(
child
,
params
[
"name"
]
.
(
string
)),
nil
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'name' field was missing or not a string"
)
}
return
ds
.
NewLogDatastore
(
child
,
nameField
),
nil
case
"measure"
:
case
"measure"
:
child
,
err
:=
r
.
constructDatastore
(
params
[
"child"
]
.
(
map
[
string
]
interface
{}))
childField
,
ok
:=
params
[
"child"
]
.
(
map
[
string
]
interface
{})
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'child' field was missing or not a map"
)
}
child
,
err
:=
r
.
constructDatastore
(
childField
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
prefix
:=
params
[
"prefix"
]
.
(
string
)
prefix
,
ok
:=
params
[
"prefix"
]
.
(
string
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'prefix' field was missing or not a string"
)
}
return
r
.
openMeasureDB
(
prefix
,
child
)
return
r
.
openMeasureDB
(
prefix
,
child
)
...
@@ -52,12 +65,6 @@ func (r *FSRepo) constructDatastore(params map[string]interface{}) (repo.Datasto
...
@@ -52,12 +65,6 @@ func (r *FSRepo) constructDatastore(params map[string]interface{}) (repo.Datasto
}
}
}
}
type
mountConfig
struct
{
Path
string
ChildType
string
Child
*
json
.
RawMessage
}
func
(
r
*
FSRepo
)
openMountDatastore
(
mountcfg
[]
interface
{})
(
repo
.
Datastore
,
error
)
{
func
(
r
*
FSRepo
)
openMountDatastore
(
mountcfg
[]
interface
{})
(
repo
.
Datastore
,
error
)
{
var
mounts
[]
mount
.
Mount
var
mounts
[]
mount
.
Mount
for
_
,
iface
:=
range
mountcfg
{
for
_
,
iface
:=
range
mountcfg
{
...
@@ -83,22 +90,35 @@ func (r *FSRepo) openMountDatastore(mountcfg []interface{}) (repo.Datastore, err
...
@@ -83,22 +90,35 @@ func (r *FSRepo) openMountDatastore(mountcfg []interface{}) (repo.Datastore, err
}
}
func
(
r
*
FSRepo
)
openFlatfsDatastore
(
params
map
[
string
]
interface
{})
(
repo
.
Datastore
,
error
)
{
func
(
r
*
FSRepo
)
openFlatfsDatastore
(
params
map
[
string
]
interface
{})
(
repo
.
Datastore
,
error
)
{
p
:=
params
[
"path"
]
.
(
string
)
p
,
ok
:=
params
[
"path"
]
.
(
string
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'path' field is missing or not boolean"
)
}
if
!
filepath
.
IsAbs
(
p
)
{
if
!
filepath
.
IsAbs
(
p
)
{
p
=
filepath
.
Join
(
r
.
path
,
p
)
p
=
filepath
.
Join
(
r
.
path
,
p
)
}
}
sshardFun
:=
params
[
"shardFunc"
]
.
(
string
)
sshardFun
,
ok
:=
params
[
"shardFunc"
]
.
(
string
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'shardFunc' field is missing or not a string"
)
}
shardFun
,
err
:=
flatfs
.
ParseShardFunc
(
sshardFun
)
shardFun
,
err
:=
flatfs
.
ParseShardFunc
(
sshardFun
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
flatfs
.
CreateOrOpen
(
p
,
shardFun
,
params
[
"sync"
]
.
(
bool
))
syncField
,
ok
:=
params
[
"sync"
]
.
(
bool
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'sync' field is missing or not boolean"
)
}
return
flatfs
.
CreateOrOpen
(
p
,
shardFun
,
syncField
)
}
}
func
(
r
*
FSRepo
)
openLeveldbDatastore
(
params
map
[
string
]
interface
{})
(
repo
.
Datastore
,
error
)
{
func
(
r
*
FSRepo
)
openLeveldbDatastore
(
params
map
[
string
]
interface
{})
(
repo
.
Datastore
,
error
)
{
p
:=
params
[
"path"
]
.
(
string
)
p
,
ok
:=
params
[
"path"
]
.
(
string
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"'path' field is missing or not string"
)
}
if
!
filepath
.
IsAbs
(
p
)
{
if
!
filepath
.
IsAbs
(
p
)
{
p
=
filepath
.
Join
(
r
.
path
,
p
)
p
=
filepath
.
Join
(
r
.
path
,
p
)
}
}
...
...
repo/fsrepo/fsrepo_test.go
View file @
ee935aba
...
@@ -40,8 +40,8 @@ func TestCanManageReposIndependently(t *testing.T) {
...
@@ -40,8 +40,8 @@ func TestCanManageReposIndependently(t *testing.T) {
pathB
:=
testRepoPath
(
"b"
,
t
)
pathB
:=
testRepoPath
(
"b"
,
t
)
t
.
Log
(
"initialize two repos"
)
t
.
Log
(
"initialize two repos"
)
assert
.
Nil
(
Init
(
pathA
,
&
config
.
Config
{
Datastore
:
*
config
.
DefaultDatastoreConfig
()}),
t
,
"a"
,
"should initialize successfully"
)
assert
.
Nil
(
Init
(
pathA
,
&
config
.
Config
{
Datastore
:
config
.
DefaultDatastoreConfig
()}),
t
,
"a"
,
"should initialize successfully"
)
assert
.
Nil
(
Init
(
pathB
,
&
config
.
Config
{
Datastore
:
*
config
.
DefaultDatastoreConfig
()}),
t
,
"b"
,
"should initialize successfully"
)
assert
.
Nil
(
Init
(
pathB
,
&
config
.
Config
{
Datastore
:
config
.
DefaultDatastoreConfig
()}),
t
,
"b"
,
"should initialize successfully"
)
t
.
Log
(
"ensure repos initialized"
)
t
.
Log
(
"ensure repos initialized"
)
assert
.
True
(
IsInitialized
(
pathA
),
t
,
"a should be initialized"
)
assert
.
True
(
IsInitialized
(
pathA
),
t
,
"a should be initialized"
)
...
@@ -67,7 +67,7 @@ func TestDatastoreGetNotAllowedAfterClose(t *testing.T) {
...
@@ -67,7 +67,7 @@ func TestDatastoreGetNotAllowedAfterClose(t *testing.T) {
path
:=
testRepoPath
(
"test"
,
t
)
path
:=
testRepoPath
(
"test"
,
t
)
assert
.
True
(
!
IsInitialized
(
path
),
t
,
"should NOT be initialized"
)
assert
.
True
(
!
IsInitialized
(
path
),
t
,
"should NOT be initialized"
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
*
config
.
DefaultDatastoreConfig
()}),
t
,
"should initialize successfully"
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
config
.
DefaultDatastoreConfig
()}),
t
,
"should initialize successfully"
)
r
,
err
:=
Open
(
path
)
r
,
err
:=
Open
(
path
)
assert
.
Nil
(
err
,
t
,
"should open successfully"
)
assert
.
Nil
(
err
,
t
,
"should open successfully"
)
...
@@ -84,7 +84,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
...
@@ -84,7 +84,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
t
.
Parallel
()
t
.
Parallel
()
path
:=
testRepoPath
(
"test"
,
t
)
path
:=
testRepoPath
(
"test"
,
t
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
*
config
.
DefaultDatastoreConfig
()}),
t
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
config
.
DefaultDatastoreConfig
()}),
t
)
r1
,
err
:=
Open
(
path
)
r1
,
err
:=
Open
(
path
)
assert
.
Nil
(
err
,
t
)
assert
.
Nil
(
err
,
t
)
...
@@ -106,7 +106,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
...
@@ -106,7 +106,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
func
TestOpenMoreThanOnceInSameProcess
(
t
*
testing
.
T
)
{
func
TestOpenMoreThanOnceInSameProcess
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
path
:=
testRepoPath
(
""
,
t
)
path
:=
testRepoPath
(
""
,
t
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
*
config
.
DefaultDatastoreConfig
()}),
t
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
config
.
DefaultDatastoreConfig
()}),
t
)
r1
,
err
:=
Open
(
path
)
r1
,
err
:=
Open
(
path
)
assert
.
Nil
(
err
,
t
,
"first repo should open successfully"
)
assert
.
Nil
(
err
,
t
,
"first repo should open successfully"
)
...
...
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