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

Configure Feed

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

indexserver: use temp directory on same mount as indexes

Indexing with zoekt-git-index uses tmp to clone. This is the first use
of tmp, so we introduce the tmpfriend helper to clean up defunct
tempdirs. We use tmpfriend across the Sourcegraph services.

Change-Id: Ia7bfbb35c5f174266fe120dbba06b412804cc3c2

+22
+19
cmd/zoekt-sourcegraph-indexserver/main.go
··· 28 28 29 29 "github.com/google/zoekt/build" 30 30 retryablehttp "github.com/hashicorp/go-retryablehttp" 31 + "github.com/keegancsmith/tmpfriend" 31 32 "github.com/prometheus/client_golang/prometheus" 32 33 "github.com/prometheus/client_golang/prometheus/promauto" 33 34 "github.com/prometheus/client_golang/prometheus/promhttp" ··· 463 464 return hostname 464 465 } 465 466 467 + // setupTmpDir sets up a temporary directory on the same volume as the 468 + // indexes. 469 + func setupTmpDir(index string) error { 470 + tmpRoot := filepath.Join(index, ".indexserver.tmp") 471 + if err := os.MkdirAll(tmpRoot, 0755); err != nil { 472 + return err 473 + } 474 + if !tmpfriend.IsTmpFriendDir(tmpRoot) { 475 + _, err := tmpfriend.RootTempDir(tmpRoot) 476 + return err 477 + } 478 + return nil 479 + } 480 + 466 481 func main() { 467 482 defaultIndexDir := os.Getenv("DATA_DIR") 468 483 if defaultIndexDir == "" { ··· 512 527 if err := os.MkdirAll(*index, 0755); err != nil { 513 528 log.Fatalf("MkdirAll %s: %v", *index, err) 514 529 } 530 + } 531 + 532 + if err := setupTmpDir(*index); err != nil { 533 + log.Fatalf("failed to setup TMPDIR under %s: %v", *index, err) 515 534 } 516 535 517 536 if *dbg || *debugList || *debugIndex != "" {
+1
go.mod
··· 12 12 github.com/hashicorp/go-hclog v0.12.1 // indirect 13 13 github.com/hashicorp/go-retryablehttp v0.6.4 14 14 github.com/keegancsmith/rpc v1.1.0 15 + github.com/keegancsmith/tmpfriend v0.0.0-20180423180255-86e88902a513 15 16 github.com/kylelemons/godebug v1.1.0 16 17 github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f 17 18 github.com/prometheus/client_golang v1.5.1
+2
go.sum
··· 172 172 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 173 173 github.com/keegancsmith/rpc v1.1.0 h1:bXVRk3EzbtrEegTGKxNTc+St1lR7t/Z1PAO8misBnCc= 174 174 github.com/keegancsmith/rpc v1.1.0/go.mod h1:Xow74TKX34OPPiPCdz6x1o9c0SCxRqGxDuKGk7ZOo8s= 175 + github.com/keegancsmith/tmpfriend v0.0.0-20180423180255-86e88902a513 h1:xa9SZfAid/jlS3kjwAvVDQFpe6t8SiS0Vl/H51BZYww= 176 + github.com/keegancsmith/tmpfriend v0.0.0-20180423180255-86e88902a513/go.mod h1:MhGoae1pr+JFXxDAYx3b0fMn1xtr1ly9dHa0+KHHon4= 175 177 github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= 176 178 github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= 177 179 github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=