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

Method RemoveSpansBefore

src/brpc/span.cpp:808–848  ·  view source on GitHub ↗

NOTE: may take more than 100ms

Source from the content-addressed store, hash-verified

806
807// NOTE: may take more than 100ms
808leveldb::Status SpanDB::RemoveSpansBefore(int64_t tm) {
809 if (id_db == NULL || time_db == NULL) {
810 return leveldb::Status::InvalidArgument(leveldb::Slice("NULL param"));
811 }
812 leveldb::Status rc;
813 leveldb::WriteOptions options;
814 options.sync = false;
815 leveldb::Iterator* it = time_db->NewIterator(leveldb::ReadOptions());
816 for (it->SeekToFirst(); it->Valid(); it->Next()) {
817 if (it->key().size() != 8) {
818 LOG(ERROR) << "Invalid key size: " << it->key().size();
819 continue;
820 }
821 const int64_t realtime =
822 ToLittleEndian((const uint32_t*)it->key().data());
823 if (realtime >= tm) { // removal is done.
824 break;
825 }
826 BriefSpan brief;
827 if (brief.ParseFromArray(it->value().data(), it->value().size())) {
828 uint32_t key_data[4];
829 ToBigEndian(brief.trace_id(), key_data);
830 ToBigEndian(brief.span_id(), key_data + 2);
831 leveldb::Slice key((char*)key_data, sizeof(key_data));
832 rc = id_db->Delete(options, key);
833 if (!rc.ok()) {
834 LOG(ERROR) << "Fail to delete from id_db";
835 break;
836 }
837 } else {
838 LOG(ERROR) << "Fail to parse value";
839 }
840 rc = time_db->Delete(options, it->key());
841 if (!rc.ok()) {
842 LOG(ERROR) << "Fail to delete from time_db";
843 break;
844 }
845 }
846 delete it;
847 return rc;
848}
849
850// Write span into leveldb.
851void Span::dump_to_db() {

Callers 1

dump_to_dbMethod · 0.80

Calls 13

ToLittleEndianFunction · 0.85
ToBigEndianFunction · 0.85
ValidMethod · 0.80
ParseFromArrayMethod · 0.80
okMethod · 0.80
NextMethod · 0.45
sizeMethod · 0.45
keyMethod · 0.45
dataMethod · 0.45
valueMethod · 0.45
trace_idMethod · 0.45
span_idMethod · 0.45

Tested by

no test coverage detected