Skip to content

Commit

Permalink
Make dcs-package-importer send the ReplaceIndex RPC.
Browse files Browse the repository at this point in the history
I forgot this when converting to gRPC.
  • Loading branch information
stapelberg committed Mar 31, 2016
1 parent 7a88186 commit a7cca88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
27 changes: 18 additions & 9 deletions cmd/dcs-package-importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import (
"unicode/utf8"

"github.com/Debian/dcs/goroutinez"
"github.com/Debian/dcs/grpcutil"
"github.com/Debian/dcs/index"
"github.com/Debian/dcs/proto"
_ "github.com/Debian/dcs/varz"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/net/context"
_ "golang.org/x/net/trace"
)

var (
Expand Down Expand Up @@ -90,6 +94,11 @@ var (
Name: "index_files",
Help: "Number of files in the index.",
})

tlsCertPath = flag.String("tls_cert_path", "", "Path to a .pem file containing the TLS certificate.")
tlsKeyPath = flag.String("tls_key_path", "", "Path to a .pem file containing the TLS private key.")

indexBackend proto.IndexBackendClient
)

func init() {
Expand Down Expand Up @@ -310,15 +319,8 @@ func mergeToShard() {
successfulMerges.Inc()

// Replace the current index with the newly created index.
resp, err := http.Get(fmt.Sprintf("http://localhost:28081/replace?shard=%s", filepath.Base(tmpIndexPath.Name())))
if err != nil {
log.Fatal(err)
}

defer resp.Body.Close()
if resp.StatusCode != 200 {
body, _ := ioutil.ReadAll(resp.Body)
log.Fatalf("dcs-index-backend /replace response: %+v (body: %s)\n", resp, body)
if _, err := indexBackend.ReplaceIndex(context.Background(), &proto.ReplaceIndexRequest{ReplacementPath: filepath.Base(tmpIndexPath.Name())}); err != nil {
log.Fatalf("dcs-index-backend ReplaceIndex failed: %v", err)
}
}

Expand Down Expand Up @@ -467,6 +469,13 @@ func main() {
}
}()

conn, err := grpcutil.DialTLS("localhost:28081", *tlsCertPath, *tlsKeyPath)
if err != nil {
log.Fatalf("could not connect to %q: %v", "localhost:28081", err)
}
defer conn.Close()
indexBackend = proto.NewIndexBackendClient(conn)

http.HandleFunc("/import/", importPackage)
http.HandleFunc("/merge", mergeOrError)
http.HandleFunc("/listpkgs", listPackages)
Expand Down
4 changes: 3 additions & 1 deletion dcs-package-importer.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Description=Debian Code Search: package importer
# Increase the maximum number of file descriptors since we need to open a
# couple thousand index files when merging them together into a big shard.
LimitNOFILE=8192
ExecStart=/usr/bin/dcs-package-importer
ExecStart=/usr/bin/dcs-package-importer \
-tls_cert_path=/usr/share/dcs/prod-cert.pem \
-tls_key_path=/usr/share/dcs/prod-key.pem

[Install]
WantedBy=multi-user.target

0 comments on commit a7cca88

Please sign in to comment.