github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/storage/gc/worker.go (about) 1 // Copyright 2022 zGraph Authors. All rights reserved. 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gc 16 17 import ( 18 "context" 19 "sync/atomic" 20 21 "github.com/cockroachdb/pebble" 22 "github.com/vescale/zgraph/storage/resolver" 23 ) 24 25 // worker represents a GC worker which is used to clean staled versions. 26 type worker struct { 27 db *pebble.DB 28 resolver *resolver.Scheduler 29 closed atomic.Bool 30 } 31 32 func newWorker(db *pebble.DB, resolver *resolver.Scheduler) *worker { 33 return &worker{ 34 db: db, 35 resolver: resolver, 36 } 37 } 38 39 func (w *worker) run(ctx context.Context, queue <-chan Task) { 40 for { 41 select { 42 case task, ok := <-queue: 43 if !ok { 44 return 45 } 46 w.execute(task) 47 48 case <-ctx.Done(): 49 return 50 } 51 } 52 } 53 54 func (w *worker) execute(task Task) { 55 56 }