fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

indexserver: delete tmp dir on startup (#646)

This probably caused our tmp-dirs to run full. In production we saw data
from years ago taking up disk space.

Co-authored-by: Petri-Johan Last <petri.last@sourcegraph.com>
Co-authored-by: Keegan Carruthers-Smith <keegan.csmith@gmail.com>

+20 -16
+20 -16
cmd/zoekt-sourcegraph-indexserver/main.go
··· 33 33 34 34 grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2" 35 35 "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry" 36 - "github.com/keegancsmith/tmpfriend" 37 36 "github.com/peterbourgon/ff/v3/ffcli" 38 37 "github.com/prometheus/client_golang/prometheus" 39 38 "github.com/prometheus/client_golang/prometheus/promauto" 40 39 sglog "github.com/sourcegraph/log" 41 - proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1" 42 - "github.com/sourcegraph/zoekt/grpc/internalerrs" 43 - "github.com/sourcegraph/zoekt/grpc/messagesize" 40 + "github.com/sourcegraph/mountinfo" 44 41 "go.uber.org/automaxprocs/maxprocs" 45 42 "golang.org/x/net/trace" 46 43 "golang.org/x/sys/unix" ··· 49 46 "google.golang.org/grpc/credentials/insecure" 50 47 "google.golang.org/grpc/metadata" 51 48 52 - "github.com/sourcegraph/mountinfo" 53 - 54 49 "github.com/sourcegraph/zoekt" 55 50 "github.com/sourcegraph/zoekt/build" 51 + proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1" 56 52 "github.com/sourcegraph/zoekt/debugserver" 53 + "github.com/sourcegraph/zoekt/grpc/internalerrs" 54 + "github.com/sourcegraph/zoekt/grpc/messagesize" 57 55 "github.com/sourcegraph/zoekt/internal/profiler" 58 56 ) 59 57 ··· 983 981 // 984 982 // If main is true we will delete older temp directories left around. main is 985 983 // false when this is a debug command. 986 - func setupTmpDir(main bool, index string) error { 987 - // change the target tmp directory depending on if its our main daemon or a 984 + func setupTmpDir(logger sglog.Logger, main bool, index string) error { 985 + // change the target tmp directory depending on if it's our main daemon or a 988 986 // debug sub command. 989 987 dir := ".indexserver.debug.tmp" 990 988 if main { ··· 992 990 } 993 991 994 992 tmpRoot := filepath.Join(index, dir) 995 - if err := os.MkdirAll(tmpRoot, 0755); err != nil { 996 - return err 993 + 994 + if main { 995 + logger.Info("removing tmp dir", sglog.String("tmpRoot", tmpRoot)) 996 + err := os.RemoveAll(tmpRoot) 997 + if err != nil { 998 + logger.Error("failed to remove tmp dir", sglog.String("tmpRoot", tmpRoot), sglog.Error(err)) 999 + } 997 1000 } 998 - if !tmpfriend.IsTmpFriendDir(tmpRoot) { 999 - _, err := tmpfriend.RootTempDir(tmpRoot) 1001 + 1002 + if err := os.MkdirAll(tmpRoot, 0755); err != nil { 1000 1003 return err 1001 1004 } 1002 - return nil 1005 + 1006 + return os.Setenv("TMPDIR", tmpRoot) 1003 1007 } 1004 1008 1005 1009 func printMetaData(fn string) error { ··· 1298 1302 } 1299 1303 1300 1304 func newServer(conf rootConfig) (*Server, error) { 1305 + logger := sglog.Scoped("server", "periodically reindexes enabled repositories on sourcegraph") 1306 + 1301 1307 if conf.cpuFraction <= 0.0 || conf.cpuFraction > 1.0 { 1302 1308 return nil, fmt.Errorf("cpu_fraction must be between 0.0 and 1.0") 1303 1309 } ··· 1333 1339 } 1334 1340 } 1335 1341 1336 - if err := setupTmpDir(conf.Main, conf.index); err != nil { 1342 + if err := setupTmpDir(logger, conf.Main, conf.index); err != nil { 1337 1343 return nil, fmt.Errorf("failed to setup TMPDIR under %s: %v", conf.index, err) 1338 1344 } 1339 1345 ··· 1402 1408 if cpuCount < 1 { 1403 1409 cpuCount = 1 1404 1410 } 1405 - 1406 - logger := sglog.Scoped("server", "periodically reindexes enabled repositories on sourcegraph") 1407 1411 1408 1412 q := NewQueue(conf.backoffDuration, conf.maxBackoffDuration, logger) 1409 1413