MCPcopy Create free account
hub / github.com/ElementsProject/elements / ReadWhileWriting

Method ReadWhileWriting

src/leveldb/benchmarks/db_bench.cc:853–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

851 void DeleteRandom(ThreadState* thread) { DoDelete(thread, false); }
852
853 void ReadWhileWriting(ThreadState* thread) {
854 if (thread->tid > 0) {
855 ReadRandom(thread);
856 } else {
857 // Special thread that keeps writing until other threads are done.
858 RandomGenerator gen;
859 while (true) {
860 {
861 MutexLock l(&thread->shared->mu);
862 if (thread->shared->num_done + 1 >= thread->shared->num_initialized) {
863 // Other threads have finished
864 break;
865 }
866 }
867
868 const int k = thread->rand.Next() % FLAGS_num;
869 char key[100];
870 snprintf(key, sizeof(key), "%016d", k);
871 Status s = db_->Put(write_options_, key, gen.Generate(value_size_));
872 if (!s.ok()) {
873 fprintf(stderr, "put error: %s\n", s.ToString().c_str());
874 exit(1);
875 }
876 }
877
878 // Do not count any of the preceding work/delay in stats.
879 thread->stats.Start();
880 }
881 }
882
883 void Compact(ThreadState* thread) { db_->CompactRange(nullptr, nullptr); }
884

Callers

nothing calls this directly

Calls 5

NextMethod · 0.45
PutMethod · 0.45
GenerateMethod · 0.45
ToStringMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected