func TestFromCommit(t *testing.T) { t.Parallel() repo := uniqueString("TestFromCommit") pachClient := getPachClient(t) seed := time.Now().UnixNano() rand := rand.New(rand.NewSource(seed)) err := pfsutil.CreateRepo(pachClient, repo) require.NoError(t, err) commit1, err := pfsutil.StartCommit(pachClient, repo, "") require.NoError(t, err) _, err = pfsutil.PutFile(pachClient, repo, commit1.Id, "file", 0, workload.NewReader(rand, KB)) require.NoError(t, err) err = pfsutil.FinishCommit(pachClient, repo, commit1.Id) require.NoError(t, err) commit2, err := pfsutil.StartCommit(pachClient, repo, commit1.Id) require.NoError(t, err) _, err = pfsutil.PutFile(pachClient, repo, commit2.Id, "file", 0, workload.NewReader(rand, KB)) require.NoError(t, err) err = pfsutil.FinishCommit(pachClient, repo, commit2.Id) require.NoError(t, err) var buffer bytes.Buffer require.NoError(t, pfsutil.GetFile(pachClient, repo, commit2.Id, "file", 0, 0, commit1.Id, nil, &buffer)) require.Equal(t, buffer.Len(), KB) buffer = bytes.Buffer{} require.NoError(t, pfsutil.GetFile(pachClient, repo, commit2.Id, "file", 0, 0, "", nil, &buffer)) require.Equal(t, buffer.Len(), 2*KB) }
func testFailures(t *testing.T, apiClient pfs.APIClient, cluster Cluster) { repoName := "testFailuresRepo" err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) commit, err := pfsutil.StartCommit(apiClient, repoName, "") require.NoError(t, err) require.NotNil(t, commit) newCommitID := commit.Id err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/b") require.NoError(t, err) err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/c") require.NoError(t, err) doWrites(t, apiClient, repoName, newCommitID) err = pfsutil.FinishCommit(apiClient, repoName, newCommitID) require.NoError(t, err) checkWrites(t, apiClient, repoName, newCommitID) cluster.KillRoleAssigner() for server := 0; server < testNumReplicas; server++ { cluster.Kill(server) } cluster.RestartRoleAssigner() cluster.WaitForAvailability() checkWrites(t, apiClient, repoName, newCommitID) }
func testMountBig(t *testing.T, apiClient pfs.APIClient, cluster Cluster) { repoName := "testMountBigRepo" err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) directory := "/compile/testMount" mounter := fuse.NewMounter("localhost", apiClient) ready := make(chan bool) go func() { err = mounter.Mount(directory, 0, 1, ready) require.NoError(t, err) }() <-ready _, err = os.Stat(filepath.Join(directory, repoName)) require.NoError(t, err) _, err = os.Stat(filepath.Join(directory, repoName, "scratch")) require.NoError(t, err) commit, err := pfsutil.StartCommit(apiClient, repoName, "scratch") require.NoError(t, err) require.NotNil(t, commit) newCommitID := commit.Id bigValue := make([]byte, 1024*1024*300) for i := 0; i < 1024*1024*300; i++ { bigValue[i] = 'a' } wg := sync.WaitGroup{} for j := 0; j < 5; j++ { wg.Add(1) go func(j int) { defer wg.Done() err := ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, fmt.Sprintf("big%d", j)), bigValue, 0666) require.NoError(t, err) }(j) } wg.Wait() err = pfsutil.FinishCommit(apiClient, repoName, newCommitID) require.NoError(t, err) wg = sync.WaitGroup{} for j := 0; j < 5; j++ { wg.Add(1) go func(j int) { defer wg.Done() data, err := ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, fmt.Sprintf("big%d", j))) require.NoError(t, err) require.Equal(t, bigValue, data) }(j) } wg.Wait() err = mounter.Unmount(directory) require.NoError(t, err) }
func TestJob(t *testing.T) { t.Parallel() dataRepo := uniqueString("TestJob.data") pachClient := getPachClient(t) require.NoError(t, pfsutil.CreateRepo(pachClient, dataRepo)) commit, err := pfsutil.StartCommit(pachClient, dataRepo, "") require.NoError(t, err) _, err = pfsutil.PutFile(pachClient, dataRepo, commit.Id, "file", 0, strings.NewReader("foo\n")) require.NoError(t, err) require.NoError(t, pfsutil.FinishCommit(pachClient, dataRepo, commit.Id)) job, err := ppsutil.CreateJob( pachClient, "", []string{"cp", path.Join("/pfs", dataRepo, "file"), "/pfs/out/file"}, nil, 1, []*pps.JobInput{{Commit: commit}}, "", ) require.NoError(t, err) inspectJobRequest := &pps.InspectJobRequest{ Job: job, BlockOutput: true, BlockState: true, } jobInfo, err := pachClient.InspectJob(context.Background(), inspectJobRequest) require.NoError(t, err) require.Equal(t, pps.JobState_JOB_STATE_SUCCESS.String(), jobInfo.State.String()) commitInfo, err := pfsutil.InspectCommit(pachClient, jobInfo.OutputCommit.Repo.Name, jobInfo.OutputCommit.Id) require.NoError(t, err) require.Equal(t, pfs.CommitType_COMMIT_TYPE_READ, commitInfo.CommitType) var buffer bytes.Buffer require.NoError(t, pfsutil.GetFile(pachClient, jobInfo.OutputCommit.Repo.Name, jobInfo.OutputCommit.Id, "file", 0, 0, "", nil, &buffer)) require.Equal(t, "foo\n", buffer.String()) }
func TestMountBig(t *testing.T) { t.Skip() t.Parallel() apiClient := getPfsClient(t) repoName := uniqueString("testMountBigRepo") err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) directory := "/compile/testMount" mounter := fuse.NewMounter("localhost", apiClient) ready := make(chan bool) go func() { err = mounter.Mount(directory, &pfs.Shard{Number: 0, Modulus: 1}, nil, ready) require.NoError(t, err) }() <-ready _, err = os.Stat(filepath.Join(directory, repoName)) require.NoError(t, err) commit, err := pfsutil.StartCommit(apiClient, repoName, "") require.NoError(t, err) require.NotNil(t, commit) newCommitID := commit.Id bigValue := make([]byte, 1024*1024*300) for i := 0; i < 1024*1024*300; i++ { bigValue[i] = 'a' } wg := sync.WaitGroup{} for j := 0; j < 5; j++ { wg.Add(1) go func(j int) { defer wg.Done() err := ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, fmt.Sprintf("big%d", j)), bigValue, 0666) require.NoError(t, err) }(j) } wg.Wait() err = pfsutil.FinishCommit(apiClient, repoName, newCommitID) require.NoError(t, err) wg = sync.WaitGroup{} for j := 0; j < 5; j++ { wg.Add(1) go func(j int) { defer wg.Done() data, err := ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, fmt.Sprintf("big%d", j))) require.NoError(t, err) require.Equal(t, bigValue, data) }(j) } wg.Wait() err = mounter.Unmount(directory) require.NoError(t, err) }
func TestJob(t *testing.T) { dataRepo := uniqueString("TestJob.data") pfsClient := getPfsClient(t) require.NoError(t, pfsutil.CreateRepo(pfsClient, dataRepo)) commit, err := pfsutil.StartCommit(pfsClient, dataRepo, "") require.NoError(t, err) _, err = pfsutil.PutFile(pfsClient, dataRepo, commit.Id, "file", 0, strings.NewReader("foo")) require.NoError(t, err) require.NoError(t, pfsutil.FinishCommit(pfsClient, dataRepo, commit.Id)) ppsClient := getPpsClient(t) job, err := ppsutil.CreateJob( ppsClient, "", []string{"cp", path.Join("/pfs", dataRepo, "file"), "/pfs/out/file"}, "", 1, []*pfs.Commit{commit}, "", ) require.NoError(t, err) inspectJobRequest := &pps.InspectJobRequest{ Job: job, BlockOutput: true, BlockState: true, } jobInfo, err := ppsClient.InspectJob(context.Background(), inspectJobRequest) require.NoError(t, err) var buffer bytes.Buffer require.NoError(t, pfsutil.GetFile(pfsClient, jobInfo.OutputCommit.Repo.Name, jobInfo.OutputCommit.Id, "file", 0, 0, nil, &buffer)) require.Equal(t, "foo", buffer.String()) }
func (b *brancher) CommitOutstanding() error { if err := b.destroyable.Destroy(); err != nil { return err } for repositoryName, commitID := range b.outputRepositoryToBranchID { if err := pfsutil.FinishCommit( b.pfsAPIClient, repositoryName, commitID, ); err != nil { return err } for inputRepositoryCommit := range b.outputRepositoryToInputRepositories[repositoryName] { if err := b.storeClient.CreatePfsCommitMapping( &pps.PfsCommitMapping{ InputRepository: inputRepositoryCommit.repositoryName, InputCommitId: inputRepositoryCommit.commitID, OutputRepository: repositoryName, OutputCommitId: commitID, Timestamp: prototime.TimeToTimestamp(b.timer.Now()), }, ); err != nil { return err } } } return nil }
func BenchmarkFuse(b *testing.B) { apiClient := getPfsClient(b) repoName := uniqueString("benchMountRepo") if err := pfsutil.CreateRepo(apiClient, repoName); err != nil { b.Error(err) } directory := "/compile/benchMount" mounter := fuse.NewMounter("localhost", apiClient) ready := make(chan bool) go func() { err := mounter.Mount(directory, &pfs.Shard{Number: 0, Modulus: 1}, nil, ready) require.NoError(b, err) }() <-ready defer func() { if err := mounter.Unmount(directory); err != nil { b.Error(err) } }() bigValue := make([]byte, 1024*1024) for i := 0; i < 1024*1024; i++ { bigValue[i] = 'a' } b.ResetTimer() for i := 0; i < b.N; i++ { commit, err := pfsutil.StartCommit(apiClient, repoName, "") if err != nil { b.Error(err) } if commit == nil { b.Error("nil branch") } newCommitID := commit.Id var wg sync.WaitGroup for j := 0; j < 1024; j++ { wg.Add(1) go func(j int) { defer wg.Done() if err = ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, fmt.Sprintf("big%d", j)), bigValue, 0666); err != nil { b.Error(err) } }(j) } wg.Wait() if err := pfsutil.FinishCommit(apiClient, repoName, newCommitID); err != nil { b.Error(err) } } }
func benchMount(b *testing.B, apiClient pfs.ApiClient) { repositoryName := "benchMountRepo" if err := pfsutil.CreateRepo(apiClient, repositoryName); err != nil { b.Error(err) } directory := "/compile/benchMount" mounter := fuse.NewMounter(apiClient) if err := mounter.Mount(repositoryName, "", directory, 0, 1); err != nil { b.Error(err) } defer func() { if err := mounter.Unmount(directory); err != nil { b.Error(err) } if err := mounter.Wait(directory); err != nil { b.Error(err) } }() bigValue := make([]byte, 1024*1024) for i := 0; i < 1024*1024; i++ { bigValue[i] = 'a' } b.ResetTimer() for i := 0; i < b.N; i++ { commit, err := pfsutil.StartCommit(apiClient, repositoryName, "scratch") if err != nil { b.Error(err) } if commit == nil { b.Error("nil branch") } newCommitID := commit.Id var wg sync.WaitGroup for j := 0; j < 1024; j++ { wg.Add(1) go func(j int) { defer wg.Done() if err = ioutil.WriteFile(filepath.Join(directory, newCommitID, fmt.Sprintf("big%d", j)), bigValue, 0666); err != nil { b.Error(err) } }(j) } wg.Wait() if err := pfsutil.FinishCommit(apiClient, repositoryName, newCommitID); err != nil { b.Error(err) } } }
func TestGrep(t *testing.T) { t.Skip() t.Parallel() dataRepo := uniqueString("TestGrep.data") pfsClient := getPfsClient(t) require.NoError(t, pfsutil.CreateRepo(pfsClient, dataRepo)) commit, err := pfsutil.StartCommit(pfsClient, dataRepo, "") require.NoError(t, err) for i := 0; i < 100; i++ { _, err = pfsutil.PutFile(pfsClient, dataRepo, commit.Id, fmt.Sprintf("file%d", i), 0, strings.NewReader("foo\nbar\nfizz\nbuzz\n")) require.NoError(t, err) } require.NoError(t, pfsutil.FinishCommit(pfsClient, dataRepo, commit.Id)) ppsClient := getPpsClient(t) job1, err := ppsutil.CreateJob( ppsClient, "", []string{"bash"}, fmt.Sprintf("grep foo /pfs/%s/* >/pfs/out/foo", dataRepo), 1, []*pps.JobInput{{Commit: commit}}, "", ) require.NoError(t, err) job2, err := ppsutil.CreateJob( ppsClient, "", []string{"bash"}, fmt.Sprintf("grep foo /pfs/%s/* >/pfs/out/foo", dataRepo), 4, []*pps.JobInput{{Commit: commit}}, "", ) require.NoError(t, err) inspectJobRequest := &pps.InspectJobRequest{ Job: job1, BlockOutput: true, BlockState: true, } job1Info, err := ppsClient.InspectJob(context.Background(), inspectJobRequest) require.NoError(t, err) inspectJobRequest.Job = job2 job2Info, err := ppsClient.InspectJob(context.Background(), inspectJobRequest) require.NoError(t, err) repo1Info, err := pfsutil.InspectRepo(pfsClient, job1Info.OutputCommit.Repo.Name) require.NoError(t, err) repo2Info, err := pfsutil.InspectRepo(pfsClient, job2Info.OutputCommit.Repo.Name) require.NoError(t, err) require.Equal(t, repo1Info.SizeBytes, repo2Info.SizeBytes) }
func TestSharding(t *testing.T) { t.Parallel() repo := uniqueString("TestSharding") pachClient := getPachClient(t) err := pfsutil.CreateRepo(pachClient, repo) require.NoError(t, err) commit, err := pfsutil.StartCommit(pachClient, repo, "") require.NoError(t, err) var wg sync.WaitGroup for i := 0; i < NUMFILES; i++ { i := i wg.Add(1) go func() { defer wg.Done() rand := rand.New(rand.NewSource(int64(i))) _, err = pfsutil.PutFile(pachClient, repo, commit.Id, fmt.Sprintf("file%d", i), 0, workload.NewReader(rand, KB)) require.NoError(t, err) }() } wg.Wait() err = pfsutil.FinishCommit(pachClient, repo, commit.Id) require.NoError(t, err) wg = sync.WaitGroup{} for i := 0; i < NUMFILES; i++ { i := i wg.Add(1) go func() { defer wg.Done() var buffer1Shard bytes.Buffer var buffer4Shard bytes.Buffer shard := &pfs.Shard{FileModulus: 1, BlockModulus: 1} err := pfsutil.GetFile(pachClient, repo, commit.Id, fmt.Sprintf("file%d", i), 0, 0, "", shard, &buffer1Shard) require.NoError(t, err) shard.BlockModulus = 4 for blockNumber := uint64(0); blockNumber < 4; blockNumber++ { shard.BlockNumber = blockNumber err := pfsutil.GetFile(pachClient, repo, commit.Id, fmt.Sprintf("file%d", i), 0, 0, "", shard, &buffer4Shard) require.NoError(t, err) } require.Equal(t, buffer1Shard.Len(), buffer4Shard.Len()) }() } wg.Wait() }
func TestBigWrite(t *testing.T) { t.Parallel() protolog.SetLevel(protolog.Level_LEVEL_DEBUG) repo := uniqueString("TestBigWrite") pfsClient := getPfsClient(t) err := pfsutil.CreateRepo(pfsClient, repo) require.NoError(t, err) commit, err := pfsutil.StartCommit(pfsClient, repo, "") require.NoError(t, err) rand := rand.New(rand.NewSource(5)) _, err = pfsutil.PutFile(pfsClient, repo, commit.Id, "file", 0, workload.NewReader(rand, 10000)) require.NoError(t, err) err = pfsutil.FinishCommit(pfsClient, repo, commit.Id) require.NoError(t, err) var buffer bytes.Buffer err = pfsutil.GetFile(pfsClient, repo, commit.Id, "file", 0, 0, nil, &buffer) require.NoError(t, err) }
func TestSharding(t *testing.T) { t.Parallel() repo := uniqueString("TestSharding") pfsClient := getPfsClient(t) err := pfsutil.CreateRepo(pfsClient, repo) require.NoError(t, err) commit, err := pfsutil.StartCommit(pfsClient, repo, "") require.NoError(t, err) var wg sync.WaitGroup for i := 0; i < NUMFILES; i++ { i := i wg.Add(1) go func() { defer wg.Done() rand := rand.New(rand.NewSource(int64(i))) _, err = pfsutil.PutFile(pfsClient, repo, commit.Id, fmt.Sprintf("file%d", i), 0, workload.NewReader(rand, 128*1024*1024)) require.NoError(t, err) }() } wg.Wait() err = pfsutil.FinishCommit(pfsClient, repo, commit.Id) require.NoError(t, err) }
func TestGrep(t *testing.T) { t.Parallel() dataRepo := uniqueString("pachyderm.TestGrep.data") pfsClient := getPfsClient(t) require.NoError(t, pfsutil.CreateRepo(pfsClient, dataRepo)) commit, err := pfsutil.StartCommit(pfsClient, dataRepo, "") require.NoError(t, err) for i := 0; i < 100; i++ { _, err = pfsutil.PutFile(pfsClient, dataRepo, commit.Id, fmt.Sprintf("file%d", i), 0, strings.NewReader("foo\nbar\nfizz\nbuzz\n")) require.NoError(t, err) } require.NoError(t, pfsutil.FinishCommit(pfsClient, dataRepo, commit.Id)) ppsClient := getPpsClient(t) _, err = ppsutil.CreateJob( ppsClient, "", []string{"bash"}, fmt.Sprintf("grep foo /pfs/%s/* >/pfs/out/foo", dataRepo), 1, []*pps.JobInput{{Commit: commit}}, "", ) require.NoError(t, err) }
func TestCommitFinishedReadDir(t *testing.T) { t.Parallel() // don't leave goroutines running var wg sync.WaitGroup defer wg.Wait() tmp, err := ioutil.TempDir("", "pachyderm-test-") if err != nil { t.Fatalf("tempdir: %v", err) } defer func() { if err := os.RemoveAll(tmp); err != nil { t.Errorf("cannot remove tempdir: %v", err) } }() // closed on successful termination quit := make(chan struct{}) defer close(quit) listener, err := net.Listen("tcp", "localhost:0") if err != nil { t.Fatalf("cannot listen: %v", err) } defer func() { _ = listener.Close() }() // TODO try to share more of this setup code with various main // functions localAddress := listener.Addr().String() srv := grpc.NewServer() const ( numShards = 1 ) sharder := shard.NewLocalSharder(localAddress, numShards) hasher := pfs.NewHasher(numShards, 1) router := shard.NewRouter( sharder, grpcutil.NewDialer( grpc.WithInsecure(), ), localAddress, ) blockDir := filepath.Join(tmp, "blocks") blockServer, err := server.NewLocalBlockAPIServer(blockDir) if err != nil { t.Fatalf("NewLocalBlockAPIServer: %v", err) } pfs.RegisterBlockAPIServer(srv, blockServer) driver, err := drive.NewDriver(localAddress) if err != nil { t.Fatalf("NewDriver: %v", err) } apiServer := server.NewAPIServer( hasher, router, ) pfs.RegisterAPIServer(srv, apiServer) internalAPIServer := server.NewInternalAPIServer( hasher, router, driver, ) pfs.RegisterInternalAPIServer(srv, internalAPIServer) wg.Add(1) go func() { defer wg.Done() if err := srv.Serve(listener); err != nil { select { case <-quit: // orderly shutdown return default: t.Errorf("grpc serve: %v", err) } } }() clientConn, err := grpc.Dial(localAddress, grpc.WithInsecure()) if err != nil { t.Fatalf("grpc dial: %v", err) } apiClient := pfs.NewAPIClient(clientConn) mounter := fuse.NewMounter(localAddress, apiClient) mountpoint := filepath.Join(tmp, "mnt") if err := os.Mkdir(mountpoint, 0700); err != nil { t.Fatalf("mkdir mountpoint: %v", err) } ready := make(chan bool) wg.Add(1) go func() { defer wg.Done() if err := mounter.Mount(mountpoint, nil, nil, ready); err != nil { t.Errorf("mount and serve: %v", err) } }() <-ready defer func() { if err := mounter.Unmount(mountpoint); err != nil { t.Errorf("unmount: %v", err) } }() const ( repoName = "foo" ) if err := pfsutil.CreateRepo(apiClient, repoName); err != nil { t.Fatalf("CreateRepo: %v", err) } commit, err := pfsutil.StartCommit(apiClient, repoName, "") if err != nil { t.Fatalf("StartCommit: %v", err) } t.Logf("open commit %v", commit.Id) const ( greetingName = "greeting" greeting = "Hello, world\n" greetingPerm = 0644 ) if err := ioutil.WriteFile(filepath.Join(mountpoint, repoName, commit.Id, greetingName), []byte(greeting), greetingPerm); err != nil { t.Fatalf("WriteFile: %v", err) } const ( scriptName = "script" script = "#!/bin/sh\necho foo\n" scriptPerm = 0750 ) if err := ioutil.WriteFile(filepath.Join(mountpoint, repoName, commit.Id, scriptName), []byte(script), scriptPerm); err != nil { t.Fatalf("WriteFile: %v", err) } if err := pfsutil.FinishCommit(apiClient, repoName, commit.Id); err != nil { t.Fatalf("FinishCommit: %v", err) } if err := fstestutil.CheckDir(filepath.Join(mountpoint, repoName, commit.Id), map[string]fstestutil.FileInfoCheck{ greetingName: func(fi os.FileInfo) error { // TODO respect greetingPerm if g, e := fi.Mode(), os.FileMode(0666); g != e { return fmt.Errorf("wrong mode: %v != %v", g, e) } if g, e := fi.Size(), int64(len(greeting)); g != e { t.Errorf("wrong size: %v != %v", g, e) } // TODO show fileModTime as mtime // if g, e := fi.ModTime().UTC(), fileModTime; g != e { // t.Errorf("wrong mtime: %v != %v", g, e) // } return nil }, scriptName: func(fi os.FileInfo) error { // TODO respect scriptPerm if g, e := fi.Mode(), os.FileMode(0666); g != e { return fmt.Errorf("wrong mode: %v != %v", g, e) } if g, e := fi.Size(), int64(len(script)); g != e { t.Errorf("wrong size: %v != %v", g, e) } // TODO show fileModTime as mtime // if g, e := fi.ModTime().UTC(), fileModTime; g != e { // t.Errorf("wrong mtime: %v != %v", g, e) // } return nil }, }); err != nil { t.Errorf("wrong directory content: %v", err) } }
func testBlockListCommits(t *testing.T, apiClient pfs.APIClient, cluster Cluster) { repoName := "testBlockListCommitsRepo" err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) baseCommit, err := pfsutil.StartCommit(apiClient, repoName, "") require.NoError(t, err) err = pfsutil.FinishCommit(apiClient, repoName, baseCommit.Id) require.NoError(t, err) repo := &pfs.Repo{ Name: repoName, } listCommitRequest := &pfs.ListCommitRequest{ Repo: repo, From: baseCommit, } commitInfos, err := apiClient.ListCommit( context.Background(), listCommitRequest, ) require.NoError(t, err) require.Equal(t, len(commitInfos.CommitInfo), 0) var newCommit *pfs.Commit var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() time.Sleep(1) commit, err := pfsutil.StartCommit(apiClient, repoName, baseCommit.Id) require.NoError(t, err) require.NotNil(t, commit) newCommit = commit }() listCommitRequest.Block = true listCommitRequest.CommitType = pfs.CommitType_COMMIT_TYPE_WRITE commitInfos, err = apiClient.ListCommit( context.Background(), listCommitRequest, ) wg.Wait() require.NoError(t, err) require.Equal(t, len(commitInfos.CommitInfo), 1) require.Equal(t, newCommit, commitInfos.CommitInfo[0].Commit) wg = sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() time.Sleep(1) err := pfsutil.FinishCommit(apiClient, repoName, newCommit.Id) require.NoError(t, err) }() listCommitRequest.Block = true listCommitRequest.CommitType = pfs.CommitType_COMMIT_TYPE_READ commitInfos, err = apiClient.ListCommit( context.Background(), listCommitRequest, ) wg.Wait() require.NoError(t, err) require.Equal(t, len(commitInfos.CommitInfo), 1) require.Equal(t, newCommit, commitInfos.CommitInfo[0].Commit) }
func TestBlockListCommits(t *testing.T) { t.Parallel() apiClient := getPfsClient(t) repoName := uniqueString("testBlockListCommitsRepo") err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) baseCommit, err := pfsutil.StartCommit(apiClient, repoName, "") require.NoError(t, err) err = pfsutil.FinishCommit(apiClient, repoName, baseCommit.Id) require.NoError(t, err) repo := &pfs.Repo{ Name: repoName, } listCommitRequest := &pfs.ListCommitRequest{ Repo: []*pfs.Repo{repo}, FromCommit: []*pfs.Commit{baseCommit}, } commitInfos, err := apiClient.ListCommit( context.Background(), listCommitRequest, ) require.NoError(t, err) require.Equal(t, len(commitInfos.CommitInfo), 0) var newCommit *pfs.Commit var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() time.Sleep(1) commit, err := pfsutil.StartCommit(apiClient, repoName, baseCommit.Id) require.NoError(t, err) require.NotNil(t, commit) newCommit = commit }() listCommitRequest.Block = true listCommitRequest.CommitType = pfs.CommitType_COMMIT_TYPE_WRITE commitInfos, err = apiClient.ListCommit( context.Background(), listCommitRequest, ) wg.Wait() require.NoError(t, err) require.Equal(t, len(commitInfos.CommitInfo), 1) require.Equal(t, newCommit, commitInfos.CommitInfo[0].Commit) wg = sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() time.Sleep(1) err := pfsutil.FinishCommit(apiClient, repoName, newCommit.Id) require.NoError(t, err) }() listCommitRequest.Block = true listCommitRequest.CommitType = pfs.CommitType_COMMIT_TYPE_READ commitInfos, err = apiClient.ListCommit( context.Background(), listCommitRequest, ) wg.Wait() require.NoError(t, err) require.Equal(t, len(commitInfos.CommitInfo), 1) require.Equal(t, newCommit, commitInfos.CommitInfo[0].Commit) }
func Cmds(address string) []*cobra.Command { var fileNumber int var fileModulus int var blockNumber int var blockModulus int shard := func() *pfs.Shard { return &pfs.Shard{ FileNumber: uint64(fileNumber), FileModulus: uint64(fileModulus), BlockNumber: uint64(blockNumber), BlockModulus: uint64(blockModulus), } } addShardFlags := func(cmd *cobra.Command) { cmd.Flags().IntVarP(&fileNumber, "file-shard", "s", 0, "file shard to read") cmd.Flags().IntVarP(&fileModulus, "file-modulus", "m", 1, "modulus of file shard") cmd.Flags().IntVarP(&blockNumber, "block-shard", "b", 0, "block shard to read") cmd.Flags().IntVarP(&blockModulus, "block-modulus", "n", 1, "modulus of block shard") } repo := &cobra.Command{ Use: "repo", Short: "Docs for repos.", Long: `Repos, short for repository, are the top level data object in Pachyderm. Repos are created with create-repo.`, Run: pkgcobra.RunFixedArgs(0, func(args []string) error { return nil }), } createRepo := &cobra.Command{ Use: "create-repo repo-name", Short: "Create a new repo.", Long: "Create a new repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.CreateRepo(apiClient, args[0]) }), } inspectRepo := &cobra.Command{ Use: "inspect-repo repo-name", Short: "Return info about a repo.", Long: "Return info about a repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } repoInfo, err := pfsutil.InspectRepo(apiClient, args[0]) if err != nil { return err } if repoInfo == nil { return fmt.Errorf("repo %s not found", args[0]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintRepoHeader(writer) pretty.PrintRepoInfo(writer, repoInfo) return writer.Flush() }), } listRepo := &cobra.Command{ Use: "list-repo", Short: "Return all repos.", Long: "Reutrn all repos.", Run: pkgcobra.RunFixedArgs(0, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } repoInfos, err := pfsutil.ListRepo(apiClient) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintRepoHeader(writer) for _, repoInfo := range repoInfos { pretty.PrintRepoInfo(writer, repoInfo) } return writer.Flush() }), } deleteRepo := &cobra.Command{ Use: "delete-repo repo-name", Short: "Delete a repo.", Long: "Delete a repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.DeleteRepo(apiClient, args[0]) }), } commit := &cobra.Command{ Use: "commit", Short: "Docs for commits.", Long: `Commits are atomic transactions on the content of a repo. Creating a commit is a multistep process: - start a new commit with start-commit - write files to it through fuse or with put-file - finish the new commit with finish-commit Commits that have been started but not finished are NOT durable storage. Commits become reliable (and immutable) when they are finished. Commits can be created with another commit as a parent. This layers the data in the commit over the data in the parent.`, Run: pkgcobra.RunFixedArgs(0, func(args []string) error { return nil }), } startCommit := &cobra.Command{ Use: "start-commit repo-name [parent-commit-id]", Short: "Start a new commit.", Long: "Start a new commit with parent-commit-id as the parent.", Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 1, Max: 2}, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } parentCommitID := "" if len(args) == 2 { parentCommitID = args[1] } commit, err := pfsutil.StartCommit(apiClient, args[0], parentCommitID) if err != nil { return err } fmt.Println(commit.Id) return nil }), } finishCommit := &cobra.Command{ Use: "finish-commit repo-name commit-id", Short: "Finish a started commit.", Long: "Finish a started commit. Commit-id must be a writeable commit.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.FinishCommit(apiClient, args[0], args[1]) }), } inspectCommit := &cobra.Command{ Use: "inspect-commit repo-name commit-id", Short: "Return info about a commit.", Long: "Return info about a commit.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } commitInfo, err := pfsutil.InspectCommit(apiClient, args[0], args[1]) if err != nil { return err } if commitInfo == nil { return fmt.Errorf("commit %s not found", args[1]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintCommitInfoHeader(writer) pretty.PrintCommitInfo(writer, commitInfo) return writer.Flush() }), } listCommit := &cobra.Command{ Use: "list-commit repo-name", Short: "Return all commits on a repo.", Long: "Return all commits on a repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } commitInfos, err := pfsutil.ListCommit(apiClient, args) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintCommitInfoHeader(writer) for _, commitInfo := range commitInfos { pretty.PrintCommitInfo(writer, commitInfo) } return writer.Flush() }), } deleteCommit := &cobra.Command{ Use: "delete-commit repo-name commit-id", Short: "Delete a commit.", Long: "Delete a commit.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.DeleteCommit(apiClient, args[0], args[1]) }), } file := &cobra.Command{ Use: "file", Short: "Docs for files.", Long: `Files are the lowest level data object in Pachyderm. Files can be written to started (but not finished) commits with put-file. Files can be read from finished commits with get-file.`, Run: pkgcobra.RunFixedArgs(0, func(args []string) error { return nil }), } putFile := &cobra.Command{ Use: "put-file repo-name commit-id path/to/file", Short: "Put a file from stdin", Long: "Put a file from stdin. Directories must exist. commit-id must be a writeable commit.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } _, err = pfsutil.PutFile(apiClient, args[0], args[1], args[2], 0, os.Stdin) return err }), } getFile := &cobra.Command{ Use: "get-file repo-name commit-id path/to/file", Short: "Return the contents of a file.", Long: "Return the contents of a file.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.GetFile(apiClient, args[0], args[1], args[2], 0, 0, "", shard(), os.Stdout) }), } addShardFlags(getFile) inspectFile := &cobra.Command{ Use: "inspect-file repo-name commit-id path/to/file", Short: "Return info about a file.", Long: "Return info about a file.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2], "", shard()) if err != nil { return err } if fileInfo == nil { return fmt.Errorf("file %s not found", args[2]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintFileInfoHeader(writer) pretty.PrintFileInfo(writer, fileInfo) return writer.Flush() }), } addShardFlags(inspectFile) listFile := &cobra.Command{ Use: "list-file repo-name commit-id path/to/dir", Short: "Return the files in a directory.", Long: "Return the files in a directory.", Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 2, Max: 3}, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } var path string if len(args) == 3 { path = args[2] } fileInfos, err := pfsutil.ListFile(apiClient, args[0], args[1], path, "", shard()) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintFileInfoHeader(writer) for _, fileInfo := range fileInfos { pretty.PrintFileInfo(writer, fileInfo) } return writer.Flush() }), } addShardFlags(listFile) deleteFile := &cobra.Command{ Use: "delete-file repo-name commit-id path/to/file", Short: "Delete a file.", Long: "Delete a file.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.DeleteFile(apiClient, args[0], args[1], args[2]) }), } var mountPoint string mount := &cobra.Command{ Use: "mount [repo/commit:alias...]", Short: "Mount pfs locally.", Long: "Mount pfs locally.", Run: pkgcobra.Run(func(args []string) error { //lion.SetLevel(lion.LevelDebug) apiClient, err := getAPIClient(address) if err != nil { return err } mounter := fuse.NewMounter(address, apiClient) return mounter.Mount(mountPoint, shard(), parseCommitMounts(args), nil) }), } mount.Flags().StringVarP(&mountPoint, "mount-point", "p", "/pfs", "root of mounted filesystem") addShardFlags(mount) var result []*cobra.Command result = append(result, repo) result = append(result, createRepo) result = append(result, inspectRepo) result = append(result, listRepo) result = append(result, deleteRepo) result = append(result, commit) result = append(result, startCommit) result = append(result, finishCommit) result = append(result, inspectCommit) result = append(result, listCommit) result = append(result, deleteCommit) result = append(result, file) result = append(result, putFile) result = append(result, getFile) result = append(result, inspectFile) result = append(result, listFile) result = append(result, deleteFile) result = append(result, mount) return result }
func Cmds(address string) ([]*cobra.Command, error) { var number int var modulus int shard := func() *pfs.Shard { return &pfs.Shard{Number: uint64(number), Modulus: uint64(modulus)} } createRepo := &cobra.Command{ Use: "create-repo repo-name", Short: "Create a new repo.", Long: "Create a new repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.CreateRepo(apiClient, args[0]) }), } inspectRepo := &cobra.Command{ Use: "inspect-repo repo-name", Short: "Return info about a repo.", Long: "Return info about a repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } repoInfo, err := pfsutil.InspectRepo(apiClient, args[0]) if err != nil { return err } if repoInfo == nil { return fmt.Errorf("repo %s not found", args[0]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintRepoHeader(writer) pretty.PrintRepoInfo(writer, repoInfo) return writer.Flush() }), } listRepo := &cobra.Command{ Use: "list-repo", Short: "Return all repos.", Long: "Reutrn all repos.", Run: pkgcobra.RunFixedArgs(0, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } repoInfos, err := pfsutil.ListRepo(apiClient) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintRepoHeader(writer) for _, repoInfo := range repoInfos { pretty.PrintRepoInfo(writer, repoInfo) } return writer.Flush() }), } deleteRepo := &cobra.Command{ Use: "delete-repo repo-name", Short: "Delete a repo.", Long: "Delete a repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.DeleteRepo(apiClient, args[0]) }), } startCommit := &cobra.Command{ Use: "start-commit repo-name [parent-commit-id]", Short: "Start a new commit.", Long: "Start a new commit with parent-commit-id as the parent.", Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 1, Max: 2}, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } parentCommitID := "" if len(args) == 2 { parentCommitID = args[1] } commit, err := pfsutil.StartCommit(apiClient, args[0], parentCommitID) if err != nil { return err } fmt.Println(commit.Id) return nil }), } finishCommit := &cobra.Command{ Use: "finish-commit repo-name commit-id", Short: "Finish a started commit.", Long: "Finish a started commit. Commit-id must be a writeable commit.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.FinishCommit(apiClient, args[0], args[1]) }), } inspectCommit := &cobra.Command{ Use: "inspect-commit repo-name commit-id", Short: "Return info about a commit.", Long: "Return info about a commit.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } commitInfo, err := pfsutil.InspectCommit(apiClient, args[0], args[1]) if err != nil { return err } if commitInfo == nil { return fmt.Errorf("commit %s not found", args[1]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintCommitInfoHeader(writer) pretty.PrintCommitInfo(writer, commitInfo) return writer.Flush() }), } listCommit := &cobra.Command{ Use: "list-commit repo-name", Short: "Return all commits on a repo.", Long: "Return all commits on a repo.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } commitInfos, err := pfsutil.ListCommit(apiClient, args) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintCommitInfoHeader(writer) for _, commitInfo := range commitInfos { pretty.PrintCommitInfo(writer, commitInfo) } return writer.Flush() }), } deleteCommit := &cobra.Command{ Use: "delete-commit repo-name commit-id", Short: "Delete a commit.", Long: "Delete a commit.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.DeleteCommit(apiClient, args[0], args[1]) }), } mkdir := &cobra.Command{ Use: "mkdir repo-name commit-id path/to/dir", Short: "Make a directory.", Long: "Make a directory. Parent directories need not exist.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.MakeDirectory(apiClient, args[0], args[1], args[2]) }), } putFile := &cobra.Command{ Use: "put-file repo-name commit-id path/to/file", Short: "Put a file from stdin", Long: "Put a file from stdin. Directories must exist. commit-id must be a writeable commit.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } _, err = pfsutil.PutFile(apiClient, args[0], args[1], args[2], 0, os.Stdin) return err }), } getFile := &cobra.Command{ Use: "get-file repo-name commit-id path/to/file", Short: "Return the contents of a file.", Long: "Return the contents of a file.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.GetFile(apiClient, args[0], args[1], args[2], 0, math.MaxInt64, shard(), os.Stdout) }), } getFile.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from") getFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") inspectFile := &cobra.Command{ Use: "inspect-file repo-name commit-id path/to/file", Short: "Return info about a file.", Long: "Return info about a file.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2], shard()) if err != nil { return err } if fileInfo == nil { return fmt.Errorf("file %s not found", args[2]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintFileInfoHeader(writer) pretty.PrintFileInfo(writer, fileInfo) return writer.Flush() }), } inspectFile.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from") inspectFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") listFile := &cobra.Command{ Use: "list-file repo-name commit-id path/to/dir", Short: "Return the files in a directory.", Long: "Return the files in a directory.", Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 2, Max: 3}, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } var path string if len(args) == 3 { path = args[2] } fileInfos, err := pfsutil.ListFile(apiClient, args[0], args[1], path, shard()) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintFileInfoHeader(writer) for _, fileInfo := range fileInfos { pretty.PrintFileInfo(writer, fileInfo) } return writer.Flush() }), } listFile.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from") listFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") deleteFile := &cobra.Command{ Use: "delete-file repo-name commit-id path/to/file", Short: "Delete a file.", Long: "Delete a file.", Run: pkgcobra.RunFixedArgs(2, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } return pfsutil.DeleteFile(apiClient, args[0], args[1], args[2]) }), } listChange := &cobra.Command{ Use: "list-change repo-name commit-id path/to/dir", Short: "Return the changes in a directory.", Long: "Return the changes in a directory.", Run: pkgcobra.RunFixedArgs(3, func(args []string) error { apiClient, err := getAPIClient(address) if err != nil { return err } changeInfos, err := pfsutil.ListChange(apiClient, args[0], args[1], args[2], shard()) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintChangeHeader(writer) for _, changeInfo := range changeInfos { pretty.PrintChange(writer, changeInfo) } return writer.Flush() }), } listChange.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from") listChange.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") inspectServer := &cobra.Command{ Use: "inspect-server server-id", Short: "Inspect a server.", Long: "Inspect a server.", Run: pkgcobra.RunFixedArgs(1, func(args []string) error { clusterAPIClient, err := getClusterAPIClient(address) if err != nil { return err } serverInfo, err := pfsutil.InspectServer(clusterAPIClient, args[0]) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintServerInfoHeader(writer) pretty.PrintServerInfo(writer, serverInfo) return writer.Flush() }), } listServer := &cobra.Command{ Use: "list-server", Short: "Return all servers in the cluster.", Long: "Return all servers in the cluster.", Run: pkgcobra.RunFixedArgs(0, func(args []string) error { clusterAPIClient, err := getClusterAPIClient(address) if err != nil { return err } serverInfos, err := pfsutil.ListServer(clusterAPIClient) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintServerInfoHeader(writer) for _, serverInfo := range serverInfos { pretty.PrintServerInfo(writer, serverInfo) } return writer.Flush() }), } var mountPoint string mount := &cobra.Command{ Use: "mount [repo/commit:alias...]", Short: "Mount pfs locally.", Long: "Mount pfs locally.", Run: pkgcobra.Run(func(args []string) error { protolog.SetLevel(protolog.Level_LEVEL_DEBUG) apiClient, err := getAPIClient(address) if err != nil { return err } mounter := fuse.NewMounter(address, apiClient) return mounter.Mount(mountPoint, shard(), parseCommitMounts(args), nil) }), } mount.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from") mount.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") mount.Flags().StringVarP(&mountPoint, "mount-point", "p", "/pfs", "root of mounted filesystem") var result []*cobra.Command result = append(result, createRepo) result = append(result, inspectRepo) result = append(result, listRepo) result = append(result, deleteRepo) result = append(result, startCommit) result = append(result, finishCommit) result = append(result, inspectCommit) result = append(result, listCommit) result = append(result, deleteCommit) result = append(result, mkdir) result = append(result, putFile) result = append(result, getFile) result = append(result, inspectFile) result = append(result, listFile) result = append(result, deleteFile) result = append(result, listChange) result = append(result, inspectServer) result = append(result, listServer) result = append(result, mount) return result, nil }
func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) logrus.Register() address := appEnv.PachydermPfsd1Port if address == "" { address = appEnv.Address } else { address = strings.Replace(address, "tcp://", "", -1) } clientConn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { return err } apiClient := pfs.NewApiClient(clientConn) var shard int var modulus int createRepo := cobramainutil.Command{ Use: "create-repo repo-name", Short: "Create a new repo.", Long: "Create a new repo.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.CreateRepo(apiClient, args[0]) }, }.ToCobraCommand() inspectRepo := cobramainutil.Command{ Use: "inspect-repo repo-name", Short: "Return info about a repo.", Long: "Return info about a repo.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { repoInfo, err := pfsutil.InspectRepo(apiClient, args[0]) if err != nil { return err } if repoInfo == nil { return fmt.Errorf("repo %s not found", args[0]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintRepoHeader(writer) pretty.PrintRepoInfo(writer, repoInfo) return writer.Flush() }, }.ToCobraCommand() listRepo := cobramainutil.Command{ Use: "list-repo", Short: "Return all repos.", Long: "Reutrn all repos.", NumArgs: 0, Run: func(cmd *cobra.Command, args []string) error { repoInfos, err := pfsutil.ListRepo(apiClient) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintRepoHeader(writer) for _, repoInfo := range repoInfos { pretty.PrintRepoInfo(writer, repoInfo) } return writer.Flush() }, }.ToCobraCommand() deleteRepo := cobramainutil.Command{ Use: "delete-repo repo-name", Short: "Delete a repo.", Long: "Delete a repo.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.DeleteRepo(apiClient, args[0]) }, }.ToCobraCommand() startCommit := cobramainutil.Command{ Use: "start-commit repo-name parent-commit-id", Short: "Start a new commit.", Long: "Start a new commit with parent-commit-id as the parent.", NumArgs: 2, Run: func(cmd *cobra.Command, args []string) error { commit, err := pfsutil.StartCommit(apiClient, args[0], args[1]) if err != nil { return err } fmt.Println(commit.Id) return nil }, }.ToCobraCommand() finishCommit := cobramainutil.Command{ Use: "finish-commit repo-name commit-id", Short: "Finish a started commit.", Long: "Finish a started commit. Commit-id must be a writeable commit.", NumArgs: 2, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.FinishCommit(apiClient, args[0], args[1]) }, }.ToCobraCommand() inspectCommit := cobramainutil.Command{ Use: "inspect-commit repo-name commit-id", Short: "Return info about a commit.", Long: "Return info about a commit.", NumArgs: 2, Run: func(cmd *cobra.Command, args []string) error { commitInfo, err := pfsutil.InspectCommit(apiClient, args[0], args[1]) if err != nil { return err } if commitInfo == nil { return fmt.Errorf("commit %s not found", args[1]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintCommitInfoHeader(writer) pretty.PrintCommitInfo(writer, commitInfo) return writer.Flush() }, }.ToCobraCommand() listCommit := cobramainutil.Command{ Use: "list-commit repo-name", Short: "Return all commits on a repo.", Long: "Return all commits on a repo.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { commitInfos, err := pfsutil.ListCommit(apiClient, args[0]) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintCommitInfoHeader(writer) for _, commitInfo := range commitInfos { pretty.PrintCommitInfo(writer, commitInfo) } return writer.Flush() }, }.ToCobraCommand() deleteCommit := cobramainutil.Command{ Use: "delete-commit repo-name commit-id", Short: "Delete a commit.", Long: "Delete a commit.", NumArgs: 2, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.DeleteCommit(apiClient, args[0], args[1]) }, }.ToCobraCommand() putBlock := cobramainutil.Command{ Use: "put-block repo-name commit-id path/to/file", Short: "Put a block from stdin", Long: "Put a block from stdin. Directories must exist. commit-id must be a writeable commit.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { block, err := pfsutil.PutBlock(apiClient, args[0], args[1], args[2], os.Stdin) if err != nil { return err } fmt.Println(block.Hash) return nil }, }.ToCobraCommand() getBlock := cobramainutil.Command{ Use: "get-block hash", Short: "Return the contents of a block.", Long: "Return the contents of a block.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.GetBlock(apiClient, args[0], os.Stdout) }, }.ToCobraCommand() inspectBlock := cobramainutil.Command{ Use: "inspect-block hash", Short: "Return info about a block.", Long: "Return info about a block.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { blockInfo, err := pfsutil.InspectBlock(apiClient, args[0]) if err != nil { return err } if blockInfo == nil { return fmt.Errorf("block %s not found", args[2]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintBlockInfoHeader(writer) pretty.PrintBlockInfo(writer, blockInfo) return writer.Flush() }, }.ToCobraCommand() listBlock := cobramainutil.Command{ Use: "list-block", Short: "Return the blocks in a directory.", Long: "Return the blocks in a directory.", NumArgs: 0, Run: func(cmd *cobra.Command, args []string) error { blockInfos, err := pfsutil.ListBlock(apiClient, uint64(shard), uint64(modulus)) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintBlockInfoHeader(writer) for _, blockInfo := range blockInfos { pretty.PrintBlockInfo(writer, blockInfo) } return writer.Flush() }, }.ToCobraCommand() listBlock.Flags().IntVarP(&shard, "shard", "s", 0, "shard to read from") listBlock.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") mkdir := cobramainutil.Command{ Use: "mkdir repo-name commit-id path/to/dir", Short: "Make a directory.", Long: "Make a directory. Parent directories need not exist.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.MakeDirectory(apiClient, args[0], args[1], args[2]) }, }.ToCobraCommand() putFile := cobramainutil.Command{ Use: "put-file repo-name commit-id path/to/file", Short: "Put a file from stdin", Long: "Put a file from stdin. Directories must exist. commit-id must be a writeable commit.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { _, err := pfsutil.PutFile(apiClient, args[0], args[1], args[2], 0, os.Stdin) return err }, }.ToCobraCommand() getFile := cobramainutil.Command{ Use: "get-file repo-name commit-id path/to/file", Short: "Return the contents of a file.", Long: "Return the contents of a file.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.GetFile(apiClient, args[0], args[1], args[2], 0, math.MaxInt64, os.Stdout) }, }.ToCobraCommand() inspectFile := cobramainutil.Command{ Use: "inspect-file repo-name commit-id path/to/file", Short: "Return info about a file.", Long: "Return info about a file.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2]) if err != nil { return err } if fileInfo == nil { return fmt.Errorf("file %s not found", args[2]) } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintFileInfoHeader(writer) pretty.PrintFileInfo(writer, fileInfo) return writer.Flush() }, }.ToCobraCommand() listFile := cobramainutil.Command{ Use: "list-file repo-name commit-id path/to/dir", Short: "Return the files in a directory.", Long: "Return the files in a directory.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { fileInfos, err := pfsutil.ListFile(apiClient, args[0], args[1], args[2], uint64(shard), uint64(modulus)) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintFileInfoHeader(writer) for _, fileInfo := range fileInfos { pretty.PrintFileInfo(writer, fileInfo) } return writer.Flush() }, }.ToCobraCommand() listFile.Flags().IntVarP(&shard, "shard", "s", 0, "shard to read from") listFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") deleteFile := cobramainutil.Command{ Use: "delete-file repo-name commit-id path/to/file", Short: "Delete a file.", Long: "Delete a file.", NumArgs: 2, Run: func(cmd *cobra.Command, args []string) error { return pfsutil.DeleteFile(apiClient, args[0], args[1], args[2]) }, }.ToCobraCommand() listChange := cobramainutil.Command{ Use: "list-change repo-name commit-id path/to/dir", Short: "Return the changes in a directory.", Long: "Return the changes in a directory.", NumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { changeInfos, err := pfsutil.ListChange(apiClient, args[0], args[1], args[2], uint64(shard), uint64(modulus)) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintChangeHeader(writer) for _, changeInfo := range changeInfos { pretty.PrintChange(writer, changeInfo) } return writer.Flush() }, }.ToCobraCommand() listChange.Flags().IntVarP(&shard, "shard", "s", 0, "shard to read from") listChange.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") inspectServer := cobramainutil.Command{ Use: "inspect-server server-id", Short: "Inspect a server.", Long: "Inspect a server.", NumArgs: 1, Run: func(cmd *cobra.Command, args []string) error { serverInfo, err := pfsutil.InspectServer(apiClient, args[0]) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintServerInfoHeader(writer) pretty.PrintServerInfo(writer, serverInfo) return writer.Flush() }, }.ToCobraCommand() listServer := cobramainutil.Command{ Use: "list-server", Short: "Return all servers in the cluster.", Long: "Return all servers in the cluster.", NumArgs: 0, Run: func(cmd *cobra.Command, args []string) error { serverInfos, err := pfsutil.ListServer(apiClient) if err != nil { return err } writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) pretty.PrintServerInfoHeader(writer) for _, serverInfo := range serverInfos { pretty.PrintServerInfo(writer, serverInfo) } return writer.Flush() }, }.ToCobraCommand() mount := cobramainutil.Command{ Use: "mount mountpoint repo-name [commit-id]", Short: "Mount a repo as a local file system.", Long: "Mount a repo as a local file system.", MinNumArgs: 2, MaxNumArgs: 3, Run: func(cmd *cobra.Command, args []string) error { mountPoint := args[0] repo := args[1] commitID := "" if len(args) == 3 { commitID = args[2] } mounter := fuse.NewMounter(apiClient) if err := mounter.Mount(repo, commitID, mountPoint, uint64(shard), uint64(modulus)); err != nil { return err } return mounter.Wait(mountPoint) }, }.ToCobraCommand() mount.Flags().IntVarP(&shard, "shard", "s", 0, "shard to read from") mount.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards") rootCmd := &cobra.Command{ Use: "pfs", Long: `Access the PFS API. Note that this CLI is experimental and does not even check for common errors. The environment variable PFS_ADDRESS controls what server the CLI connects to, the default is 0.0.0.0:650.`, } rootCmd.AddCommand(protoclient.NewVersionCommand(clientConn, pachyderm.Version, nil)) rootCmd.AddCommand(createRepo) rootCmd.AddCommand(inspectRepo) rootCmd.AddCommand(listRepo) rootCmd.AddCommand(deleteRepo) rootCmd.AddCommand(startCommit) rootCmd.AddCommand(finishCommit) rootCmd.AddCommand(inspectCommit) rootCmd.AddCommand(listCommit) rootCmd.AddCommand(deleteCommit) rootCmd.AddCommand(mkdir) rootCmd.AddCommand(putBlock) rootCmd.AddCommand(getBlock) rootCmd.AddCommand(inspectBlock) rootCmd.AddCommand(listBlock) rootCmd.AddCommand(putFile) rootCmd.AddCommand(getFile) rootCmd.AddCommand(inspectFile) rootCmd.AddCommand(listFile) rootCmd.AddCommand(deleteFile) rootCmd.AddCommand(listChange) rootCmd.AddCommand(inspectServer) rootCmd.AddCommand(listServer) rootCmd.AddCommand(mount) return rootCmd.Execute() }
func (w *worker) work(pfsClient pfs.APIClient, ppsClient pps.APIClient) error { opt := w.rand.Float64() switch { case opt < repo: repoName := w.randString(10) if err := pfsutil.CreateRepo(pfsClient, repoName); err != nil { return err } w.repos = append(w.repos, &pfs.Repo{Name: repoName}) commit, err := pfsutil.StartCommit(pfsClient, repoName, "") if err != nil { return err } w.started = append(w.started, commit) case opt < commit: if len(w.started) >= maxStartedCommits || len(w.finished) == 0 { if len(w.started) == 0 { return nil } i := w.rand.Intn(len(w.started)) commit := w.started[i] if err := pfsutil.FinishCommit(pfsClient, commit.Repo.Name, commit.Id); err != nil { return err } w.started = append(w.started[:i], w.started[i+1:]...) w.finished = append(w.finished, commit) } else { if len(w.finished) == 0 { return nil } commit := w.finished[w.rand.Intn(len(w.finished))] commit, err := pfsutil.StartCommit(pfsClient, commit.Repo.Name, commit.Id) if err != nil { return err } w.started = append(w.started, commit) } case opt < file: if len(w.started) == 0 { return nil } commit := w.started[w.rand.Intn(len(w.started))] if _, err := pfsutil.PutFile(pfsClient, commit.Repo.Name, commit.Id, w.randString(10), 0, w.reader()); err != nil { return err } case opt < job: if len(w.startedJobs) >= maxStartedJobs { job := w.startedJobs[0] w.startedJobs = w.startedJobs[1:] jobInfo, err := ppsClient.InspectJob( context.Background(), &pps.InspectJobRequest{ Job: job, BlockState: true, }, ) if err != nil { return err } if jobInfo.State != pps.JobState_JOB_STATE_SUCCESS { return fmt.Errorf("job %s failed", job.Id) } w.jobs = append(w.jobs, job) } else { if len(w.finished) == 0 { return nil } inputs := [5]string{} var jobInputs []*pps.JobInput repoSet := make(map[string]bool) for i := range inputs { commit := w.finished[w.rand.Intn(len(w.finished))] if _, ok := repoSet[commit.Repo.Name]; ok { continue } repoSet[commit.Repo.Name] = true inputs[i] = commit.Repo.Name jobInputs = append(jobInputs, &pps.JobInput{Commit: commit}) } var parentJobID string if len(w.jobs) > 0 { parentJobID = w.jobs[w.rand.Intn(len(w.jobs))].Id } outFilename := w.randString(10) job, err := ppsutil.CreateJob( ppsClient, "", []string{"bash"}, w.grepCmd(inputs, outFilename), 1, jobInputs, parentJobID, ) if err != nil { return err } w.startedJobs = append(w.startedJobs, job) } case opt < pipeline: if len(w.repos) == 0 { return nil } inputs := [5]string{} var pipelineInputs []*pps.PipelineInput repoSet := make(map[string]bool) for i := range inputs { repo := w.repos[w.rand.Intn(len(w.repos))] if _, ok := repoSet[repo.Name]; ok { continue } repoSet[repo.Name] = true inputs[i] = repo.Name pipelineInputs = append(pipelineInputs, &pps.PipelineInput{Repo: repo}) } pipelineName := w.randString(10) outFilename := w.randString(10) if err := ppsutil.CreatePipeline( ppsClient, pipelineName, "", []string{"bash"}, w.grepCmd(inputs, outFilename), 1, pipelineInputs, ); err != nil { return err } w.pipelines = append(w.pipelines, ppsutil.NewPipeline(pipelineName)) } return nil }
func testMount(t *testing.T, apiClient pfs.APIClient, cluster Cluster) { repoName := "testMountRepo" err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) directory := "/compile/testMount" mounter := fuse.NewMounter("localhost", apiClient) ready := make(chan bool) go func() { err = mounter.Mount(directory, &pfs.Shard{Number: 0, Modulus: 1}, nil, ready) require.NoError(t, err) }() <-ready _, err = os.Stat(filepath.Join(directory, repoName)) require.NoError(t, err) commit, err := pfsutil.StartCommit(apiClient, repoName, "") require.NoError(t, err) require.NotNil(t, commit) newCommitID := commit.Id _, err = os.Stat(filepath.Join(directory, repoName, newCommitID)) require.NoError(t, err) err = ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, "foo"), []byte("foo"), 0666) require.NoError(t, err) _, err = pfsutil.PutFile(apiClient, repoName, newCommitID, "bar", 0, strings.NewReader("bar")) require.NoError(t, err) bigValue := make([]byte, 1024*1024) for i := 0; i < 1024*1024; i++ { bigValue[i] = 'a' } err = ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, "big1"), bigValue, 0666) require.NoError(t, err) _, err = pfsutil.PutFile(apiClient, repoName, newCommitID, "big2", 0, bytes.NewReader(bigValue)) require.NoError(t, err) err = pfsutil.FinishCommit(apiClient, repoName, newCommitID) require.NoError(t, err) fInfo, err := os.Stat(filepath.Join(directory, repoName, newCommitID, "foo")) require.NoError(t, err) require.Equal(t, int64(3), fInfo.Size()) data, err := ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "foo")) require.NoError(t, err) require.Equal(t, "foo", string(data)) data, err = ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "bar")) require.NoError(t, err) require.Equal(t, "bar", string(data)) data, err = ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "big1")) require.NoError(t, err) require.Equal(t, bigValue, data) data, err = ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "big2")) require.NoError(t, err) require.Equal(t, bigValue, data) err = mounter.Unmount(directory) require.NoError(t, err) }
func (w *worker) work(pfsClient pfs.APIClient, ppsClient pps.APIClient) error { opt := w.rand.Float64() switch { case opt < repo: repoName := w.name() if err := pfsutil.CreateRepo(pfsClient, repoName); err != nil { return err } w.repos = append(w.repos, &pfs.Repo{Name: repoName}) commit, err := pfsutil.StartCommit(pfsClient, repoName, "") if err != nil { return err } w.started = append(w.started, commit) case opt < commit: if len(w.started) >= maxStartedCommits { i := w.rand.Intn(len(w.started)) commit := w.started[i] if err := pfsutil.FinishCommit(pfsClient, commit.Repo.Name, commit.Id); err != nil { return err } w.started = append(w.started[:i], w.started[i+1:]...) w.finished = append(w.finished, commit) } else { commit := w.finished[w.rand.Intn(len(w.finished))] commit, err := pfsutil.StartCommit(pfsClient, commit.Repo.Name, commit.Id) if err != nil { return err } w.started = append(w.started, commit) } case opt < file: commit := w.started[w.rand.Intn(len(w.started))] if _, err := pfsutil.PutFile(pfsClient, commit.Repo.Name, commit.Id, w.name(), 0, w.reader()); err != nil { return err } case opt < job: inputs := [5]string{} var inputCommits []*pfs.Commit for i := range inputs { randI := w.rand.Intn(len(w.finished)) inputs[i] = w.finished[randI].Repo.Name inputCommits = append(inputCommits, w.finished[randI]) } var parentJobID string if len(w.jobs) > 0 { parentJobID = w.jobs[w.rand.Intn(len(w.jobs))].Id } outFilename := w.name() job, err := ppsutil.CreateJob( ppsClient, "", []string{"sh"}, w.grepCmd(inputs, outFilename), 1, inputCommits, parentJobID, ) if err != nil { return err } w.jobs = append(w.jobs, job) case opt < pipeline: inputs := [5]string{} var inputRepos []*pfs.Repo for i := range inputs { randI := w.rand.Intn(len(w.repos)) inputs[i] = w.repos[randI].Name inputRepos = append(inputRepos, w.repos[randI]) } pipelineName := w.name() outFilename := w.name() if err := ppsutil.CreatePipeline( ppsClient, pipelineName, "", []string{"sh"}, w.grepCmd(inputs, outFilename), 1, inputRepos, ); err != nil { return err } w.pipelines = append(w.pipelines, ppsutil.NewPipeline(pipelineName)) } return nil }
func testMount(t *testing.T, apiClient pfs.ApiClient, internalAPIClient pfs.InternalApiClient, cluster Cluster) { repositoryName := "testMountRepo" err := pfsutil.CreateRepo(apiClient, repositoryName) require.NoError(t, err) directory := "/compile/testMount" mounter := fuse.NewMounter(apiClient) err = mounter.Mount(repositoryName, directory, "", 0, 1) require.NoError(t, err) _, err = os.Stat(filepath.Join(directory, "scratch")) require.NoError(t, err) commit, err := pfsutil.StartCommit(apiClient, repositoryName, "scratch") require.NoError(t, err) require.NotNil(t, commit) newCommitID := commit.Id _, err = os.Stat(filepath.Join(directory, newCommitID)) require.NoError(t, err) err = ioutil.WriteFile(filepath.Join(directory, newCommitID, "foo"), []byte("foo"), 0666) require.NoError(t, err) _, err = pfsutil.PutFile(apiClient, repositoryName, newCommitID, "bar", 0, strings.NewReader("bar")) require.NoError(t, err) bigValue := make([]byte, 1024*1024) for i := 0; i < 1024*1024; i++ { bigValue[i] = 'a' } err = ioutil.WriteFile(filepath.Join(directory, newCommitID, "big1"), bigValue, 0666) require.NoError(t, err) _, err = pfsutil.PutFile(apiClient, repositoryName, newCommitID, "big2", 0, bytes.NewReader(bigValue)) require.NoError(t, err) err = pfsutil.FinishCommit(apiClient, repositoryName, newCommitID) require.NoError(t, err) fInfo, err := os.Stat(filepath.Join(directory, newCommitID, "foo")) require.NoError(t, err) require.Equal(t, int64(3), fInfo.Size()) data, err := ioutil.ReadFile(filepath.Join(directory, newCommitID, "foo")) require.NoError(t, err) require.Equal(t, "foo", string(data)) data, err = ioutil.ReadFile(filepath.Join(directory, newCommitID, "bar")) require.NoError(t, err) require.Equal(t, "bar", string(data)) data, err = ioutil.ReadFile(filepath.Join(directory, newCommitID, "big1")) require.NoError(t, err) require.Equal(t, bigValue, data) data, err = ioutil.ReadFile(filepath.Join(directory, newCommitID, "big2")) require.NoError(t, err) require.Equal(t, bigValue, data) err = mounter.Unmount(directory) require.NoError(t, err) err = mounter.Wait(directory) require.NoError(t, err) }
func testSimple(t *testing.T, apiClient pfs.APIClient, cluster Cluster) { repoName := "testSimpleRepo" err := pfsutil.CreateRepo(apiClient, repoName) require.NoError(t, err) commit, err := pfsutil.StartCommit(apiClient, repoName, "") require.NoError(t, err) require.NotNil(t, commit) newCommitID := commit.Id newCommitInfo, err := pfsutil.InspectCommit(apiClient, repoName, newCommitID) require.NoError(t, err) require.NotNil(t, newCommitInfo) require.Equal(t, newCommitID, newCommitInfo.Commit.Id) require.Equal(t, pfs.CommitType_COMMIT_TYPE_WRITE, newCommitInfo.CommitType) require.Nil(t, newCommitInfo.ParentCommit) commitInfos, err := pfsutil.ListCommit(apiClient, repoName) require.NoError(t, err) require.Equal(t, 1, len(commitInfos)) require.Equal(t, newCommitInfo.Commit, commitInfos[0].Commit) err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/b") require.NoError(t, err) err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/c") require.NoError(t, err) err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/d") require.NoError(t, err) doWrites(t, apiClient, repoName, newCommitID) doBlockWrites(t, apiClient, repoName, newCommitID) err = pfsutil.FinishCommit(apiClient, repoName, newCommitID) require.NoError(t, err) newCommitInfo, err = pfsutil.InspectCommit(apiClient, repoName, newCommitID) require.NoError(t, err) require.NotNil(t, newCommitInfo) require.Equal(t, newCommitID, newCommitInfo.Commit.Id) require.Equal(t, pfs.CommitType_COMMIT_TYPE_READ, newCommitInfo.CommitType) require.Nil(t, newCommitInfo.ParentCommit) checkWrites(t, apiClient, repoName, newCommitID) checkBlockWrites(t, apiClient, repoName, newCommitID) fileInfos, err := pfsutil.ListFile(apiClient, repoName, newCommitID, "a/b", &pfs.Shard{Number: 0, Modulus: 1}) require.NoError(t, err) require.Equal(t, testSize, len(fileInfos)) fileInfos, err = pfsutil.ListFile(apiClient, repoName, newCommitID, "a/c", &pfs.Shard{Number: 0, Modulus: 1}) require.NoError(t, err) require.Equal(t, testSize, len(fileInfos)) var fileInfos2 [7][]*pfs.FileInfo var wg sync.WaitGroup for i := 0; i < 7; i++ { i := i wg.Add(1) go func() { defer wg.Done() fileInfos3, iErr := pfsutil.ListFile(apiClient, repoName, newCommitID, "a/b", &pfs.Shard{Number: uint64(i), Modulus: 7}) require.NoError(t, iErr) fileInfos2[i] = fileInfos3 }() } wg.Wait() count := 0 for i := 0; i < 7; i++ { count += len(fileInfos2[i]) } require.Equal(t, testSize, count) }
func TestPipeline(t *testing.T) { t.Parallel() pachClient := getPachClient(t) // create repos dataRepo := uniqueString("TestPipeline.data") require.NoError(t, pfsutil.CreateRepo(pachClient, dataRepo)) // create pipeline pipelineName := uniqueString("pipeline") outRepo := pps.PipelineRepo(ppsutil.NewPipeline(pipelineName)) require.NoError(t, ppsutil.CreatePipeline( pachClient, pipelineName, "", []string{"cp", path.Join("/pfs", dataRepo, "file"), "/pfs/out/file"}, nil, 1, []*pps.PipelineInput{{Repo: &pfs.Repo{Name: dataRepo}}}, )) // Do first commit to repo commit1, err := pfsutil.StartCommit(pachClient, dataRepo, "") require.NoError(t, err) _, err = pfsutil.PutFile(pachClient, dataRepo, commit1.Id, "file", 0, strings.NewReader("foo\n")) require.NoError(t, err) require.NoError(t, pfsutil.FinishCommit(pachClient, dataRepo, commit1.Id)) listCommitRequest := &pfs.ListCommitRequest{ Repo: []*pfs.Repo{outRepo}, CommitType: pfs.CommitType_COMMIT_TYPE_READ, Block: true, } listCommitResponse, err := pachClient.ListCommit( context.Background(), listCommitRequest, ) require.NoError(t, err) outCommits := listCommitResponse.CommitInfo require.Equal(t, 1, len(outCommits)) var buffer bytes.Buffer require.NoError(t, pfsutil.GetFile(pachClient, outRepo.Name, outCommits[0].Commit.Id, "file", 0, 0, "", nil, &buffer)) require.Equal(t, "foo\n", buffer.String()) // Do second commit to repo commit2, err := pfsutil.StartCommit(pachClient, dataRepo, commit1.Id) require.NoError(t, err) _, err = pfsutil.PutFile(pachClient, dataRepo, commit2.Id, "file", 0, strings.NewReader("bar\n")) require.NoError(t, err) require.NoError(t, pfsutil.FinishCommit(pachClient, dataRepo, commit2.Id)) listCommitRequest = &pfs.ListCommitRequest{ Repo: []*pfs.Repo{outRepo}, FromCommit: []*pfs.Commit{outCommits[0].Commit}, CommitType: pfs.CommitType_COMMIT_TYPE_READ, Block: true, } listCommitResponse, err = pachClient.ListCommit( context.Background(), listCommitRequest, ) require.NoError(t, err) require.NotNil(t, listCommitResponse.CommitInfo[0].ParentCommit) require.Equal(t, outCommits[0].Commit.Id, listCommitResponse.CommitInfo[0].ParentCommit.Id) outCommits = listCommitResponse.CommitInfo require.Equal(t, 1, len(outCommits)) buffer = bytes.Buffer{} require.NoError(t, pfsutil.GetFile(pachClient, outRepo.Name, outCommits[0].Commit.Id, "file", 0, 0, "", nil, &buffer)) require.Equal(t, "foo\nbar\n", buffer.String()) }