MCPcopy Create free account
hub / github.com/apache/brpc / dump_to_db

Method dump_to_db

src/brpc/span.cpp:851–893  ·  view source on GitHub ↗

Write span into leveldb.

Source from the content-addressed store, hash-verified

849
850// Write span into leveldb.
851void Span::dump_to_db() {
852 StartIndexingIfNeeded();
853
854 std::string value_buf;
855
856 butil::intrusive_ptr<SpanDB> db;
857 if (GetSpanDB(&db) != 0) {
858 if (g_span_ending) {
859 return;
860 }
861 SpanDB* db2 = SpanDB::Open();
862 if (db2 == NULL) {
863 LOG(WARNING) << "Fail to open SpanDB";
864 return;
865 }
866 ResetSpanDB(db2);
867 db.reset(db2);
868 }
869
870 leveldb::Status st = db->Index(shared_from_this(), &value_buf);
871 if (!st.ok()) {
872 LOG(WARNING) << st.ToString();
873 if (st.IsNotFound() || st.IsIOError() || st.IsCorruption()) {
874 ResetSpanDB(NULL);
875 return;
876 }
877 }
878
879 // Remove old spans
880 const int64_t now = butil::gettimeofday_us();
881 if (now > g_last_delete_tm + SPAN_DELETE_INTERVAL_US) {
882 g_last_delete_tm = now;
883 leveldb::Status st = db->RemoveSpansBefore(
884 now - FLAGS_rpcz_keep_span_seconds * 1000000L);
885 if (!st.ok()) {
886 LOG(ERROR) << st.ToString();
887 if (st.IsNotFound() || st.IsIOError() || st.IsCorruption()) {
888 ResetSpanDB(NULL);
889 return;
890 }
891 }
892 }
893}
894
895// ========== SpanContainer ============
896

Callers 1

dump_and_destroyMethod · 0.80

Calls 9

StartIndexingIfNeededFunction · 0.85
GetSpanDBFunction · 0.85
ResetSpanDBFunction · 0.85
IndexMethod · 0.80
okMethod · 0.80
RemoveSpansBeforeMethod · 0.80
gettimeofday_usFunction · 0.50
resetMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected