func (a *internalAPIServer) ListCommit(ctx context.Context, request *pfs.ListCommitRequest) (response *pfs.CommitInfos, retErr error) {
	defer func(start time.Time) { a.Log(request, response, retErr, time.Since(start)) }(time.Now())
	version, err := a.getVersion(ctx)
	if err != nil {
		return nil, err
	}
	shards, err := a.router.GetMasterShards(version)
	if err != nil {
		return nil, err
	}
	commitInfos, err := a.filteredListCommits(request.Repo, request.FromCommit, request.CommitType, shards)
	if err != nil {
		return nil, err
	}
	if len(commitInfos) == 0 && request.Block {
		commitChan := make(chan *pfs.CommitInfo)
		if err := a.registerCommitWaiter(request, shards, commitChan); err != nil {
			return nil, err
		}
		for commitInfo := range commitChan {
			commitInfos = append(commitInfos, commitInfo)
		}
	}
	return &pfs.CommitInfos{
		CommitInfo: pfs.Reduce(commitInfos),
	}, nil
}
Beispiel #2
0
func (a *apiServer) ListCommit(ctx context.Context, request *pfs.ListCommitRequest) (response *pfs.CommitInfos, retErr error) {
	defer func(start time.Time) { a.Log(request, response, retErr, time.Since(start)) }(time.Now())
	a.versionLock.RLock()
	defer a.versionLock.RUnlock()
	ctx = versionToContext(a.version, ctx)
	clientConns, err := a.router.GetAllClientConns(a.version)
	if err != nil {
		return nil, err
	}
	var wg sync.WaitGroup
	var lock sync.Mutex
	var commitInfos []*pfs.CommitInfo
	var loopErr error
	for _, clientConn := range clientConns {
		wg.Add(1)
		go func(clientConn *grpc.ClientConn) {
			defer wg.Done()
			subCommitInfos, err := pfs.NewInternalAPIClient(clientConn).ListCommit(ctx, request)
			if err != nil {
				if loopErr == nil {
					loopErr = err
				}
				return
			}
			lock.Lock()
			defer lock.Unlock()
			commitInfos = append(commitInfos, subCommitInfos.CommitInfo...)
		}(clientConn)
	}
	wg.Wait()
	if loopErr != nil {
		return nil, loopErr
	}
	return &pfs.CommitInfos{CommitInfo: pfs.Reduce(commitInfos)}, nil
}
Beispiel #3
0
func (d *driver) inspectCommit(commit *pfs.Commit, shards map[uint64]bool) (*pfs.CommitInfo, error) {
	var commitInfos []*pfs.CommitInfo
	for shard := range shards {
		if diffInfo, ok := d.finished.get(&drive.Diff{
			Commit: commit,
			Shard:  shard,
		}); ok {
			commitInfos = append(commitInfos,
				&pfs.CommitInfo{
					Commit:       commit,
					CommitType:   pfs.CommitType_COMMIT_TYPE_READ,
					ParentCommit: diffInfo.ParentCommit,
					Started:      diffInfo.Started,
					Finished:     diffInfo.Finished,
					SizeBytes:    diffInfo.SizeBytes,
				})
		}
		if diffInfo, ok := d.started.get(&drive.Diff{
			Commit: commit,
			Shard:  shard,
		}); ok {
			commitInfos = append(commitInfos,
				&pfs.CommitInfo{
					Commit:       commit,
					CommitType:   pfs.CommitType_COMMIT_TYPE_WRITE,
					ParentCommit: diffInfo.ParentCommit,
				})
		}
	}
	commitInfo := pfs.Reduce(commitInfos)
	if len(commitInfo) < 1 {
		return nil, fmt.Errorf("commit %s/%s not found", commit.Repo.Name, commit.Id)
	}
	if len(commitInfo) > 1 {
		return nil, fmt.Errorf("multiple commitInfos, (this is likely a bug)")
	}
	return commitInfo[0], nil
}