virtual void Process(){ string key = client_->cmd_part[1]; string val; if(db.Get(key, &val)) sprintf(client_->writebuf, "VALUE %s %d\r\n%s\r\n", key.c_str(), (int)key.length(), val.c_str()); else sprintf(client_->writebuf, "NOT_FOUND\r\n"); get_ready_to_write(client_); }
int main(int argc, char** argv) { srand (time(NULL)); if(argc != 3){ cout<<"invalid parameter!!"<<endl; return 0; } string key, val; int type = atoi(argv[1]); int counter = 0; if(type == 3){ key = argv[2]; } else{ counter = atoi(argv[2]); } cout<<"type:"<<type<<endl; cout<<"counter:"<<counter<<endl; DB* db; Options options; // Optimize RocksDB. This is the easiest way to get RocksDB to perform well options.IncreaseParallelism(); options.OptimizeLevelStyleCompaction(); // create the DB if it's not already present options.create_if_missing = true; // open DB Status s = DB::Open(options, kDBPath, &db); assert(s.ok()); if(type == 3){ s = db->Get(ReadOptions(), key, &val); cout<<"ret:"<<val<<endl; } else if(type == 1){ time_t now = time(NULL); for(int i = 0; i < counter ; i++){ key = "key_" + boost::lexical_cast<string>(i); val = "val_" + boost::lexical_cast<string>(i)+"_" +boost::lexical_cast<string>(now); s = db->Put(WriteOptions(), key, val); } } else if(type == 2){ int k; for(int i = 0; i < counter ; i++){ k = rand() % counter; key = "key_" + boost::lexical_cast<string>(k); s = db->Get(ReadOptions(), key, &val); } cout<<key<<":"<<val<<endl; } delete db; return 0; }
int fsck(int argc, char** argv) { const char* path; if(argc == 2) { path = argv[1]; } else { path = "./harq.db"; } std::cout << "Checking " << path << "...\n"; Options opts; opts.paranoid_checks = true; ReadOptions ro; ro.verify_checksums = true; DB* db; Status s = DB::Open(opts, path, &db); if(!s.ok()) { std::cout << "Unable to open: " << s.ToString() << "\n"; return 1; } std::string val; wire::QueueConfiguration cfg; s = db->Get(ro, "!harq.config", &val); if(!s.ok()) { std::cout << "Unable to read configuration: " << s.ToString() << "\n"; return 1; } if(!cfg.ParseFromString(val)) { std::cout << "Corrupt configuration detected.\n"; return 1; } std::cout << cfg.queues_size() << " queues detected.\n"; bool some_bad = false; for(int i = 0; i < cfg.queues_size(); i++) { const wire::QueueDeclaration& decl = cfg.queues(i); std::cout << "name: " << decl.name() << "\n"; switch(decl.type()) { case wire::QueueDeclaration::eBroadcast: std::cout << " type: broadcast\n"; break; case wire::QueueDeclaration::eTransient: std::cout << " type: transient\n"; break; case wire::QueueDeclaration::eDurable: std::cout << " type: durable\n"; break; default: std::cout << " type: UNKNOWN(" << decl.type() << ")\n"; break; } s = db->Get(ro, decl.name(), &val); if(!s.ok()) { std::cout << " Unable to find queue on disk!\n"; } else { wire::Queue qi; if(!qi.ParseFromString(val)) { std::cout << " Queue information corrupt on disk!\n"; } else { std::cout << " total messages: " << qi.size() << "\n" << " ranges:\n"; for(int j = 0; j < qi.ranges_size(); j++) { const wire::MessageRange& range = qi.ranges(j); std::cout << " " << range.start() << " - " << range.start() + range.count() << "\n"; } int valid = 0; for(int j = 0; j < qi.ranges_size(); j++) { const wire::MessageRange& range = qi.ranges(j); int fin = range.start() + range.count(); for(int m = range.start(); m < fin; m++) { std::stringstream tmp; tmp << decl.name() << ":" << m; s = db->Get(ro, tmp.str(), &val); if(!s.ok()) { std::cerr << "Missing message '" << tmp.str() << "'\n"; } else { wire::Message msg; if(!msg.ParseFromString(val)) { some_bad = true; std::cerr << "Corrupt message detected '" << tmp.str() << "'\n"; } else { valid++; } } } } std::cout << " valid messages: " << valid << "\n"; } } } return some_bad ? 1 : 0; }