func (a *internalAPIServer) ListFile(ctx context.Context, request *pfs.ListFileRequest) (*pfs.FileInfos, error) { version, err := a.getVersion(ctx) if err != nil { return nil, err } shards, err := a.router.GetMasterShards(version) if err != nil { return nil, err } if request.Shard == nil { request.Shard = &pfs.Shard{Number: 0, Modulo: 1} } sharder := route.NewSharder(request.Shard.Modulo, 0) var wg sync.WaitGroup var lock sync.Mutex var fileInfos []*pfs.FileInfo seenDirectories := make(map[string]bool) var loopErr error for shard := range shards { wg.Add(1) go func(shard uint64) { defer wg.Done() subFileInfos, err := a.driver.ListFile(request.File, shard) lock.Lock() defer lock.Unlock() if err != nil { if loopErr == nil { loopErr = err } return } for _, fileInfo := range subFileInfos { if fileInfo.FileType == pfs.FileType_FILE_TYPE_DIR { if seenDirectories[fileInfo.File.Path] { continue } seenDirectories[fileInfo.File.Path] = true } if sharder.GetShard(fileInfo.File) == request.Shard.Number { fileInfos = append(fileInfos, fileInfo) } } }(shard) } wg.Wait() if loopErr != nil { return nil, loopErr } return &pfs.FileInfos{ FileInfo: fileInfos, }, nil }
func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) logrus.Register() discoveryClient, err := getEtcdClient() if err != nil { return err } sharder := route.NewSharder(appEnv.NumShards, appEnv.NumReplicas) addresser := route.NewDiscoveryAddresser( discoveryClient, sharder, "namespace", ) return addresser.AssignRoles(nil) }
func (a *internalAPIServer) ListChange(ctx context.Context, request *pfs.ListChangeRequest) (*pfs.Changes, error) { version, err := a.getVersion(ctx) if err != nil { return nil, err } shards, err := a.router.GetMasterShards(version) if err != nil { return nil, err } if request.Shard == nil { request.Shard = &pfs.Shard{Number: 0, Modulo: 1} } sharder := route.NewSharder(request.Shard.Modulo, 0) var wg sync.WaitGroup var lock sync.Mutex var changes []*pfs.Change var loopErr error for shard := range shards { wg.Add(1) go func(shard uint64) { defer wg.Done() subChanges, err := a.driver.ListChange(request.File, request.From, shard) lock.Lock() defer lock.Unlock() if err != nil { if loopErr == nil { loopErr = err } return } for _, change := range subChanges { if sharder.GetShard(change.File) == request.Shard.Number { changes = append(changes, change) } } }(shard) } wg.Wait() if loopErr != nil { return nil, loopErr } return &pfs.Changes{ Change: changes, }, nil }
func (a *internalAPIServer) ListBlock(ctx context.Context, request *pfs.ListBlockRequest) (*pfs.BlockInfos, error) { version, err := a.getVersion(ctx) if err != nil { return nil, err } shards, err := a.router.GetMasterShards(version) if err != nil { return nil, err } if request.Shard == nil { request.Shard = &pfs.Shard{Number: 0, Modulo: 1} } sharder := route.NewSharder(request.Shard.Modulo, 0) var wg sync.WaitGroup var lock sync.Mutex var blockInfos []*pfs.BlockInfo var loopErr error for shard := range shards { wg.Add(1) go func(shard uint64) { defer wg.Done() subBlockInfos, err := a.driver.ListBlock(shard) lock.Lock() defer lock.Unlock() if err != nil { if loopErr == nil { loopErr = err } return } for _, blockInfo := range subBlockInfos { if request.Shard == nil || sharder.GetBlockShard(blockInfo.Block) == request.Shard.Number { blockInfos = append(blockInfos, blockInfo) } } }(shard) } wg.Wait() if loopErr != nil { return nil, loopErr } return &pfs.BlockInfos{ BlockInfo: blockInfos, }, nil }
func checkBlockWrites(tb testing.TB, apiClient pfs.ApiClient, repositoryName string, commitID string) { var wg sync.WaitGroup defer wg.Wait() for i := 0; i < testSize; i++ { i := i wg.Add(1) go func() { defer wg.Done() buffer := bytes.NewBuffer(nil) sharder := route.NewSharder(testShardsPerServer*testNumServers, testNumReplicas) block := sharder.GetBlock([]byte(fmt.Sprintf("hello%d", i))) iErr := pfsutil.GetBlock(apiClient, block.Hash, buffer) require.NoError(tb, iErr) // buffer = bytes.NewBuffer(nil) // require.Equal(tb, fmt.Sprintf("hello%d", i), buffer.String()) // iErr = pfsutil.GetFile(apiClient, repositoryName, commitID, // fmt.Sprintf("a/d/file%d", i), 0, math.MaxInt64, buffer) // require.NoError(tb, iErr) // require.Equal(tb, fmt.Sprintf("hello%d", i), buffer.String()) }() } }
func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) logrus.Register() discoveryClient, err := getEtcdClient() if err != nil { return err } address := appEnv.Address if address == "" { address, err = netutil.ExternalIP() if err != nil { return err } } sharder := route.NewSharder(appEnv.NumShards, appEnv.NumReplicas) address = fmt.Sprintf("%s:%d", address, appEnv.Port) addresser := route.NewDiscoveryAddresser( discoveryClient, sharder, "namespace", ) var driver drive.Driver switch appEnv.DriverType { case "btrfs": driver, err = btrfs.NewDriver(appEnv.DriverRoot, "") if err != nil { return err } default: return fmt.Errorf("unknown value for PFS_DRIVER_TYPE: %s", appEnv.DriverType) } apiServer := server.NewAPIServer( route.NewSharder( appEnv.NumShards, 0, ), route.NewRouter( addresser, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), ) internalAPIServer := server.NewInternalAPIServer( route.NewSharder( appEnv.NumShards, 0, ), route.NewRouter( addresser, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), driver, ) go func() { if err := addresser.Register(nil, "id", address, internalAPIServer); err != nil { log.Print(err) } }() // TODO(pedge): no! trace.AuthRequest = func(_ *http.Request) (bool, bool) { return true, true } return protoserver.Serve( uint16(appEnv.Port), func(s *grpc.Server) { pfs.RegisterApiServer(s, apiServer) pfs.RegisterInternalApiServer(s, internalAPIServer) }, protoserver.ServeOptions{ HTTPPort: uint16(appEnv.HTTPPort), DebugPort: uint16(appEnv.DebugPort), Version: pachyderm.Version, HTTPRegisterFunc: func(ctx context.Context, mux *runtime.ServeMux, clientConn *grpc.ClientConn) error { return pfs.RegisterApiHandler(ctx, mux, clientConn) }, }, ) }