github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/externalresource/broker/interfaces.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package broker 15 16 import ( 17 "context" 18 19 pb "github.com/pingcap/tiflow/engine/enginepb" 20 resModel "github.com/pingcap/tiflow/engine/pkg/externalresource/model" 21 "github.com/pingcap/tiflow/engine/pkg/tenant" 22 ) 23 24 // A Broker is created and maintained by the executor 25 // and provides file resources to the tasks. 26 type Broker interface { 27 pb.BrokerServiceServer 28 29 // OpenStorage creates a storage Handle for a worker. 30 OpenStorage( 31 ctx context.Context, 32 projectInfo tenant.ProjectInfo, 33 workerID resModel.WorkerID, 34 jobID resModel.JobID, 35 resourcePath resModel.ResourceID, 36 opts ...OpenStorageOption, 37 ) (Handle, error) 38 39 // OnWorkerClosed is called when a worker is closing. 40 // The implementation should do necessary garbage collection 41 // for the worker, especially local temporary files. 42 OnWorkerClosed( 43 ctx context.Context, 44 workerID resModel.WorkerID, 45 jobID resModel.JobID, 46 ) 47 48 GetEnabledBucketStorage() (bool, resModel.ResourceType) 49 50 Close() 51 } 52 53 type openStorageOptions struct { 54 cleanBeforeOpen bool 55 } 56 57 // OpenStorageOption is an option for OpenStorage. 58 type OpenStorageOption func(*openStorageOptions) 59 60 // WithCleanBeforeOpen indicates that the storage should be cleaned before open. 61 func WithCleanBeforeOpen() OpenStorageOption { 62 return func(opts *openStorageOptions) { 63 opts.cleanBeforeOpen = true 64 } 65 }