提交 f0154fe1 编写于 作者: W wangjiawei04

fix icode RULE085

Change-Id: Ibea30897533f648436b855cd7aa804ca2a009fd0
上级 f9c7b181
...@@ -47,7 +47,7 @@ void print_res(const Request& req, ...@@ -47,7 +47,7 @@ void print_res(const Request& req,
std::string route_tag, std::string route_tag,
uint64_t elapse_ms) { uint64_t elapse_ms) {
LOG(INFO) << "Receive Response size: " << res.ress_size(); LOG(INFO) << "Receive Response size: " << res.ress_size();
for(size_t i = 0; i < res.ress_size(); i++) { for (size_t i = 0; i < res.ress_size(); i++) {
KVDBRes val = res.ress(i); KVDBRes val = res.ress(i);
LOG(INFO) << "Receive value from demo-server: " << val.value(); LOG(INFO) << "Receive value from demo-server: " << val.value();
} }
...@@ -100,7 +100,7 @@ int main(int argc, char** argv) { ...@@ -100,7 +100,7 @@ int main(int argc, char** argv) {
while (true) { while (true) {
if(global_key > 10000) if (global_key > 10000)
break; break;
timeval start; timeval start;
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
......
...@@ -33,16 +33,16 @@ int KVDBEchoOp::debug() { ...@@ -33,16 +33,16 @@ int KVDBEchoOp::debug() {
const Request* req = dynamic_cast<const Request*>(get_request_message()); const Request* req = dynamic_cast<const Request*>(get_request_message());
Response* res = mutable_data<Response>(); Response* res = mutable_data<Response>();
LOG(INFO) << "Receive request in KVDB echo service: " << req->ShortDebugString(); LOG(INFO) << "Receive request in KVDB echo service: " << req->ShortDebugString();
for(size_t i = 0; i < req->reqs_size(); i++) { for (size_t i = 0; i < req->reqs_size(); i++) {
auto kvdbreq = req->reqs(i); auto kvdbreq = req->reqs(i);
std::string op = kvdbreq.op(); std::string op = kvdbreq.op();
std::string key = kvdbreq.key(); std::string key = kvdbreq.key();
std::string val = kvdbreq.value(); std::string val = kvdbreq.value();
if(op == "SET") { if (op == "SET") {
db->Put(key, val); db->Put(key, val);
KVDBRes* kvdb_value_res = res->mutable_ress()->Add(); KVDBRes* kvdb_value_res = res->mutable_ress()->Add();
kvdb_value_res -> set_value("OK"); kvdb_value_res -> set_value("OK");
} else if(op == "GET") { } else if (op == "GET") {
std::string getvalue = db->Get(key); std::string getvalue = db->Get(key);
KVDBRes* kvdb_value_res = res->mutable_ress()->Add(); KVDBRes* kvdb_value_res = res->mutable_ress()->Add();
kvdb_value_res -> set_value(getvalue); kvdb_value_res -> set_value(getvalue);
...@@ -52,7 +52,7 @@ int KVDBEchoOp::debug() { ...@@ -52,7 +52,7 @@ int KVDBEchoOp::debug() {
} }
void KVDBEchoOp::DBInit() { void KVDBEchoOp::DBInit() {
if(db.get() == nullptr) { if (db.get() == nullptr) {
db = RocksDBWrapper::RocksDBWrapperFactory("kvdb"); db = RocksDBWrapper::RocksDBWrapperFactory("kvdb");
} }
} }
......
...@@ -39,7 +39,7 @@ std::vector<std::string> StringSplit(std::string str, char split) { ...@@ -39,7 +39,7 @@ std::vector<std::string> StringSplit(std::string str, char split) {
std::vector<std::string> strs; std::vector<std::string> strs;
std::istringstream f(str); std::istringstream f(str);
std:: string s; std:: string s;
while(getline(f, s, split)) { while (getline(f, s, split)) {
strs.push_back(s); strs.push_back(s);
} }
return strs; return strs;
...@@ -52,13 +52,13 @@ TEST_F(KVDBTest, AbstractKVDB_Func_Test) { ...@@ -52,13 +52,13 @@ TEST_F(KVDBTest, AbstractKVDB_Func_Test) {
std::string get_list = "getlist.txt"; std::string get_list = "getlist.txt";
std::ifstream set_file(set_list); std::ifstream set_file(set_list);
std::ifstream get_file(get_list); std::ifstream get_file(get_list);
for( std::string line; getline(set_file, line ); ) for ( std::string line; getline(set_file, line ); )
{ {
std::vector<std::string> strs = StringSplit (line, ' '); std::vector<std::string> strs = StringSplit (line, ' ');
kvdb->Set(strs[0], strs[1]); kvdb->Set(strs[0], strs[1]);
} }
for( std::string line; getline(set_file, line ); ) { for ( std::string line; getline(set_file, line ); ) {
std::vector<std::string> strs = StringSplit(line, ' '); std::vector<std::string> strs = StringSplit(line, ' ');
std::string val = kvdb->Get(strs[0]); std::string val = kvdb->Get(strs[0]);
ASSERT_EQ(val, strs[1]); ASSERT_EQ(val, strs[1]);
......
...@@ -36,29 +36,29 @@ char** my_argv; ...@@ -36,29 +36,29 @@ char** my_argv;
void db_thread_test(AbsKVDBPtr kvdb, int size) { void db_thread_test(AbsKVDBPtr kvdb, int size) {
for(int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
kvdb->Set(std::to_string(i), std::to_string(i)); kvdb->Set(std::to_string(i), std::to_string(i));
kvdb->Get(std::to_string(i)); kvdb->Get(std::to_string(i));
} }
} }
TEST_F(KVDBTest, AbstractKVDB_Thread_Test) { TEST_F(KVDBTest, AbstractKVDB_Thread_Test) {
if(my_argc != 3) { if (my_argc != 3) {
std::cerr << "illegal input! should be db_thread ${num_of_thread} ${num_of_ops_each_thread}" << std::endl; std::cerr << "illegal input! should be db_thread ${num_of_thread} ${num_of_ops_each_thread}" << std::endl;
return; return;
} }
int num_of_thread = atoi(my_argv[1]); int num_of_thread = atoi(my_argv[1]);
int nums_of_ops_each_thread = atoi(my_argv[2]); int nums_of_ops_each_thread = atoi(my_argv[2]);
std::vector<AbsKVDBPtr> kvdbptrs; std::vector<AbsKVDBPtr> kvdbptrs;
for(int i= 0; i < num_of_thread; i++) { for (int i= 0; i < num_of_thread; i++) {
kvdbptrs.push_back(std::make_shared<RocksKVDB>()); kvdbptrs.push_back(std::make_shared<RocksKVDB>());
kvdbptrs[i]->CreateDB(); kvdbptrs[i]->CreateDB();
} }
std::vector<std::thread> tarr; std::vector<std::thread> tarr;
for(int i = 0; i< num_of_thread; i++) { for (int i = 0; i< num_of_thread; i++) {
tarr.push_back(std::thread(db_thread_test, kvdbptrs[i], nums_of_ops_each_thread)); tarr.push_back(std::thread(db_thread_test, kvdbptrs[i], nums_of_ops_each_thread));
} }
for(int i = 0; i< num_of_thread; i++) { for (int i = 0; i< num_of_thread; i++) {
tarr[i].join(); tarr[i].join();
} }
return; return;
......
...@@ -49,10 +49,10 @@ void UpdateTestIn(std::string); ...@@ -49,10 +49,10 @@ void UpdateTestIn(std::string);
TEST_F(KVDBTest, AbstractKVDB_Unit_Test) { TEST_F(KVDBTest, AbstractKVDB_Unit_Test) {
kvdb->CreateDB(); kvdb->CreateDB();
kvdb->SetDBName("test_kvdb"); kvdb->SetDBName("test_kvdb");
for(int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
kvdb->Set(std::to_string(i), std::to_string(i * 2)); kvdb->Set(std::to_string(i), std::to_string(i * 2));
} }
for(int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
std::string val = kvdb->Get(std::to_string(i)); std::string val = kvdb->Get(std::to_string(i));
ASSERT_EQ(val, std::to_string(i * 2)); ASSERT_EQ(val, std::to_string(i * 2));
} }
...@@ -101,15 +101,15 @@ TEST_F(KVDBTest, MockParamDict_Unit_Test) { ...@@ -101,15 +101,15 @@ TEST_F(KVDBTest, MockParamDict_Unit_Test) {
void GenerateTestIn(std::string filename) { void GenerateTestIn(std::string filename) {
std::ifstream in_file(filename); std::ifstream in_file(filename);
if(in_file.good()) { if (in_file.good()) {
in_file.close(); in_file.close();
std::string cmd = "rm -rf "+ filename; std::string cmd = "rm -rf "+ filename;
system(cmd.c_str()); system(cmd.c_str());
} }
std::ofstream out_file(filename); std::ofstream out_file(filename);
for(size_t i = 0; i < 100000; i++) { for (size_t i = 0; i < 100000; i++) {
out_file << i << " " << i << " "; out_file << i << " " << i << " ";
for(size_t j = 0; j < 3; j++) { for (size_t j = 0; j < 3; j++) {
out_file << i << " "; out_file << i << " ";
} }
out_file << std::endl; out_file << std::endl;
...@@ -119,15 +119,15 @@ void GenerateTestIn(std::string filename) { ...@@ -119,15 +119,15 @@ void GenerateTestIn(std::string filename) {
void UpdateTestIn(std::string filename) { void UpdateTestIn(std::string filename) {
std::ifstream in_file(filename); std::ifstream in_file(filename);
if(in_file.good()) { if (in_file.good()) {
in_file.close(); in_file.close();
std::string cmd = "rm -rf " + filename; std::string cmd = "rm -rf " + filename;
system(cmd.c_str()); system(cmd.c_str());
} }
std::ofstream out_file(filename); std::ofstream out_file(filename);
for(size_t i = 0; i < 10000; i++) { for (size_t i = 0; i < 10000; i++) {
out_file << i << " " << i << " "; out_file << i << " " << i << " ";
for(size_t j = 0; j < 3; j++) { for (size_t j = 0; j < 3; j++) {
out_file << i + 1 << " "; out_file << i + 1 << " ";
} }
out_file << std::endl; out_file << std::endl;
......
...@@ -35,8 +35,8 @@ std::string MockDictReader::GetMD5() { ...@@ -35,8 +35,8 @@ std::string MockDictReader::GetMD5() {
char buffer[max_buffer]; char buffer[max_buffer];
cmd.append(" 2>&1"); cmd.append(" 2>&1");
stream = popen(cmd.c_str(), "r"); stream = popen(cmd.c_str(), "r");
if(stream) { if (stream) {
if(fgets(buffer, max_buffer, stream) != NULL) { if (fgets(buffer, max_buffer, stream) != NULL) {
data.append(buffer); data.append(buffer);
} }
} }
...@@ -62,8 +62,8 @@ std::chrono::system_clock::time_point MockDictReader::GetTimeStamp() { ...@@ -62,8 +62,8 @@ std::chrono::system_clock::time_point MockDictReader::GetTimeStamp() {
void MockDictReader::Read(std::vector<std::string>& res) { void MockDictReader::Read(std::vector<std::string>& res) {
std::string line; std::string line;
std::ifstream infile(this->filename_); std::ifstream infile(this->filename_);
if(infile.is_open()) { if (infile.is_open()) {
while(getline(infile, line)) { while (getline(infile, line)) {
res.push_back(line); res.push_back(line);
} }
} }
...@@ -90,10 +90,10 @@ std::vector<float> MockParamDict::GetSparseValue(std::string feasign, std::strin ...@@ -90,10 +90,10 @@ std::vector<float> MockParamDict::GetSparseValue(std::string feasign, std::strin
//TODO: the concatation of feasign and slot is TBD. //TODO: the concatation of feasign and slot is TBD.
std::string result = front_db->Get(feasign + slot); std::string result = front_db->Get(feasign + slot);
std::vector<float> value; std::vector<float> value;
if(result == "NOT_FOUND") if (result == "NOT_FOUND")
return value; return value;
uint8_t* raw_values_ptr = reinterpret_cast<uint8_t *>(&result[0]); uint8_t* raw_values_ptr = reinterpret_cast<uint8_t *>(&result[0]);
for(size_t i = 0; i < result.size(); i += 4) { for (size_t i = 0; i < result.size(); i += 4) {
float temp = BytesToFloat(raw_values_ptr + i); float temp = BytesToFloat(raw_values_ptr + i);
value.push_back(temp); value.push_back(temp);
} }
...@@ -124,11 +124,11 @@ bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, con ...@@ -124,11 +124,11 @@ bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, con
std::string key = feasign + slot; std::string key = feasign + slot;
uint8_t* values_ptr = new uint8_t[values.size() * 4]; uint8_t* values_ptr = new uint8_t[values.size() * 4];
std::string value; std::string value;
for(size_t i = 0; i < values.size(); i++) { for (size_t i = 0; i < values.size(); i++) {
FloatToBytes(values[i], values_ptr + 4 * i); FloatToBytes(values[i], values_ptr + 4 * i);
} }
char* raw_values_ptr = reinterpret_cast<char*>(values_ptr); char* raw_values_ptr = reinterpret_cast<char*>(values_ptr);
for(size_t i = 0; i < values.size()*4 ; i++) { for (size_t i = 0; i < values.size()*4 ; i++) {
value.push_back(raw_values_ptr[i]); value.push_back(raw_values_ptr[i]);
} }
back_db->Set(key, value); back_db->Set(key, value);
...@@ -138,16 +138,16 @@ bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, con ...@@ -138,16 +138,16 @@ bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, con
void MockParamDict::UpdateBaseModel() { void MockParamDict::UpdateBaseModel() {
std::thread t([&] () { std::thread t([&] () {
for(AbsDictReaderPtr dict_reader: this->dict_reader_lst_) { for (AbsDictReaderPtr dict_reader: this->dict_reader_lst_) {
if(dict_reader->CheckDiff()) { if (dict_reader->CheckDiff()) {
std::vector<std::string> strs; std::vector<std::string> strs;
dict_reader->Read(strs); dict_reader->Read(strs);
for(const std::string& str: strs) { for (const std::string& str: strs) {
std::vector<std::string> arr; std::vector<std::string> arr;
std::istringstream in(str); std::istringstream in(str);
copy(std::istream_iterator<std::string>(in), std::istream_iterator<std::string>(), back_inserter(arr)); copy(std::istream_iterator<std::string>(in), std::istream_iterator<std::string>(), back_inserter(arr));
std::vector<float> nums; std::vector<float> nums;
for(size_t i = 2; i < arr.size(); i++) { for (size_t i = 2; i < arr.size(); i++) {
nums.push_back(std::stof(arr[i])); nums.push_back(std::stof(arr[i]));
} }
this->InsertSparseValue(arr[0], arr[1], nums); this->InsertSparseValue(arr[0], arr[1], nums);
......
...@@ -28,7 +28,7 @@ std::string RocksDBWrapper::Get(std::string key) { ...@@ -28,7 +28,7 @@ std::string RocksDBWrapper::Get(std::string key) {
options.verify_checksums = true; options.verify_checksums = true;
std::string result; std::string result;
rocksdb::Status s = db_->Get(options, key, &result); rocksdb::Status s = db_->Get(options, key, &result);
if(s.IsNotFound()) { if (s.IsNotFound()) {
result = "NOT_FOUND"; result = "NOT_FOUND";
} }
return result; return result;
...@@ -37,7 +37,7 @@ std::string RocksDBWrapper::Get(std::string key) { ...@@ -37,7 +37,7 @@ std::string RocksDBWrapper::Get(std::string key) {
bool RocksDBWrapper::Put(std::string key, std::string value) { bool RocksDBWrapper::Put(std::string key, std::string value) {
rocksdb::WriteOptions options; rocksdb::WriteOptions options;
rocksdb::Status s = db_->Put(options, key, value); rocksdb::Status s = db_->Put(options, key, value);
if(s.ok()) { if (s.ok()) {
return true; return true;
} else { } else {
return false; return false;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "kvdb/kvdb_impl.h" #include "kvdb/kvdb_impl.h"
void ParamDictMgr::UpdateAll() { void ParamDictMgr::UpdateAll() {
for(auto it = this->ParamDictMap.begin(); it!= this->ParamDictMap.end(); ++it) { for (auto it = this->ParamDictMap.begin(); it!= this->ParamDictMap.end(); ++it) {
it->second->UpdateBaseModel(); it->second->UpdateBaseModel();
} }
......
...@@ -26,10 +26,10 @@ void test_rockskvdb() { ...@@ -26,10 +26,10 @@ void test_rockskvdb() {
void test_rocksdbwrapper() { void test_rocksdbwrapper() {
std::shared_ptr<RocksDBWrapper> db = RocksDBWrapper::RocksDBWrapperFactory("TEST"); std::shared_ptr<RocksDBWrapper> db = RocksDBWrapper::RocksDBWrapperFactory("TEST");
for(size_t i = 0; i < 1000; i++) { for (size_t i = 0; i < 1000; i++) {
db->Put(std::to_string(i), std::to_string(i * 2)); db->Put(std::to_string(i), std::to_string(i * 2));
} }
for(size_t i = 0; i < 1000; i++) { for (size_t i = 0; i < 1000; i++) {
std::string res = db->Get(std::to_string(i)); std::string res = db->Get(std::to_string(i));
std::cout << res << " "; std::cout << res << " ";
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册