kbobyrev updated this revision to Diff 310381.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.

Resolve the comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92198/new/

https://reviews.llvm.org/D92198

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp

Index: clang-tools-extra/clangd/index/remote/Client.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <grpc++/grpc++.h>
-
 #include "Client.h"
 #include "Service.grpc.pb.h"
+#include "grpc/impl/codegen/connectivity_state.h"
+#include "grpcpp/channel.h"
 #include "index/Index.h"
 #include "marshalling/Marshalling.h"
 #include "support/Logger.h"
@@ -17,14 +17,33 @@
 #include "clang/Basic/Version.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include <grpc++/grpc++.h>
 
 #include <chrono>
+#include <memory>
+#include <thread>
 
 namespace clang {
 namespace clangd {
 namespace remote {
 namespace {
 
+llvm::StringRef toString(const grpc_connectivity_state &State) {
+  switch (State) {
+  case GRPC_CHANNEL_IDLE:
+    return "idle";
+  case GRPC_CHANNEL_CONNECTING:
+    return "connecting";
+  case GRPC_CHANNEL_READY:
+    return "ready";
+  case GRPC_CHANNEL_TRANSIENT_FAILURE:
+    return "transient failure";
+  case GRPC_CHANNEL_SHUTDOWN:
+    return "shutdown";
+  }
+  llvm_unreachable("Not a valid grpc_connectivity_state.");
+}
+
 class IndexClient : public clangd::SymbolIndex {
   template <typename RequestT, typename ReplyT>
   using StreamingCall = std::unique_ptr<grpc::ClientReader<ReplyT>> (
@@ -36,6 +55,7 @@
   bool streamRPC(ClangdRequestT Request,
                  StreamingCall<RequestT, ReplyT> RPCCall,
                  CallbackT Callback) const {
+    auto OldStatus = Channel->GetState(/*try_to_connect=*/false);
     bool FinalResult = false;
     trace::Span Tracer(RequestT::descriptor()->name());
     const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request);
@@ -68,14 +88,18 @@
     SPAN_ATTACH(Tracer, "Status", Reader->Finish().ok());
     SPAN_ATTACH(Tracer, "Successful", Successful);
     SPAN_ATTACH(Tracer, "Failed to parse", FailedToParse);
+    vlog("Remote index ({0}): {1} -> {2}", ServerAddress, toString(OldStatus),
+         toString(Channel->GetState(/*try_to_connect=*/false)));
     return FinalResult;
   }
 
 public:
   IndexClient(
-      std::shared_ptr<grpc::Channel> Channel, llvm::StringRef ProjectRoot,
+      std::shared_ptr<grpc::Channel> Channel, llvm::StringRef Address,
+      llvm::StringRef ProjectRoot,
       std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000))
-      : Stub(remote::v1::SymbolIndex::NewStub(Channel)),
+      : Stub(remote::v1::SymbolIndex::NewStub(Channel)), Channel(Channel),
+        ServerAddress(Address),
         ProtobufMarshaller(new Marshaller(/*RemoteIndexRoot=*/"",
                                           /*LocalIndexRoot=*/ProjectRoot)),
         DeadlineWaitingTime(DeadlineTime) {
@@ -118,6 +142,8 @@
 
 private:
   std::unique_ptr<remote::v1::SymbolIndex::Stub> Stub;
+  std::shared_ptr<grpc::Channel> Channel;
+  llvm::SmallString<256> ServerAddress;
   std::unique_ptr<Marshaller> ProtobufMarshaller;
   // Each request will be terminated if it takes too long.
   std::chrono::milliseconds DeadlineWaitingTime;
@@ -129,9 +155,9 @@
                                                llvm::StringRef ProjectRoot) {
   const auto Channel =
       grpc::CreateChannel(Address.str(), grpc::InsecureChannelCredentials());
-  Channel->GetState(true);
+  Channel->GetState(/*try_to_connect=*/true);
   return std::unique_ptr<clangd::SymbolIndex>(
-      new IndexClient(Channel, ProjectRoot));
+      new IndexClient(Channel, Address, ProjectRoot));
 }
 
 } // namespace remote
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to