Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional --destination param on mount #203

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions cmd/datamon/cmd/bundle_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"

Expand Down Expand Up @@ -77,12 +78,23 @@ var mountBundleCmd = &cobra.Command{
return
}

path, err := sanitizePath(params.bundle.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", params.bundle.DataPath)
return
var err error

var consumableStorePath string
if params.bundle.DataPath == "" {
consumableStorePath, err = ioutil.TempDir("", "datamon-mount-destination")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the bundle hash and write the bundle descriptor last or write a done marker file. The next time we can skip downloading the files and reused the json files downloaded.. ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bundle descriptor and filelists are written to disk at the same time it's used to initialize the in-memory structures. #218 contains the change to read ${destination}/.datamon/ folder from disk into in-memory structures.

since this implementation places the destination in a temporary directory that might vanish after the process exits, it's not clear where the reusable json files are to be stored... i suppose creating a subdirectory of ${HOME}/.datamon, say ${HOME}/.datamon/meta-cache, is a reasonable option?

creating a new issue to document the intent of these changes seems more likely to me than including them in this diff.

if err != nil {
log.Fatalf("Couldn't create temporary directory: %v\n", err)
return
}
} else {
consumableStorePath, err = sanitizePath(params.bundle.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", params.bundle.DataPath)
return
}
createPath(consumableStorePath)
}
createPath(path)

metadataSource, err := gcs.New(params.repo.MetadataBucket, config.Credential)
if err != nil {
Expand All @@ -92,7 +104,7 @@ var mountBundleCmd = &cobra.Command{
if err != nil {
onDaemonError(err)
}
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), path))
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), consumableStorePath))

err = setLatestOrLabelledBundle(metadataSource)
if err != nil {
Expand Down Expand Up @@ -141,7 +153,7 @@ func init() {
addLabelNameFlag(mountBundleCmd)
// todo: #165 add --cpuprof to all commands via root
addCPUProfFlag(mountBundleCmd)
requiredFlags = append(requiredFlags, addDataPathFlag(mountBundleCmd))
addDataPathFlag(mountBundleCmd)
requiredFlags = append(requiredFlags, addMountPathFlag(mountBundleCmd))

for _, flag := range requiredFlags {
Expand Down
24 changes: 20 additions & 4 deletions cmd/datamon/cmd/bundle_mutable_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"log"

daemonizer "github.com/jacobsa/daemonize"

Expand Down Expand Up @@ -34,8 +36,22 @@ var mutableMountBundleCmd = &cobra.Command{
runDaemonized()
return
}

DieIfNotDirectory(params.bundle.DataPath)
var err error
var consumableStorePath string
if params.bundle.DataPath == "" {
consumableStorePath, err = ioutil.TempDir("", "datamon-mount-destination")
if err != nil {
log.Fatalf("Couldn't create temporary directory: %v\n", err)
return
}
} else {
consumableStorePath, err = sanitizePath(params.bundle.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", params.bundle.DataPath)
return
}
createPath(consumableStorePath)
}

metadataSource, err := gcs.New(params.repo.MetadataBucket, config.Credential)
if err != nil {
Expand All @@ -45,7 +61,7 @@ var mutableMountBundleCmd = &cobra.Command{
if err != nil {
onDaemonError(err)
}
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), params.bundle.DataPath))
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), consumableStorePath))

bd := core.NewBDescriptor(
core.Message(params.bundle.Message),
Expand Down Expand Up @@ -91,7 +107,7 @@ func init() {
addBucketNameFlag(mutableMountBundleCmd)
addDaemonizeFlag(mutableMountBundleCmd)
addBlobBucket(mutableMountBundleCmd)
requiredFlags = append(requiredFlags, addDataPathFlag(mutableMountBundleCmd))
addDataPathFlag(mutableMountBundleCmd)
requiredFlags = append(requiredFlags, addMountPathFlag(mutableMountBundleCmd))
requiredFlags = append(requiredFlags, addCommitMessageFlag(mutableMountBundleCmd))

Expand Down
60 changes: 49 additions & 11 deletions cmd/datamon/cmd/cli_fuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestBundleMount(t *testing.T) {
func testBundleMount(t *testing.T, testType string) {
cleanup := setupTests(t)
defer cleanup()
runCmd(t, []string{"repo",
Expand All @@ -39,16 +39,42 @@ func TestBundleMount(t *testing.T) {
)
defer os.RemoveAll(pathBackingFs)
defer os.RemoveAll(pathToMount)
cmd := exec.Command(
"../datamon",
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
)
var cmdParams []string
switch testType {
case "nostream-dest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
"--stream=false",
}
case "stream-dest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
}
case "nostream-nodest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
}
default:
require.True(t, false, "unexpected test type '"+testType+"'")
}
cmd := exec.Command("../datamon", cmdParams...)
require.NoError(t, cmd.Start())
time.Sleep(5 * time.Second)
for _, file := range testUploadTrees[1] {
Expand All @@ -62,6 +88,18 @@ func TestBundleMount(t *testing.T) {
require.Equal(t, "signal: killed", err.Error(), "cmd exit with killed error")
}

func TestBundleMount(t *testing.T) {
testBundleMount(t, "stream-dest")
}

func TestBundleMountNoStream(t *testing.T) {
testBundleMount(t, "nostream-dest")
}

func TestBundleMountNoStreamNoDest(t *testing.T) {
testBundleMount(t, "nostream-nodest")
}

func mutableMountOutputToBundleID(t *testing.T, out string) string {
lines := strings.Split(out, "\n")
var bundleKVLine string
Expand Down
12 changes: 12 additions & 0 deletions cmd/datamon/cmd/cli_fuse_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/sh

# this shell wrapper around the cli_fuse_tests.go to remind how to run the tests.
# these tests are not run as part of CI since FUSE is unavailable via CircleCI.

(cd .. && go build)

go test -tags fuse_cli -list Mount |grep -v '^ok' |while read -r test_name; do
umount /tmp/mmp
rm -r /tmp/mmp /tmp/mmfs
go test -v -tags fuse_cli -run '^'"${test_name}"'$'
done